:root {
  --bg: #0b0e14;
  --panel: #12161f;
  --panel-2: #171c28;
  --line: #232a3a;
  --line-strong: #3a4256;
  --text: #e6e9f0;
  --muted: #99a1b5;
  --accent: #c9a86a;
  --accent-dim: #8a744a;
  --danger: #d47b7b;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #14100a; padding: 8px 16px;
}
.skip-link:focus { left: 0; }

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

body {
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: rgba(201, 168, 106, 0.15);
  background: radial-gradient(1200px 600px at 50% -200px, #141a28 0%, var(--bg) 60%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

.wrap {
  max-width: 1080px; margin: 0 auto;
  padding: 0 max(20px, env(safe-area-inset-left)) calc(80px + env(safe-area-inset-bottom))
           max(20px, env(safe-area-inset-right));
}

header.site {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 10px 16px;
  padding: 28px 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 28px;
}
.brand { font-family: var(--serif); }
.brand h1 { font-size: 26px; margin: 0; letter-spacing: 0.06em; }
.brand h1 .star { color: var(--accent); }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; font-family: var(--sans); }

.langs { display: flex; gap: 8px; }
.langs button {
  background: none; border: 1px solid var(--line); color: var(--muted);
  padding: 4px 10px; cursor: pointer; font-size: 12px; letter-spacing: 0.08em;
  transition-property: transform, color, border-color, background-color;
  transition-duration: 0.12s; transition-timing-function: ease-out;
}
.langs button:active { transform: scale(0.96); }
.langs button.active {
  color: var(--accent); border-color: var(--accent-dim);
  background: rgba(201, 168, 106, 0.1);
}

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 22px 24px; margin-bottom: 22px;
}
.card h2 {
  font-family: var(--serif); font-size: 18px; font-weight: normal;
  letter-spacing: 0.05em; margin: 0 0 16px; color: var(--accent);
}

form .grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 16px;
}
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; letter-spacing: 0.04em; }
input, select {
  width: 100%; background: #10141d; color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 4px; padding: 8px 10px;
  font-size: 16px; font-family: var(--sans);
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* full row, never `span 2`: a span forces an implicit track and overflows
   narrow viewports (Galaxy Fold cover screen, iPhone SE) */
.place-wrap { position: relative; grid-column: 1 / -1; }
.place-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  background: var(--panel-2); border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.28);
  max-height: 240px; overflow-y: auto;
}
.place-results div {
  padding: 10px 12px; cursor: pointer; font-size: 13px;
  transition-property: background-color, color;
  transition-duration: 0.12s; transition-timing-function: ease-out;
}
.place-results div:hover, .place-results div.active { background: var(--line); color: var(--accent); }
.place-results .sub { color: var(--muted); font-size: 12px; }
.place-results .geo-status { color: var(--muted); cursor: default; font-style: italic; }

