/* GHOST Align
   Palette comes from the ghost itself: its violet, a pale wash of it, and one warm
   counter-colour (amber) reserved for "Not yet". Paper matches inthemachine.ai. */

:root {
  --paper: #fafafa;
  --card: #ffffff;
  --ink: #1f1830;
  --muted: #696279;
  --line: #e7e2ef;
  --ghost: #7453b4;
  --ghost-deep: #4e3690;
  --wash: #efe9fa;
  --amber: #a86a12;
  --amber-wash: #fbf0d9;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --text: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --r-s: 8px;
  --r-l: 20px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1rem/1.55 var(--text);
}
h1, h2, h3 { text-wrap: balance; font-family: var(--display); font-weight: 600; line-height: 1.12; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 .8em; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ghost); outline-offset: 2px; border-radius: 4px; }
a { color: var(--ghost-deep); }
.noscript { padding: 2rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

/* ── Buttons ── */
.btn {
  border: 1.5px solid var(--ink); background: var(--ink); color: #fff;
  padding: .7rem 1.2rem; border-radius: 999px; font-family: var(--display); font-weight: 600;
}
.btn:hover { background: var(--ghost-deep); border-color: var(--ghost-deep); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.quiet { background: transparent; color: var(--ink); }
.btn.quiet:hover { background: var(--wash); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--ghost-deep); text-decoration: underline; text-underline-offset: 3px; }

/* ── Sign-in ── */
.door { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1.25rem; }
.door-inner { width: min(27rem, 100%); }
.door img { width: 112px; height: auto; display: block; margin-bottom: 1.25rem; animation: float 6s ease-in-out infinite; }
.door h1 { font-size: clamp(2.6rem, 9vw, 3.75rem); letter-spacing: -0.03em; }
.door .lede { font-size: 1.15rem; margin: .9rem 0 2rem; max-width: 24rem; }
.who { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1.25rem; }
.who button {
  padding: .9rem .5rem; border-radius: var(--r-s); border: 1.5px solid var(--line); background: var(--card);
  font-family: var(--display); font-weight: 600; font-size: 1.05rem;
}
.who button[aria-pressed="true"] { border-color: var(--ghost); background: var(--wash); color: var(--ghost-deep); }
.field { display: block; margin-bottom: 1rem; }
.field span { display: block; font-weight: 700; margin-bottom: .3rem; }
.field input, .field textarea, .field select {
  width: 100%; padding: .7rem .8rem; border: 1.5px solid var(--line); border-radius: var(--r-s); background: var(--card);
}
.field input:focus, .field textarea:focus { border-color: var(--ghost); outline: none; }
.error { color: #8a2c0d; background: #fdeee7; border-radius: var(--r-s); padding: .6rem .8rem; margin-bottom: 1rem; }

@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* ── Frame ── */
.top {
  display: flex; align-items: center; gap: 1.25rem; padding: .8rem clamp(1rem, 3vw, 2.25rem);
  border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 700; font-size: 1.3rem; letter-spacing: -0.02em; }
.brand img { width: 26px; height: auto; }
.tabs { display: flex; gap: .2rem; margin-left: .5rem; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: .45rem .8rem; border-radius: 999px; color: var(--muted); font-weight: 700; }
.tabs button[aria-current="page"] { background: var(--ink); color: #fff; }
.tabs button:hover:not([aria-current="page"]) { background: var(--wash); color: var(--ink); }
.me { margin-left: auto; display: flex; gap: .9rem; align-items: baseline; white-space: nowrap; }

.layout {
  display: grid; grid-template-columns: minmax(17.5rem, 21rem) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3.5rem);
  padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2.25rem) 6rem; max-width: 80rem; margin: 0 auto; align-items: start;
}
.side { position: sticky; top: 4.6rem; }
.page { max-width: 46rem; margin: 0 auto; padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 3vw, 2rem) 6rem; }
.page h1 { font-size: clamp(2rem, 5vw, 2.9rem); letter-spacing: -0.025em; margin-bottom: 1rem; }
.page h2 { font-size: 1.45rem; margin: 2.4rem 0 .7rem; }
.page ol, .page ul { padding-left: 1.25rem; margin: 0 0 1em; }
.page li { margin-bottom: .45em; }

