:root {
  color-scheme: dark light;
  --bg: #0a0f1f;
  --bg2: #111a33;
  --panel: #131c38;
  --border: #2a3760;
  --text: #e8ecf8;
  --muted: #9aa8cf;
  --accent: #ffd23f;
  --link: #8fb4ff;
  --ok: #3ecf8e;
  --err: #ff6b6b;
  --focus: #ffd23f;
  --input: #0d1530;
  --sky: #0b1330;
  --grid: rgba(150, 170, 230, 0.28);
  --ocean: #0e1f45;
  --land: #2f6b4f;
  --night: rgba(2, 5, 25, 0.2);
  --close: rgba(255, 210, 63, 0.22);
  --plate: #e9e1cf;
  --plate-line: #2a2418;
  --plate-date: #7a5c2e;
  --plate-back: #8d8574;
  --today: #d4380d;
  --shadow: rgba(20, 16, 10, 0.55);
  --ground: #28432f;
  --wall: #5a4a3e;
  --sun: #ffd23f;
  --gnomon: #9aa3ad;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2fb;
    --bg2: #e1e8f7;
    --panel: #ffffff;
    --border: #b9c4e0;
    --text: #141a30;
    --muted: #4a587f;
    --accent: #b36b00;
    --link: #0a4fc4;
    --ok: #0c7a4a;
    --err: #b00020;
    --focus: #0a4fc4;
    --input: #ffffff;
    --sky: #dbe6ff;
    --grid: rgba(40, 60, 120, 0.25);
    --ocean: #cfe0ff;
    --land: #8fc9a4;
    --night: rgba(10, 20, 80, 0.2);
    --close: rgba(255, 190, 0, 0.35);
    --ground: #b7d3a8;
    --wall: #c9b8a6;
    --sun: #e0a800;
    --gnomon: #6b737c;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 60%) fixed;
  overflow-wrap: anywhere;
}

body.busy { cursor: progress; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin-bottom: 0.6rem; color: var(--accent); }
h3 { font-size: 1rem; margin: 0.9rem 0 0.4rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--panel); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.note { color: var(--accent); }
.doc-link { color: var(--accent); }
.site-footer { text-align: center; padding: 1rem; }
.site-footer a { color: var(--accent); }

.top {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap;
  padding: 1rem clamp(0.75rem, 3vw, 2rem) 0.5rem;
}
.top p { margin: 0.2rem 0 0; }
.status { display: flex; gap: 0.5rem; align-items: center; }

.badge {
  display: inline-block; padding: 0.05rem 0.5rem; margin-left: 0.4rem; border-radius: 999px; font-size: 0.78rem;
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: var(--ok); }

.banner {
  margin: 0.5rem clamp(0.75rem, 3vw, 2rem); padding: 0.6rem 0.9rem; border: 1px solid var(--err); color: var(--err);
  border-radius: 8px; background: var(--panel); display: flex; justify-content: space-between; gap: 0.75rem; align-items: flex-start;
}
.banner[hidden] { display: none; }
.banner button { border: 0; background: transparent; color: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 0.3rem; }

.controls {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 0.75rem;
  padding: 0.5rem clamp(0.75rem, 3vw, 2rem);
}
fieldset { margin: 0; padding: 0.6rem 0.8rem 0.8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); min-width: 0; }
legend { padding: 0 0.4rem; color: var(--accent); font-weight: 600; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); gap: 0.5rem; margin-bottom: 0.5rem; }
.fields label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.4rem; }

input, select, button {
  font: inherit; color: var(--text); background: var(--input); border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem 0.55rem;
  min-width: 0; max-width: 100%;
}
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; padding: 0; accent-color: var(--accent); }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.link { background: none; border: 0; padding: 0; color: var(--link); text-decoration: underline; text-align: left; }

.check, label.inline { display: inline-flex; gap: 0.4rem; align-items: center; color: var(--text); font-size: 0.9rem; }
.toggles { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-bottom: 0.5rem; }

.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 0.75rem;
  padding: 0.5rem clamp(0.75rem, 3vw, 2rem) 2rem;
}
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem 1rem; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
@media (min-width: 1250px) { .panel.span2 { grid-column: span 2; } }

