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

:root {
  --bg: #000000;
  --surface: #1C1C1E;
  --surface2: #2C2C2E;
  --surface3: #3A3A3C;
  --surface4: #48484A;
  --text: #F5F5F7;
  --text2: #98989D;
  --text3: #6E6E73;
  --x: #0A84FF;
  --o: #FF453A;
  --mini-pad: 8px;
  --grid-pad: 12px;
}

html, body {
  height: 100%;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow-x: hidden;
}

input { font-family: inherit; }
input::placeholder { color: var(--text3); }
button { font-family: inherit; }

.hidden { display: none !important; }

/* ── Screens ── */

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px 64px;
}

.screen.active { display: flex; }

.center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  width: 100%;
  max-width: 520px;
}

/* ── HOME ── */

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.logo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.logo-grid div {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.home-hero h1 {
  font-size: clamp(38px, 8vw, 52px);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.02;
  text-align: center;
}

.home-hero p {
  max-width: 400px;
  text-align: center;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text2);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  border-radius: 20px;
  background: var(--surface);
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  transition: background 0.2s, transform 0.15s;
  user-select: none;
}

.mode-card:hover {
  background: #232325;
  transform: translateY(-1px);
}

.mode-card:active { transform: translateY(0); }

.mode-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  line-height: 1;
  flex-shrink: 0;
}

.mode-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.mode-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.mode-sub {
  font-size: 14px;
  color: var(--text2);
}

.mode-chevron {
  font-size: 20px;
  color: var(--surface4);
  line-height: 1;
}

/* ── LOBBY ── */

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  font-size: 15px;
  color: var(--text2);
  cursor: pointer;
  transition: color 0.2s;
  padding: 0;
}

.back-btn:hover { color: var(--text); }

.lobby-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.lobby-header h2 {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.lobby-header p {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text2);
}

.card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.card-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
}

.room-code {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: 16px;
  background: #000;
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text);
}

.card-actions {
  display: flex;
  gap: 10px;
}

.btn-secondary {
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface2);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  text-align: center;
}

.btn-secondary:hover { background: var(--surface3); }

.btn-primary {
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  background: var(--x);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  text-align: center;
}

.btn-primary:hover { background: #3A9BFF; }

.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  color: var(--surface4);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.08);
}

.join-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.join-input {
  flex: 1;
  padding: 14px 18px;
  border-radius: 16px;
  border: none;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  letter-spacing: 0.12em;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.btn-join {
  padding: 14px 22px;
  border-radius: 16px;
  background: var(--text);
  color: #000;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  border: none;
}

.btn-join:hover { opacity: 0.86; }

.lobby-note {
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text3);
  max-width: 340px;
}

/* ── WAITING ── */

.waiting-content { gap: 22px; }

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.82); }
}

.pulse-dots { display: flex; gap: 8px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #30D158;
  animation: pulseDot 1.3s ease-in-out infinite;
}

.waiting-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.wait-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.wait-room {
  font-size: 15px;
  color: var(--text2);
}

.btn-cancel {
  padding: 11px 22px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  transition: background 0.2s;
}

