:root {
  --bg: #05070d; --panel: rgba(17, 21, 33, .78); --panel-2: #1a2033; --border: #252c42;
  --text: #e8e6df; --muted: #8d93a8; --moon: #e9e4d4; --accent: #c9b98a; --accent-2: #7fa7ff;
  --good: #7dd3a8; --warn: #f2c14e; --sun: #ffb347; --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { background: radial-gradient(ellipse at 20% -10%, #141a2e 0%, var(--bg) 55%) fixed; min-height: 100vh; }
#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
a { color: var(--accent-2); }
h1 { font-family: var(--serif); font-weight: 500; font-size: 44px; line-height: 1.1; margin: 4px 0 8px; letter-spacing: .01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 11px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num, .v, .tile-value { font-variant-numeric: tabular-nums; }

/* ---- top bar ---- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: rgba(5, 7, 13, .8); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .02em; flex: 1; }
.brand-moon { width: 22px; height: 22px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip, .btn, .linkbtn, .unit-toggle button, .orient-toggle button { font: inherit; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip:hover { border-color: #3a4462; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 6px var(--good); }
.chip.off .dot { background: var(--muted); box-shadow: none; }
.timectl { display: flex; gap: 6px; }
.timectl input { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; font: inherit; font-size: 13px; color-scheme: dark; }
#now-btn.live { border-color: var(--good); color: var(--good); }
.unit-toggle, .orient-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.unit-toggle button, .orient-toggle button { background: transparent; color: var(--muted); border: 0; padding: 5px 11px; font-size: 13px; }
.unit-toggle button.active, .orient-toggle button.active { background: var(--panel-2); color: var(--text); }

/* ---- layout ---- */
#app { position: relative; z-index: 1; padding: 20px; max-width: 1240px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
  backdrop-filter: blur(4px); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-3 h3:first-child { margin-top: 0; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.banner { background: #2a2410; border: 1px solid #5a4a18; color: var(--warn); border-radius: 10px; padding: 8px 14px; margin-bottom: 12px; }
.linkbtn { background: none; border: 0; color: var(--accent-2); text-decoration: underline; padding: 0; }

/* ---- hero ---- */
.hero { display: grid; grid-template-columns: minmax(260px, 420px) 1fr; gap: 36px; align-items: center; margin: 8px 0 24px; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; gap: 12px; } h1 { font-size: 34px; } }
.moon-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#moon-big { width: 100%; max-width: 400px; aspect-ratio: 1; overflow: visible; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 600; }
.big-stat { font-family: var(--serif); font-size: 64px; line-height: 1; margin: 6px 0 14px; }
.big-stat .unit { font-family: inherit; font-size: 18px; color: var(--muted); margin-left: 8px; font-family: -apple-system, "Segoe UI", sans-serif; }
.cycle { max-width: 520px; margin-bottom: 20px; }
.cycle-bar { position: relative; height: 8px; border-radius: 4px; background: #1b2133; overflow: hidden; }
.cycle-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #3a4260, var(--moon)); border-radius: 4px; }
.cycle-marks { position: absolute; inset: 0; display: flex; justify-content: space-evenly; }
.cycle-marks span { width: 1px; background: rgba(5,7,13,.8); }
.cycle-labels { display: flex; justify-content: space-between; margin-top: 4px; }
.hero-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; max-width: 560px; }
.k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.v { font-size: 22px; font-weight: 600; }
.s { color: var(--muted); font-size: 12px; }

/* ---- tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 520px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tile-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }
.tile-value { font-size: 20px; font-weight: 600; margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { color: var(--muted); font-size: 12px; }

/* ---- tables ---- */
table.kv { border-collapse: collapse; width: 100%; }
table.kv td { padding: 5px 0; border-bottom: 1px solid rgba(37, 44, 66, .6); vertical-align: top; }
table.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
table.kv tr:last-child td { border-bottom: 0; }
table.kv td:first-child { color: var(--muted); }

/* ---- sky ---- */
.sky-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: center; }
@media (max-width: 520px) { .sky-wrap { grid-template-columns: 1fr; } #sky-dial { max-width: 240px; margin: 0 auto; } }
#sky-dial { width: 100%; }
#alt-chart { width: 100%; height: 170px; display: block; }
.legend { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.sw { display: inline-block; width: 14px; height: 8px; border-radius: 2px; margin-left: 8px; }
.sw.moon { background: var(--moon); height: 3px; }
.sw.night { background: #1a2552; }

/* ---- orbit ---- */
#orbit-svg { width: 100%; max-height: 280px; display: block; margin-bottom: 8px; }
.orbit-bar { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; margin: 4px 0 14px; }
.ob-end.right { text-align: right; }
.ob-end .v { font-size: 16px; }
.ob-track { position: relative; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent), #2b3350); }
.ob-dot { position: absolute; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--moon);
  box-shadow: 0 0 10px rgba(233,228,212,.7); transition: left .6s; }

/* ---- phases ---- */
.phase-list { list-style: none; margin: 0; padding: 0; }
.phase-list li { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 7px 0;
  border-bottom: 1px solid rgba(37, 44, 66, .6); }
.phase-list li:last-child { border-bottom: 0; }
.phase-list svg { width: 30px; height: 30px; }
.phase-list .when { text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.phase-list .name { font-weight: 600; }
.pill { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 4px; margin-left: 6px; vertical-align: 1px; }
.pill.super { background: var(--accent); color: #1a1405; }
.pill.micro { background: #3a4466; color: var(--text); }
.pill.blue { background: var(--accent-2); color: #06102a; }
.pill.vis { background: rgba(125, 211, 168, .18); color: var(--good); }
.pill.novis { background: rgba(141, 147, 168, .15); color: var(--muted); }
.specials { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.special { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }

/* ---- calendar ---- */
.cal-nav { display: flex; gap: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
#cal-head div { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding-bottom: 4px; }
.cal-day { position: relative; border-radius: 8px; padding: 4px 2px 6px; text-align: center; min-height: 62px; background: rgba(26, 32, 51, .45); }
.cal-day.today { outline: 1px solid var(--accent); }
.cal-day.empty { background: transparent; }
.cal-day .d { font-size: 11px; color: var(--muted); }
.cal-day svg { width: 60%; max-width: 30px; aspect-ratio: 1; display: block; margin: 2px auto; }
.cal-day .e { font-size: 9px; line-height: 1.15; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-day .e.apsis { color: var(--accent-2); }
.cal-day .e.eclipse { color: var(--warn); }

/* ---- eclipses ---- */
.ev-list { list-style: none; margin: 0; padding: 0; }
.ev-list li { padding: 7px 0; border-bottom: 1px solid rgba(37, 44, 66, .6); }
.ev-list li:last-child { border-bottom: 0; }
.ev-list .t { font-weight: 600; }

/* ---- fun ---- */
.fun-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.fact { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.fact .v { font-size: 20px; }
.fact .s { margin-top: 2px; }
.fact.yes .v { color: var(--good); }

/* ---- dialog ---- */
dialog { background: #10141f; color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin-top: 0; }
dialog label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0; }
dialog input { display: block; width: 100%; margin-top: 4px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font: inherit; color-scheme: dark; }
dialog .row { display: flex; gap: 10px; }
dialog .row > * { flex: 1; }
dialog .row.end { justify-content: flex-end; margin-top: 14px; }
dialog .row.end > * { flex: 0 0 auto; }
dialog .or { text-align: center; margin: 12px 0 2px; }
.btn { background: var(--accent); color: #1a1405; border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
#geo-btn { width: 100%; }

footer { text-align: center; padding: 16px 0 40px; }
