/* Semantic color layer (MECHANICS §11: per-player themes may override the
   theme tokens, never the semantic tokens). */
:root {
  /* theme layer (themable later) */
  --bg: #14161a;
  --bg-raised: #1c1f25;
  --bg-inset: #101216;
  --ink: #d8d5cc;
  --ink-dim: #8b897f;
  --line: #2a2e36;
  --accent: #c9a227;

  /* semantic layer (never themed) */
  --ok: #5a9e6f;
  --warn: #c9a227;
  --danger: #b5533c;
  --info: #5b84a8;
  --status-succeeded: var(--ok);
  --status-close_call: var(--warn);
  --status-failed: var(--danger);
  --status-overridden: var(--info);
  --status-skill_based: var(--info);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1.5;
}
h1, h2, h3, button, .phase-chip, .status-chip, .skill-chip, .game-meta, .hint, label {
  font-family: 'Gill Sans', 'Trebuchet MS', Verdana, sans-serif;
}
code, .mono { font-family: 'Courier New', monospace; }
a { color: var(--accent); }
a.quiet { color: var(--ink-dim); text-decoration: none; }

button {
  background: var(--bg-raised);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #14161a; border-color: var(--accent); font-weight: 600; }

input, textarea {
  width: 100%;
  background: var(--bg-inset);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
}
label { display: block; margin: 0.6rem 0; color: var(--ink-dim); }
label input, label textarea { margin-top: 0.25rem; color: var(--ink); }

.error-banner {
  background: color-mix(in srgb, var(--danger) 18%, var(--bg-raised));
  border: 1px solid var(--danger);
  border-radius: 4px;
  padding: 0.6rem 1rem;
  margin: 0.75rem 0;
}
.error-banner ul { margin: 0; padding-left: 1.2rem; }
.notice {
  background: color-mix(in srgb, var(--info) 18%, var(--bg-raised));
  border: 1px solid var(--info);
  border-radius: 4px;
  padding: 0.5rem 0.8rem;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
.hint { color: var(--ink-dim); font-size: 0.85rem; }
.empty-state { color: var(--ink-dim); font-style: italic; font-size: 0.9rem; }
.points-left { font-weight: 700; color: var(--accent); }
.points-left.over { color: var(--danger); }

/* ---------- landing ---------- */
.landing { max-width: 1000px; margin: 0 auto; padding: 3rem 1rem; }
.landing-head h1 { letter-spacing: 0.35em; margin-bottom: 0.2rem; }
.tagline { color: var(--ink-dim); font-style: italic; }
.landing-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: 2rem; }
.card { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 6px; padding: 1rem 1.25rem; }

/* ---------- wizard ---------- */
.wizard { max-width: 760px; margin: 0 auto; padding: 2rem 1rem; }
.wizard-step { border: 1px solid var(--line); border-radius: 6px; padding: 1rem 1.25rem; margin: 1rem 0; background: var(--bg-raised); }
.specialty-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.specialty-option { border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem; cursor: pointer; }
.specialty-option:has(input:checked) { border-color: var(--accent); }
.specialty-name { display: block; font-weight: 700; }
.specialty-detail { display: block; font-size: 0.8rem; color: var(--ink-dim); }
.skill-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem 1.5rem; }
.skill-row { display: grid; grid-template-columns: 1fr 2rem 4rem 3rem; align-items: center; gap: 0.5rem; margin: 0.15rem 0; }
.skill-row.is-primary .skill-name { color: var(--accent); font-weight: 700; }
.skill-base { color: var(--ink-dim); text-align: right; }
.skill-total { color: var(--ink-dim); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.wizard-nav { display: flex; gap: 0.75rem; justify-content: flex-end; }

/* ---------- game shell ---------- */
.game-shell { display: flex; flex-direction: column; height: 100vh; }
.game-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); background: var(--bg-raised);
  flex-wrap: wrap; gap: 0.5rem;
}
.game-title { display: flex; align-items: baseline; gap: 1rem; }
.game-title h1 { margin: 0; font-size: 1.1rem; letter-spacing: 0.15em; }
.clock { color: var(--accent); }
.game-meta { display: flex; gap: 1.25rem; align-items: baseline; font-size: 0.85rem; color: var(--ink-dim); }