/* ── The ring ── */
.ring { display: block; width: min(100%, 17rem); margin: 0 auto; }
.tick { stroke-width: 7; stroke-linecap: round; stroke: #dcd6e6; cursor: pointer; transition: stroke .5s; }
.tick:hover { stroke-width: 9; }
.t-banked { stroke: var(--ghost); }
.t-parked { stroke: #b9a6dd; stroke-dasharray: 1 9; }
.t-linked { stroke: #a48bd6; }
.t-contested, .t-stuck { stroke: #d39a35; }
.ring.revealed .t-new { animation: land .9s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes land { from { stroke: #fff; stroke-width: 16; } }
.count { text-align: center; margin: .6rem 0 0; }
.count b { font: 600 2.5rem/1 var(--display); letter-spacing: -0.03em; }
.count span { display: block; color: var(--muted); }

.roundbox { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.roundbox h2 { font-size: 1.3rem; }
.seals { list-style: none; padding: 0; margin: .9rem 0 0; display: grid; gap: .3rem; }
.seals li { display: flex; align-items: center; gap: .55rem; }
.dot { width: .8rem; height: .8rem; border-radius: 50%; border: 2px solid var(--ghost); flex: none; }
.dot.on { background: var(--ghost); }
.dot.away { border-color: #cfc8db; }

.checkin { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.checkin h3 { font-size: 1.05rem; margin-bottom: .2rem; }
.slider { display: grid; grid-template-columns: 1fr 2rem; align-items: center; column-gap: .6rem; margin-top: .7rem; }
.slider label { grid-column: 1 / -1; font-size: .92rem; }
.slider input { width: 100%; accent-color: var(--ghost); }
.slider output { font: 600 1.1rem var(--display); text-align: right; }
.trend { width: 100%; border-collapse: collapse; margin-top: .9rem; font-size: .875rem; }
.trend th, .trend td { text-align: right; padding: .2rem 0 .2rem .5rem; font-weight: 400; }
.trend th:first-child, .trend td:first-child { text-align: left; padding-left: 0; }
.trend thead th { color: var(--muted); }

.sealbox { margin-top: 1.4rem; }
.sealbox .btn { width: 100%; }
.sealbox p { margin: .6rem 0 0; }
.missing { background: var(--amber-wash); border-radius: var(--r-s); padding: .7rem .8rem; margin-top: .8rem; font-size: .92rem; }
.missing ul { margin: .3rem 0 0; padding-left: 1.1rem; }

/* ── Main column ── */
.hello h1 { font-size: clamp(1.9rem, 4.2vw, 2.8rem); letter-spacing: -0.025em; max-width: 18ch; }
.hello p { font-size: 1.1rem; max-width: 36rem; margin-top: .8rem; }

.last { background: var(--wash); border-radius: var(--r-l); padding: 1.3rem 1.5rem; margin-top: 1.6rem; }
.last h2 { font-size: 1.3rem; margin-bottom: .5rem; }
.last ul { margin: 0 0 .6rem; padding-left: 1.1rem; }
.last summary { cursor: pointer; }
.synth { white-space: pre-line; background: var(--card); border-radius: var(--r-s); padding: .9rem 1rem; margin-top: .8rem; }
.synth-by { font-size: .875rem; color: var(--muted); margin-top: .4rem; }

.filters { display: flex; gap: .35rem; flex-wrap: wrap; margin: 2rem 0 .4rem; }
.filters button { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: .35rem .85rem; }
.filters button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }

.section-h { font-size: 1.05rem; color: var(--muted); font-family: var(--text); font-weight: 700; letter-spacing: 0; margin: 2rem 0 .5rem; }

.clause { border-top: 1px solid var(--line); }
.clause:last-child { border-bottom: 1px solid var(--line); }
.clause-head {
  width: 100%; text-align: left; background: none; border: 0; padding: .95rem .25rem; display: grid;
  grid-template-columns: 1fr auto; gap: .15rem 1rem; align-items: baseline;
}
.clause-head:hover h3 { color: var(--ghost-deep); }
.clause-head h3 { font-size: 1.18rem; }
.clause-head .sum { grid-column: 1; color: var(--muted); }
.chips { grid-row: 1 / span 2; grid-column: 2; display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; }
.chip { font-size: .8rem; font-weight: 700; padding: .12rem .6rem; border-radius: 999px; white-space: nowrap; border: 1.5px solid transparent; }
.chip.s-open { border-color: var(--line); color: var(--muted); }
.chip.s-banked { background: var(--ghost); color: #fff; }
.chip.s-parked { border-color: var(--ghost); color: var(--ghost-deep); border-style: dashed; }
.chip.s-linked { background: var(--wash); color: var(--ghost-deep); }
.chip.s-contested, .chip.s-stuck { background: var(--amber-wash); color: var(--amber); }
.chip.yours { background: var(--ink); color: #fff; }
.tier { font-size: .8rem; color: var(--muted); }

.clause-body { padding: .2rem .25rem 1.8rem; max-width: 44rem; }
.know { background: var(--paper); border-left: 3px solid var(--ghost); padding: .15rem 0 .15rem 1rem; margin: .4rem 0 1.4rem; }
.know h4, .clause-body h4 { font: 700 .95rem var(--text); margin: 0 0 .4rem; }
.know ul { margin: 0; padding-left: 1.1rem; }
.know li { margin-bottom: .45rem; }

.cand { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-l); padding: 1.1rem 1.25rem; margin-bottom: .9rem; }
.cand.chosen { border-color: var(--ghost); }
.cand-label { font-weight: 700; margin-bottom: .5rem; display: flex; gap: .6rem; flex-wrap: wrap; align-items: baseline; }
.cand-label small { font-weight: 400; color: var(--muted); font-size: .875rem; }
.cand-text { white-space: pre-line; }
.cand-why { color: var(--muted); font-size: .92rem; margin-top: .6rem; }
.stance { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .9rem; }
.stance button { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: .4rem .95rem; font-weight: 700; }
.stance button:disabled { cursor: default; opacity: .7; }
.stance button[aria-pressed="true"].v3 { background: var(--ghost); border-color: var(--ghost); color: #fff; }
.stance button[aria-pressed="true"].v2 { background: var(--wash); border-color: var(--ghost); color: var(--ghost-deep); }
.stance button[aria-pressed="true"].v1 { background: var(--amber-wash); border-color: var(--amber); color: var(--amber); }
.pub { list-style: none; display: flex; gap: .3rem 1.1rem; flex-wrap: wrap; padding: 0; margin: .8rem 0 0; font-size: .875rem; color: var(--muted); }
.pub b.v3 { color: var(--ghost-deep); }
.pub b.v2 { color: var(--ghost); }
.pub b.v1 { color: var(--amber); }

.thread { list-style: none; padding: 0; margin: 0 0 1rem; }
.thread li { padding: .55rem 0; border-top: 1px dashed var(--line); white-space: pre-line; }
.thread b { font-weight: 700; }
.mine textarea, .mine input[type="text"] { width: 100%; padding: .65rem .8rem; border: 1.5px solid var(--line); border-radius: var(--r-s); background: var(--card); resize: vertical; }
.mine textarea:focus, .mine input:focus { border-color: var(--ghost); outline: none; }
.mine label.lab { display: block; font-weight: 700; margin: 1rem 0 .3rem; }
.mine details { margin-top: 1rem; }
.aihelp { margin: .7rem 0 0; }
.aihelp .btn { padding: .45rem 1rem; margin-right: .5rem; }
.mine summary { cursor: pointer; font-weight: 700; color: var(--ghost-deep); }
.kind { display: flex; gap: 1.1rem; flex-wrap: wrap; margin: .7rem 0 .5rem; }
.linklist { max-height: 14rem; overflow: auto; border: 1.5px solid var(--line); border-radius: var(--r-s); padding: .5rem .8rem; margin-top: .6rem; background: var(--card); }
.linklist label { display: block; padding: .15rem 0; }
.lockedtext { white-space: pre-line; background: var(--card); border: 1.5px solid var(--ghost); border-radius: var(--r-l); padding: 1.1rem 1.25rem; }

/* ── Widgets ── */
.widget { background: var(--wash); border-radius: var(--r-l); padding: 1.1rem 1.25rem; margin-bottom: 1.2rem; }
.widget h4 { margin-bottom: .2rem; }
.widget input[type="range"] { width: 100%; accent-color: var(--ghost); }
.widget input[type="number"] { padding: .5rem .7rem; border: 1.5px solid var(--line); border-radius: var(--r-s); width: 11rem; background: var(--card); }
.wtable { width: 100%; border-collapse: collapse; margin-top: .7rem; font-variant-numeric: tabular-nums; }
.wtable th, .wtable td { text-align: right; padding: .3rem 0 .3rem .8rem; border-top: 1px solid #ddd2f1; }
.wtable th:first-child, .wtable td:first-child { text-align: left; padding-left: 0; }
.wtable thead th { border-top: 0; font-weight: 700; font-size: .875rem; vertical-align: bottom; }
.bar { display: block; width: 100%; height: 10px; }
.bar rect.bg { fill: #ddd2f1; }
.bar rect.fg { fill: var(--ghost); }

/* ── Document ── */
.doc h2 { border-top: 1px solid var(--line); padding-top: 1.4rem; }
.doc h3 { font-size: 1.1rem; margin: 1.3rem 0 .35rem; }
.doc .dtext { white-space: pre-line; }
.doc .dopen { color: var(--amber); background: var(--amber-wash); border-radius: var(--r-s); padding: .5rem .8rem; }
.signs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.2rem; }
.signs div { border-top: 1.5px solid var(--ink); padding-top: .5rem; }

/* ── Ledger ── */
.ledger { width: 100%; border-collapse: collapse; font-size: .92rem; }
.ledger th, .ledger td { text-align: left; padding: .4rem .8rem .4rem 0; border-top: 1px solid var(--line); vertical-align: top; }
.hash { font-size: .8rem; color: var(--muted); word-break: break-all; }

.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: .7rem 1.2rem; border-radius: 999px; z-index: 20; max-width: calc(100vw - 2rem);
}

/* ── Small screens ── */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  /* On a phone: ring and round first, then the clauses, then check-in and seal. */
  .side { display: contents; }
  .layout > main { order: 2; margin-top: 2rem; }
  .side .checkin, .side .sealbox { order: 3; }
  .ring { width: 12.5rem; }
  .top { flex-wrap: wrap; gap: .5rem 1rem; }
  .tabs { order: 3; width: 100%; margin-left: 0; flex-wrap: nowrap; overflow-x: auto; }
  .tabs button { padding: .4rem .65rem; white-space: nowrap; }
  .chips { grid-row: auto; grid-column: 1; flex-direction: row; align-items: center; margin-top: .3rem; }
  .clause-head { grid-template-columns: 1fr; }
  .signs { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .door img, .ring.revealed .t-new { animation: none; }
  .tick { transition: none; }
}

@media print {
  .top, .noprint { display: none !important; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
}