.btn-cancel:hover { background: #232325; }

/* ── GAME ── */

.game-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 960px;
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 16px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  border-radius: 980px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-pill-text {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.turn-timer {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  background: rgba(255,255,255,0.06);
  padding: 2px 9px;
  border-radius: 980px;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s;
}

.turn-timer.timer-warn {
  color: #fff;
  background: var(--o);
}

.turn-timer:empty { display: none; }

.mode-label {
  font-size: 13px;
  color: var(--text3);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ── GAME LAYOUT ── */

.game-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

.game-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.game-side {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── BOARD ── */

.boards-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: var(--grid-pad);
  background: #141416;
  border-radius: 30px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
  width: 100%;
}

.mini-board {
  position: relative;
  padding: var(--mini-pad);
  border-radius: 20px;
  background: var(--surface);
  transition: opacity 0.25s, box-shadow 0.25s;
}

.cell-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.game-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  font-size: clamp(10px, 3.8vw, 25px);
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background 0.18s, transform 0.12s, box-shadow 0.15s;
}

.game-cell:hover { transform: scale(1.06); }
.game-cell:active { transform: scale(0.94); }

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  pointer-events: none;
  font-size: clamp(30px, 10vw, 76px);
  font-weight: 300;
  line-height: 1;
  transition: opacity 0.3s;
  background: rgba(20, 20, 22, 0.88);
  opacity: 0;
}

.win-line {
  position: absolute;
  inset: var(--mini-pad);
  overflow: visible;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.win-line-path {
  fill: none;
  stroke-width: 0.13;
  stroke-linecap: round;
}

.win-line-main {
  inset: var(--grid-pad);
}

.win-line-main .win-line-path {
  stroke-width: 0.05;
}

/* ── PLAYER CHIPS ── */

.player-chips {
  display: flex;
  align-items: center;
  gap: 22px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  border-radius: 980px;
  transition: background 0.2s, box-shadow 0.2s;
}

.chip-mark {
  font-size: 19px;
  line-height: 1;
}

.chip-label {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.chip-vs {
  font-size: 13px;
  color: var(--surface4);
}

/* ── REMATCH ── */

.rematch-request {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  font-size: 14px;
  font-weight: 500;
}

.rematch-request.active { display: flex; }

.rematch-request-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.rematch-request-actions button {
  flex: none;
  padding: 8px 14px;
  font-size: 13px;
}

/* ── GAME ACTIONS ── */

.game-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-undo {
  padding: 10px 20px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  transition: background 0.2s;
  border: none;
}

.btn-undo:hover { background: #232325; }

.btn-rematch {
  padding: 10px 20px;
  border-radius: 14px;
  background: #30D158;
  color: #000;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  border: none;
}

.btn-rematch:hover { opacity: 0.86; }
.btn-rematch:disabled { opacity: 0.5; cursor: default; }

.btn-new-game {
  padding: 10px 20px;
  border-radius: 14px;
  background: var(--text);
  color: #000;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  border: none;
}

.btn-new-game:hover { opacity: 0.86; }

.game-hint {
  max-width: 440px;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text3);
}

/* ── SIDE PANEL (LOG / CHAT) ── */

.side-tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.side-tab {
  position: relative;
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.side-tab.active {
  background: var(--surface2);
  color: var(--text);
}

.tab-badge {
  position: absolute;
  top: 2px;
  right: 8px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--o);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}

@keyframes tabPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.side-tab.tab-pulse {
  animation: tabPulse 0.9s ease-in-out 2;
}

.side-panel {
  display: none;
  flex-direction: column;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  overflow: hidden;
  height: 320px;
}

.side-panel.active { display: flex; }

.log-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.log-entry {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text2);
}

.log-entry.log-highlight {
  color: var(--text);
  font-weight: 600;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-bubble {
  max-width: 84%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  background: var(--surface2);
  align-self: flex-start;
  word-break: break-word;
}

.chat-bubble.mine {
  background: var(--x);
  color: #fff;
  align-self: flex-end;
}

.chat-empty {
  color: var(--text3);
  font-size: 12.5px;
  text-align: center;
  margin: auto;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 12px;
  border: none;
  outline: none;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
}

.btn-chat-send {
  padding: 9px 14px;
  border-radius: 12px;
  border: none;
  background: var(--x);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-chat-send:hover { opacity: 0.86; }

/* ── RESPONSIVE ── */

@media (max-width: 860px) {
  .game-layout { flex-direction: column; }
  .game-side { width: 100%; }
  .side-panel { height: 220px; }
}

@media (max-width: 520px) {
  :root { --mini-pad: 6px; --grid-pad: 9px; }
  .screen { padding: 32px 14px 40px; }
  .game-col { gap: 14px; }
  .game-layout { gap: 14px; }
  .status-pill-text { font-size: 12px; }
  .mode-label { display: none; }
  .boards-grid { gap: 7px; border-radius: 22px; }
  .mini-board { border-radius: 15px; }
  .cell-grid { gap: 4px; }
  .game-cell { border-radius: 8px; }
  .board-overlay { border-radius: 15px; }
  .rematch-request { flex-direction: column; align-items: stretch; text-align: center; }
  .side-panel { height: 190px; }
}

@media (max-width: 360px) {
  .status-pill { padding: 7px 11px; }
  .status-pill-text { font-size: 11px; }
  .turn-timer { font-size: 11px; padding: 2px 7px; }
}
