:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --fg: #1c2127;
  --muted: #66707c;
  --line: #d9dde3;
  --accent: #0b7fbf;
  --accent-fg: #ffffff;
  --map-bg: #0e1013;
  --input: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #181c21;
    --fg: #e4e8ed;
    --muted: #8e98a4;
    --line: #2a3038;
    --accent: #39a7e6;
    --accent-fg: #06121b;
    --map-bg: #090b0d;
    --input: #0f1216;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.note { font-size: 12px; color: var(--muted); margin: .4rem 0 0; }
kbd { border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 11px; }
code { font-size: 12px; }

button, select, input {
  font: inherit;
  color: var(--fg);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, button.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.link { background: none; border: none; padding: 0; color: var(--accent); }
select { width: 100%; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- picker / confirm ---------- */
.screen { min-height: 100%; }
.picker-inner, .confirm-inner { max-width: 1100px; margin: 0 auto; padding: 32px 16px; }
.lede { color: var(--muted); margin: 0 0 24px; }
.brand-head { display: flex; align-items: center; gap: 14px; margin-bottom: .5rem; }
.brand-head h1 { margin: 0; }
.tt-logo-link { display: inline-flex; flex: none; }
.tt-logo {
  display: inline-block; width: 48px; aspect-ratio: 1; background: var(--fg);
  -webkit-mask: url(ttlogo.svg) center / contain no-repeat;
  mask: url(ttlogo.svg) center / contain no-repeat;
}
.tt-logo.small { width: 28px; }
.topbar .title { align-items: center; }
.version { margin-top: 32px; padding-top: 12px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.card:hover { border-color: var(--accent); }
.card-main {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 0; border: none; background: none;
}
.card > a { align-self: flex-start; }
.card img { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #15171a; border-radius: 6px; }
.card-name { font-weight: 600; font-size: 15px; }
.confirm-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; margin-top: 16px; align-items: start; }
.confirm-grid img { width: 100%; border-radius: 8px; background: #15171a; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 12px 0 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 720px) { .confirm-grid { grid-template-columns: 1fr; } }

/* ---------- viewer ---------- */
#viewer { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .title { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; min-width: 0; }
.workspace { flex: 1; display: flex; min-height: 0; }
.side {
  width: 300px; flex: none; overflow-y: auto; padding: 8px;
  background: var(--panel); border-right: 1px solid var(--line);
}
.panel { border-bottom: 1px solid var(--line); padding: 8px 4px 12px; }
.panel summary { font-weight: 600; cursor: pointer; margin-bottom: 8px; }
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.layer-row { display: flex; align-items: center; gap: 8px; cursor: pointer; line-height: 1.25; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; flex: none; vertical-align: -2px; margin-right: 4px; }
.layer-row .sw { margin-right: 0; }
.slider { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.slider input { flex: 1; padding: 0; }
.coords { display: grid; grid-template-columns: auto 1fr 1fr; gap: 4px 6px; align-items: center; margin-top: 8px; font-size: 12px; }
.coords.one { grid-template-columns: auto 1fr; }
.coords label { color: var(--muted); }
.coords input { width: 100%; min-width: 0; padding: 4px 6px; font-variant-numeric: tabular-nums; }
.coords span { color: var(--muted); }

.views { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#map { flex: 1; min-height: 240px; background: var(--map-bg); }
#map.crosshair, #map.crosshair .leaflet-interactive { cursor: crosshair; }
#map[data-cut="h"] .line-grab { cursor: ns-resize; }
#map[data-cut="v"] .line-grab { cursor: ew-resize; }
#map.moving-line-h, #map.moving-line-h .leaflet-interactive { cursor: ns-resize; }
#map.moving-line-v, #map.moving-line-v .leaflet-interactive { cursor: ew-resize; }
.xs-wrap { height: 280px; flex: none; display: flex; flex-direction: column; border-top: 1px solid var(--line); background: var(--panel); }
.xs-head { display: flex; gap: 12px; align-items: baseline; padding: 6px 12px 0; flex-wrap: wrap; }
.xs-help { margin-left: auto; }
.small-btn { padding: 2px 8px; font-size: 12px; }
.error { color: #d0303a; }
.xs { position: relative; flex: 1; min-height: 0; }
.xs canvas { display: block; touch-action: none; cursor: grab; }
.xs-tip {
  position: absolute; pointer-events: none; padding: 6px 8px; font-size: 12px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

/* crosshair: above the layers and line, below the map controls */
.guide-lines { position: absolute; inset: 0; pointer-events: none; z-index: 650; overflow: hidden; }
.guide-lines > div { position: absolute; background: rgba(255, 255, 255, .85); box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.ch-h { top: 0; left: 0; right: 0; height: 1px; }
.ch-v { top: 0; bottom: 0; left: 0; width: 1px; }

/* leaflet bits */
.leaflet-container { background: var(--map-bg); font: inherit; }
.scalebar, .readout {
  background: rgba(10, 12, 15, .75); color: #e8ecf0; padding: 4px 8px; border-radius: 4px;
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.scalebar .bar { height: 6px; border: 2px solid #e8ecf0; border-top: none; margin-bottom: 2px; }
.zero-icon {
  border: 2px solid #ff5ab4; border-radius: 50%;
  background:
    linear-gradient(#ff5ab4, #ff5ab4) center / 2px 100% no-repeat,
    linear-gradient(#ff5ab4, #ff5ab4) center / 100% 2px no-repeat;
}

/* narrow screens: stack the sidebar under the views */
@media (max-width: 800px) {
  #viewer { height: auto; }
  .workspace { flex-direction: column-reverse; }
  .side { width: 100%; border-right: none; }
  #map { height: 60vh; flex: none; }
  .xs-help { margin-left: 0; }
}
