:root {
  --bg: #1f2547;
  --surface: #283063;
  --surface-2: #323b74;
  --line: #414a87;
  --ink: #eef0f8;
  --muted: #a6adcf;
  --glow: #f5b841;
  --glow-ink: #f5b841;
  --glow-haze: rgba(245, 184, 65, 0.22);
  --rose: #f0909d;
  --ok: #8fd6a8;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.6rem;
  --step-3: 2.4rem;
  --radius-card: 18px;
  --radius-control: 999px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4fa;
    --surface: #ffffff;
    --surface-2: #eceef7;
    --line: #d7dbec;
    --ink: #1f2547;
    --muted: #586086;
    --glow: #f5b841;
    --glow-ink: #8a5a00;
    --glow-haze: rgba(245, 184, 65, 0.35);
    --rose: #b3263b;
    --ok: #1d7a45;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--step-0) / 1.55 var(--sans);
}
main { max-width: 56rem; margin: 0 auto; padding: 0 16px 4rem; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: var(--step-3); letter-spacing: -0.01em; }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
p { margin: 0 0 1rem; max-width: 68ch; }
a { color: var(--glow-ink); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--glow); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: var(--step--1); color: var(--muted); }
.lede { font-size: var(--step-1); color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.error { color: var(--rose); font-weight: 600; }
.flash { max-width: 56rem; margin: 0 auto 1rem; padding: 0.75rem 16px; color: var(--ok); }

/* ---------- header ---------- */
.top {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1.25rem 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
}
.wordmark {
  font-family: var(--serif);
  font-size: var(--step-1);
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.wick {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--glow);
  box-shadow: 0 0 14px 3px var(--glow-haze);
}
.nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: 0.25rem 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--glow); }
.signout { margin-left: auto; }
button.link { background: none; border: 0; color: var(--muted); padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }

/* ---------- controls ---------- */
button, .button {
  font: 600 var(--step--1) / 1 var(--sans);
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  background: var(--glow);
  color: #2a1d00;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.secondary, .button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: transparent; color: var(--rose); border-color: currentColor; }
button:disabled { opacity: 0.55; cursor: progress; }
input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: 100%;
}
label { display: grid; gap: 0.3rem; font-size: var(--step--1); color: var(--muted); }
label.check { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); }
label.check input { width: auto; }
/* min-width: fieldsets default to min-content, which lets a wide control push the box past a phone's edge */
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 0.75rem 1rem 1rem; margin: 0; min-width: 0; }
/* iOS Safari gives time inputs a fixed intrinsic width and centred text; make them behave like the other fields */
input[type="time"] { -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; min-height: 2.75rem; text-align: left; }
input[type="time"]::-webkit-date-and-time-value { text-align: left; }
label.check input { flex: none; }
legend { padding: 0 0.4rem; color: var(--muted); font-size: var(--step--1); }
.stack { display: grid; gap: 1rem; max-width: 34rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.row > label { flex: 1 1 9rem; min-width: 0; }
.narrow { max-width: 30rem; margin: 2rem auto; }

/* ---------- landing ---------- */
.hero { padding: 3rem 0 2rem; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); max-width: 18ch; }
.hero-lanterns { display: flex; gap: 1.1rem; margin-bottom: 2rem; }
.hero-lanterns .glow { width: 26px; height: 26px; }
.waitlist { margin: 2rem 0 1rem; max-width: 32rem; }
.waitlist .row input { flex: 1 1 14rem; }
.points { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 2rem; padding: 2rem 0; border-top: 1px solid var(--line); }
.points h2 { font-size: var(--step-1); }
.points p { color: var(--muted); }
.fineprint { font-size: var(--step--1); color: var(--muted); }

