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

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #273549;
  --border: #334155;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.container.wide {
  max-width: 900px;
  justify-content: flex-start;
  padding-top: 1.5rem;
}

/* ─── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: 100%;
}

/* ─── Typography ──────────────────────────────────────────────────────────── */
.logo {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 1rem;
}

h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* ─── Form controls ───────────────────────────────────────────────────────── */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.75rem 1rem;
  font-size: 1rem;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

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

.field { margin-bottom: 1rem; }

/* ─── Radio group ─────────────────────────────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.radio-option {
  flex: 1;
  min-width: 120px;
}

.radio-option input[type="radio"] {
  display: none;
}

.radio-option label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.875rem;
  color: var(--text);
  text-align: center;
}

.radio-option label .icon {
  font-size: 1.75rem;
}

.radio-option input[type="radio"]:checked + label {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
  color: var(--accent);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #0f172a; }
.btn-primary:hover:not(:disabled) { background: #67d1fb; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-success { background: var(--success); color: #0f172a; }
.btn-success:hover:not(:disabled) { background: #6ee7a0; }

.btn-danger { background: var(--danger); color: #0f172a; }

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  min-height: 36px;
}

.btn-icon {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
}

/* ─── Alert / Error ───────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-error { background: rgba(248, 113, 113, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.alert-success { background: rgba(74, 222, 128, 0.15); border: 1px solid var(--success); color: var(--success); }
.alert-info { background: rgba(56, 189, 248, 0.1); border: 1px solid var(--accent); color: var(--accent); }

/* ─── Home page ───────────────────────────────────────────────────────────── */
.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  margin-top: 0.5rem;
}

.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0.5rem 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

/* ─── Game layout ─────────────────────────────────────────────────────────── */
.game-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  width: 100%;
}

@media (min-width: 640px) {
  .game-layout {
    grid-template-columns: 280px 1fr;
    align-items: start;
  }
}

/* ─── Hangman SVG ─────────────────────────────────────────────────────────── */
.hangman-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.hangman-svg {
  width: 100%;
  max-width: 200px;
}

.hangman-svg line, .hangman-svg circle, .hangman-svg path {
  stroke: var(--text);
  stroke-width: 3;
  stroke-linecap: round;
}

.hangman-svg .gallows {
  stroke: var(--text-muted);
}

.wrong-count {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.wrong-count span {
  color: var(--danger);
  font-weight: 700;
}

/* ─── Word display ────────────────────────────────────────────────────────── */
.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin: 1rem 0;
  overflow-x: auto;
}

.letter-box {
  width: 36px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  border-bottom: 3px solid var(--text);
  color: var(--accent);
  transition: color 0.2s;
  flex-shrink: 0;
}

.letter-box.space {
  border-bottom: none;
  width: 16px;
}

/* ─── Keyboard ────────────────────────────────────────────────────────────── */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.3rem;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

.key:hover:not(.guessed):not(:disabled) { background: var(--accent); color: #0f172a; }
.key:active:not(.guessed) { transform: scale(0.92); }

.key.correct {
  background: rgba(74, 222, 128, 0.2);
  color: var(--success);
  border-color: var(--success);
  cursor: default;
}

.key.wrong {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border-color: var(--danger);
  cursor: default;
  opacity: 0.6;
}

.key.guessed { cursor: default; }

/* ─── Players list ────────────────────────────────────────────────────────── */
.players-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.players-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.player-dot.active { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.player-dot.host { background: var(--warning); }

.player-name { flex: 1; }
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--warning);
  color: #0f172a;
}

.badge.you { background: var(--accent); }
.badge.turn { background: var(--success); }

/* ─── Share link ──────────────────────────────────────────────────────────── */
.share-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.share-box input {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  min-width: 0;
}

/* ─── Status banner ───────────────────────────────────────────────────────── */
.status-banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-align: center;
  font-size: 1rem;
}

.status-banner.won { background: rgba(74, 222, 128, 0.15); color: var(--success); border: 1px solid var(--success); }
.status-banner.lost { background: rgba(248, 113, 113, 0.15); color: var(--danger); border: 1px solid var(--danger); }
.status-banner.turn { background: rgba(56, 189, 248, 0.1); color: var(--accent); border: 1px solid var(--accent); }
.status-banner.wait { background: rgba(148, 163, 184, 0.1); color: var(--text-muted); border: 1px solid var(--border); }

/* ─── Lobby ───────────────────────────────────────────────────────────────── */
.lobby-waiting {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Game over reveal ────────────────────────────────────────────────────── */
.word-reveal {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--warning);
}

/* ─── Chat ────────────────────────────────────────────────────────────────── */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
  padding-right: 0.25rem;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-message {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 0.875rem;
  line-height: 1.4;
}

.chat-name {
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-message.chat-message-me .chat-name {
  color: var(--accent);
}

.chat-text {
  color: var(--text);
  word-break: break-word;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.chat-input-row input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

/* ─── Browse games ────────────────────────────────────────────────────────── */
.browse-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.no-rooms-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 1.5rem 0;
  font-size: 0.9rem;
}

.rooms-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.rooms-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.rooms-list-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.rooms-list-host {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rooms-list-meta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.rooms-list-players,
.rooms-list-mode {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rooms-list-join {
  flex-shrink: 0;
  width: auto;
}

/* ─── Responsive tweaks ───────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .card { padding: 1.5rem 0.75rem; }
  .logo { font-size: 2rem; }
  .letter-box { width: 28px; height: 38px; font-size: 1.1rem; }
  .key { min-height: 40px; font-size: 0.75rem; }
}
