:root {
  --bg: #161325;
  --panel: #262040;
  --text: #f4f3f8;
  --muted: #aaa3c4;
  --purple: #675887;
  --brand: #12a19a;
  --brand-dark: #0b6b66;
  --chance: #1c8a4b;
  --disaster: #b3261e;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.screen {
  display: none;
  position: fixed;
  inset: 0;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen.active { display: flex; }

/* ---------- Setup ---------- */

.setup {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3vmin;
  overflow-y: auto;
}
.logo { width: min(60vw, 420px); height: auto; }
.setup h1 { margin: 0; font-size: clamp(26px, 5vmin, 48px); color: var(--brand); }
.step { margin: 2vmin 0 0; font-size: clamp(20px, 4vmin, 36px); font-weight: 700; color: var(--muted); }
.step .chance { color: #4fd487; }
.step .disaster { color: #ff6b5f; }

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3vmin;
  width: min(100%, 1000px);
}
@media (orientation: landscape) { #nations { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.type-btn, .nation {
  border-radius: 22px;
  font-weight: 900;
  box-shadow: 0 6px 0 rgb(0 0 0 / .4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1vmin;
}
.type-btn:active, .nation:active { transform: translateY(4px); box-shadow: 0 2px 0 rgb(0 0 0 / .4); }

.type-btn {
  min-height: clamp(140px, 30vmin, 280px);
  font-size: clamp(30px, 6.5vmin, 60px);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.type-btn span { font-size: 1.3em; line-height: 1; }
.type-btn.chance { background: var(--chance); }
.type-btn.disaster { background: var(--disaster); }

.nation {
  background: var(--c);
  min-height: clamp(110px, 24vmin, 220px);
  font-size: clamp(36px, 8vmin, 72px);
}
.nation small { font-size: .38em; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; opacity: .9; }

.link { background: none; color: var(--muted); font-size: clamp(18px, 3vmin, 26px); font-weight: 700; padding: 12px 24px; }

.error { color: #ff8a80; font-weight: 700; text-align: center; }

/* ---------- Spin ---------- */

#spin { flex-direction: column; align-items: center; }

#type-banner {
  padding: 1.5vmin 6vmin;
  border-radius: 999px;
  font-size: clamp(30px, 7vmin, 64px);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .06em;
  box-shadow: 0 5px 0 rgb(0 0 0 / .4);
}
#type-banner.chance { background: var(--chance); }
#type-banner.disaster { background: var(--disaster); }

.stage {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vmin;
  min-height: 0;
}
@media (orientation: landscape) { .stage { flex-direction: row; gap: 6vw; } }

.wheel-wrap {
  position: relative;
  width: min(78vmin, 92vw);
  aspect-ratio: 1;
}
@media (orientation: landscape) { .wheel-wrap { width: min(74vh, 60vw); } }
@media (orientation: portrait) { .wheel-wrap { width: min(92vw, 62vh); } }

#wheel {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  box-shadow: 0 10px 40px rgb(0 0 0 / .55);
  will-change: transform;
}

.pointer {
  position: absolute;
  top: -3%;
  left: 50%;
  translate: -50% 0;
  width: 10vmin;
  height: 9vmin;
  background: #fff; /* white outline so it shows on green and red wheels */
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  filter: drop-shadow(0 3px 3px rgb(0 0 0 / .6));
  z-index: 2;
}
.pointer::after {
  content: '';
  position: absolute;
  inset: .9vmin 1.6vmin 1.9vmin;
  background: var(--brand);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.big {
  background: var(--brand);
  color: #fff;
  font-weight: 900;
  font-size: clamp(26px, 6vmin, 52px);
  padding: 3vmin 7vmin;
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--brand-dark);
  white-space: nowrap;
}
.big:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--brand-dark); }
.big:disabled { opacity: .35; }

.corner {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--panel);
  font-size: 24px;
  opacity: .5;
}
.corner.left { left: max(16px, env(safe-area-inset-left)); }
.corner.right { right: max(16px, env(safe-area-inset-right)); }

/* Hold-progress ring on the admin button */
#admin-btn .ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(var(--brand) calc(var(--p, 0) * 1turn), transparent 0);
  mask: radial-gradient(circle, transparent 58%, #000 60%);
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 60%);
}
#admin-btn.holding { opacity: 1; }
#admin-btn.holding .ring { animation: fill var(--hold) linear forwards; }
@property --p { syntax: '<number>'; inherits: false; initial-value: 0; }
@keyframes fill { to { --p: 1; } }

