/* WikiBattle — hand-rolled styles, no framework. */

:root {
  --paper: #f7f3ec;
  --paper-2: #fffdf9;
  --ink: #1f1d1a;
  --ink-2: #5b564e;
  --ink-3: #8e877c;
  --line: #e3dccf;
  --line-2: #cfc6b5;
  --accent: #b8412a;
  --accent-ink: #fff;
  --accent-soft: #f6e3dd;
  --teal: #2b6f6a;
  --teal-soft: #dcecea;
  --gold: #c9971c;
  --gold-soft: #fbf0cf;
  --danger: #a12d2d;
  --radius: 12px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(31, 29, 26, .06), 0 8px 24px -12px rgba(31, 29, 26, .25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
body.has-overlay { overflow: hidden; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
a { color: var(--teal); }
button { font: inherit; }
[hidden] { display: none !important; }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 243, 236, .9);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-family: var(--serif); font-size: 22px; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand span { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.chip {
  border: 1px solid var(--line-2); background: var(--paper-2); color: var(--ink-2);
  border-radius: 999px; padding: 4px 12px; font-family: var(--mono); font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); box-shadow: 0 0 0 3px rgba(142,135,124,.2); }
.conn-dot.online { background: #3c9a5f; box-shadow: 0 0 0 3px rgba(60,154,95,.2); }

/* ---- shared ------------------------------------------------------------ */
#app { min-height: calc(100% - var(--topbar-h)); }
.view { padding: 24px 20px 48px; max-width: 1240px; margin: 0 auto; }
.card {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 11.5px; color: var(--ink-3); margin: 0 0 6px; font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.error { color: var(--danger); background: #fbe9e9; border: 1px solid #f1c9c9; border-radius: var(--radius-sm); padding: 8px 12px; margin: 12px 0 0; font-size: 14px; }
.hint { color: var(--ink-3); font-size: 12.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--paper-2); color: var(--ink); cursor: pointer; font-weight: 600;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover:not(:disabled) { background: #f1ece2; border-color: var(--ink-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #a3381f; border-color: #a3381f; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: rgba(31,29,26,.06); border-color: transparent; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.btn-block { width: 100%; }

.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); font: inherit;
}
.input:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
.input-code { font-family: var(--mono); letter-spacing: .25em; text-transform: uppercase; text-align: center; font-size: 18px; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--ink-2); }

/* ---- landing ------------------------------------------------------------ */
.view-landing { max-width: 420px; padding-top: 56px; }
.tagline { color: var(--ink-2); text-align: center; margin: 0 0 20px; }
.landing-card { display: flex; flex-direction: column; gap: 12px; }
.join-row { display: grid; grid-template-columns: 1fr 88px 88px; gap: 8px; }
.join-row .input { margin: 0; }

/* ---- lobby -------------------------------------------------------------- */
.view-lobby { max-width: 520px; }
.lobby-card { text-align: center; display: flex; flex-direction: column; gap: 10px; }
.lobby-card p { margin: 0; }
.code-display { font-family: var(--mono); font-size: clamp(40px, 10vw, 64px); letter-spacing: .28em; padding-left: .28em; font-weight: 700; margin: 4px 0 8px; }
.share-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 10px 0 20px; }
.share-row .input { font-family: var(--mono); font-size: 13px; }
.waiting { color: var(--ink-2); margin: 0 0 18px; }
.dots::after { content: "…"; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ---- game --------------------------------------------------------------- */
.view-game { padding-top: 14px; padding-bottom: 20px; }
.game-status {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px;
  padding: 0 4px 12px; color: var(--ink-2); font-size: 14px;
}
.status-round { font-family: var(--serif); font-size: 17px; color: var(--ink); }
.status-vs { color: var(--ink-3); }
.status-you strong { color: var(--ink); }
.status-opp strong { color: var(--teal); }
.status-opp.ready strong::after { content: " ✓"; color: #3c9a5f; }
.status-detail { color: var(--ink-3); margin-left: 6px; font-style: italic; }
.status-detail::before { content: "· "; }

.game-grid {
  display: grid; grid-template-columns: minmax(320px, 5fr) minmax(360px, 7fr); gap: 16px;
  height: calc(100vh - var(--topbar-h) - 74px); min-height: 480px;
}
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.panel-header h2 { font-size: 18px; }

/* articles */
.articles { overflow-y: auto; padding: 16px 18px 24px; scroll-behavior: smooth; }
.article { margin-bottom: 22px; }
.article-header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.article-index { width: 22px; height: 22px; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.article-title { font-family: var(--serif); font-size: 18px; font-weight: 600; color: var(--ink); text-decoration: none; }
.article-title:hover { color: var(--teal); text-decoration: underline; }
.article-body { margin: 0; line-height: 1.85; font-size: 15px; color: var(--ink); }
.word {
  cursor: pointer; border-radius: 4px; padding: 1px 2px; margin: 0 -2px;
  transition: background .08s, color .08s;
}
.word:hover, .word:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.word:active { background: var(--accent); color: var(--accent-ink); }

/* character sheet */
.sheet { overflow-y: auto; padding: 16px 18px 8px; display: flex; flex-direction: column; gap: 10px; }
.field {
  border: 1.5px dashed var(--line-2); border-radius: var(--radius-sm); padding: 10px 12px;
  cursor: pointer; background: #fff; transition: border-color .12s, box-shadow .12s;
}
.field:hover { border-color: var(--ink-3); }
.field.active { border-style: solid; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.locked { cursor: default; background: var(--paper); }
.field.full .field-count { color: var(--accent); font-weight: 700; }
.field.shake { animation: shake .3s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.field-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.field-key { width: 18px; height: 18px; border-radius: 4px; background: var(--paper); border: 1px solid var(--line-2); color: var(--ink-3); font-family: var(--mono); font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
.field.active .field-key { background: var(--accent); border-color: var(--accent); color: #fff; }
.field-label { font-weight: 600; color: var(--ink); margin: 0; font-size: 13px; }
.req { color: var(--ink-3); font-weight: 400; font-size: 12px; }
.field-count { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.tokens { display: flex; flex-wrap: wrap; gap: 5px; min-height: 30px; align-items: center; }
.token {
  border: 1px solid var(--line-2); background: var(--paper); color: var(--ink); border-radius: 6px;
  padding: 3px 9px; font-size: 14px; cursor: pointer; line-height: 1.4;
}
.token:hover:not(:disabled) { background: #fbe9e9; border-color: var(--danger); color: var(--danger); text-decoration: line-through; }
.token:disabled { cursor: default; opacity: .9; }
.sheet-footer { padding: 10px 18px 16px; border-top: 1px solid var(--line); margin-top: auto; }
.sheet-footer .error { margin: 0 0 10px; }
.sheet-footer .muted { margin: 8px 0 0; text-align: center; min-height: 1.2em; }

/* ---- overlays ----------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  background: rgba(31, 29, 26, .55); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 40px;
}
.judging { text-align: center; max-width: 420px; margin-top: 18vh; }
.judging h2 { margin: 14px 0 0; font-size: 22px; }
.spinner { width: 38px; height: 38px; border-radius: 50%; margin: 0 auto; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result { max-width: 760px; width: 100%; padding: 28px 30px 24px; animation: rise .35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.result h2 { font-size: clamp(24px, 4vw, 34px); line-height: 1.15; }
.result-winner { font-size: 17px; margin: 8px 0 18px; font-weight: 600; }
.result-winner.won { color: #2e7d4c; }
.result-winner.lost { color: var(--ink-2); }
.story { font-family: var(--serif); font-size: 17.5px; line-height: 1.6; border-left: 3px solid var(--accent); padding-left: 16px; margin: 0 0 22px; }
.story p { margin: 0 0 12px; }
.story p:last-child { margin-bottom: 0; }
.result-sheets { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.result-sheet { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; background: var(--paper); }
.result-sheet.winner { border-color: var(--gold); background: var(--gold-soft); }
.result-sheet-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.crown { color: #8a6412; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 11px; }
.result-sheet-name { font-size: 20px; margin: 4px 0 8px; }
.result-sheet dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 14px; }
.result-sheet dt { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding-top: 2px; }
.result-sheet dd { margin: 0; }
.result-sources { font-size: 12.5px; color: var(--ink-3); margin: 10px 0 0; }
.scoreboard { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 15px; margin-bottom: 18px; flex-wrap: wrap; }
.score-side { display: inline-flex; align-items: center; gap: 8px; }
.score-n { font-family: var(--mono); font-size: 22px; font-weight: 700; }
.score-sep { color: var(--ink-3); }
.score-rounds { width: 100%; text-align: center; color: var(--ink-3); font-size: 13px; }
.result-actions { display: flex; justify-content: center; gap: 10px; }
.result .muted { text-align: center; margin: 10px 0 0; }

/* ---- toast -------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.5); animation: rise .25s ease-out; max-width: calc(100% - 32px);
}

/* ---- responsive --------------------------------------------------------- */
@media (max-width: 860px) {
  .game-grid { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .panel-sheet { position: sticky; top: calc(var(--topbar-h) + 4px); z-index: 4; max-height: 52vh; }
  .sheet { padding: 10px 14px 6px; gap: 8px; }
  .panel-articles { min-height: 60vh; }
  .articles { overflow: visible; }
  .result-sheets { grid-template-columns: 1fr; }
  .hint { display: none; }
  .join-row { grid-template-columns: 1fr 96px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- landing options ----------------------------------------------------- */
.options { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.option-check { cursor: pointer; font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.option-check input { margin: 0; accent-color: var(--accent); }
.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: 999px; padding: 2px; background: #fff; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented span { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.segmented input:checked + span { background: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 1px; }
.center { text-align: center; }

/* ---- draft picking ------------------------------------------------------- */
.view-picking { padding-top: 14px; }
.picking-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 4px 12px; }
.picking-head h2 { font-size: 22px; }
.pool { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.pool-card {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px;
  background: var(--paper-2); border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: transform .08s, border-color .12s, box-shadow .12s;
}
.pool-card.pickable { cursor: pointer; }
.pool-card.pickable:hover, .pool-card.pickable:focus-visible { border-color: var(--accent); transform: translateY(-2px); outline: none; box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.pool-card.taken { opacity: .6; background: var(--paper); }
.pool-card.taken.mine { opacity: 1; border-color: var(--accent); background: var(--accent-soft); }
.pool-title { font-size: 17px; margin: 0; }
.pool-blurb { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; flex: 1; }
.pool-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; margin-top: 4px; }
.pool-owner { font-weight: 700; color: var(--ink-2); }
.pool-card.mine .pool-owner { color: var(--accent); }
.pool-pick { font-weight: 700; color: var(--accent); }
.picks-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.picks-summary h4 { margin: 0 0 4px; font-size: 14px; }
.picks-summary ol { margin: 0; padding-left: 20px; font-size: 14px; color: var(--ink-2); }
.picks-summary p { grid-column: 1 / -1; margin: 0; }
.status-audience { color: var(--ink-3); }
.status-drafted { width: 100%; font-size: 13px; color: var(--ink-3); }

/* ---- spectators ---------------------------------------------------------- */
.view-spectate { max-width: 960px; }
.spectate-body h2 { font-size: 22px; margin: 6px 0 14px; }
.spectate-body .card { padding: 32px; }
.spectate-body .spinner { margin-bottom: 12px; }
.btn-vote { width: 100%; margin-top: 12px; }
.result-sheet.voted { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tally-badge { font-family: var(--mono); font-size: 12px; color: var(--ink-2); background: var(--paper-2); border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 8px; }
.voting .result-sheets { margin-top: 14px; }

/* ---- result extras ------------------------------------------------------- */
.result-image { margin: 0 0 18px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); background: var(--paper); }
.result-image img { display: block; width: 100%; max-height: 420px; object-fit: cover; }
.image-pending { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 22px; color: var(--ink-3); font-size: 14px; }
.image-pending .spinner { width: 22px; height: 22px; border-width: 3px; margin: 0; }

/* ---- async challenge ----------------------------------------------------- */
.view-challenge { max-width: 560px; }
.challenge-card h2 { font-size: 26px; margin: 4px 0 10px; }
.challenge-card .share-row { margin: 12px 0 14px; }
.challenge-card .result-actions { justify-content: flex-start; margin-top: 14px; }
.challenge-card .input { margin: 12px 0 4px; }

@media (max-width: 860px) {
  .join-row { grid-template-columns: 1fr 72px 72px; }
  .picks-summary { grid-template-columns: 1fr; }
}