/* ---------- the lantern glow: the one bold thing ---------- */
.glow {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  flex: none;
}
.glow.dim, .player[data-state="paused"] .glow {
  border-color: var(--glow);
  background: radial-gradient(circle at 50% 45%, var(--glow-haze), transparent 70%);
}
.glow.on, .player[data-state="playing"] .glow {
  border-color: var(--glow);
  background: radial-gradient(circle at 50% 42%, #fff4cf 0%, var(--glow) 45%, #d98a14 100%);
  box-shadow: 0 0 22px 6px var(--glow-haze);
  animation: breathe 4.5s ease-in-out infinite;
}
.player[data-state="offline"] .glow { border-style: dashed; opacity: 0.6; }
@keyframes breathe {
  50% { box-shadow: 0 0 34px 10px var(--glow-haze); }
}
@media (prefers-reduced-motion: reduce) {
  .glow.on, .player[data-state="playing"] .glow { animation: none; }
}

/* ---------- players ---------- */
.players { display: grid; gap: 1rem; margin-top: 1rem; }
.player {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  grid-template-areas: "glow what facts" "glow actions actions";
  gap: 0.75rem 1.25rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}
.player[data-state="playing"] { border-color: color-mix(in srgb, var(--glow) 45%, var(--line)); }
.player .glow { grid-area: glow; margin-top: 0.2rem; }
.player .what { grid-area: what; min-width: 0; }
.player h2 { font-size: var(--step-1); margin-bottom: 0.1rem; }
.player .state { font-size: var(--step--1); color: var(--muted); margin: 0 0 0.6rem; }
.player[data-state="playing"] .state { color: var(--glow-ink); font-weight: 600; }
.player .card-title { font-family: var(--serif); font-size: var(--step-2); line-height: 1.15; margin: 0 0 0.2rem; overflow-wrap: anywhere; }
.player .track { color: var(--muted); margin-bottom: 0.6rem; }
progress {
  appearance: none;
  width: 100%;
  max-width: 26rem;
  height: 4px;
  border: 0;
  border-radius: 2px;
  background: var(--surface-2);
}
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 2px; }
progress::-webkit-progress-value { background: var(--glow); border-radius: 2px; }
progress::-moz-progress-bar { background: var(--glow); border-radius: 2px; }
.facts { grid-area: facts; margin: 0; display: grid; gap: 0.4rem; align-content: start; text-align: right; }
.facts div { display: flex; gap: 0.5rem; justify-content: flex-end; }
.facts dt { color: var(--muted); font-size: var(--step--1); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.actions button { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.actions button:first-child { background: var(--glow); color: #2a1d00; border-color: transparent; }
.toolbar { display: flex; justify-content: flex-end; margin-top: 1rem; }
.toolbar[hidden] { display: none; }
.toolbar + .note { text-align: right; }
.player { grid-template-areas: "glow what facts" "glow actions actions" "glow more more"; }
.more { grid-area: more; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.more summary { cursor: pointer; color: var(--muted); font-size: var(--step--1); width: fit-content; }
.more[open] summary { margin-bottom: 0.75rem; }
.control-row { display: flex; flex-wrap: wrap; align-items: end; gap: 0.5rem; margin-bottom: 0.75rem; }
.control-row label { flex: 1 1 10rem; }
.control-row button { flex: 0 0 auto; }
.control-label { width: 100%; font-size: var(--step--1); color: var(--muted); }
.control-row output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--glow); }
@media (max-width: 560px) {
  .player { grid-template-columns: 46px 1fr; grid-template-areas: "glow what" "facts facts" "actions actions" "more more"; }
  .facts { text-align: left; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); }
  .facts div { justify-content: flex-start; flex-direction: column; gap: 0; }
}

/* ---------- connect, approvals, notifications ---------- */
.connect { padding: 1.5rem; border: 1px dashed var(--glow); border-radius: var(--radius-card); margin: 1rem 0; }
.approvals:empty, .notifications:empty { display: none; }
.approvals { display: grid; gap: 0.75rem; margin: 1rem 0; }
.approval {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 1rem 1.25rem;
  border-radius: 14px;
  background: var(--surface-2);
  border-left: 4px solid var(--glow);
}
.approval p { margin: 0; flex: 1 1 16rem; }
.approval .who { display: block; color: var(--muted); font-size: var(--step--1); }
.notifications { margin-top: 2rem; }
.notifications ul { list-style: none; padding: 0; margin: 0 0 0.75rem; display: grid; gap: 0.5rem; }
.notifications li { padding: 0.75rem 1rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.notifications time { display: block; color: var(--muted); font-size: var(--step--1); }

/* ---------- history ---------- */
.nights { display: grid; gap: 1.5rem; margin: 2rem 0; }
.night h2 { font-size: var(--step-1); margin-bottom: 0.5rem; }
.bar-row { display: grid; grid-template-columns: minmax(7rem, 11rem) 1fr 4.5rem; gap: 0.75rem; align-items: center; }
.bar-row .who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .mins { text-align: right; font-variant-numeric: tabular-nums; }
meter { width: 100%; height: 10px; }
meter::-webkit-meter-bar { background: var(--surface-2); border: 0; border-radius: 5px; }
meter::-webkit-meter-optimum-value { background: var(--glow); border-radius: 5px; }
meter::-moz-meter-bar { background: var(--glow); border-radius: 5px; }
h2.section { margin-top: 2.5rem; }
.table-wrap { overflow-x: auto; }
table.sessions { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
.sessions th { text-align: left; color: var(--muted); font-weight: 600; padding: 0.5rem 0.75rem 0.5rem 0; border-bottom: 1px solid var(--line); }
.sessions td { padding: 0.6rem 0.75rem 0.6rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }

/* ---------- activity ---------- */
.activity { list-style: none; padding: 0; margin: 1.5rem 0; }
.activity li { display: grid; grid-template-columns: 11rem 9rem 1fr; gap: 0.25rem 1rem; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
.activity time { color: var(--muted); font-size: var(--step--1); }
.activity .tool { font-weight: 600; }
.activity .detail { grid-column: 3; color: var(--muted); font-size: var(--step--1); }
.activity .badge { grid-column: 3; color: var(--rose); font-size: var(--step--1); }
@media (max-width: 560px) {
  .activity li { grid-template-columns: 1fr; }
  .activity .detail, .activity .badge { grid-column: 1; }
}

/* ---------- ask ---------- */
.chat { display: grid; gap: 1rem; margin: 1.5rem 0; }
.msg { padding: 0.9rem 1.1rem; border-radius: 16px; max-width: 42rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { justify-self: end; background: var(--surface-2); }
.msg.assistant { justify-self: start; background: var(--surface); border: 1px solid var(--line); }
.msg.thinking { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 0.75rem; align-items: end; position: sticky; bottom: 0; padding: 0.75rem 0; background: var(--bg); }
.chat-form textarea { resize: vertical; }
.suggestions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.chip { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }

/* ---------- settings ---------- */
.panel { padding: 1.5rem 0 2rem; border-top: 1px solid var(--line); }
.panel:first-of-type { border-top: 0; }
.panel > p { color: var(--muted); }
.rules, .tokens { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; gap: 0.75rem; }
.rules li, .tokens li { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; padding: 0.9rem 1rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.rules li > div { flex: 1 1 18rem; }
.rules p { margin: 0.2rem 0 0; color: var(--muted); font-size: var(--step--1); }
.tokens li > span:first-child { flex: 1; font-weight: 600; }
.inline-rule { max-width: none; margin-top: 1rem; }
.token-once { padding: 1rem 1.25rem; border-radius: 12px; border: 1px solid var(--glow); margin-bottom: 1rem; }
.token-once code { display: block; overflow-wrap: anywhere; font-size: var(--step--1); margin: 0.5rem 0; }
.delete-form { display: grid; gap: 0.75rem; }

/* ---------- refinements ---------- */
.stack > button, .stack > .button { justify-self: start; }
.inline-rule > button { justify-self: start; }
.delete-form > button { justify-self: start; }
@media (max-width: 560px) {
  .top { gap: 0.75rem 1rem; }
  .nav { order: 3; flex-basis: 100%; gap: 0.25rem 1.1rem; }
}

.site-footer { max-width: 44rem; margin: 3rem auto 2rem; padding: 0 1rem; font-size: var(--step--1); color: var(--muted); }
.site-footer a { color: inherit; }
.prose { max-width: 40rem; }
.prose h2 { margin-top: 2rem; }
.prose li { margin: 0.4rem 0; }

/* Approvals waiting, on the Players link */
.nav .count { display: inline-block; min-width: 1.35em; margin-left: 0.35em; padding: 0 0.35em; border-radius: 999px; background: var(--glow); color: #1f2547; font-size: var(--step--1); font-weight: 600; text-align: center; line-height: 1.35; }

/* Add-a-rule forms */
.add-rule { border-top: 1px solid var(--line); padding: 0.75rem 0; }
.add-rule summary { cursor: pointer; font-weight: 600; }
.add-rule[open] summary { margin-bottom: 0.75rem; }
.days { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
.days legend { font-size: var(--step--1); color: var(--muted); }
