:root {
  --bg: #14151a;
  --bg-gradient: radial-gradient(ellipse at top, #262a4a 0%, #14151a 55%);
  --bg2: #24252b;
  --bg2-hover: #2d2e35;
  --card: #212227;
  --text: #f3f3f5;
  --muted: #9497a6;
  --accent: #6366f1;
  --accent-hover: #7678f4;
  --accent2: #ec4899;
  --danger: #ef4444;
  --success: #22c55e;
  --border: #34353d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

h1 {
  text-align: center;
  font-size: 1.7rem;
  margin: 0 0 4px;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  margin: 0 0 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.center { text-align: center; }

a { color: inherit; }

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, opacity .15s ease;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: var(--bg2); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--bg2-hover); }

input[type="text"], input[type="number"] {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
}

input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}

label.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 6px;
}

.field { margin-bottom: 16px; }

.error-box {
  display: none;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}
.error-box.show { display: block; }

.info-box {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.game-picker {
  display: grid;
  gap: 12px;
}

.game-card {
  display: block;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 16px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 1.05rem;
  transition: background .15s ease, border-color .15s ease;
}
.game-card:hover { background: var(--bg2-hover); border-color: var(--accent); }
.game-card small {
  display: block;
  color: var(--muted);
  font-weight: 400;
  margin-top: 4px;
  font-size: 0.82rem;
}

.room-code {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-align: center;
  color: var(--accent2);
  margin: 4px 0 2px;
}

.share-link {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  word-break: break-all;
  color: var(--muted);
  text-align: center;
}

.dot-progress {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
}
.dot-progress .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border);
}
.dot-progress .dot.active { background: var(--accent2); }
.dot-progress .dot.done { background: var(--accent); }

.item-stage { text-align: center; margin-bottom: 20px; }
.item-stage .counter { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.item-stage img {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.item-stage h2 { margin: 12px 0 4px; font-size: 1.3rem; }
.item-stage .waiting { color: var(--muted); font-size: 0.9rem; }

.rank-grid { display: grid; grid-template-columns: 34px 1fr; gap: 0; }
.rank-grid-inner { display: grid; gap: 8px; }

.grid-row { display: grid; grid-template-columns: 34px repeat(var(--cols, 1), 1fr); gap: 8px; align-items: stretch; margin-bottom: 8px; }
.rank-chip {
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 0.9rem;
}
.grid-header { display: grid; grid-template-columns: 34px repeat(var(--cols, 1), 1fr); gap: 8px; margin-bottom: 10px; }
.grid-header .col-name {
  text-align: center; font-size: 0.8rem; color: var(--muted); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.grid-header .col-name.is-you { color: var(--accent2); }

.cell {
  border-radius: 10px;
  min-height: 46px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem;
  text-align: center;
  padding: 4px;
  overflow: hidden;
}
.cell.empty {
  background: repeating-linear-gradient(135deg, var(--bg2), var(--bg2) 6px, #2a2b32 6px, #2a2b32 12px);
  color: transparent;
}
.cell.selectable {
  background: transparent;
  border: 2px dashed var(--accent);
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
}
.cell.selectable:hover { background: rgba(99, 102, 241, 0.15); }
.cell.filled { background: var(--bg2-hover); color: var(--muted); }
.cell.revealed { color: white; font-weight: 600; }
.cell.revealed.own-pending { opacity: 0.8; outline: 2px dashed rgba(255,255,255,0.5); outline-offset: -2px; }

.rank-1 { background: #ec4899; } .rank-2 { background: #f97316; }
.rank-3 { background: #eab308; } .rank-4 { background: #22c55e; }
.rank-5 { background: #3b82f6; } .rank-6 { background: #6366f1; }
.rank-7 { background: #a855f7; } .rank-8 { background: #14b8a6; }
.rank-9 { background: #ef4444; } .rank-10 { background: #f59e0b; }
.rank-11 { background: #84cc16; } .rank-12 { background: #06b6d4; }

.player-list { list-style: none; padding: 0; margin: 0; }
.player-list li {
  background: var(--bg2);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center;
}
.player-list .tag { font-size: 0.75rem; color: var(--muted); }
.player-list .status-done { color: var(--success); }
.player-list .status-fail { color: var(--danger); }

.hangman-word {
  font-size: 1.7rem;
  letter-spacing: 0.25em;
  text-align: center;
  font-weight: 700;
  margin: 18px 0;
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  margin-top: 16px;
}
.key {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 0;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
.key:hover:not(:disabled) { background: var(--bg2-hover); }
.key:disabled { opacity: 0.3; cursor: not-allowed; }
.key.correct { background: rgba(34, 197, 94, 0.25); border-color: var(--success); }
.key.wrong { background: rgba(239, 68, 68, 0.25); border-color: var(--danger); }

.lives {
  text-align: center;
  font-size: 1.3rem;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.scoreboard { list-style: none; padding: 0; margin: 0; }
.scoreboard li {
  display: flex; justify-content: space-between;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg2);
  margin-bottom: 8px;
}
.scoreboard li.first { background: rgba(236, 72, 153, 0.15); border: 1px solid var(--accent2); }
.scoreboard .pts { font-weight: 700; color: var(--accent2); }

.reveal-panel { text-align: center; margin: 16px 0; }
.reveal-panel img {
  width: 100%; max-width: 320px; border-radius: 14px; border: 1px solid var(--border);
}

.badge {
  display: inline-block;
  background: var(--accent2);
  color: white;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 700;
}
