/* TicTacWhat — Color palette:
   #5289AD  medium blue (primary/action)
   #243C4C  dark navy (backgrounds, headers)
   #ACBCBF  light blue-gray (secondary text, borders)
   #F4FCFB  near-white (page bg, cards)
   #698696  slate blue-gray (accent, muted)
*/

:root {
  --c-primary: #5289AD;
  --c-dark: #243C4C;
  --c-mid: #ACBCBF;
  --c-light: #F4FCFB;
  --c-accent: #698696;
  --c-x: #5289AD;
  --c-o: #d4735a;
  --c-win: #2ecc71;
  --c-command-forced: #e8a020;
  --c-switcheroo-flipped: #9b59b6;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(36,60,76,0.13);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--c-light);
  color: var(--c-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── NAV ─────────────────────────────────────────── */
.nav {
  background: var(--c-dark);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--c-light);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav-brand span { color: var(--c-primary); }

.nav-links { display: flex; align-items: center; gap: 1.5rem; }

.nav-links a {
  color: var(--c-mid);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color .2s;
}

.nav-links a:hover { color: var(--c-light); }

.nav-links .btn-nav {
  background: var(--c-primary);
  color: #fff;
  padding: .4rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  transition: background .2s;
}

.nav-links .btn-nav:hover { background: #3f6e91; color: #fff; }

/* ── HAMBURGER ────────────────────────────────────── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-hamburger span {
  display: block;
  height: 2px;
  background: var(--c-mid);
  border-radius: 2px;
  transition: transform .25s, opacity .2s;
}

.nav-hamburger.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.active span:nth-child(2) { opacity: 0; }
.nav-hamburger.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 640px) {
  .nav-hamburger { display: flex; }

  .nav-links {
    display: none;
    position: absolute;
    top: 60px;
    left: 0; right: 0;
    background: var(--c-dark);
    flex-direction: column;
    align-items: stretch;
    padding: .75rem 1.5rem 1rem;
    gap: .1rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 99;
  }

  .nav-links.open { display: flex; }

  .nav-links a {
    padding: .65rem 0;
    border-bottom: 1px solid rgba(172,188,191,0.1);
    font-size: 1rem;
  }

  .nav-links .btn-nav {
    margin-top: .5rem;
    text-align: center;
    padding: .65rem;
    border-radius: 8px;
  }
}

/* ── MESSAGES ─────────────────────────────────────── */
.messages {
  list-style: none;
  padding: .75rem 2rem;
}

.messages li {
  padding: .6rem 1rem;
  border-radius: 8px;
  margin-bottom: .4rem;
  font-size: .9rem;
}

.messages .success { background: #d4edda; color: #155724; }
.messages .error   { background: #f8d7da; color: #721c24; }
.messages .info    { background: #d1ecf1; color: #0c5460; }
.messages .warning { background: #fff3cd; color: #856404; }

/* ── PAGE / MAIN ──────────────────────────────────── */
main { flex: 1; padding: 2rem; max-width: 1200px; margin: 0 auto; width: 100%; }

.page-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--c-dark);
  margin-bottom: 1.5rem;
}

/* ── CARDS ────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

/* ── BUTTONS ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .65rem 1.4rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: transform .1s, box-shadow .1s, background .2s;
}

.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: #3f6e91; }

.btn-dark { background: var(--c-dark); color: #fff; }
.btn-dark:hover { background: #1a2b38; }

.btn-accent { background: var(--c-accent); color: #fff; }
.btn-accent:hover { background: #526878; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--c-primary);
  color: var(--c-primary);
}

.btn-outline:hover { background: var(--c-primary); color: #fff; }

.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #a93226; }

.btn-sm { padding: .4rem .9rem; font-size: .85rem; }
.btn-lg { padding: 1rem 2.5rem; font-size: 1.1rem; border-radius: 12px; }
.btn-xl { padding: 1.5rem 3rem; font-size: 1.3rem; border-radius: 16px; box-shadow: var(--shadow); }

/* ── FORMS ────────────────────────────────────────── */
.form-group { margin-bottom: 1.2rem; }
.form-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .4rem; color: var(--c-dark); }
.form-input {
  width: 100%;
  padding: .65rem .9rem;
  border: 2px solid var(--c-mid);
  border-radius: 8px;
  font-size: .95rem;
  color: var(--c-dark);
  background: var(--c-light);
  transition: border-color .2s;
}

.form-input:focus { outline: none; border-color: var(--c-primary); }
.form-hint { font-size: .8rem; color: var(--c-accent); margin-top: .3rem; }
.form-error { font-size: .85rem; color: #c0392b; margin-top: .3rem; }

.errorlist { list-style: none; }
.errorlist li { color: #c0392b; font-size: .85rem; margin-top: .25rem; }

/* ── LANDING PAGE ─────────────────────────────────── */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 2rem;
  text-align: center;
}

.landing-hero {
  margin-bottom: 3rem;
}

.landing-title {
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 900;
  color: var(--c-dark);
  line-height: 1.1;
}

.landing-title span { color: var(--c-primary); }

.landing-subtitle {
  font-size: 1.1rem;
  color: var(--c-accent);
  margin-top: .75rem;
}

.landing-buttons {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── GAME MODE SELECTION ──────────────────────────── */
.chaos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.chaos-card { padding: 1.25rem 1rem; }

@media (max-width: 500px) {
  .chaos-grid { grid-template-columns: 1fr; }
  .chaos-card { display: flex; align-items: center; gap: 1rem; text-align: left; padding: .9rem 1rem; }
  .chaos-card .mode-icon { font-size: 2rem; margin: 0; flex-shrink: 0; }
  .chaos-card .mode-title { margin: 0; }
  .chaos-card .mode-desc { margin: 0; }
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.mode-card {
  background: #fff;
  border: 3px solid transparent;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  cursor: pointer;
  transition: border-color .2s, transform .15s, box-shadow .2s;
  text-align: center;
  box-shadow: var(--shadow);
}

.mode-card:hover {
  border-color: var(--c-primary);
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(82,137,173,0.22);
}

.mode-card.selected { border-color: var(--c-primary); background: rgba(82,137,173,0.06); }

.mode-icon { font-size: 3rem; margin-bottom: .75rem; }
.mode-title { font-size: 1.3rem; font-weight: 800; color: var(--c-dark); }
.mode-desc { font-size: .85rem; color: var(--c-accent); margin-top: .4rem; line-height: 1.5; }

/* ── GAME BOARD ───────────────────────────────────── */
.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 60px);
  padding: 1rem;
  gap: 1rem;
}

.game-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 600px;
  background: var(--c-dark);
  color: var(--c-light);
  padding: .6rem 1.2rem;
  border-radius: 12px;
  font-size: .9rem;
}

.game-info-bar .player-label { font-weight: 700; }
.game-info-bar .x-label { color: #7ec8e8; }
.game-info-bar .o-label { color: #e8a07e; }
.turn-indicator { font-weight: 600; color: var(--c-mid); }

/* Board container: fill as much viewport as possible */
.board-wrap {
  width: min(90vw, 90vh, 560px);
  aspect-ratio: 1;
  position: relative;
}

/* Full-screen during play: expand to fill viewport */
.board-wrap.fullscreen-board {
  width: min(calc(100vw - 2rem), calc(100vh - 200px));
  max-width: 640px;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  gap: 10px;
}

.cell {
  background: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.5rem, 8vmin, 6rem);
  font-weight: 900;
  cursor: pointer;
  border: 3px solid var(--c-mid);
  transition: background .15s, border-color .15s, transform .1s;
  position: relative;
  user-select: none;
}

.cell:hover:not(.taken):not(.disabled) {
  background: rgba(82,137,173,0.08);
  border-color: var(--c-primary);
  transform: scale(1.02);
}

.cell.x-cell { color: var(--c-x); border-color: rgba(82,137,173,0.4); }
.cell.o-cell { color: var(--c-o); border-color: rgba(212,115,90,0.4); }
.cell.taken  { cursor: default; }
.cell.disabled { cursor: not-allowed; opacity: .7; }

.cell.win-cell {
  background: rgba(46,204,113,0.15);
  border-color: var(--c-win);
  box-shadow: 0 0 0 3px rgba(46,204,113,0.3);
}

/* Command grid: the forced cell */
.cell.commanded {
  border-color: var(--c-command-forced);
  box-shadow: 0 0 0 3px rgba(232,160,32,0.35);
  animation: pulse-command 1.2s ease-in-out infinite;
}

/* Switcheroo-flipped cells in history */
.cell.switcheroo-flip { border-color: var(--c-switcheroo-flipped); }
.cell.command-forced-history { border-color: var(--c-command-forced); }

@keyframes pulse-command {
  0%, 100% { box-shadow: 0 0 0 3px rgba(232,160,32,0.35); }
  50% { box-shadow: 0 0 0 6px rgba(232,160,32,0.15); }
}

/* Win overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36,60,76,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadein .3s ease;
}

.win-modal {
  background: var(--c-light);
  border-radius: 20px;
  padding: 3rem 2.5rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 420px;
  width: 90%;
}

.win-title { font-size: 2.5rem; font-weight: 900; color: var(--c-dark); }
.win-subtitle { font-size: 1.1rem; color: var(--c-accent); margin-top: .5rem; }
.win-actions { margin-top: 1.5rem; display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Skip/chaos notification */
.skip-toast {
  background: var(--c-dark);
  color: var(--c-light);
  padding: .6rem 1.4rem;
  border-radius: 50px;
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  animation: slideup .3s ease;
  max-width: 400px;
}

@keyframes slideup {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Command grid symbol chooser */
.symbol-chooser {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  padding: .75rem 1rem;
  background: rgba(232,160,32,0.1);
  border: 2px solid var(--c-command-forced);
  border-radius: 12px;
}

.symbol-chooser label { font-weight: 700; color: var(--c-dark); }

.symbol-btn {
  padding: .5rem 1.5rem;
  border-radius: 8px;
  font-size: 1.5rem;
  font-weight: 900;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all .15s;
}

.symbol-btn.x-btn { color: var(--c-x); border-color: var(--c-x); }
.symbol-btn.x-btn:hover, .symbol-btn.x-btn.active { background: var(--c-x); color: #fff; }
.symbol-btn.o-btn { color: var(--c-o); border-color: var(--c-o); }
.symbol-btn.o-btn:hover, .symbol-btn.o-btn.active { background: var(--c-o); color: #fff; }

/* Pause button */
.game-controls { display: flex; gap: .75rem; justify-content: center; }

/* Skip counters (chaos mode) */
.skip-counters {
  display: flex;
  gap: 1.5rem;
  background: var(--c-dark);
  color: var(--c-mid);
  border-radius: 10px;
  padding: .5rem 1.2rem;
  font-size: .9rem;
}

.skip-counters strong { color: var(--c-light); }

/* ── PROFILE ──────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--c-primary);
}

.profile-avatar-placeholder {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--c-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--c-dark);
  border: 4px solid var(--c-primary);
}

.profile-username { font-size: 1.6rem; font-weight: 800; }
.profile-name { color: var(--c-accent); margin-top: .2rem; }

.profile-detail { display: flex; flex-direction: column; gap: .5rem; }
.profile-field { display: flex; gap: .5rem; font-size: .95rem; }
.profile-field .label { color: var(--c-accent); font-weight: 600; min-width: 110px; }

/* ── FRIEND LIST ──────────────────────────────────── */
.friend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.friend-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .15s;
  text-decoration: none;
  color: inherit;
}

.friend-card:hover { transform: translateY(-2px); }

.friend-thumb {
  width: 56px; height: 56px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: .5rem;
  border: 3px solid var(--c-mid);
}

.friend-thumb-placeholder {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--c-mid);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  margin: 0 auto .5rem;
}

.friend-name { font-weight: 700; font-size: .95rem; }

/* ── HISTORY / REPLAY ─────────────────────────────── */
.history-game {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}

.history-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: min(200px, 40vw);
}

.history-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 900;
  border-radius: 6px;
  background: var(--c-light);
  border: 2px solid var(--c-mid);
}

.history-cell.x-cell { color: var(--c-x); }
.history-cell.o-cell { color: var(--c-o); }
.history-cell.win-cell { background: rgba(46,204,113,0.18); border-color: var(--c-win); }
.history-cell.commanded-cell { border-color: var(--c-command-forced); }
.history-cell.switcheroo-cell { border-color: var(--c-switcheroo-flipped); }

.winner-badge {
  display: inline-block;
  padding: .25rem .75rem;
  border-radius: 50px;
  font-size: .8rem;
  font-weight: 700;
}

.badge-win { background: rgba(46,204,113,0.2); color: #1a7a42; }
.badge-loss { background: rgba(192,57,43,0.15); color: #922b21; }
.badge-draw { background: rgba(172,188,191,0.3); color: var(--c-dark); }

/* ── ABOUT PAGE ───────────────────────────────────── */
.about-section { margin-bottom: 3rem; }
.about-section h2 { font-size: 1.5rem; color: var(--c-primary); margin-bottom: 1rem; }
.about-section p, .about-section li { line-height: 1.7; color: var(--c-dark); }
.about-section ul { padding-left: 1.5rem; }
.about-section li { margin-bottom: .4rem; }

/* ── UTILS ────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted { color: var(--c-accent); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.wrap { flex-wrap: wrap; }

/* ── FOOTER ───────────────────────────────────────── */
footer {
  background: var(--c-dark);
  color: var(--c-mid);
  text-align: center;
  padding: 1rem;
  font-size: .85rem;
}

footer a { color: var(--c-primary); text-decoration: none; }

/* ── RESPONSIVE ───────────────────────────────────── */
@media (max-width: 640px) {
  main { padding: 1rem; }
  .landing-buttons { flex-direction: column; align-items: center; }
  .board-wrap.fullscreen-board { width: calc(100vw - 1rem); }
  .game-info-bar { font-size: .8rem; }
}
