:root {
  --paper: #efe6d2;
  --paper-2: #e4d8bd;
  --ink: #1d1a16;
  --muted: #6d6456;
  --accent: #c8321f;
  --ok: #2f7d4a;
  --card: #fbf7ee;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(0,0,0,.06), 0 2px 8px rgba(40,30,10,.10);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.35), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0,0,0,.012) 0 2px, transparent 2px 4px),
    var(--paper);
  min-height: 100dvh;
}
[hidden] { display: none !important; }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }

.title {
  font-family: "American Typewriter", "Courier New", Courier, monospace;
  font-size: 28px; letter-spacing: -.5px; margin: 8px 0 16px;
}
.title small { font-size: 14px; color: var(--muted); font-family: inherit; letter-spacing: 0; text-transform: uppercase; }
h2 { font-size: 17px; margin: 0; display: flex; align-items: center; gap: 8px; }
.hint, .muted { color: var(--muted); font-size: 14px; margin: 0; }
.error { color: var(--accent); margin: 0; font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.count { font-size: 12px; font-weight: 600; background: var(--paper-2); color: var(--muted); padding: 2px 8px; border-radius: 99px; }

label { font-weight: 600; font-size: 15px; display: flex; flex-direction: column; gap: 6px; }
input, textarea {
  font: inherit; font-size: 17px; color: var(--ink);
  background: #fff; border: 1.5px solid #cfc3a8; border-radius: 8px; padding: 12px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.45; font-size: 16px; }
input:focus, textarea:focus { outline: 3px solid rgba(200,50,31,.25); border-color: var(--accent); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-3 label { font-size: 13px; }
@media (max-width: 480px) { .grid-3 { grid-template-columns: 1fr; } }

.btn {
  font: inherit; font-weight: 700; font-size: 17px;
  min-height: 48px; padding: 0 20px; border-radius: 10px;
  border: 2px solid var(--ink); background: #fff; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .06s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 60px; font-size: 20px; width: 100%; }
.btn:disabled { opacity: .4; cursor: default; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(251,247,238,.95); backdrop-filter: blur(6px);
  border-top: 1px solid #d8ccb2;
  display: flex; gap: 8px; align-items: center; justify-content: flex-end;
}
.status { margin-right: auto; font-size: 14px; color: var(--muted); }
.status.ok { color: var(--ok); font-weight: 700; }
.status.error { color: var(--accent); font-weight: 700; }

/* ---------- tiles ---------- */
:root { --tile-font: 18px; }
.tile {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--tile-font); line-height: 1.05;
  padding: .38em .62em .42em;
  border: 0; margin: 0;
  background: #fff; color: #111;
  white-space: nowrap;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.25));
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
button.tile { cursor: pointer; min-height: 44px; font: inherit; font-size: var(--tile-font); }
button.tile:active { transform: scale(.94) !important; }
.tile.used { opacity: .18; filter: none; }
.tile-filler {
  background: #f7f3ea; color: #2a2a2a; font-weight: 600;
  border: 1px dashed #b9ae95; clip-path: none; filter: none;
}
.tile-sm { --tile-font: 17px; }
.tile-md { --tile-font: 20px; }
.tile-lg { --tile-font: 30px; }
@media (min-width: 600px) { .tile-lg { --tile-font: 40px; } }

.note {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 10px 8px; padding: 18px 14px; min-height: 96px;
  background: #fffdf8; border-radius: 4px;
  box-shadow: 0 2px 0 #e2d7bf, 0 10px 24px rgba(40,30,10,.14);
  background-image: repeating-linear-gradient(0deg, transparent 0 31px, rgba(80,110,160,.10) 31px 32px);
}
.note-lg { padding: 28px 16px; gap: 14px 10px; min-height: 40vh; }
.compose-note { min-height: 120px; }
.placeholder { color: var(--muted); font-style: italic; }

.hand { display: flex; flex-wrap: wrap; gap: 10px 8px; justify-content: center; padding: 4px 0; }
.hand.filler { gap: 6px; }
.hand.filler .tile { --tile-font: 15px; min-height: 40px; }

/* ---------- game layout ---------- */
.page-player .wrap, .page-host .wrap { padding-top: 0; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  position: sticky; top: 0; z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  background: linear-gradient(var(--paper) 75%, transparent);
  font-weight: 700;
}
.topbar .score, .pill { background: var(--ink); color: #fff; padding: 4px 12px; border-radius: 99px; font-size: 14px; }
.prompt {
  font-family: "American Typewriter", "Courier New", monospace;
  font-size: 22px; line-height: 1.3; margin: 6px 0; text-align: center;
}
.counter { text-align: center; text-transform: uppercase; letter-spacing: 1.5px; font-size: 13px; font-weight: 800; color: var(--accent); margin: 8px 0 0; }
.byline { text-align: center; font-size: 22px; font-weight: 800; margin: 8px 0; }
.center { text-align: center; align-items: center; }
h2.big { font-size: 26px; justify-content: center; margin-top: 8px; }
.big-ok { font-size: 24px; font-weight: 800; color: var(--ok); margin: 8px 0 0; }
.hero { display: flex; gap: 10px; justify-content: center; padding: 28px 0 18px; }
.hero .tile:nth-child(2) { margin-top: 14px; }
.code-input { font-size: 28px; letter-spacing: 6px; text-transform: uppercase; text-align: center; font-weight: 800; }

.timer {
  display: flex; justify-content: space-between; align-items: center;
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px;
  padding: 0 4px 6px;
}
.timer-round { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.timer.urgent .timer-text { color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(251,247,238,.96); backdrop-filter: blur(6px);
  border-top: 1px solid #d8ccb2;
}
.actionbar .btn.primary { min-width: 140px; }
.actionbar .error { position: absolute; bottom: 100%; left: 0; right: 0; background: var(--accent); color: #fff; padding: 8px 16px; font-size: 14px; }
.confirm { font-size: 14px; font-weight: 600; flex-wrap: wrap; }
.confirm .btn { min-height: 40px; padding: 0 14px; }

.scoreboard { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: rank; }
.scoreboard li {
  counter-increment: rank;
  display: flex; align-items: center; gap: 10px;
  background: var(--card); padding: 12px 14px; border-radius: 8px; box-shadow: var(--shadow);
  font-weight: 600;
}
.scoreboard li::before { content: counter(rank); font-weight: 800; color: var(--muted); width: 1.4em; }
.scoreboard li span { flex: 1; }
.scoreboard li.mine { outline: 3px solid var(--accent); }
h3 { margin: 18px 0 4px; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  background: var(--accent); color: #fff; text-align: center; font-weight: 700;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
}

/* ---------- host ---------- */
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.tiny { min-height: 36px; min-width: 40px; padding: 0; font-size: 20px; }
.url { font-weight: 800; font-size: 20px; margin: 0; word-break: break-all; }
.roomcode { font-size: 56px; font-weight: 900; letter-spacing: 10px; margin: 0; font-family: "Courier New", monospace; }
.qr svg { width: 200px; height: 200px; display: block; margin: 4px auto 0; }
.players { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; background: var(--card); padding: 10px 12px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 600; min-width: 0; }
.players .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.players li.offline .dot { background: #bbb; }
.players li.offline { opacity: .6; }
.players li.done { outline: 2px solid var(--ok); }
.players .status { color: var(--muted); font-size: 13px; }
.players li.done .status { color: var(--ok); font-weight: 800; font-size: 16px; }
.big-count { font-size: 30px; font-weight: 900; margin: 6px 0; }
.timer-inline { padding: 0; font-size: 22px; }
.secret { text-align: center; color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.btn.big-nav { min-width: 72px; min-height: 60px; font-size: 24px; }
.btn.big-nav-wide { min-height: 60px; font-size: 20px; flex: 1; max-width: 260px; }
.judges { line-height: 1.2; }
.vote-grid { display: flex; flex-direction: column; gap: 14px; }
.vote-card { all: unset; display: block; border-radius: 6px; outline: 4px solid transparent; outline-offset: 4px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.vote-card.selected { outline-color: var(--accent); }
.vote-card.selected .note { background-color: #fff6d6; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); background: var(--accent); color: #fff; padding: 12px 16px; border-radius: 10px; font-weight: 700; z-index: 30; text-align: center; }

/* compose: keep prompt + note in view while picking tiles */
.compose-head {
  position: sticky; top: 50px; z-index: 4;
  background: var(--paper); padding: 4px 0 10px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 10px 12px -10px rgba(40,30,10,.25);
}
.compose-head .note { max-height: 30vh; overflow-y: auto; align-content: flex-start; }
.compose-head .hint { font-size: 12px; }
.prompt-sm { font-size: 17px; margin: 0; }
.actionbar .btn { white-space: nowrap; }
.note { align-content: center; }
.compose-head .note { align-content: flex-start; }
