/* =========================================================================
   Peka & Packa — public styles
   Elegant, restrained, travel-publication aesthetic. Light + dark.
   ========================================================================= */

:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f0ece4;
  --ink: #1d1b18;
  --ink-soft: #55504a;
  --muted: #8a8379;
  --line: #e4ddd2;
  --brand: #1f6feb;
  --brand-ink: #0a3a8c;
  --accent: #bf6b2e;
  --ok: #2f7d54;
  --no: #b23b3b;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --radius: 14px;
  --radius-sm: 9px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #201d16;
    --surface-2: #2a251c;
    --ink: #f2ede3;
    --ink-soft: #cabfae;
    --muted: #9a9384;
    --line: #362f24;
    --brand: #6ba5ff;
    --brand-ink: #a9c8ff;
    --accent: #e0995a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
/* Ensure the [hidden] attribute always wins over display rules on .overlay,
   .players-strip, .timer, .modal, etc. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0 0 .5em; }
a { color: var(--brand-ink); }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; font-weight: 700; color: var(--accent); margin: 0 0 .4rem; }
.error { color: var(--no); font-weight: 600; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .55rem 1rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-ghost { background: transparent; }
.btn-lg { padding: .8rem 1.5rem; font-size: 1.05rem; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-danger { color: var(--no); border-color: color-mix(in srgb, var(--no) 40%, var(--line)); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .2rem; }
.stack { display: grid; gap: .9rem; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.no { background: color-mix(in srgb, var(--no) 16%, transparent); color: var(--no); }
.tag { font-size: .7rem; background: var(--surface-2); color: var(--ink-soft); padding: .08rem .45rem; border-radius: 999px; }

/* =======================================================================
   Landing
   ======================================================================= */
.landing-wrap { max-width: 960px; margin: 0 auto; padding: 3rem 1rem 4rem; }
.landing-wrap.narrow { max-width: 560px; }
.landing-hero { text-align: center; margin-bottom: 2.5rem; }
.landing-hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); letter-spacing: -.01em; }
.lede { font-size: 1.15rem; color: var(--ink-soft); max-width: 34ch; margin: .5rem auto 0; }
.landing-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 2.5rem; }
.landing-cards .card h2 { margin-bottom: .3rem; }
.join-form { display: flex; gap: .5rem; }
.join-form input { flex: 1; text-transform: uppercase; }
.landing-how { text-align: center; }
.steps { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; max-width: 820px; margin: 1rem auto 0; }
.steps li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; font-size: .92rem; text-align: left; }
.steps span { display: inline-flex; width: 1.7rem; height: 1.7rem; align-items: center; justify-content: center; border-radius: 999px; background: var(--brand); color: #fff; font-weight: 700; margin-bottom: .5rem; }
.landing-foot { text-align: center; margin-top: 3rem; color: var(--muted); font-size: .85rem; }

@media (max-width: 640px) {
  .landing-cards { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr 1fr; }
}

/* =======================================================================
   Game shell
   ======================================================================= */
.game { background: var(--bg); }
.game-app { max-width: 1040px; margin: 0 auto; min-height: 100vh; padding-bottom: 3rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); z-index: 5; }
.brand { font-family: var(--serif); font-weight: 700; text-decoration: none; color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.conn { font-size: .8rem; }
.conn-connecting { color: var(--accent); }
.conn-connected { color: var(--ok); }
.conn-disconnected { color: var(--no); }
.phase-label { font-size: .85rem; color: var(--muted); font-weight: 600; }

.players-strip { display: flex; gap: .5rem; flex-wrap: wrap; padding: .7rem 1rem; }
.player-chip { display: flex; align-items: center; gap: .4rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .3rem .7rem; font-size: .88rem; font-weight: 600; }
.player-chip .dot { width: .5rem; height: .5rem; border-radius: 999px; background: var(--ok); }
.player-chip.off .dot { background: var(--muted); }
.player-chip .host-tag { font-size: .68rem; color: var(--accent); }
.player-chip .you { font-size: .68rem; color: var(--brand-ink); }
.player-chip .ready { color: var(--ok); }

.timer { padding: .3rem 1rem .6rem; }
.timer-bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.timer-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); width: 100%; transition: width .95s linear; }
.timer-text { font-size: .8rem; color: var(--muted); }
.timer.urgent .timer-fill { background: var(--no); }