.actions { margin-top: 18px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
button.primary {
  background: var(--accent); color: #14100a; border: none; border-radius: 4px;
  padding: 10px 26px; font-size: 14px; letter-spacing: 0.05em; cursor: pointer;
  font-family: var(--sans); font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { background: var(--accent-dim); cursor: default; }
button.primary, button.ghost {
  transition-property: transform, filter, background-color, border-color, color;
  transition-duration: 0.12s; transition-timing-function: ease-out;
}
button.primary:active:not(:disabled), button.ghost:active { transform: scale(0.96); }
button.ghost {
  background: none; border: 1px solid var(--accent-dim); color: var(--accent);
  border-radius: 4px; padding: 9px 20px; font-size: 13px; cursor: pointer;
}
button.ghost.small { padding: 5px 12px; font-size: 12px; }
.notice {
  color: #d9c9a8; font-size: 13px; margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
}
.assistant-out {
  white-space: pre-wrap; font-family: var(--mono); font-size: 13px;
  background: #10141d; border: 1px solid var(--line-strong); border-radius: 4px;
  padding: 16px 18px; margin-top: 14px; max-width: none;
}
.hint { color: var(--muted); font-size: 12px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; white-space: pre-wrap; }

.meta-bar {
  display: flex; flex-wrap: wrap; gap: 10px 28px;
  font-size: 13.5px; color: var(--muted); font-family: var(--mono);
  line-height: 1.5;
}
.meta-bar b { color: var(--text); font-weight: normal; }

.duo { display: grid; grid-template-columns: minmax(320px, 640px) 1fr; gap: 24px; align-items: start; }
/* grid items default to min-width:auto and inherit table min-content width,
   defeating the inner scroll wrappers on narrow screens */
.duo > * { min-width: 0; }
@media (max-width: 780px) { .duo { grid-template-columns: 1fr; } }

@media (max-width: 480px) {
  .card { padding: 16px 14px; }
  .wrap { padding: 0 12px 60px; }
  body { font-size: 14.5px; }
}

/* touch devices: honest tap targets */
@media (pointer: coarse) {
  .langs button { padding: 10px 14px; min-height: 44px; }
  .place-results div { padding: 14px 12px; }
  button.ghost.small { padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .caret::after { animation: none; }
  * { scroll-behavior: auto !important; }
  button.primary:active:not(:disabled), button.ghost:active,
  .langs button:active { transform: none; }
}

#wheel { width: 100%; height: auto; display: block; }

.weights h3, .side h3 {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.12em; margin: 18px 0 8px; font-weight: normal;
}
.bar-row {
  display: grid; grid-template-columns: minmax(104px, auto) 1fr 26px;
  gap: 12px; align-items: center; margin: 6px 0; font-size: 13.5px;
}
.pattern-row { margin: 7px 0; font-size: 13.5px; line-height: 1.5; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: start; color: var(--muted); font-weight: normal; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.1em;
  border-bottom: 1px solid var(--line);
  padding-block: 6px; padding-inline: 0 10px;
}
td {
  padding-block: 8px; padding-inline: 0 12px;
  border-bottom: 1px solid rgba(35, 42, 58, 0.55); vertical-align: top; line-height: 1.5;
}
td.glyph { font-size: 17px; color: var(--accent); width: 30px; }
td.num, .mono { font-family: var(--mono); font-size: 13px; }
tr.retro td { color: #d9c9a8; }
.tag {
  display: inline-block; font-size: 10.5px; letter-spacing: 0.06em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 3px; padding: 0 6px; margin-left: 6px;
}
.tag.strong { color: var(--accent); border-color: var(--accent-dim); }

/* scroll shadows: edge fades appear only while content actually overflows,
   giving hidden columns a visible cue (pure CSS, self-managing) */
.table-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(to right, var(--panel) 30%, rgba(18, 22, 31, 0)) left center,
    linear-gradient(to left, var(--panel) 30%, rgba(18, 22, 31, 0)) right center,
    linear-gradient(to right, rgba(0, 0, 0, 0.5), transparent) left center,
    linear-gradient(to left, rgba(0, 0, 0, 0.5), transparent) right center;
  background-repeat: no-repeat;
  background-size: 44px 100%, 44px 100%, 16px 100%, 16px 100%;
  background-attachment: local, local, scroll, scroll;
}

/* houses: compact responsive grid instead of a half-empty column */
.houses-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 2px 26px;
}
.house-cell {
  display: flex; align-items: baseline; gap: 9px; font-size: 13.5px;
  padding: 7px 0; border-bottom: 1px solid rgba(35, 42, 58, 0.55);
}
.house-cell .hn { font-family: var(--mono); color: var(--muted); min-width: 17px; text-align: right; }
.house-cell .glyph-s { font-size: 15px; }
.house-cell .hsign { color: var(--muted); }

/* triangular aspectarium — width:auto overrides the global 100% table rule
   that stretched the staircase into broken empty rows on phones */
.matrix { border-collapse: collapse; width: auto; }
.matrix td {
  width: 28px; height: 28px; min-width: 28px; padding: 0;
  text-align: center; vertical-align: middle;
  border: 1px solid #2a3143; font-size: 14px;
}
.matrix td.mdiag {
  background: var(--panel-2); color: #e6c98f; font-size: 15px;
  border-color: var(--line-strong);
}
.matrix td.mcell:not(.empty) { cursor: pointer; font-weight: 600; }
.matrix td.mcell:not(.empty):hover { background: rgba(201, 168, 106, 0.09); }

@media (min-width: 781px) {
  .aspects-duo { grid-template-columns: auto 1fr; }
}
#t-aspects td, #t-transits td { white-space: nowrap; }
.aglyph { color: var(--accent); font-size: 15px; }

/* transits */
.chips { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 12px 0; }
.chip {
  border: 1px solid var(--line); border-radius: 4px; padding: 4px 9px;
  font-size: 13px; white-space: nowrap;
}
.chip .rx { color: #d47b7b; font-weight: 600; }
.chip .hn { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
#transit-prose { margin-top: 14px; }
.wheel-actions { display: flex; gap: 12px; margin-top: 10px; }
.dst-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* floating stream bar: progress + cancel stay reachable during the
   long generation even when the user has scrolled deep into sections */
.stream-bar {
  position: fixed; z-index: 50;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; gap: 12px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 10px 14px;
  font-size: 13px; color: var(--muted);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
}
.check { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.check input { width: auto; accent-color: var(--accent); }

/* responsive tables: compact names/motion on phones, fold secondary columns */
.nm-short { display: none; }
@media (max-width: 640px) {
  .nm-full { display: none; }
  .nm-short { display: inline; }
  .col-sec { display: none; }
  th, td { padding-inline-end: 8px; }
}
@media (max-width: 560px) {
  .matrix td { width: 19px; height: 19px; min-width: 19px; font-size: 10px; }
  .matrix td.mdiag { font-size: 11px; }
}
#matrix-tip { min-height: 1.3em; margin-top: 8px; }

.section-card h2 { margin-bottom: 4px; }
.section-card .status { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
/* elapsed counters tick every second: tabular digits keep them still */
.status, .stream-bar, .hint { font-variant-numeric: tabular-nums; }

/* terminology hints: dotted underline invites, tap/click explains */
button.term {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; letter-spacing: inherit;
  text-transform: inherit; cursor: help;
  text-decoration: underline dotted;
  text-decoration-color: var(--accent-dim);
  text-underline-offset: 3px;
}
button.term.tag {
  border: 1px solid var(--line); border-radius: 3px; padding: 0 6px;
  font-size: 10.5px; letter-spacing: 0.06em; color: var(--muted);
}
button.term.tag.strong { color: var(--accent); border-color: var(--accent-dim); }
.term-tip {
  position: absolute; z-index: 70;
  background: var(--panel-2); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 10px 14px;
  font-size: 13px; line-height: 1.55; color: var(--text);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
}
.prose { font-size: 15.5px; max-width: 74ch; line-height: 1.68; }
.prose h3 { font-family: var(--serif); font-weight: normal; color: var(--accent); font-size: 16px; margin: 20px 0 6px; }
.prose p { margin: 10px 0; }
.prose li { margin: 4px 0; }
.prose strong { color: #f0e7d4; }
.caret::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

footer.site {
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.hidden { display: none; }

/* ---------- print: readings on paper, dark-on-white ---------- */
@media print {
  :root { --text: #16181d; --muted: #4a4f5c; --accent: #6b5322; --line: #c9ccd4; --line-strong: #b4b8c2; }
  body { background: #fff; color: #16181d; font-size: 12pt; }
  .card, .section-card { background: #fff; border-color: #c9ccd4; break-inside: avoid; }
  .card h2, .prose h3, .brand h1 { color: #6b5322; }
  .prose strong { color: #16181d; }
  .langs, form, .actions, #btn-interpret, #btn-download, #btn-cancel,
  #assistant-card .actions, .place-results, .skip-link, #wheel { display: none !important; }
  .duo { grid-template-columns: 1fr; }
  .table-scroll { overflow: visible; }
  td, th { border-color: #c9ccd4; color: #16181d; }
  th { color: #4a4f5c; }
  tr.retro td { color: #6b5322; }
  .meta-bar, .hint, .bar-row { color: #4a4f5c; }
  .bar { background: #e2e4ea; } .bar i { background: #6b5322; }
  .assistant-out { background: #f4f5f7; border-color: #c9ccd4; color: #16181d; }
  .tag { color: #4a4f5c; border-color: #b4b8c2; }
  .tag.strong { color: #6b5322; border-color: #6b5322; }
  a { color: #16181d; text-decoration: none; }
}
