:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --good: #22c55e;
  --bad: #ef4444;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior: none;
}
#app { max-width: 520px; margin: 0 auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
h1, h2 { font-weight: 800; }
h2 { font-size: 1.05rem; margin-bottom: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: var(--card2);
  transition: transform .05s, filter .1s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); filter: brightness(1.15); }
.btn-primary { background: var(--accent); color: #1a1206; }
.btn-secondary { background: var(--card2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-small { padding: 6px 12px; font-size: .85rem; border-radius: 8px; }
.big { width: 100%; padding: 16px; font-size: 1.15rem; }

input[type=text], select, textarea {
  width: 100%;
  background: var(--card2);
  border: none;
  border-radius: 12px;
  padding: 14px;
  color: var(--text);
  font-size: 1.05rem;
  margin-bottom: 10px;
}
input[type=text]:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); }
textarea { font-family: inherit; resize: vertical; }

/* join */
.join-box { text-align: center; margin-top: 12vh; }
.logo { font-size: 2.2rem; margin-bottom: 4px; }
.tagline { color: var(--muted); margin-bottom: 18px; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 2; min-width: 0;
  text-align: center;
  font-size: clamp(1.5rem, 6vw, 2rem);
  font-weight: 800;
  letter-spacing: .35em;
  padding: 16px 8px;
  margin-bottom: 0;
}
.join-hint { color: var(--muted); font-size: .8rem; margin-top: 8px; }
.error { color: #fca5a5; margin-top: 10px; font-weight: 600; }

/* lobby */
.room-code-wrap { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.room-code { font-size: 2.6rem; font-weight: 900; letter-spacing: .35em; color: var(--accent); font-variant-numeric: tabular-nums; }
.invite-hint { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.player-list { list-style: none; }
.player-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 6px; border-bottom: 1px solid var(--card2);
}
.player-list li:last-child { border-bottom: none; }
.player-list .host-badge { color: var(--accent); font-size: .8rem; margin-left: 6px; }
.player-list .offline { color: var(--muted); font-style: italic; font-size: .8rem; }
.score-chip { background: var(--card2); border-radius: 8px; padding: 2px 10px; font-weight: 800; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; color: var(--muted); font-size: .85rem; font-weight: 700; margin-bottom: 6px; }
.field output { float: right; font-weight: 800; color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; font-size: .95rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.mode-row, .deck-row { display: flex; flex-wrap: wrap; gap: 8px; }
.mode-btn, .deck-btn {
  border: 2px solid var(--card2);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 90px;
}
.mode-btn.active, .deck-btn.active { border-color: var(--accent); background: rgba(245,158,11,.15); }
.mode-desc { display: block; color: var(--muted); font-size: .8rem; margin-top: 6px; }
.custom-deck { margin-bottom: 14px; }
.custom-deck summary { color: var(--muted); cursor: pointer; margin-bottom: 8px; font-size: .9rem; }
.custom-deck small { color: var(--muted); }

/* game */
.screen-game-full { height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.game-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.game-timer {
  font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums;
  background: var(--card); border-radius: 12px; padding: 4px 16px;
}
.game-timer.low { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.game-meta { color: var(--muted); font-size: .9rem; text-align: right; }
.game-body { flex: 1; display: flex; flex-direction: column; gap: 12px; }

.card-view {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); border-radius: var(--radius); padding: 24px; text-align: center;
  min-height: 240px;
}
.card-view .cat-chip {
  background: var(--card2); border-radius: 999px; padding: 4px 14px;
  font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 16px;
}
.card-view .identity {
  font-size: clamp(1.8rem, 8vw, 3.2rem); font-weight: 900; line-height: 1.15;
  word-break: break-word;
}
.card-img {
  max-width: 100%; max-height: 38vh; border-radius: 12px; object-fit: contain;
  margin-bottom: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.35);
}
.card-view .hint-text { color: var(--muted); font-size: 1rem; margin-top: 16px; }

.hidden-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); border-radius: var(--radius); min-height: 240px;
}
.hidden-card .question-mark { font-size: 4.5rem; }
.hidden-card .who-label { font-size: 1.5rem; font-weight: 800; margin-bottom: 14px; color: var(--muted); }
.hint-stack { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; width: 100%; max-width: 340px; }
.hint-stack .hint-line { background: var(--card2); border-radius: 10px; padding: 12px; font-size: 1.1rem; font-weight: 600; }
.hint-line.revealed { border-left: 4px solid var(--accent); }
.hint-line.locked { color: var(--muted); opacity: .5; }

.action-row { display: flex; gap: 10px; }
.action-row .btn { flex: 1; padding: 16px; font-size: 1.1rem; }
.btn-good { background: var(--good); color: #052e16; }
.btn-bad { background: var(--bad); color: #2d0505; }
.btn-warn { background: var(--accent); color: #1a1206; }

.vote-banner { text-align: center; font-size: 1.2rem; font-weight: 700; padding: 14px; background: var(--card); border-radius: var(--radius); }
.vote-counts { display: flex; justify-content: center; gap: 24px; font-size: 1.3rem; font-weight: 800; margin-top: 8px; }
.vote-counts .yes { color: var(--good); }
.vote-counts .no { color: var(--bad); }

/* forehead mode */
.forehead-wrap { flex: 1; position: relative; display: flex; flex-direction: column; }
.forehead-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); border-radius: var(--radius); text-align: center; padding: 20px;
  min-height: 320px; position: relative;
}
.forehead-card .identity { font-size: clamp(2rem, 10vw, 3.6rem); font-weight: 900; }
.forehead-zone { position: absolute; width: 100%; height: 34%; border: none; background: transparent; }
.forehead-zone.top { top: 0; }
.forehead-zone.bottom { bottom: 0; }
.forehead-hint { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 8px; }

/* results */
.results-card { text-align: center; margin-top: 6vh; }
.winner-banner { font-size: 1.4rem; font-weight: 900; color: var(--accent); margin-bottom: 16px; }
.results-list { list-style: none; text-align: left; margin-bottom: 16px; }
.results-list li {
  display: flex; justify-content: space-between; padding: 12px 6px;
  border-bottom: 1px solid var(--card2); font-size: 1.1rem; font-weight: 600;
}
.results-list li:first-child { color: var(--accent); font-size: 1.3rem; }

/* chat */
.chat { position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 50; }
.chat-head { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.chat-panel {
  background: var(--card); border-radius: var(--radius); padding: 10px;
  width: min(320px, calc(100vw - 24px)); height: 320px; display: flex; flex-direction: column;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.chat-messages { flex: 1; overflow-y: auto; font-size: .9rem; }
.chat-messages p { padding: 4px 8px; }
.chat-messages .from { color: var(--accent); font-weight: 700; }
.chat-input-row input { margin-bottom: 0; padding: 10px; }

/* toast */
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--card2); color: var(--text); padding: 12px 20px; border-radius: 999px;
  font-weight: 700; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

@media (min-width: 700px) {
  #app { max-width: 640px; }
  .lobby-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
}
