:root {
  --bg: #f5f2ff;
  --ink: #1f1738;
  --panel: #ffffff;
  --line: #ddd2f3;
  --accent: #ba91ff;
  --accent-hover: #cbabff;
  --accent-soft: #efe6ff;
  --warn: #e66a2c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, #ece1ff 0%, transparent 35%),
    radial-gradient(circle at 80% 5%, #dbe4ff 0%, transparent 30%),
    var(--bg);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  background: linear-gradient(130deg, #7d4dff, #082064);
  color: #fff;
  border-radius: 16px;
  padding: 16px;
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
}

.brand p {
  margin: 8px 0 0;
  font-size: 0.95rem;
  opacity: 0.95;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.panel-card h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.row {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

label {
  font-size: 0.85rem;
  font-weight: 500;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
  font-family: "IBM Plex Mono", Consolas, monospace;
}

input[type="file"] {
  display: none;
}

.file-input-wrap {
  display: inline-flex;
  cursor: pointer;
  border: 1px dashed #9d86cf;
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 500;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms ease, background 140ms ease;
}

.btn:hover:enabled {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  border-color: #9f73ef;
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover:enabled {
  background: var(--accent-hover);
}

.btn.ghost {
  border-color: #d7c7f5;
  background: #fbf8ff;
}

.button-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #7f59d8;
}

.muted {
  margin-top: 8px;
  color: #5f5287;
  font-size: 0.85rem;
}

.history-card {
  flex: 1;
  min-height: 180px;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.results-head h2 {
  margin: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid #d7c7f5;
  background: #fbf8ff;
  color: #5f5287;
  cursor: pointer;
}

.icon-btn:hover {
  background: #efe7ff;
}

#resultsList {
  margin: 0;
  padding-left: 16px;
  max-height: 220px;
  overflow: auto;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.85rem;
}

#resultsList .result-item.area-result {
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 8px;
  transition: background 140ms ease;
}

#resultsList .result-item.area-result:hover {
  background: #efe7ff;
}

#resultsList .result-item.area-result.active {
  background: #e3d2ff;
  border: 1px solid #c5a7f7;
}

.canvas-panel {
  position: relative;
  background: #111a3d;
  border-radius: 18px;
  border: 1px solid #283a86;
  overflow: hidden;
  min-height: calc(100vh - 28px);
}

#measureCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.mode-badge {
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-family: "IBM Plex Mono", Consolas, monospace;
  color: #2d1b57;
  background: #ecdcff;
  border: 1px solid #c6a8f2;
}

.top-overlay-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid #c6a8f2;
  background: rgba(236, 220, 255, 0.96);
}

.zoom-btn {
  width: 30px;
  height: 30px;
  border: 1px solid #b796ea;
  border-radius: 999px;
  background: #fff;
  color: #2d1b57;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.zoom-btn:hover {
  background: #f6efff;
}

.zoom-btn:active {
  transform: translateY(1px);
}

.zoom-percent {
  min-width: 48px;
  text-align: center;
  font-family: "IBM Plex Mono", Consolas, monospace;
  font-size: 0.8rem;
  color: #2d1b57;
  font-weight: 600;
}

.hint-bar {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  z-index: 2;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #cdb9ef;
  border-radius: 12px;
  padding: 10px;
  font-size: 0.87rem;
}

.mobile-scroll-wrap {
  display: none;
}

.mobile-scroll-wrap[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    min-height: 100dvh;
    padding: 0;
    gap: 0;
  }

  .canvas-panel {
    min-height: 62dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .control-panel {
    order: 2;
    background: #f9f5ff;
    border-top: 1px solid #d6c8f1;
    padding: 12px;
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
    animation: mobilePanelIn 240ms ease;
  }

  .brand {
    border-radius: 12px;
    padding: 12px;
  }

  .panel-card {
    border-radius: 12px;
    padding: 12px;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  #resultsList {
    max-height: 120px;
  }

  .top-overlay-controls {
    top: 10px;
    left: 10px;
    gap: 6px;
  }

  .mobile-scroll-wrap {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 4;
    display: block;
    width: 34px;
    height: 170px;
    border-radius: 999px;
    border: 1px solid #c6a8f2;
    background: rgba(236, 220, 255, 0.95);
  }

  .mobile-scroll-range {
    position: absolute;
    left: -55px;
    top: 72px;
    width: 140px;
    height: 24px;
    margin: 0;
    transform: rotate(-90deg);
    accent-color: #7f59d8;
  }

  .mode-badge {
    padding: 6px 9px;
    font-size: 0.74rem;
  }

  .zoom-controls {
    gap: 4px;
    padding: 3px;
  }

  .zoom-btn {
    width: 28px;
    height: 28px;
  }
}

@keyframes mobilePanelIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