.tri-panel { display: grid; grid-template-columns: 1fr 380px 300px; gap: 0; flex: 1; min-height: 0; }
.game-shell.solo .tri-panel { grid-template-columns: 1fr 380px; }
.panel { overflow-y: auto; padding: 1rem; min-height: 0; }
.panel-round { border-left: 1px solid var(--line); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.panel-chat { display: flex; flex-direction: column; }

/* round panel */
#round-panel { flex: 1; }
.phase-chip {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  border: 1px solid var(--line); border-radius: 10px; padding: 0.1rem 0.55rem; vertical-align: middle;
}
.phase-drafting { color: var(--ink-dim); }
.phase-proposal { color: var(--info); border-color: var(--info); }
.phase-ready { color: var(--warn); border-color: var(--warn); }
.phase-locked_in { color: var(--ok); border-color: var(--ok); }
.my-proposal { background: var(--bg-inset); border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem 0.8rem; margin: 0.6rem 0; }
.my-proposal .label { font-size: 0.75rem; text-transform: uppercase; color: var(--ink-dim); letter-spacing: 0.1em; }
.teammate { border-top: 1px solid var(--line); padding: 0.5rem 0; }
.teammate-name { font-weight: 700; margin-right: 0.5rem; }
.teammate-text { margin: 0.3rem 0 0; }
.teammate-text.empty { color: var(--ink-dim); font-style: italic; }
.proposal-form { border-top: 1px solid var(--line); padding-top: 0.75rem; }
.proposal-buttons { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.round-rest, .round-processing { text-align: center; padding: 2rem 0; }
.beat-indicator {
  display: flex; gap: 0.6rem; align-items: baseline; justify-content: center;
  border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.8rem;
  margin-bottom: 0.6rem; background: var(--bg-raised);
}
.beat-indicator.quiet { border-style: dashed; color: var(--ink-dim); }
.beat-label { font-weight: 700; letter-spacing: 0.06em; }
.beat-progress { color: var(--ink-dim); font-size: 0.85rem; }
.beat-chip { color: var(--accent); border-color: var(--accent); }
.rest-actions { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.75rem; align-items: center; }
.camp-form { display: flex; gap: 0.4rem; }
.camp-form input { width: 12rem; }
.quiet-button { margin-top: 0.6rem; color: var(--ink-dim); font-size: 0.85rem; }
.escalation { color: var(--danger); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; }

/* chat */
#chat-region { flex: 1; overflow-y: auto; }
.chat-msg { margin: 0.5rem 0; }
.chat-msg p { margin: 0.1rem 0 0; }
.chat-name { font-weight: 700; font-size: 0.85rem; }
.chat-msg.mine .chat-name { color: var(--accent); }
.chat-time { color: var(--ink-dim); font-size: 0.75rem; margin-left: 0.4rem; }
.chat-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* field log */
.log-columns { display: grid; grid-template-columns: 1fr 240px; gap: 1.25rem; }
.log-round { border-bottom: 1px solid var(--line); padding: 0.9rem 0; }
.log-round-head { display: flex; gap: 1rem; align-items: baseline; margin-bottom: 0.4rem; }
.round-num { font-weight: 700; letter-spacing: 0.1em; font-size: 0.85rem; }
.round-clock { color: var(--ink-dim); font-size: 0.85rem; }
.narrative { white-space: pre-wrap; }
details { margin: 0.5rem 0; }
details summary { cursor: pointer; color: var(--ink-dim); font-size: 0.85rem; }
details ul { margin: 0.4rem 0; padding-left: 1rem; list-style: none; }
.receipt { margin: 0.35rem 0; }
.receipt-actor { font-weight: 700; margin-right: 0.35rem; }
.receipt-reason { display: block; color: var(--ink-dim); font-size: 0.9rem; }
.status-chip {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  border-radius: 10px; padding: 0.05rem 0.5rem; margin: 0 0.3rem;
  border: 1px solid var(--line);
}
.status-succeeded { color: var(--status-succeeded); border-color: var(--status-succeeded); }
.status-close_call { color: var(--status-close_call); border-color: var(--status-close_call); }
.status-failed { color: var(--status-failed); border-color: var(--status-failed); }
.status-overridden { color: var(--status-overridden); border-color: var(--status-overridden); }
.status-skill_based { color: var(--status-skill_based); border-color: var(--status-skill_based); }
.skill-chip {
  font-size: 0.7rem; border: 1px dashed var(--line); border-radius: 10px;
  padding: 0.05rem 0.5rem; color: var(--ink-dim); margin-left: 0.3rem;
}
.corrections code { color: var(--warn); }
.round-toasts { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.toast {
  font-size: 0.85rem; border-left: 3px solid var(--info);
  background: var(--bg-inset); padding: 0.3rem 0.6rem; margin: 0.25rem 0; border-radius: 0 4px 4px 0;
}
.toast-rep { border-left-color: var(--warn); }
.toast-xp, .toast-skillup { border-left-color: var(--ok); }
.toast-injury, .toast-debuff { border-left-color: var(--danger); }

/* side panel */
.side-block { margin-bottom: 1.25rem; }
.side-block h3 {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.15em;
  color: var(--ink-dim); border-bottom: 1px solid var(--line); padding-bottom: 0.25rem;
}
.inv-row, .crew-row, .rep-row { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.9rem; margin: 0.25rem 0; }
.inv-detail, .crew-detail { color: var(--ink-dim); font-size: 0.8rem; text-align: right; }
.nearby-item { margin: 0.3rem 0; font-size: 0.9rem; }
.nearby-item span { display: block; color: var(--ink-dim); font-size: 0.8rem; }
.thread-row { font-size: 0.85rem; margin: 0.35rem 0; padding-left: 0.5rem; border-left: 2px solid var(--accent); }
.rep-value { font-weight: 700; }
.health-healthy { color: var(--ok); }
.health-wounded { color: var(--warn); }
.health-critical, .health-downed { color: var(--danger); }

.recap-card {
  background: var(--bg-raised); border: 1px solid var(--accent); border-radius: 6px;
  margin: 0.75rem 1rem 0; padding: 0.8rem 1.2rem;
}
.recap-card h2 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--accent); }
.recap-digest { font-size: 0.9rem; }
.log-search { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.stats-table { border-collapse: collapse; width: 100%; }
.stats-table th, .stats-table td { border-bottom: 1px solid var(--line); padding: 0.3rem 0.5rem; text-align: left; font-size: 0.9rem; }

.contract-row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.4rem; font-size: 0.85rem; margin: 0.3rem 0; flex-wrap: wrap; }
.contract-row .codex-meta { flex-basis: 100%; }
button.mini { padding: 0.1rem 0.5rem; font-size: 0.75rem; }
.vendor-block { margin-bottom: 0.5rem; }

/* journal */
.journal { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 1.5rem; padding: 1rem; overflow-y: auto; }
.journal-col h2 { border-bottom: 1px solid var(--line); padding-bottom: 0.3rem; }
.chronicle-entry, .codex-entry { margin-bottom: 0.9rem; }
.provenance { color: var(--ink-dim); font-size: 0.75rem; font-family: 'Gill Sans', 'Trebuchet MS', sans-serif; }
.codex-entry h3 { margin: 0.4rem 0 0.2rem; }
.codex-meta { font-size: 0.75rem; color: var(--ink-dim); font-weight: 400; }
.codex-entry ul { margin: 0.2rem 0; padding-left: 1.1rem; }
.journal-thread { margin-bottom: 0.5rem; }
@media (max-width: 960px) { .journal { grid-template-columns: 1fr; } }

/* ---------- opening scene (Ceremony 0) ---------- */
.opening-scene {
  background: var(--bg-raised); border: 1px solid var(--accent); border-radius: 6px;
  padding: 0.9rem 1.1rem; margin-bottom: 0.9rem; text-align: left;
}
.opening-title { margin: 0 0 0.5rem; font-size: 1rem; letter-spacing: 0.2em; color: var(--accent); text-transform: uppercase; }
.opening-narrative { font-size: 0.95rem; }
.suggested-actions { margin-top: 0.8rem; display: flex; flex-direction: column; gap: 0.4rem; }
.suggested-actions .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-dim); }
.action-chip {
  text-align: left; font-family: Georgia, 'Times New Roman', serif; font-size: 0.9rem;
  background: var(--bg-inset); border: 1px dashed var(--line); border-radius: 6px;
  padding: 0.45rem 0.7rem; line-height: 1.4;
}
.action-chip:hover { border-color: var(--accent); border-style: solid; }
.action-chip .skill-chip { margin: 0 0.4rem 0 0; border-color: var(--accent); color: var(--accent); }

