* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg1: #16163a;
  --bg2: #241b4d;
  --panel: #22224d;
  --panel-2: #2c2c5e;
  --line: #3c3c78;
  --text: #f1f1fa;
  --muted: #9c9cc8;
  --accent: #ff5c8a;
  --accent-2: #ffd166;
  --good: #4ade80;
  --teal: #5eead4;
  --radius: 16px;
}

html, body { height: 100%; }

body {
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, var(--bg1), var(--bg2));
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ============ buttons & inputs ============ */

.btn {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 1.05rem;
  cursor: pointer;
  color: #fff;
  background: var(--panel-2);
  border: 1px solid var(--line);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
.btn-primary, .btn-secondary { border: none; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, #ff5c8a, #ff8c5c); box-shadow: 0 6px 20px rgba(255, 92, 138, 0.35); }
.btn-secondary { background: linear-gradient(135deg, #6366f1, #8b5cf6); box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35); }
.btn-ghost { background: transparent; border: 2px solid var(--line); color: var(--muted); box-shadow: none; }
.btn-tiny { padding: 6px 14px; font-size: 0.85rem; }

input, select {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted); font-weight: 600; }

/* ============ home ============ */

#screen-home { align-items: center; justify-content: center; padding: 24px; }

.home-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 40px 44px;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.logo {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.6rem;
  text-align: center;
  letter-spacing: 1px;
}
.logo span { color: var(--accent); }
.tagline { text-align: center; color: var(--muted); margin-bottom: 10px; }

.field-label { font-size: 0.85rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.avatar-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar-opt {
  font-size: 1.5rem;
  padding: 6px 0;
  text-align: center;
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
  user-select: none;
}
.avatar-opt:hover { transform: scale(1.15); }
.avatar-opt.selected { border-color: var(--accent); background: rgba(255, 92, 138, 0.15); }

.home-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.home-actions .btn-primary { width: 100%; padding: 14px; font-size: 1.2rem; }
.home-actions .btn-ghost { width: 100%; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 8px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.3rem;
}

.party-toggle { display: flex; align-items: center; gap: 10px; }
.party-toggle-label { font-size: 0.85rem; font-weight: 800; color: var(--muted); user-select: none; }

.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; cursor: pointer; flex-shrink: 0; }
.toggle-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
  pointer-events: none;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.toggle-switch input:checked ~ .toggle-track { background: rgba(255, 92, 138, 0.25); border-color: var(--accent); }
.toggle-switch input:checked ~ .toggle-track .toggle-thumb { transform: translateX(20px); background: var(--accent); }
.toggle-switch input:focus-visible ~ .toggle-track { box-shadow: 0 0 0 2px var(--accent); }

/* ============ browse open rooms ============ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 26, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-family: 'Fredoka', sans-serif; font-size: 1.2rem; }

.browse-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; min-height: 60px; }
.browse-empty { color: var(--muted); font-weight: 700; text-align: center; padding: 18px 0; }
.browse-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.browse-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.browse-code { font-family: 'Fredoka', sans-serif; font-size: 1.1rem; letter-spacing: 3px; color: var(--accent-2); }
.browse-meta { font-size: 0.78rem; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ lobby ============ */

#screen-lobby { align-items: center; justify-content: center; padding: 24px; }

.lobby-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 44px;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

.lobby-title { font-family: 'Fredoka', sans-serif; text-align: center; font-size: 1.6rem; }

.code-box {
  background: var(--panel-2);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.code-label { font-size: 0.75rem; font-weight: 800; letter-spacing: 2px; color: var(--muted); }
.code-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 3rem;
  letter-spacing: 14px;
  padding-left: 14px;
  color: var(--accent-2);
}
.code-btns { display: flex; gap: 8px; }

.lobby-players { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 64px; }
.lobby-player {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 18px 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}
.lobby-player .av { font-size: 1.4rem; }

.settings-row { display: flex; gap: 16px; justify-content: center; }
.setting { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.setting label { font-size: 0.8rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.setting select { min-width: 110px; text-align: center; }
.settings-row.locked { opacity: 0.55; pointer-events: none; }

.lobby-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lobby-actions .btn-primary { width: 100%; padding: 14px; font-size: 1.2rem; }
.lobby-wait { color: var(--muted); font-weight: 700; }

/* ============ game ============ */

#screen-game { padding: 12px; gap: 12px; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 18px;
  gap: 12px;
}
.hdr-left { display: flex; align-items: center; gap: 10px; }
.hdr-logo { font-size: 1.5rem; }
.hdr-round { font-weight: 800; color: var(--muted); white-space: nowrap; }
.hdr-word {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  letter-spacing: 5px;
  text-align: center;
  flex: 1;
  min-height: 1.5em;
  white-space: nowrap;
  overflow: hidden;
}
.hdr-word.is-word { color: var(--accent-2); }
.hdr-word.guessed-it { color: var(--good); }
.hdr-right { display: flex; align-items: center; gap: 12px; }
.hdr-timer { font-weight: 800; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.hdr-timer.low { color: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.hdr-code { font-family: 'Fredoka', sans-serif; color: var(--muted); letter-spacing: 3px; }

.game-main {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 280px;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

/* players */
.player-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.player-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.player-card.me { border-color: #6366f1; }
.player-card.drawer { border-color: var(--accent-2); background: rgba(255, 209, 102, 0.08); }
.player-card.guessed-ok { border-color: var(--good); background: rgba(74, 222, 128, 0.08); }
.player-card .av { font-size: 1.6rem; }
.player-card .info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.player-card .nm { font-weight: 800; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-card .sc { font-size: 0.8rem; color: var(--muted); font-weight: 700; }
.player-card .badges { font-size: 0.95rem; }

/* canvas */
.canvas-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: calc(100vh - 210px);
  margin: 0 auto;
}
#board {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  touch-action: none;
  display: block;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 18, 43, 0.82);
  backdrop-filter: blur(3px);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  padding: 20px;
}
.overlay-card { text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; max-width: 90%; }
.overlay-title { font-family: 'Fredoka', sans-serif; font-size: 1.4rem; }

.choose-words { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.word-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.15rem;
  padding: 14px 26px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  text-transform: capitalize;
}
.word-btn:hover { transform: scale(1.07); border-color: var(--accent); }

.reveal-word { font-family: 'Fredoka', sans-serif; font-size: 2.2rem; color: var(--accent-2); text-transform: capitalize; }
.reveal-gains { display: flex; flex-direction: column; gap: 4px; font-weight: 800; }
.reveal-gains .gain-pos { color: var(--good); }
.reveal-gains .gain-zero { color: var(--muted); }

.podium { display: flex; gap: 18px; align-items: flex-end; justify-content: center; }
.podium-spot { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 800; }
.podium-spot .pav { font-size: 2.2rem; }
.podium-spot .medal { font-size: 1.6rem; }
.podium-spot .psc { color: var(--accent-2); }
.podium-rest { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-weight: 700; }

/* toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.colors { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.25);
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 2px var(--accent); }
.tool-group { display: flex; gap: 6px; align-items: center; }
.sizes { display: flex; gap: 4px; align-items: center; }
.size-dot {
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.size-dot:hover { transform: scale(1.2); }
.size-dot.selected { box-shadow: 0 0 0 2px var(--accent); }
.tool-btn {
  font-size: 1.15rem;
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 5px 10px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.tool-btn:hover { transform: scale(1.1); }
.tool-btn.selected { border-color: var(--accent); }

/* chat */
.chat-col {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  min-height: 0;
}
.msg { line-height: 1.35; word-wrap: break-word; }
.msg .who { font-weight: 800; color: var(--teal); }
.msg-system { color: var(--muted); font-style: italic; }
.msg-correct { color: var(--good); font-weight: 800; }
.msg-close { color: var(--accent-2); font-weight: 800; }
.msg-guessed { color: var(--teal); font-style: italic; opacity: 0.85; }

.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; padding: 10px 14px; min-width: 0; }
.btn-send { padding: 8px 16px; }

/* toast */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  padding: 12px 24px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 100;
  animation: toast-in 0.25s;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ============ imposter mode ============ */

.settings-col { display: flex; flex-direction: column; gap: 18px; }
.settings-col.locked { opacity: 0.55; pointer-events: none; }

.mode-setting { align-items: stretch; }
.mode-setting > label { text-align: center; }
.mode-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.mode-card {
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s, border-color 0.12s;
}
.mode-card:hover { transform: translateY(-2px); }
.mode-card.selected { border-color: var(--accent); background: rgba(255, 92, 138, 0.1); }
.mode-icon { font-size: 1.8rem; }
.mode-name { font-family: 'Fredoka', sans-serif; font-size: 1.05rem; }
.mode-desc { font-size: 0.78rem; color: var(--muted); font-weight: 700; line-height: 1.3; }

.imp-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 24, 55, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 20px;
  font-weight: 800;
  font-size: 0.95rem;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 4;
  pointer-events: none;
}
.imp-banner.my-turn { border-color: var(--accent-2); color: var(--accent-2); animation: pulse 1.2s infinite; }

.blind-cover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(18, 18, 43, 0.55);
  border-radius: var(--radius);
  pointer-events: none;
  z-index: 3;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.1rem;
  text-align: center;
  padding: 20px;
}
.blind-icon { font-size: 2.4rem; }

.hdr-word.is-imposter { color: var(--accent); }

/* ============ team draw mode ============ */

.team-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}
.team-col {
  background: var(--panel-2);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.team-col-a { border-color: rgba(230, 57, 70, 0.4); }
.team-col-b { border-color: rgba(0, 180, 216, 0.4); }
.team-col-header { font-family: 'Fredoka', sans-serif; font-size: 1rem; }
.team-col-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 30px; width: 100%; }
.team-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.team-shuffle-btn { grid-column: 1 / -1; justify-self: center; }

.player-card.team-a { border-left: 4px solid #e63946; }
.player-card.team-b { border-left: 4px solid #00b4d8; }

.hdr-teamscore { font-weight: 800; font-size: 0.95rem; color: var(--muted); white-space: nowrap; }
.hdr-teamscore .ta { color: #ff8494; }
.hdr-teamscore .tb { color: #5eead4; }

.reveal-teamscore { font-weight: 800; color: var(--muted); font-size: 1rem; }

.team-winner-banner {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.3rem;
  padding: 10px 18px;
  border-radius: 14px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid var(--accent-2);
  color: var(--accent-2);
}

.role-icon { font-size: 3rem; }
.role-hint { color: var(--muted); font-weight: 700; max-width: 420px; line-height: 1.45; }

.action-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.action-title { font-family: 'Fredoka', sans-serif; font-size: 1.1rem; }
.action-sub { color: var(--muted); font-weight: 700; font-size: 0.85rem; }

.vote-options { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.vote-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s, border-color 0.1s;
}
.vote-btn:hover:not(:disabled) { transform: scale(1.06); border-color: var(--accent); }
.vote-btn:disabled { opacity: 0.55; cursor: default; }
.vote-btn.voted { border-color: var(--accent); background: rgba(255, 92, 138, 0.18); opacity: 1; }

.guess-form { display: flex; gap: 8px; width: 100%; max-width: 420px; }
.guess-form input { flex: 1; min-width: 0; }

.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: baseline;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.impresult-votes { display: flex; flex-direction: column; gap: 3px; font-weight: 700; font-size: 0.9rem; color: var(--muted); max-height: 150px; overflow-y: auto; }
.vote-line.correct { color: var(--good); }

/* ============ responsive ============ */

@media (max-width: 900px) {
  .game-main {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }
  .player-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }
  .player-card { min-width: 130px; flex-shrink: 0; }
  .canvas-wrap { max-height: none; }
  .chat-col { min-height: 240px; }
  .hdr-word { font-size: 1.1rem; letter-spacing: 3px; }
  .hdr-code { display: none; }
  .home-card, .lobby-card { padding: 28px 22px; }
  .code-value { font-size: 2.2rem; letter-spacing: 8px; padding-left: 8px; }
}
