:root {
  --bg: #0f2a1d;
  --bg2: #163b29;
  --card: #fffaf0;
  --ink: #2b1d14;
  --red: #c8102e;
  --red-dark: #9b0c23;
  --gold: #f3c24d;
  --muted: #7b6a5c;
  --radius: 16px;
  --board: min(92vw, 560px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 700px at 50% -10%, #24563b 0%, var(--bg2) 40%, var(--bg) 100%) fixed;
  -webkit-tap-highlight-color: transparent;
}
main { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; padding: 28px 16px 64px; }
.loading { color: #fff; text-align: center; opacity: .7; }

h1 {
  color: #fff; text-align: center; margin: 4px 0 4px;
  font-size: clamp(28px, 7vw, 42px); letter-spacing: -0.5px;
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.sub { color: #d8ead9; text-align: center; margin: 0 0 22px; font-size: 16px; }

.panel {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 12px 30px rgba(0,0,0,.25), inset 0 0 0 3px rgba(200,16,46,.08);
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 18px; }
label { display: block; font-weight: 700; font-size: 14px; margin: 0 0 6px; }
input[type=text] {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px;
  border: 2px solid #e6dccb; border-radius: 12px; background: #fff; color: var(--ink);
}
input[type=text]:focus { outline: none; border-color: var(--red); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.field { margin-bottom: 16px; }

button {
  font: inherit; font-weight: 700; border: 0; cursor: pointer; border-radius: 12px;
  padding: 12px 18px; font-size: 16px; color: #fff; background: var(--red);
  box-shadow: 0 3px 0 var(--red-dark); transition: transform .05s, filter .15s;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--red-dark); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
button.secondary { background: #2f6b4a; box-shadow: 0 3px 0 #1d4a32; }
button.ghost { background: transparent; color: var(--red); box-shadow: none; padding: 6px 10px; font-size: 14px; }
button.big { width: 100%; padding: 15px; font-size: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; min-height: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; background: #fdeaea; color: var(--red-dark);
  border-radius: 999px; padding: 6px 6px 6px 12px; font-weight: 700; font-size: 15px;
}
.chip button { background: none; box-shadow: none; color: var(--red-dark); padding: 0 6px; font-size: 18px; line-height: 1; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

.mini-grid { display: grid; gap: 3px; width: 72px; margin-top: 10px; }
.mini-grid span { aspect-ratio: 1; border-radius: 3px; background: #c9c9c9; }
.mini-grid span.e { background: #ece6da; }
.preview { display: flex; gap: 14px; align-items: center; }

.share { display: flex; gap: 8px; align-items: stretch; margin: 6px 0 14px; }
.share input { font-size: 14px; }
.warn { background: #fff4d6; border-radius: 10px; padding: 10px 12px; font-size: 14px; color: #6b4e00; }

/* who are you */
.names { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.names button { background: #fff; color: var(--ink); box-shadow: 0 3px 0 #e2d6c2; border: 2px solid #eee2cf; }
.names button:disabled { background: #eee; color: #999; text-decoration: line-through; box-shadow: none; }

/* board */
.status {
  color: #fff; text-align: center; font-size: 18px; margin: 0 0 14px; min-height: 26px;
}
.status b { color: var(--gold); }
.board {
  width: var(--board); margin: 0 auto; display: grid; gap: 8px;
  grid-template-columns: repeat(var(--n), 1fr);
  padding: 10px; border-radius: 20px;
  background: repeating-linear-gradient(45deg, #c8102e 0 14px, #fff 14px 28px);
  box-shadow: 0 16px 40px rgba(0,0,0,.35);
}
.cell {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--card); display: grid; place-items: center; text-align: center;
  font-size: calc(var(--board) / var(--n) / 6.2); line-height: 1.1;
  user-select: none; -webkit-user-select: none;
}
.cell .prize { padding: 6%; word-break: break-word; }
.cell .prize .emoji { display: block; font-size: 1.6em; margin-bottom: .15em; }
.cell .prize b { color: var(--red); }
.cell .prize small { display: block; color: var(--muted); font-size: .7em; margin-top: .2em; }
.cell canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity .5s; }
.cell.taken { background: #6f7f75; color: #e9efe9; }
.cell.taken .prize { opacity: .85; font-size: .85em; }
.cell.locked canvas { cursor: not-allowed; filter: grayscale(.5) brightness(.85); }
.cell.winner { box-shadow: inset 0 0 0 4px var(--gold); animation: pop .5s ease; }
@keyframes pop { 40% { transform: scale(1.08); } }

.result {
  text-align: center; background: var(--card); border-radius: var(--radius); padding: 18px;
  margin: 0 auto 18px; width: var(--board); box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.result .big-name { font-size: clamp(28px, 8vw, 40px); color: var(--red); font-weight: 800; margin: 4px 0; }

.admin table { width: 100%; border-collapse: collapse; font-size: 15px; }
.admin td { padding: 8px 4px; border-bottom: 1px solid #efe5d5; }
.admin td:last-child { text-align: right; }
.pill { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: #eee; color: #666; }
.pill.joined { background: #fff1c9; color: #7a5600; }
.pill.drawn { background: #d9f2df; color: #1f6b37; }

.footer { color: #a9c7b1; text-align: center; font-size: 13px; margin-top: 24px; }
.footer a { color: #fff; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); z-index: 10;
  background: #1c1c1c; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700;
  transition: transform .25s; max-width: 90vw; text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.flake { position: absolute; top: -20px; color: #fff; opacity: .7; animation: fall linear infinite; }
@keyframes fall { to { transform: translate(var(--drift), 105vh) rotate(360deg); } }
.confetti { position: fixed; top: -30px; z-index: 20; pointer-events: none; animation: fall linear forwards; font-size: 26px; }

/* confirm dialog */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px;
  background: rgba(6, 20, 13, .6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .18s;
}
.modal-backdrop.open { opacity: 1; }
.modal {
  width: min(380px, 100%); background: var(--card); border-radius: 20px; padding: 26px 22px 20px;
  text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.4), inset 0 0 0 3px rgba(200,16,46,.1);
  transform: translateY(12px) scale(.96); transition: transform .18s;
}
.modal-backdrop.open .modal { transform: none; }
.modal-emoji { font-size: 44px; line-height: 1; margin-bottom: 8px; }
.modal h2 { margin: 0 0 8px; font-size: 24px; }
.modal h2 .hl { color: var(--red); }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 16px; line-height: 1.4; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; }
.modal-actions .ghost-btn { background: #fff; color: var(--ink); border: 2px solid #e6dccb; box-shadow: 0 3px 0 #e2d6c2; }
