/* Heliograph — sundial observatory theme.
   Palette: deep indigo ink, brass & gold, parchment; astronomical calm. */

:root {
  --ink-0: #0d0b14;
  --ink-1: #14101f;
  --ink-2: #1d1830;
  --ink-3: #282040;
  --line: #3a3157;
  --parch: #f2e7cf;
  --parch-dim: #c9bda0;
  --parch-faint: #8f8672;
  --brass: #d9a441;
  --brass-hi: #f2c66d;
  --copper: #e07a3f;
  --teal: #4fbbb0;
  --steel: #7e8fd4;
  --rose: #d4698e;
  --day: #f2c66d;
  --twilight: #b07cc9;
  --night: #5b67a8;
  --radius: 14px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ink-0);
  color: var(--parch);
  font-family: var(--font-ui);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100dvh; width: 100%; }

/* ============ viewport ============ */
#viewport { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(13,11,20,.82), rgba(13,11,20,.0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--brass-hi); }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand h1 {
  font-family: var(--font-display); font-weight: 500;
  font-size: 20px; letter-spacing: .04em; margin: 0; line-height: 1;
}
.tagline {
  margin: 2px 0 0; font-size: 10.5px; letter-spacing: .22em;
  text-transform: uppercase; color: var(--parch-faint);
}

#status-strip {
  display: flex; align-items: center; gap: 10px; margin-left: 8px;
  min-width: 0; overflow: hidden;
}
.badge {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  padding: 3px 10px; border-radius: 20px; border: 1px solid;
  text-transform: uppercase; white-space: nowrap;
}
.badge-day { color: #ffe9b0; border-color: #a5813c; background: rgba(217,164,65,.18); }
.badge-civil-twilight, .badge-nautical-twilight, .badge-astronomical-twilight {
  color: #e3c9f2; border-color: #7b5a9e; background: rgba(176,124,201,.16);
}
.badge-night { color: #b9c6f5; border-color: #4a5588; background: rgba(91,103,168,.18); }
.badge-polar-day { color: #ffe9b0; border-color: #a5813c; background: rgba(217,164,65,.26); }
.badge-polar-night { color: #9fb4f2; border-color: #3d4d8f; background: rgba(70,85,160,.3); }
.where-when {
  font-family: var(--font-display); font-size: 14px; color: var(--parch-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.chip {
  appearance: none; border: 1px solid var(--line); border-radius: 20px;
  background: rgba(20,16,31,.72); color: var(--parch);
  font: 600 12.5px var(--font-ui); letter-spacing: .03em;
  padding: 7px 13px; cursor: pointer; backdrop-filter: blur(6px);
  transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: var(--brass); color: var(--brass-hi); }
.chip:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.chip-action { border-color: #6b5a33; color: var(--brass-hi); }
.chip-icon { margin-right: 6px; }
.chip-panel-toggle { font-size: 14px; padding: 7px 11px; }

#legend {
  position: absolute; left: 14px; bottom: 14px; z-index: 5;
  padding: 10px 12px; border-radius: 10px;
  background: rgba(13,11,20,.62); border: 1px solid rgba(58,49,87,.7);
  backdrop-filter: blur(6px); font-size: 11.5px; color: var(--parch-dim);
}
.legend-title { font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--parch-faint); margin-bottom: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 1.5px 0; }
.legend-row.off { opacity: .28; }
.sw { width: 16px; height: 4px; border-radius: 2px; display: inline-block; flex: none; }
.sw.sel { background: var(--brass-hi); box-shadow: 0 0 6px rgba(242,198,109,.8); }
.sw.jun { background: var(--copper); }
.sw.dec { background: var(--steel); }
.sw.eq  { background: var(--teal); }
.sw.an  { background: var(--rose); }

#scene-hud {
  position: absolute; right: 14px; bottom: 14px; z-index: 5;
  font-size: 10.5px; letter-spacing: .1em; color: var(--parch-faint);
  text-transform: uppercase; pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}

/* ============ help overlay ============ */
#help-overlay {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(9,7,15,.66); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
#help-overlay[hidden] { display: none; }
.help-card {
  position: relative; max-width: 620px; width: 100%; max-height: 100%; overflow: auto;
  background: linear-gradient(180deg, var(--ink-2), var(--ink-1));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 26px; box-shadow: 0 24px 60px rgba(0,0,0,.55);
}
.help-card h2 { font-family: var(--font-display); font-weight: 500; color: var(--brass-hi); margin: 0 0 12px; }
.help-card h3 { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--parch-faint); margin: 14px 0 6px; }
.help-card ul { margin: 0; padding: 0; list-style: none; }
.help-card li { padding: 2.5px 0; color: var(--parch-dim); font-size: 13px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 26px; }
kbd {
  display: inline-block; min-width: 18px; text-align: center;
  font: 600 11px var(--mono); color: var(--brass-hi);
  background: var(--ink-3); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; margin-right: 4px;
}
.help-note { font-size: 12px; color: var(--parch-faint); border-top: 1px solid var(--line); padding-top: 12px; margin: 14px 0 0; }
.help-close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: 50%; background: none;
  color: var(--parch); font-size: 18px; cursor: pointer;
}
.help-close:hover { border-color: var(--brass); color: var(--brass-hi); }

/* ============ panel ============ */
#panel {
  flex: 0 0 384px; max-width: 384px; height: 100%;
  background: linear-gradient(180deg, var(--ink-1), var(--ink-0));
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: margin-right .28s ease;
}
#panel.hidden { margin-right: -384px; }
.panel-grip { display: none; }
.panel-scroll { overflow-y: auto; padding: 12px 14px 26px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.card {
  background: linear-gradient(180deg, rgba(40,32,64,.42), rgba(29,24,48,.35));
  border: 1px solid rgba(58,49,87,.75); border-radius: var(--radius);
  padding: 14px 15px; margin-bottom: 12px;
}
.card h2 {
  font-family: var(--font-display); font-weight: 500; font-size: 15px;
  letter-spacing: .05em; color: var(--brass-hi);
  margin: 0 0 10px; padding-bottom: 8px; border-bottom: 1px solid rgba(58,49,87,.6);
}

/* clock card */
.clock-row { display: flex; align-items: baseline; gap: 14px; margin-bottom: 8px; }
.clock {
  font-family: var(--font-display); font-size: 44px; line-height: 1;
  color: var(--parch); font-variant-numeric: tabular-nums; letter-spacing: .02em;
}
.clock-sub { font-size: 12px; color: var(--parch-dim); line-height: 1.5; }
#clock-solar { font-variant-numeric: tabular-nums; color: var(--parch-faint); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 26px;
  background: transparent; cursor: pointer; margin: 2px 0 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background:
    linear-gradient(90deg, #1c2440 0%, #4a3d66 8%, #b0764f 15%, #e8b34b 30%, #f5d98d 50%, #e8b34b 70%, #b0764f 85%, #4a3d66 92%, #1c2440 100%);
  border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px;
  border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe9b0, var(--brass) 70%);
  border: 2px solid #3a2c12; box-shadow: 0 0 10px rgba(217,164,65,.7); cursor: grab;
}
input[type="range"]::-moz-range-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #1c2440 0%, #4a3d66 8%, #b0764f 15%, #e8b34b 30%, #f5d98d 50%, #e8b34b 70%, #b0764f 85%, #4a3d66 92%, #1c2440 100%);
  border: 1px solid var(--line);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe9b0, var(--brass) 70%);
  border: 2px solid #3a2c12; box-shadow: 0 0 10px rgba(217,164,65,.7); cursor: grab;
}
.time-marks { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--parch-faint); font-variant-numeric: tabular-nums; margin-top: 2px; }