.screen-host { padding: 1rem; }
.screen { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head { text-align: center; margin-bottom: 1rem; }
.section-head h1 { font-size: 1.8rem; }

/* Setup */
.setup-grid { display: grid; gap: 1rem; }
.option-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .5rem .9rem; cursor: pointer; font-weight: 600; font-size: .9rem; }
.chip-btn.selected { background: var(--brand); color: #fff; border-color: var(--brand); }
.waiting-note { text-align: center; color: var(--muted); font-style: italic; }

/* Destination cards / voting */
.dest-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.dcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.dcard-photo { aspect-ratio: 3/2; background-size: cover; background-position: center; background-color: var(--surface-2); }
.dcard-body { padding: 1rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.dcard-title { font-family: var(--serif); font-weight: 700; font-size: 1.2rem; display: flex; align-items: center; gap: .5rem; }
.chip { font-size: .68rem; background: var(--surface-2); color: var(--ink-soft); padding: .1rem .5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: .05em; }
.dcard-desc { font-size: .92rem; color: var(--ink-soft); margin: 0; }
.dcard-meta { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .82rem; color: var(--muted); margin-top: auto; }
.dcard.selectable { cursor: pointer; transition: border-color .15s, transform .06s; }
.dcard.selectable:hover { border-color: var(--brand); }
.dcard.fav { outline: 3px solid var(--brand); }
.dcard.alt { outline: 3px dashed var(--accent); }
.vote-tags { display: flex; gap: .4rem; padding: 0 1rem 1rem; }
.pick-tag { font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; }
.pick-tag.fav { background: var(--brand); color: #fff; }
.pick-tag.alt { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }

.vote-instructions { text-align: center; color: var(--ink-soft); margin-bottom: 1rem; }
.vote-actions { display: flex; justify-content: center; gap: .8rem; margin-top: 1.2rem; }

/* Host-only destructive control (close & delete room) during preparation. */
.danger-zone { margin-top: 2rem; padding-top: 1.2rem; border-top: 1px dashed var(--line); text-align: center; }
.danger-zone .btn-danger { background: transparent; }
.danger-zone .btn-danger:hover { background: color-mix(in srgb, var(--no) 12%, transparent); }
.danger-zone p { margin: .5rem 0 0; }

/* Reveal votes */
.reveal-votes { display: grid; gap: .6rem; max-width: 560px; margin: 1rem auto; }
.reveal-vote { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .6rem .9rem; }
.tally { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.tally-item { text-align: center; }
.tally-count { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; }
.resolve-reason { text-align: center; font-size: 1.15rem; font-weight: 600; margin: 1rem auto; max-width: 40ch; }
.winner-banner { text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); max-width: 520px; margin: 1rem auto; }

/* Priorities */
.priority-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; max-width: 640px; margin: 1rem auto; }
.priority-card { text-align: center; padding: 1.2rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; transition: border-color .15s, transform .06s; }
.priority-card:hover { border-color: var(--brand); }
.priority-card.selected { outline: 3px solid var(--brand); }
.priority-emoji { font-size: 2rem; }
.priority-label { font-weight: 700; font-family: var(--serif); }

/* Build board */
.build-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.2rem; }
.board { display: grid; gap: 1rem; }
.board-day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.board-day h3, .board-day h4 { margin: 0 0 .6rem; }
.slot { border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: .6rem; margin-bottom: .5rem; min-height: 62px; transition: background .15s, border-color .15s; }
.slot:last-child { margin-bottom: 0; }
.slot-label { font-size: .78rem; color: var(--muted); font-weight: 700; margin-bottom: .3rem; }
.slot.droptarget { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent); border-style: solid; cursor: pointer; }
.slot-filled { border-style: solid; background: var(--surface-2); }
.slot-activity strong { display: block; font-size: .95rem; }
.slot-meta { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; margin-top: .25rem; }
.slot .cost { font-size: .78rem; color: var(--accent); font-weight: 700; }
.slot .by { font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.slot-span { opacity: .7; font-size: .78rem; font-style: italic; }

.palette { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; align-self: start; position: sticky; top: 70px; max-height: 78vh; overflow: auto; }
.palette h3 { margin-top: 0; }
.act-item { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .6rem; margin-bottom: .5rem; cursor: grab; background: var(--bg); }
.act-item.placed { opacity: .4; cursor: default; }
.act-item.selected { outline: 2px solid var(--brand); }
.act-item .act-title { font-weight: 700; font-size: .9rem; }
.act-item .act-meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.turn-banner { text-align: center; font-weight: 600; padding: .6rem; border-radius: var(--radius-sm); margin-bottom: .8rem; }
.turn-banner.mine { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.turn-banner.theirs { background: var(--surface-2); color: var(--ink-soft); }
.budget-meter { margin: .6rem 0; }
.budget-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.budget-fill { height: 100%; background: var(--ok); transition: width .3s; }
.budget-fill.warn { background: var(--accent); }
.budget-fill.over { background: var(--no); }
.build-controls { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }

@media (max-width: 800px) {
  .dest-cards { grid-template-columns: 1fr; }
  .build-layout { grid-template-columns: 1fr; }
  .palette { position: static; max-height: none; }
}

/* Toasts + overlay */
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 20; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: .6rem .9rem; border-radius: var(--radius-sm); font-size: .9rem; box-shadow: var(--shadow); animation: fade .2s ease; }
.toast.err { background: var(--no); color: #fff; }
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 75%, transparent); display: flex; align-items: center; justify-content: center; z-index: 30; backdrop-filter: blur(3px); }
.overlay-card { text-align: center; }
.spinner { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 999px; margin: 0 auto 1rem; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 25; background: color-mix(in srgb, var(--bg) 60%, transparent); }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; max-width: 420px; width: 92vw; box-shadow: var(--shadow); text-align: center; }
.modal-actions { display: flex; gap: .6rem; justify-content: center; margin-top: 1rem; }