/* ---------- Reveal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgb(0 0 0 / .8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vmin;
  padding: 16px;
}
.overlay[hidden] { display: none; }

#card {
  width: min(92vw, 900px);
  max-height: 78vh;
  overflow: hidden;
  border-radius: 28px;
  padding: 5vmin 6vmin;
  text-align: center;
  background: #fff;
  color: #111;
  border: 1.6vmin solid;
  animation: pop .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
#card.chance { border-color: var(--chance); }
#card.disaster { border-color: var(--disaster); }

.card-type {
  display: inline-block;
  padding: 1vmin 4vmin;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: clamp(18px, 4vmin, 36px);
}
#card.chance .card-type { background: var(--chance); }
#card.disaster .card-type { background: var(--disaster); }

.card-title { margin: 3vmin 0 1vmin; font-size: clamp(30px, 7.5vmin, 76px); line-height: 1.05; }
.card-text { margin: 2vmin 0; font-size: clamp(22px, 5vmin, 48px); line-height: 1.25; }
.card-effect {
  margin: 3vmin 0 0;
  font-size: clamp(22px, 5.2vmin, 50px);
  font-weight: 900;
  padding: 2vmin;
  border-radius: 14px;
  background: #f1f1f1;
}

.reveal-actions { display: flex; gap: 3vmin; }
.reveal-actions button {
  padding: 2.5vmin 6vmin;
  border-radius: 999px;
  font-size: clamp(18px, 3.6vmin, 32px);
  font-weight: 800;
  background: var(--panel);
}
.reveal-actions .primary { background: var(--brand); color: #fff; }

@keyframes pop { from { transform: scale(.4); opacity: 0; } }

@media (prefers-reduced-motion: reduce) { #card { animation: none; } }

/* ---------- Join, login, dashboard ---------- */

.panel {
  background: var(--panel);
  border-radius: 20px;
  padding: clamp(16px, 3vmin, 28px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 900px);
}
.panel.narrow { width: min(100%, 460px); }
.panel h2 { margin: 0; font-size: clamp(20px, 3.4vmin, 30px); }
.panel label { font-weight: 700; color: var(--muted); font-size: 16px; }
.panel .big { align-self: stretch; margin-top: 6px; font-size: clamp(22px, 4vmin, 34px); padding: 14px; }
.muted { color: var(--muted); margin: 0; }

input {
  font: inherit;
  font-size: 20px;
  color: var(--text);
  background: var(--bg);
  border: 2px solid #3a335a;
  border-radius: 12px;
  padding: 12px 14px;
  width: 100%;
  -webkit-user-select: text;
  user-select: text;
  color-scheme: dark;
}
input:focus { outline: none; border-color: var(--brand); }

.code-input {
  font-size: clamp(36px, 8vmin, 60px);
  font-weight: 900;
  letter-spacing: .3em;
  text-align: center;
  padding: 10px 0 10px .3em;
}

.school-name { margin: 0; font-size: clamp(18px, 3vmin, 26px); font-weight: 700; }

