/* Platonic Clock. Colours are tokens; dark is the default for the sky. */
:root {
  --bg: #f2efe6;
  --panel: #fbfaf6;
  --ink: #1d2533;
  --muted: #5d6677;
  --line: #d8d2c3;
  --field: #ffffff;
  --sky: #fdfcf7;
  --star-ink: #1d2533;
  --bound: rgba(55, 70, 100, 0.32);
  --conname: rgba(40, 52, 78, 0.55);
  --starname: rgba(29, 37, 51, 0.85);
  --ring: #ebe5d4;
  --ring-alt: #e1d8c2;
  --ring-ink: #39404f;
  --tick: #6b7384;
  --accent: #b4441f;
  --accent-soft: rgba(180, 68, 31, 0.14);
  --track: rgba(36, 104, 150, 0.6);
  --event: #7a3fa0;
  --cloud: rgba(70, 85, 120, 0.16);
  --halo: rgba(253, 252, 247, 0.85);
  --pole: #c81e1e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e16;
    --panel: #10161f;
    --ink: #e5e8ee;
    --muted: #98a1b3;
    --line: #253043;
    --field: #0c121c;
    --sky: #050913;
    --star-ink: initial;
    --bound: rgba(140, 160, 205, 0.26);
    --conname: rgba(170, 186, 218, 0.5);
    --starname: rgba(220, 228, 245, 0.8);
    --ring: #121a29;
    --ring-alt: #172137;
    --ring-ink: #c8d0e1;
    --tick: #7e889d;
    --accent: #ff8b5e;
    --accent-soft: rgba(255, 139, 94, 0.16);
    --track: rgba(124, 196, 255, 0.6);
    --event: #d6a6ff;
    --cloud: rgba(185, 200, 255, 0.11);
    --halo: rgba(5, 9, 19, 0.85);
    --pole: #ff4f4f;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a0e16;
  --panel: #10161f;
  --ink: #e5e8ee;
  --muted: #98a1b3;
  --line: #253043;
  --field: #0c121c;
  --sky: #050913;
  --star-ink: initial;
  --bound: rgba(140, 160, 205, 0.26);
  --conname: rgba(170, 186, 218, 0.5);
  --starname: rgba(220, 228, 245, 0.8);
  --ring: #121a29;
  --ring-alt: #172137;
  --ring-ink: #c8d0e1;
  --tick: #7e889d;
  --accent: #ff8b5e;
  --accent-soft: rgba(255, 139, 94, 0.16);
  --track: rgba(124, 196, 255, 0.6);
  --event: #d6a6ff;
  --cloud: rgba(185, 200, 255, 0.11);
  --halo: rgba(5, 9, 19, 0.85);
  --pole: #ff4f4f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 100vh;
}

/* ---- stage ------------------------------------------------------------ */

.stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px;
  min-width: 0;
}

/* The readout lives in the top-left corner, outside the round dial. Its size is
   fixed (rows never wrap), so the dial only resizes with the window. */
.readout {
  position: absolute;
  top: 8px;
  left: 12px;
  z-index: 2;
  pointer-events: none;
}
.readout .title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.readout .year {
  font-size: 48px;
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin: 0 0 4px;
}
.readout table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 290px;
  font-size: 12px;
  line-height: 1.3;
}
.readout th[scope="row"] { width: 122px; text-align: left; font-weight: 500; color: var(--muted); padding: 1px 8px 1px 0; white-space: nowrap; }
.readout td { padding: 1px 0; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout td b { font-weight: 600; }
.readout .pole-row th, .readout .pole-row td, .readout .pole-row td b { color: var(--pole); }
.pole-mark {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border: 2px solid var(--pole);
  border-radius: 50%;
  vertical-align: -1px;
}
.pole-text { color: var(--pole); font-weight: 600; }

/* Big turn buttons in the dial's bottom corners; they scale with the dial
   (container query units) so they never reach the zodiac ring. */
.clock-wrap { container-type: inline-size; }
.turn-btn {
  position: absolute;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.8cqw 1.2cqw 0.7cqw;
  border-radius: 1.4cqw;
  font-size: clamp(11px, 1.5cqw, 14px);
  line-height: 1.1;
}
.turn-btn svg { width: clamp(30px, 6.4cqw, 60px); height: clamp(30px, 6.4cqw, 60px); fill: var(--accent); }
.turn-btn.left { left: 0; }
.turn-btn.right { right: 0; }
.turn-btn:hover svg { fill: var(--ink); }
.turn-btn:disabled { opacity: 0.35; cursor: default; }

.clock-wrap { position: relative; width: min(100%, calc(100vh - 16px)); }
/* Desktop: the dial hugs the bottom-right corner (next to the panel); its width
   is set by layoutStage() in app.js so the readout fits in the top-left corner. */
@media (min-width: 901px) {
  .stage { height: 100vh; }
  .clock-wrap { position: absolute; right: 8px; bottom: 8px; }
}
#clock {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  outline: none;
}
#clock:focus-visible .disk-edge { stroke: var(--accent); stroke-width: 6; }