/* =======================================================================
   Result page
   ======================================================================= */
.result-wrap { max-width: 860px; margin: 0 auto; padding: 0 1rem 4rem; }
.result-hero { border-radius: var(--radius); overflow: hidden; margin: 1rem 0; min-height: 260px; background-size: cover; background-position: center; background-color: var(--surface-2); display: flex; align-items: flex-end; }
.result-hero-inner { padding: 1.5rem; color: #fff; }
.result-hero h1 { font-size: clamp(2rem, 7vw, 3.2rem); color: #fff; }
.result-hero .eyebrow { color: #ffd24d; }
.hero-sub { color: rgba(255,255,255,.9); margin: 0; }
.hero-meta { display: flex; gap: .8rem 1.2rem; flex-wrap: wrap; margin-top: .5rem; color: rgba(255,255,255,.92); font-weight: 600; font-size: .9rem; }
.decision-note { text-align: center; font-size: 1.1rem; font-weight: 600; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.result-section { margin: 1.8rem 0; }
.result-section h2 { font-size: 1.4rem; border-bottom: 2px solid var(--line); padding-bottom: .3rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.board-readonly { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.cost-total { text-align: right; font-size: 1.05rem; }
.contrib-list, .priority-list, .tradeoff-list { list-style: none; padding: 0; display: grid; gap: .5rem; }
.priority-list li { display: flex; align-items: center; gap: .5rem; }
.pri-emoji { font-size: 1.2rem; }
.tradeoff-list li { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: .5rem .8rem; }

.explore-head { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; flex-wrap: wrap; }
.disclosure { font-size: .8rem; color: var(--muted); max-width: 48ch; }
.article-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; text-decoration: none; color: var(--ink); }
.article-card:hover { border-color: var(--brand); }
.article-body { display: flex; flex-direction: column; gap: .1rem; }
.article-arrow { font-size: 1.4rem; color: var(--brand); }
.offer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.offer-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.ad-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); border: 1px solid var(--line); padding: .05rem .4rem; border-radius: 4px; }
.offer-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.offer-img { width: 100%; border-radius: var(--radius-sm); margin-bottom: .5rem; }
.widget-frame { width: 100%; border: 0; border-radius: var(--radius-sm); background: #fff; }
.widget-fallback { padding: 1rem; background: var(--surface-2); border-radius: var(--radius-sm); color: var(--ink-soft); font-size: .9rem; }
.share-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.share-row input { flex: 1; min-width: 0; }
.share-actions { margin-top: .8rem; }

@media (max-width: 640px) {
  .share-row { flex-direction: column; align-items: stretch; }
  .share-row .btn { width: 100%; }
  .share-actions .btn { display: block; width: 100%; text-align: center; }
}

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---- Spectator / read-only viewer mode -------------------------------- */
.spectator-banner {
  background: #1e293b;
  color: #fff;
  text-align: center;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}
.watch-row {
  margin-top: 0.9rem;
  text-align: center;
}
.player-chip.spectators {
  background: rgba(100, 116, 139, 0.18);
  font-variant-numeric: tabular-nums;
}