/* action character counter */
.char-counter {
  text-align: right; font-size: 0.75rem; color: var(--ink-dim);
  font-family: 'Gill Sans', 'Trebuchet MS', Verdana, sans-serif;
  margin-top: 0.15rem;
}
.char-counter.near-cap { color: var(--warn); font-weight: 700; }

/* crew-consent envelope */
.pending-crew {
  background: color-mix(in srgb, var(--warn) 12%, var(--bg-raised));
  border: 1px dashed var(--warn); border-radius: 6px;
  padding: 0.5rem 0.8rem; margin-bottom: 0.6rem; text-align: left;
}
.pending-crew .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-dim); }
.pending-crew-row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin: 0.35rem 0; font-size: 0.9rem; }

/* processing indicator */
.processing-dot {
  display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%;
  background: var(--accent); margin-right: 0.35rem; animation: qr-pulse 1.2s ease-in-out infinite;
}
@keyframes qr-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ---------- form validation surfacing ---------- */
.field-error {
  display: block; color: var(--danger); font-size: 0.85rem; margin-top: 0.2rem;
  font-family: 'Gill Sans', 'Trebuchet MS', Verdana, sans-serif;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:hover { border-color: var(--line); }

/* ---------- wizard steppers + pronoun chips ---------- */
.stepper { display: inline-flex; align-items: center; gap: 0.2rem; }
.stepper input {
  width: 2.4rem; text-align: center; padding: 0.3rem 0.1rem;
  -moz-appearance: textfield; appearance: textfield; caret-color: transparent;
}
.stepper button {
  min-width: 2.2rem; min-height: 2.2rem; padding: 0; line-height: 1;
  font-size: 1.1rem; font-weight: 700;
}
.skill-row { grid-template-columns: 1fr 1.6rem auto 3.2rem; }
.stat-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin: 0.4rem 0; }
.chip-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.3rem 0; }
.chip { display: inline-flex; margin: 0; position: relative; }
.chip input {
  position: absolute; inset: 0; opacity: 0; margin: 0;
  width: 100%; height: 100%; pointer-events: none;
}
.chip span {
  border: 1px solid var(--line); border-radius: 14px; padding: 0.3rem 0.85rem;
  font-size: 0.9rem; cursor: pointer; color: var(--ink); background: var(--bg-inset);
}
.chip:has(input:checked) span { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.pronoun-field > .label { display: block; margin-top: 0.6rem; color: var(--ink-dim); font-family: 'Gill Sans', 'Trebuchet MS', Verdana, sans-serif; }
#pronouns-custom { max-width: 12rem; }

/* ---------- collapsible side sections (panel architecture) ---------- */
details.side-block { margin: 0 0 0.9rem; }
details.side-block summary {
  list-style: none; cursor: pointer; border-bottom: 1px solid var(--line);
  padding-bottom: 0.25rem; display: flex; align-items: baseline; justify-content: space-between;
}
details.side-block summary::-webkit-details-marker { display: none; }
details.side-block summary::after { content: "+"; color: var(--ink-dim); font-size: 0.8rem; }
details.side-block[open] summary::after { content: "–"; }
details.side-block summary h3 { margin: 0; border: none; padding: 0; }

/* ---------- mobile bottom bar + sheets ---------- */
.bottom-bar { display: none; }

/* reading mode: single column, bottom bar, side panels as bottom sheets */
@media (max-width: 960px) {
  .game-shell { height: auto; min-height: 100vh; padding-bottom: 64px; }
  .tri-panel, .game-shell.solo .tri-panel { display: flex; flex-direction: column; }
  .panel { overflow: visible; min-height: auto; }
  .panel-round { border: none; border-bottom: 1px solid var(--line); order: -1; }
  .log-columns { grid-template-columns: 1fr; }
  .beat-indicator { position: relative; z-index: 1; }
  button { min-height: 2.4rem; }  /* no mid-letter clipping on small screens */

  .bottom-bar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--bg-raised); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-bar button {
    flex: 1; border: none; border-radius: 0; background: none; padding: 0.8rem 0.2rem;
    font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-dim);
  }
  .bottom-bar button.bar-active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

  /* Crew & Gear sheet: .log-side leaves the flow and slides up over content.
     Open state lives on <body> so poll re-renders can't close it. */
  .log-side {
    position: fixed; left: 0; right: 0; bottom: 56px; top: 18%; z-index: 30;
    background: var(--bg-raised); border-top: 2px solid var(--accent);
    border-radius: 10px 10px 0 0; padding: 1rem 1rem 2rem; overflow-y: auto;
    transform: translateY(110%); visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  body.sheet-side-open .log-side { transform: none; visibility: visible; }

  .panel-chat {
    position: fixed; left: 0; right: 0; bottom: 56px; top: 18%; z-index: 30;
    background: var(--bg-raised); border-top: 2px solid var(--accent);
    border-radius: 10px 10px 0 0; padding: 1rem; overflow-y: auto;
    transform: translateY(110%); visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  body.sheet-chat-open .panel-chat { transform: none; visibility: visible; }
}

@media (min-width: 961px) {
  /* Desktop keeps the adaptive tri-panel; sheets never engage. */
  .log-side, .panel-chat { transform: none; visibility: visible; }
}