.scroll { overflow-x: auto; max-width: 100%; position: relative; }
.min-w { min-width: 640px; }

table.data { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
table.data th, table.data td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data thead th { color: var(--muted); font-weight: 600; white-space: nowrap; }
table.data tbody th { font-weight: 600; white-space: nowrap; }
table.data.wide { min-width: 820px; }
table.matrix td, table.matrix th { text-align: center; }
table.matrix td.close { background: var(--close); font-weight: 700; }
table.matrix td.diag { color: var(--muted); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.15rem 0.9rem; margin: 0.4rem 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

ul.plain, ul.legend { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 0.15rem 0; }
ul.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.82rem; color: var(--muted); margin-top: 0.4rem; }
.swatch { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 3px; margin-right: 0.35rem; vertical-align: -0.12rem; border: 1px solid var(--border); }

.clock-wrap { text-align: center; padding: 0.3rem 0 0.6rem; }
.clock-label { color: var(--muted); font-size: 0.85rem; }
.clock { font-size: 2.4rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }

.svg-wrap { width: 100%; }
.svg-wrap.square { max-width: 560px; margin: 0 auto; }
.svg-wrap svg, .map-svg { display: block; width: 100%; height: auto; }

.map-ocean { fill: var(--ocean); }
.map-land { fill: var(--land); stroke: rgba(0, 0, 0, 0.3); stroke-width: 0.4; }
.map-grid { stroke: var(--grid); stroke-width: 0.5; }
.map-grid.eq { stroke-width: 1; }
.night { fill: var(--night); stroke: none; }
.map-svg { cursor: crosshair; border-radius: 6px; }
.mk-sun circle { fill: #ffd23f; stroke: #fff; stroke-width: 1.5; }
.mk-moon circle { fill: #e6e9f3; stroke: #333; stroke-width: 1.5; }
.mk-obs circle { fill: none; stroke: var(--err); stroke-width: 2; }
.mk-obs line { stroke: var(--err); stroke-width: 2; }
.mk-sun-sw { background: #ffd23f; border-radius: 50%; }
.mk-moon-sw { background: #e6e9f3; border-radius: 50%; }
.mk-obs-sw { background: transparent; border: 2px solid var(--err); border-radius: 50%; }

section.sub { margin-top: 0.4rem; }

@media (max-width: 480px) {
  h1 { font-size: 1.3rem; }
  .clock { font-size: 1.9rem; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dd { margin-bottom: 0.3rem; }
}

[hidden] { display: none !important; }

.place-line { margin: 0.5rem 0 0; }
.fields.one { grid-template-columns: 1fr; }
.slider { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }
.slider input { width: 100%; padding: 0; accent-color: var(--accent); }
.fields > label { min-width: 0; }
.fields select { width: 100%; text-overflow: ellipsis; }

/* dial face */
.faces { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); max-width: 720px; margin: 0 auto; }
.faces.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); max-width: 1200px; }
.face-fig { margin: 0; }
.face-fig figcaption { text-align: center; margin-top: 0.3rem; }
.face-svg { display: block; width: 100%; height: auto; }
.f-plate { fill: var(--plate); stroke: var(--plate-line); stroke-width: 0.5; }
.f-hour, .f-ana, .f-meridian { stroke: var(--plate-line); fill: none; stroke-linecap: round; }
.f-hour.half, .f-ana.half { opacity: 0.6; }
.f-hour.noon { stroke: #8b1d0f; }
.f-ana.desc { stroke-dasharray: 4 3; }
.f-meridian { opacity: 0.5; }
.f-date { stroke: var(--plate-date); fill: none; opacity: 0.8; }
.f-date.eq, .f-date.sol { opacity: 1; }
.f-today { stroke: var(--today); fill: none; stroke-dasharray: 6 4; }
.f-foot { stroke: #3c3528; fill: #3c3528; }
.f-substyle { fill: none; stroke-dasharray: 5 4; }
.f-p0 { fill: var(--plate); stroke: #3c3528; }
.f-shadow path { fill: var(--shadow); stroke: none; }
.f-shadow .f-shadow-line, .f-shadow-line { fill: none; stroke: var(--shadow); stroke-linecap: round; }
.f-nodus { fill: var(--today); stroke: #fff; stroke-width: 0.5; }
.f-rod { fill: #3c3528; stroke: #fff; stroke-width: 0.5; }
.f-hlabel { fill: var(--plate-line); font-weight: 700; font-family: system-ui, sans-serif; }
.f-hlabel.half { font-weight: 400; }
.f-dlabel { fill: var(--plate-date); font-family: system-ui, sans-serif; }
.f-dark { fill: rgba(5, 8, 20, 0.45); }
.f-dark-t { fill: #fff; font-weight: 700; font-family: system-ui, sans-serif; paint-order: stroke; stroke: rgba(0, 0, 0, 0.6); stroke-width: 0.6; }
.f-orient, .f-ruler { stroke: var(--text); fill: none; }
.f-orient-t, .f-ruler-t, .f-caption { fill: var(--text); font-family: system-ui, sans-serif; }
.f-ellipse { stroke: var(--plate-line); fill: none; }
.f-scale { stroke: var(--plate-date); }
.f-hpoint { fill: var(--plate-line); }
.sw-hour { background: var(--plate-line); }
.sw-date { background: var(--plate-date); }
.sw-today { background: var(--today); }
.sw-shadow { background: var(--shadow); }
.sw-nodus { background: var(--today); border-radius: 50%; }

/* 3D scene */
.scene-wrap { touch-action: none; cursor: grab; user-select: none; }
.scene-wrap:active { cursor: grabbing; }
.scene-svg { display: block; width: 100%; height: auto; max-height: 70vh; }
.s-ground { fill: var(--ground); }
.s-grid { stroke: rgba(255, 255, 255, 0.12); }
.s-card { fill: var(--text); font-weight: 700; }
.s-wall { fill: var(--wall); }
.s-post { stroke: #6d6253; stroke-linecap: round; }
.s-plate { fill: var(--plate); stroke: #6d6253; stroke-width: 1; }
.s-plate.back { fill: var(--plate-back); }
.s-hour { stroke: var(--plate-line); fill: none; }
.s-hour.half { opacity: 0.6; }
.s-date { stroke: var(--plate-date); fill: none; opacity: 0.7; }
.s-hlabel { fill: var(--plate-line); font-weight: 700; }
.s-shadow { fill: var(--shadow); }
.s-shadow-line { stroke: var(--shadow); stroke-linecap: round; fill: none; }
.s-nodus { fill: var(--today); }
.s-dark { fill: rgba(5, 8, 20, 0.35); }
.s-gnomon { fill: var(--gnomon); stroke: #3d434a; stroke-width: 1; stroke-linejoin: round; }
.s-rod { stroke: var(--gnomon); stroke-linecap: round; }
.s-hpoint { fill: var(--plate); stroke: #222; stroke-width: 0.5; }
.s-sunray { stroke: var(--sun); stroke-dasharray: 6 4; }
.s-sun { fill: var(--sun); stroke: #fff6c0; stroke-width: 1.5; }
.s-sunray.below, .s-sun.below { opacity: 0.3; }

.prose p, .prose li { max-width: 80ch; }
.prose ol, .prose ul { padding-left: 1.4rem; }
.prose li { margin: 0.25rem 0; }
.map-grid.trop { stroke-dasharray: 3 3; }

#print-area { display: none; }

@media print {
  #screen { display: none; }
  #print-area { display: block; }
  body { background: #fff; color: #000; margin: 0; }
  .print-page { break-after: page; }
  .print-page p { font: 10pt/1.3 sans-serif; margin: 0 0 4mm; }
  .face-svg.print { width: auto; }
  .f-plate { fill: #fff; stroke: #000; stroke-width: 0.4; }
  .f-hour, .f-ana, .f-meridian, .f-ellipse, .f-scale, .f-foot { stroke: #000; }
  .f-hour.noon { stroke: #000; }
  .f-date { stroke: #666; opacity: 1; }
  .f-date.eq, .f-date.sol { stroke: #000; }
  .f-foot, .f-hpoint { fill: #000; }
  .f-p0 { fill: #fff; stroke: #000; }
  .f-hlabel, .f-dlabel, .f-ruler-t, .f-orient-t, .f-caption { fill: #000; }
  .f-orient, .f-ruler { stroke: #000; }
}

@page { margin: 10mm; }