.btn-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  appearance: none; border: 1px solid var(--line); border-radius: 9px;
  background: rgba(40,32,64,.5); color: var(--parch);
  font: 600 12.5px var(--font-ui); padding: 7px 12px; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--brass); color: var(--brass-hi); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:focus-visible, .chip:focus-visible, .seg button:focus-visible, .preset-grid button:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 2px;
}
.btn-play { width: 44px; font-size: 14px; }
.btn-ghost { background: transparent; }
.btn-jump { flex: 1 1 0; padding: 7px 4px; font-size: 12px; white-space: nowrap; }
.jumps { gap: 6px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  appearance: none; border: none; background: transparent; color: var(--parch-dim);
  font: 600 12px var(--font-ui); padding: 7px 11px; cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: none; }
.seg button.on { background: rgba(217,164,65,.18); color: var(--brass-hi); }
.seg button:hover { color: var(--brass-hi); }

/* chart */
#chart { width: 100%; height: 150px; display: block; cursor: crosshair; border-radius: 8px; }
.chart-legend { display: flex; gap: 14px; margin-top: 8px; font-size: 11.5px; color: var(--parch-dim); flex-wrap: wrap; }
.chart-legend label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.chart-legend input { accent-color: var(--brass); }

/* readouts */
.grid-read {
  display: grid; grid-template-columns: 1fr auto; gap: 3px 10px;
  font-size: 12.5px; align-items: baseline;
}
.grid-read .lbl { color: var(--parch-faint); letter-spacing: .02em; }
.grid-read .val { font-variant-numeric: tabular-nums; color: var(--parch); text-align: right; }
.shadow-read { margin-top: 10px; padding-top: 10px; border-top: 1px dashed rgba(58,49,87,.8); }
.lbl-row { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.incidence { margin-top: 10px; padding-top: 10px; border-top: 1px dashed rgba(58,49,87,.8); }
.unit { color: var(--parch-faint); font-size: 12px; }

input[type="number"], input[type="text"], input[type="date"], select {
  background: rgba(13,11,20,.6); border: 1px solid var(--line); border-radius: 8px;
  color: var(--parch); font: 500 12.5px var(--font-ui); font-variant-numeric: tabular-nums;
  padding: 6px 8px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--brass); outline-offset: 1px; border-color: var(--brass); }