.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  white-space: nowrap;
  transform: translate(12px, -50%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

/* ---- SVG layers (units: 1000 = sky disk radius) -------------------------- */

.sky { fill: var(--sky); }
.disk-edge { fill: none; stroke: var(--line); stroke-width: 4; }
#cloud-glow stop { stop-color: var(--cloud); }

.boundaries { fill: none; stroke: var(--bound); stroke-width: 2.5; stroke-dasharray: 12 8; }

.con-labels text {
  fill: var(--conname);
  font-size: 30px;
  letter-spacing: 4px;
  text-anchor: middle;
  dominant-baseline: central;
  text-transform: uppercase;
}

.star { fill: var(--star-ink, var(--c)); }

.star-labels text, .event-label {
  font-size: 27px;
  paint-order: stroke;
  stroke: var(--halo);
  stroke-width: 8px;
  stroke-linejoin: round;
}
.star-labels text { fill: var(--starname); }

.pole-star { pointer-events: none; }
.pole-star-dot { fill: var(--pole); }
.pole-star-ring { fill: none; stroke: var(--pole); stroke-width: 5; }
.pole-star text {
  fill: var(--pole);
  font-size: 30px;
  font-weight: 600;
  paint-order: stroke;
  stroke: var(--halo);
  stroke-width: 8px;
  stroke-linejoin: round;
}

.track { fill: none; stroke: var(--track); stroke-width: 4; stroke-dasharray: 4 12; stroke-linecap: round; }

.event-dot { fill: var(--event); stroke: var(--halo); stroke-width: 4; cursor: pointer; }
.event-label { fill: var(--event); cursor: pointer; }
.event-tick { fill: var(--event); stroke: var(--halo); stroke-width: 3; cursor: pointer; }
.near .event-dot, .near.event-tick { fill: var(--accent); }
.near.event-label { fill: var(--accent); }
.event-label { dominant-baseline: central; font-size: 25px; }

.ring-bg { fill: var(--ring); }
.ring-tick { stroke: var(--tick); stroke-width: 2.5; fill: none; }
.ring-tick.major { stroke-width: 4; }
.ring-label { fill: var(--ring-ink); font-size: 26px; text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }
.now-tick { stroke: var(--accent); stroke-width: 6; }
.seam-tick { stroke: var(--muted); stroke-width: 8; }
.now-label { fill: var(--accent); font-size: 24px; text-anchor: middle; dominant-baseline: central; font-weight: 600; }

.zodiac-seg { fill: var(--ring); stroke: var(--bg); stroke-width: 4; }
.zodiac-seg.alt { fill: var(--ring-alt); }
.zodiac-name { fill: var(--ring-ink); font-size: 36px; letter-spacing: 2px; dominant-baseline: central; }
.zodiac-name.small { font-size: 30px; }

.cardinal circle { fill: var(--panel); stroke: var(--tick); stroke-width: 4; }
.cardinal text { fill: var(--ring-ink); font-size: 34px; text-anchor: middle; dominant-baseline: central; }
.cardinal line { stroke: var(--tick); stroke-width: 4; }
.cardinal.age circle { stroke: var(--accent); fill: var(--accent-soft); stroke-width: 6; }
.cardinal.age text { fill: var(--accent); font-weight: 700; }
.cardinal.age line { stroke: var(--accent); stroke-width: 6; }

.hand line { stroke: var(--accent); stroke-width: 6; stroke-linecap: round; }
.true-pole { fill: none; stroke: var(--accent); stroke-width: 6; pointer-events: none; }
.hand .hub { fill: var(--accent); }
.hand rect { fill: var(--accent); }
.hand text { fill: var(--panel); font-size: 32px; font-weight: 650; font-variant-numeric: tabular-nums; }
.ghost { stroke: var(--muted); stroke-width: 3; stroke-dasharray: 10 10; }
/* The hand and the hover line must not swallow clicks on events beneath them. */
.hand, .ghost { pointer-events: none; }

/* ---- panel ------------------------------------------------------------ */

.panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  height: 100vh;
  overflow-y: auto;
  position: sticky;
  top: 0;
  padding: 8px 18px 24px;
}
.panel section { padding: 12px 0 14px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; font-weight: 650; }
.panel h3 { font-size: 13px; margin: 12px 0 6px; }
.panel label { display: block; margin: 6px 0; }
.panel p { margin: 6px 0; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row > label { margin: 0; }
.grow { flex: 1; }
.check { display: flex !important; align-items: center; gap: 8px; }
.slider output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; }
.slider-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: -2px; }

input, select, button, .button {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
}
input[type="number"] { width: 110px; font-variant-numeric: tabular-nums; }
input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }
#ev-label, #ev-note { width: 100%; }
#ev-year { width: 100%; }
button, .button { cursor: pointer; display: inline-block; }
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }
#year-slider { width: 100%; margin: 10px 0 6px; }
.cycle-row { justify-content: space-between; }
.pole-row { justify-content: space-between; margin-bottom: 4px; }
.cycle-row button { padding: 3px 8px; font-size: 12px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent { color: var(--accent); }
.error { color: var(--accent); font-size: 13px; }

.event-list { list-style: none; margin: 8px 0; padding: 0; }
.event-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.event-list li:hover { background: var(--accent-soft); }
.event-list li.empty { display: block; cursor: default; color: var(--muted); }
.event-list li.empty:hover { background: none; }
.event-list .ev-when { font-weight: 600; font-variant-numeric: tabular-nums; }
.event-list .ev-delta { color: var(--muted); font-size: 12px; text-align: right; }
.event-list .ev-label { grid-column: 1 / -1; }
.event-list .ev-note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.event-list .ev-tag { font-size: 11px; color: var(--event); margin-left: 6px; font-weight: 500; }
.event-list .ev-del { grid-column: 2; grid-row: 1; justify-self: end; padding: 0 6px; font-size: 12px; }
.event-list li.selected { background: var(--accent-soft); }

details summary { cursor: pointer; font-weight: 600; margin: 8px 0; }
#event-form { margin-top: 4px; }

.checks { padding-left: 18px; margin: 4px 0; }
.checks li { margin: 2px 0; }
.about p { color: var(--ink); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .stage { flex-direction: column; align-items: stretch; }
  .readout { position: static; margin: 4px 4px 6px; }
  .readout .year { font-size: 40px; }
  .panel { height: auto; position: static; border-left: 0; border-top: 1px solid var(--line); }
  .clock-wrap { width: 100%; }
}
