/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #121213;
  --surface: #1a1a1b;
  --surface2: #242424;
  --border: #3a3a3c;
  --text: #ffffff;
  --text-muted: #818384;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --correct-bright: #6aaa64;
  --present-bright: #c9b458;
  --key-bg: #818384;
  --key-text: #fff;
  --accent: #538d4e;
  --radius: 6px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Screens ===== */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 900px;
  padding: 16px;
  min-height: 100vh;
}
.screen.active { display: flex; }

/* ===== Header ===== */
header {
  text-align: center;
  margin-bottom: 24px;
  padding: 16px 0 8px;
  border-bottom: 1px solid var(--border);
  width: 100%;
}
h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--text);
}
.tagline { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; letter-spacing: 1px; }
.room-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.85rem;
  margin-top: 8px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-muted);
}
.room-badge span { color: var(--text); font-size: 1rem; }
#btn-copy-code {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 1rem; padding: 0 2px;
  transition: color 0.15s;
}
#btn-copy-code:hover { color: var(--text); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== Forms ===== */
.form-group { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
input[type="text"] {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--correct-bright); }
input.code-input {
  text-transform: uppercase;
  letter-spacing: 4px;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* ===== Length Picker ===== */
.length-picker {
  display: flex;
  gap: 8px;
}
.len-btn {
  flex: 1;
  padding: 8px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.len-btn.active {
  border-color: var(--correct-bright);
  color: var(--text);
  background: rgba(106, 170, 100, 0.15);
}
.len-btn:hover:not(.active) { border-color: #555; color: var(--text); }

/* ===== Buttons ===== */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--correct); color: #fff; }
.btn-primary:hover { background: var(--correct-bright); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: #666; }
.hidden { display: none !important; }

/* ===== Error ===== */
.error-msg {
  color: #e74c3c;
  font-size: 0.88rem;
  text-align: center;
  margin-top: 8px;
  min-height: 1.2em;
}
.guess-error {
  color: var(--present-bright);
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.4em;
  margin-top: 4px;
}

/* ===== Lobby ===== */
.lobby-info { text-align: center; color: var(--text-muted); font-size: 0.9rem; }
.lobby-info strong { color: var(--text); }
.section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.lobby-players ul, #game-player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lobby-players li, #game-player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.player-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-host { background: var(--present); color: #000; }
.badge-solved { background: var(--correct); color: #fff; }
.badge-failed { background: #555; color: #fff; }
.player-guesses { margin-left: auto; font-size: 0.78rem; color: var(--text-muted); }

/* ===== Game Screen ===== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 12px 0 8px;
  width: 100%;
  margin-bottom: 16px;
}
.game-header .header-left { display: flex; flex-direction: column; }
.game-header h1 { font-size: 1.6rem; letter-spacing: 4px; }
.room-badge-small { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 2px; }
#game-info { font-size: 0.82rem; color: var(--text-muted); text-align: right; }

.game-layout {
  display: flex;
  gap: 24px;
  width: 100%;
  flex: 1;
  justify-content: center;
  align-items: flex-start;
}

/* ===== Board ===== */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
#board {
  display: grid;
  gap: 5px;
}
.tile-row {
  display: flex;
  gap: 5px;
}
.tile {
  width: 52px;
  height: 52px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  text-transform: uppercase;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.tile.filled { border-color: #565758; }
.tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.tile.absent  { background: var(--absent); border-color: var(--absent); color: #fff; }

/* Reveal animation */
@keyframes flip {
  0%   { transform: scaleY(1); }
  50%  { transform: scaleY(0); }
  100% { transform: scaleY(1); }
}
.tile.reveal { animation: flip 0.4s ease forwards; }

/* Shake animation */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}
.tile-row.shake { animation: shake 0.35s ease; }

/* Bounce on win */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}
.tile.bounce { animation: bounce 0.4s ease; }

/* ===== Smaller tiles for longer words ===== */
.word-6 .tile { width: 46px; height: 46px; font-size: 1.3rem; }
.word-7 .tile { width: 42px; height: 42px; font-size: 1.2rem; }
.word-8 .tile { width: 38px; height: 38px; font-size: 1.1rem; }

/* ===== Players Sidebar ===== */
.players-sidebar {
  min-width: 160px;
  max-width: 200px;
  padding-top: 4px;
}
.players-sidebar .section-label { margin-bottom: 8px; }
.player-dots {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.dot.used { background: var(--text-muted); }
.dot.solved { background: var(--correct-bright); }
.dot.failed { background: #555; }

/* ===== Keyboard ===== */
.keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0 16px;
  flex-shrink: 0;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.kb-row button {
  height: 52px;
  min-width: 36px;
  padding: 0 6px;
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s;
  flex: 1;
  max-width: 43px;
}
.kb-row button:active { opacity: 0.8; }
.kb-wide { max-width: 66px !important; font-size: 0.75rem !important; }

.kb-row button.correct { background: var(--correct); }
.kb-row button.present { background: var(--present); }
.kb-row button.absent  { background: var(--absent); }

/* ===== Results Screen ===== */
.results-card { max-width: 460px; }
.result-banner {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 4px;
}
.result-banner.won { background: rgba(106, 170, 100, 0.2); color: var(--correct-bright); }
.result-banner.lost { background: rgba(58, 58, 60, 0.5); color: var(--text-muted); }
.result-answer { text-align: center; font-size: 0.95rem; color: var(--text-muted); }
.result-answer strong { color: var(--text); font-size: 1.1rem; letter-spacing: 2px; }
.leaderboard ol { list-style: none; counter-reset: rank; display: flex; flex-direction: column; gap: 8px; }
.leaderboard li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.leaderboard li::before {
  content: counter(rank);
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-muted);
  width: 18px;
  text-align: center;
}
.result-guesses { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); }
.result-status { font-size: 0.7rem; }

/* ===== Notifications ===== */
.notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 100;
  animation: fadeInOut 2.5s ease forwards;
  pointer-events: none;
}
@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  h1 { font-size: 1.8rem; }
  .game-layout { flex-direction: column; align-items: center; }
  .players-sidebar { max-width: 100%; width: 100%; }
  .tile { width: 44px; height: 44px; font-size: 1.3rem; }
  .word-6 .tile { width: 38px; height: 38px; font-size: 1.1rem; }
  .word-7 .tile { width: 34px; height: 34px; font-size: 1rem; }
  .word-8 .tile { width: 30px; height: 30px; font-size: 0.9rem; }
  .kb-row button { height: 44px; min-width: 28px; font-size: 0.78rem; }
}