input[type="date"] { flex: 1; }
#obj-height { width: 64px; }

.note { font-size: 11px; color: var(--parch-faint); margin: 9px 0 0; line-height: 1.5; }
.note.emph { color: var(--brass-hi); }

/* place card */
.search-wrap { position: relative; display: flex; gap: 7px; }
#search { flex: 1; }
#search-results {
  position: absolute; top: calc(100% + 5px); left: 0; right: 0; z-index: 10;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 10px;
  max-height: 220px; overflow-y: auto; box-shadow: 0 14px 34px rgba(0,0,0,.5);
}
#search-results .hit {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 12.5px;
}
#search-results .hit:hover, #search-results .hit.sel { background: rgba(217,164,65,.14); }
#search-results .hit .co { color: var(--parch-faint); font-variant-numeric: tabular-nums; font-size: 11px; }
#search-results .none { padding: 9px 12px; color: var(--parch-faint); font-size: 12px; }

.coord-row { display: flex; gap: 7px; margin-top: 10px; }
.coord-row label { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--parch-faint); flex: 1; }
.coord-row input, .coord-row select { width: 100%; }
.coord-row label { flex-direction: row; }
.coord-row input { min-width: 0; }

.map-tabs { display: flex; justify-content: flex-end; margin: 10px 0 8px; }
#globe-wrap, #map-wrap { display: flex; justify-content: center; }
#globe { width: 240px; height: 240px; cursor: grab; touch-action: none; }
#globe:active { cursor: grabbing; }
#map { width: 100%; height: auto; aspect-ratio: 2/1; border-radius: 10px; cursor: crosshair; }

.preset-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.preset-grid button {
  appearance: none; border: 1px solid var(--line); border-radius: 16px;
  background: rgba(40,32,64,.4); color: var(--parch-dim);
  font: 500 11.5px var(--font-ui); padding: 5px 11px; cursor: pointer;
}
.preset-grid button:hover { border-color: var(--brass); color: var(--brass-hi); }
.preset-grid button.on { border-color: var(--brass); color: var(--brass-hi); background: rgba(217,164,65,.14); }

.date-row { display: flex; gap: 7px; align-items: center; }
.date-row .btn { padding: 7px 12px; }

.check-col { display: flex; flex-direction: column; gap: 7px; }
.check-col label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--parch-dim); cursor: pointer; }
.check-col input { accent-color: var(--brass); width: 15px; height: 15px; }

.panel-foot { padding: 4px 6px; }
.panel-foot p { font-size: 10.5px; color: var(--parch-faint); line-height: 1.5; margin: 0; }

.noscript {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--ink-0); color: var(--parch); font: 16px var(--font-ui); z-index: 99;
}

/* ============ responsive ============ */
@media (max-width: 980px) {
  #panel { flex-basis: 340px; max-width: 340px; }
  #panel.hidden { margin-right: -340px; }
}
@media (max-width: 760px) {
  #app { flex-direction: column; }
  #viewport { flex: 1 1 auto; min-height: 0; }
  #panel {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 8;
    flex: none; max-width: none; width: 100%; height: 62%;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% - 44px));
    transition: transform .28s ease;
    box-shadow: 0 -18px 40px rgba(0,0,0,.5);
  }
  #panel.open { transform: translateY(0); }
  #panel.hidden { margin-right: 0; transform: translateY(100%); }
  .panel-grip {
    display: flex; justify-content: center; align-items: center;
    height: 30px; cursor: pointer; flex: none;
  }
  .panel-grip span { width: 46px; height: 5px; border-radius: 3px; background: var(--line); }
  .panel-scroll { padding: 0 14px 30px; }
  .clock { font-size: 36px; }
  #topbar { gap: 6px; padding: 8px 10px; flex-wrap: nowrap; }
  .brand h1 { font-size: 16px; }
  .brand-mark { width: 24px; height: 24px; }
  .tagline { display: none; }
  .where-when { display: none; }
  #status-strip { margin-left: 2px; min-width: 0; }
  .badge { font-size: 10px; padding: 3px 8px; }
  #legend { bottom: 54px; left: 10px; padding: 8px 10px; font-size: 10.5px; }
  #scene-hud { display: none; }
  .help-cols { grid-template-columns: 1fr; }
  .chip { padding: 8px 11px; font-size: 11.5px; }
  #btn-view-label { display: none; }
  .chip-icon { margin-right: 0; }
  .topbar-actions { flex: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01s !important; }
}
