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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eaeaea;
  --text-muted: #8892a4;
  --border: #2a2a4a;
  --green: #4caf50;
  --yellow: #ffc107;
  --red: #e94560;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

/* ── Layout ── */

.screen { display: none; }
.screen.active { display: flex; }

/* ── Home Screen ── */

#screen-home {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 2.5rem;
  padding: 2rem;
}

.logo {
  text-align: center;
}

.logo h1 {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #e94560, #533483);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo p {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-top: 0.4rem;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 320px;
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 80ms, opacity 150ms, background 150ms;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #ff5a75; }

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

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

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
}
.btn-danger:hover:not(:disabled) { background: rgba(233,69,96,0.1); }

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.15rem;
  width: 100%;
}

/* ── Card ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}

.card h2 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  color: var(--text);
}

/* ── Lobby / Waiting Screen ── */

#screen-lobby {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1.5rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.lobby-text {
  text-align: center;
}
.lobby-text h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.lobby-text p { color: var(--text-muted); }

.invite-code-box {
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 2rem;
  width: 100%;
  max-width: 320px;
}
.invite-code-box p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.invite-code {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--accent);
  font-family: monospace;
  cursor: pointer;
  user-select: all;
}
.invite-code-box .hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}
.copy-confirm {
  font-size: 0.82rem;
  color: var(--green);
  margin-top: 0.3rem;
  height: 1em;
}

/* ── Join Screen ── */

#screen-join {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.input-group {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.7rem 1rem;
  font-size: 1rem;
  outline: none;
  transition: border-color 150ms;
  flex: 1;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-muted); }

.error-msg {
  color: var(--red);
  font-size: 0.9rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* ── Game Screen ── */

#screen-game {
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
  gap: 0.75rem;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 540px;
  padding: 0 0.25rem;
}

.game-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e94560, #533483);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Timer ── */

.timers {
  display: flex;
  gap: 1rem;
  width: 100%;
  max-width: 540px;
}

.timer-block {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  text-align: center;
}

.timer-block.mine { border-color: var(--accent2); }
.timer-block.opponent { border-color: var(--border); }

.timer-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.timer-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: monospace;
  color: var(--text);
  transition: color 300ms;
}
.timer-value.urgent { color: var(--red); }
.timer-value.warning { color: var(--yellow); }

/* ── Board ── */

.board-container {
  width: 100%;
  max-width: 520px;
}

chess-board {
  width: 100% !important;
  --light-color: #f0d9b5;
  --dark-color: #b58863;
}

/* Highlight squares for move selection */
.highlight-from { background: rgba(20, 85, 30, 0.5) !important; }
.highlight-to   { background: rgba(20, 85, 30, 0.3) !important; }

/* ── Status bar ── */

.status-bar {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  text-align: center;
  color: var(--text-muted);
  min-height: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.status-bar .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-bar.waiting .dot { background: var(--yellow); animation: pulse 1.2s infinite; }
.status-bar.submitted .dot { background: var(--green); }
.status-bar.both .dot { background: var(--accent); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Move panel ── */

.move-panel {
  width: 100%;
  max-width: 520px;
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.selected-move {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-family: monospace;
}
.selected-move.has-move { color: var(--text); border-color: var(--accent2); }

/* ── Last turn result ── */

.last-result {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 2.4rem;
}
.last-result .moves-line { color: var(--text); font-family: monospace; margin-bottom: 0.15rem; }
.last-result .events-line { color: var(--text-muted); }

/* ── Game Over Screen ── */

#screen-gameover {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1.5rem;
}

.result-badge {
  font-size: 4rem;
}

.result-text {
  text-align: center;
}
.result-text h2 { font-size: 2rem; font-weight: 800; }
.result-text p { color: var(--text-muted); margin-top: 0.4rem; }

.gameover-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Responsive ── */

@media (max-width: 560px) {
  .logo h1 { font-size: 2.5rem; }
  #screen-game { padding: 0.5rem; }
}