.dash {
  flex-direction: column;
  align-items: center;
  gap: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.dash-head { display: flex; align-items: center; justify-content: space-between; width: min(100%, 900px); }
.logo.small { width: min(45vw, 240px); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1 1 260px; }

#active-games { display: contents; }
.game-live {
  border: 3px solid var(--brand);
}





.secondary {
  background: #3a335a;
  border-radius: 999px;
  padding: 12px 22px;
  font-weight: 800;
  font-size: 18px;
}
.secondary.danger { background: #5a2330; }

.badge {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 3px 10px;
  border-radius: 999px;
}

table { width: 100%; border-collapse: collapse; font-size: 17px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #3a335a; }
th { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .05em; }
td:first-child { white-space: nowrap; }

/* ---------- Admin area ---------- */

.who { display: flex; align-items: center; gap: 4px; }
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(100%, 900px);
  background: var(--panel);
  padding: 6px;
  border-radius: 999px;
}
.admin-nav button {
  flex: 1 1 auto;
  padding: 12px 16px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 17px;
}
.admin-nav button[aria-current="true"] { background: var(--brand); color: #fff; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 18px; width: 100%; }
.tab[hidden] { display: none; }
.tab > * { width: min(100%, 900px); }

.cards-heading { margin: 12px 0 0; font-size: 20px; }
.cards-heading.chance { color: #4fd487; }
.cards-heading.disaster { color: #ff6b5f; }
table.cards td { vertical-align: top; }
.tick { text-align: center; width: 70px; font-weight: 900; color: var(--brand); }
tr.never { opacity: .45; }

#rejoin-list { display: flex; flex-direction: column; gap: 10px; }
.rejoin-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; white-space: normal; font-size: clamp(22px, 4vmin, 32px); padding: 14px 20px; }
.rejoin-btn small { font-size: 15px; font-weight: 700; opacity: .9; }

/* ---------- v2: shared bits ---------- */

#offline {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: #b3261e; color: #fff; text-align: center; font-weight: 800;
  padding: 6px 12px; font-size: 15px;
}
.small { font-size: 15px; padding: 8px 14px; }
.small-note { font-size: 14px; }
.danger-text { color: #ff8a80; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel h3 { margin: 8px 0 0; font-size: 16px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
select {
  font: inherit; font-size: 18px; color: var(--text); background: var(--bg);
  border: 2px solid #3a335a; border-radius: 12px; padding: 11px 12px; width: 100%;
}
.file-btn { cursor: pointer; display: inline-block; }
input.saved { border-color: #4fd487; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em; font-weight: 900; }

/* Nation buttons: more than four nations wrap into three columns */
@media (orientation: landscape) { #nations.many { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
#nations .nation { font-size: clamp(24px, 5vmin, 48px); padding: 0 10px; }

/* Reveal: who drew it, and send buttons */
.card-nation { margin: 2vmin 0 0; font-size: clamp(18px, 3.4vmin, 30px); font-weight: 800; color: #555; }
.send-actions { display: flex; gap: 3vmin; flex-wrap: wrap; justify-content: center; }
.send-actions .send {
  padding: 2.4vmin 5vmin; border-radius: 999px; font-weight: 900;
  font-size: clamp(18px, 3.6vmin, 30px); background: #fff; color: #111;
  box-shadow: 0 5px 0 rgb(0 0 0 / .35);
}
.send-actions .send.sent { background: #4fd487; color: #0b3a20; box-shadow: none; }

/* ---------- Admin: live games ---------- */

.open-screens { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 640px) { .open-screens { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.open-screens .big { font-size: clamp(18px, 3vmin, 24px); padding: 12px 8px; }
.codes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .codes { grid-template-columns: 1fr; } }
.code-card {
  background: var(--bg); border-radius: 14px; padding: 12px;
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "role role" "qr code" "actions actions";
  gap: 6px 12px; align-items: center;
}
.code-role { grid-area: role; font-weight: 800; color: var(--muted); }
.code-card .code { grid-area: code; font-size: clamp(24px, 4vmin, 32px); color: var(--brand); }
.code-card > .muted { grid-column: 1 / -1; }
.code-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.code-actions .link { padding: 4px 0; font-size: 15px; }
.qr-thumb { grid-area: qr; width: 72px; height: 72px; background: #fff; border-radius: 8px; padding: 0; }
.qr-thumb span, .qr-thumb svg { display: block; width: 100%; height: 100%; }
.qr-big { width: min(80vw, 70vh); aspect-ratio: 1; background: #fff; border-radius: 16px; }
.qr-big svg { width: 100%; height: 100%; display: block; }
.qr-caption { text-align: center; font-size: 20px; margin: 0; line-height: 1.5; }
.qr-caption .code { font-size: 40px; color: var(--brand); }

.nations-editor { display: flex; flex-direction: column; gap: 8px; }
.nation-row { display: grid; grid-template-columns: 14px 1fr minmax(150px, 220px) auto; gap: 8px; align-items: center; }
.nation-row input, .nation-row select { padding: 9px 10px; font-size: 17px; }
.swatch { width: 14px; height: 36px; border-radius: 4px; background: var(--c); }
.nations-editor > .secondary { align-self: flex-start; }
.row-actions { white-space: nowrap; }
.row-actions .link { padding: 4px 6px; font-size: 15px; }

/* Cards editor */
table.cards input { padding: 6px 8px; font-size: 16px; border-radius: 8px; }
table.cards .card-in { margin: 2px 0; }
table.cards .card-in.title { font-weight: 800; }
table.cards td.w input { width: 64px; text-align: center; }
th.w, td.w { text-align: center; width: 72px; }

/* GDP bands editor */
.band-row { display: grid; grid-template-columns: 1fr 110px 130px 44px; gap: 8px; align-items: center; margin-bottom: 8px; }
.band-head { color: var(--muted); font-weight: 800; font-size: 14px; text-transform: uppercase; margin-bottom: 0; }
.band-row input { padding: 9px 10px; font-size: 17px; }
.warnings { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; color: #ffcf7a; }
.warnings .ok { color: #4fd487; }
.grow-btn { flex: 1 1 200px; }

/* ---------- Volunteer screens (Market, Dead Pool) — mobile first ---------- */

.vol { flex-direction: column; gap: 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; align-items: stretch; }
.vol > * { width: min(100%, 760px); margin-inline: auto; }
.vol-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.vol-head h1 { margin: 0; font-size: clamp(26px, 6vw, 40px); color: var(--brand); display: flex; align-items: center; gap: 10px; }
.vol-school { margin: 2px 0 0; }
.vol-code { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.vol-code strong { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 22px; letter-spacing: .1em; }
.count-badge { background: #ff6b5f; color: #fff; font-size: 18px; min-width: 32px; height: 32px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chips button { flex: none; padding: 10px 16px; border-radius: 999px; background: var(--panel); color: var(--muted); font-weight: 800; font-size: 16px; }
.chips button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.list { display: flex; flex-direction: column; gap: 10px; }
.list-heading { margin: 10px 0 0; font-size: 16px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.item {
  background: var(--panel); border-radius: 16px; padding: 14px;
  display: flex; gap: 14px; align-items: center; -webkit-user-select: none; user-select: none;
}
.item input[type=checkbox] { width: 34px; height: 34px; flex: none; accent-color: var(--brand); }
.item-text { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.item-text strong { font-size: 19px; }
.item-effect { font-size: 17px; }
.item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-time { margin-left: auto; font-size: 14px; }
.item-type { font-size: 13px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.item-type.chance { color: #4fd487; }
.item-type.disaster { color: #ff6b5f; }
.nation-tag { background: var(--c); color: #fff; font-weight: 900; padding: 3px 10px; border-radius: 999px; font-size: 15px; }
.item.is-done, .done .item { opacity: .45; }
.empty { text-align: center; padding: 20px 0; }

.dp-settings { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel); border-radius: 16px; padding: 10px 14px; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; background: #3a335a; font-size: 24px; font-weight: 900; }
.stepper strong { font-size: 24px; min-width: 28px; text-align: center; }
.dp-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.countdown { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; color: var(--brand); }
.small-big { font-size: 18px !important; padding: 10px 18px !important; box-shadow: 0 4px 0 var(--brand-dark) !important; }
.item.time-up { background: #5a1f1a; animation: pulse 1s ease-in-out infinite alternate; }
.item.time-up .countdown { color: #fff; font-size: 22px; }
@keyframes pulse { to { background: #8a2a22; } }

/* ---------- GDP ---------- */

.gdp-title { margin: 0; font-size: clamp(24px, 4vmin, 34px); color: var(--brand); }
.gdp-preview { margin: 0; font-size: 22px; min-height: 1.4em; }
.band { display: inline-block; background: #3a335a; padding: 2px 10px; border-radius: 999px; font-weight: 800; }

.game-live h2 { margin: 6px 0 2px; }
.game-live .panel-head .secondary { flex: none; }
@media (max-width: 560px) {
  .nation-row { grid-template-columns: 14px 1fr auto; grid-template-areas: "sw name del" "sw grp del"; }
  .nation-row .swatch { grid-area: sw; height: 100%; }
  .nation-row input { grid-area: name; }
  .nation-row select { grid-area: grp; }
  .nation-row button { grid-area: del; }
  .band-row { grid-template-columns: 1fr 70px 90px 40px; }
}

/* Wheel: back to the nation chooser */
.corner-pill {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  background: var(--panel);
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 800;
  font-size: 18px;
}

/* GDP: one row per nation */
#gdp-table input { padding: 8px 10px; font-size: 18px; max-width: 130px; }
#gdp-table td { vertical-align: middle; }
.gdp-val { font-weight: 900; font-size: 18px; }
.gdp-rank { font-weight: 900; font-size: 20px; color: var(--brand); text-align: center; }
tr.saved-row td { background: rgb(79 212 135 / .12); }
@media (max-width: 640px) {
  #gdp-table input { max-width: 72px; padding: 6px; }
  #gdp-table th, #gdp-table td { padding: 8px 4px; }
}

.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.badge.ended { background: #5a2330; color: #fff; }
