/* ════════════════════════════════════════════════════════════════════════
   MMO Maid · Tic-Tac-Toe — visual system

   Aesthetic: dark fantasy parchment, cool navy depth + aged-gold leaf.
   Type pairing: Cinzel display, Crimson Pro body, JetBrains Mono numerics.
   Spirit: a candlelit hall — atmosphere first, density second.
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* Navy depth */
  --bg-deepest: #0a1020;
  --bg-deep: #111a30;
  --bg-mid: #1a2545;
  --bg-elev: #22305a;

  /* Aged gold (the "MMO Maid" accent) */
  --gold-100: #f5e3ad;
  --gold-300: #e3c878;
  --gold-500: #c9a14a;
  --gold-700: #8b6a25;
  --gold-glow: rgba(201, 161, 74, 0.28);

  /* Parchment / ink */
  --ink: #ece7d3;
  --ink-dim: #c5c0a8;
  --ink-faint: #8c8674;

  /* Functional */
  --ok: #6fa46f;
  --warn: #d6953a;
  --err: #c45a55;

  /* Marks */
  --x-color: #e8c97e;       /* aged gold for X */
  --o-color: #7fb6d4;       /* old-silver-blue for O */

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.7);

  --serif: "Crimson Pro", "Garamond", Georgia, serif;
  --display: "Cinzel", "Trajan Pro", serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  background: var(--bg-deepest);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Ambient backdrop ────────────────────────────────────────────────── */

.ambient {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  overflow: hidden;
}
.ambient-glow {
  position: absolute;
  top: -20%; left: 50%; transform: translateX(-50%);
  width: 1100px; height: 1100px;
  background: radial-gradient(closest-side, var(--gold-glow), transparent 70%);
  filter: blur(40px);
  opacity: 0.55;
}
.ambient-grain {
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.4 0 0 0 0 0.2 0 0 0 0.18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.35;
  mix-blend-mode: overlay;
}

body > *:not(.ambient) { position: relative; z-index: 1; }

/* ── Headers ─────────────────────────────────────────────────────────── */

.hall-header,
.play-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 32px 48px 16px;
  border-bottom: 1px solid rgba(201, 161, 74, 0.14);
}
.hall-header__crest {
  width: 72px; height: 72px;
  display: grid; place-items: center;
  font-size: 36px;
  color: var(--gold-300);
  background: radial-gradient(circle, var(--bg-elev) 0%, var(--bg-deep) 70%);
  border: 1px solid var(--gold-700);
  border-radius: 50%;
  box-shadow: var(--shadow-sm), inset 0 0 24px rgba(201, 161, 74, 0.18);
}
.hall-title {
  margin: 0;
  font-family: var(--display);
  font-size: 38px;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--gold-100);
  text-transform: uppercase;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.hall-subtitle {
  margin: 4px 0 0;
  font-style: italic;
  color: var(--ink-dim);
  font-size: 16px;
}

.play-header__back {
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  text-decoration: none;
  text-transform: uppercase;
  padding: 10px 16px;
  border: 1px solid rgba(201, 161, 74, 0.2);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.play-header__back:hover {
  color: var(--gold-100);
  border-color: var(--gold-500);
  background: rgba(201, 161, 74, 0.08);
}
.play-header__title { flex: 1; }
.play-header__title h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: 0.08em;
  color: var(--gold-100);
}
.play-header__phase {
  margin: 4px 0 0;
  color: var(--ink-dim);
  font-style: italic;
  font-size: 15px;
}

.timer {
  display: grid;
  place-items: center;
  width: 88px; height: 88px;
  border: 2px solid var(--gold-700);
  border-radius: 50%;
  background: radial-gradient(circle, var(--bg-elev), var(--bg-deep));
  box-shadow: inset 0 0 18px rgba(201, 161, 74, 0.2);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.timer__num {
  font-family: var(--mono);
  font-size: 28px;
  color: var(--gold-100);
  font-weight: 500;
}
.timer__label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.timer--urgent {
  border-color: var(--err);
  box-shadow: 0 0 24px rgba(196, 90, 85, 0.4), inset 0 0 18px rgba(196, 90, 85, 0.25);
  animation: pulseUrgent 0.6s infinite alternate;
}
.timer--urgent .timer__num { color: #f1b1ad; }
@keyframes pulseUrgent {
  to { box-shadow: 0 0 32px rgba(196, 90, 85, 0.55), inset 0 0 24px rgba(196, 90, 85, 0.35); }
}

/* ── Main / Lobby ────────────────────────────────────────────────────── */

.hall-main { padding: 32px 48px 80px; max-width: 1280px; margin: 0 auto; }

.hall-actions {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}
.hall-stats {
  margin-left: auto;
  display: flex; gap: 28px;
  padding: 12px 24px;
  background: rgba(26, 37, 69, 0.5);
  border: 1px solid rgba(201, 161, 74, 0.15);
  border-radius: var(--radius-md);
}
.hall-stats__item {
  display: flex; flex-direction: column; align-items: center;
}
.hall-stats__num {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--gold-100);
}
.hall-stats__label {
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.tables__heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(201, 161, 74, 0.1);
}
.tables__heading h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.1em;
  color: var(--gold-300);
  font-weight: 500;
  text-transform: uppercase;
}
.tables__hint {
  color: var(--ink-faint);
  font-size: 14px;
  font-style: italic;
}
.tables__hint em { color: var(--gold-300); font-style: normal; }

.tables__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 18px;
}

.table-card {
  background: linear-gradient(165deg, var(--bg-mid) 0%, var(--bg-deep) 100%);
  border: 1px solid rgba(201, 161, 74, 0.14);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  position: relative;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.table-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold-500);
  box-shadow: var(--shadow-md);
}
.table-card--mine { border-color: var(--gold-500); box-shadow: 0 0 0 1px var(--gold-700) inset; }
.table-card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.table-card__name {
  margin: 0;
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.table-card__phase {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.phase--waiting   { color: var(--gold-300); }
.phase--playing   { color: var(--ok); }
.phase--completed { color: var(--ink-faint); }

.table-card__seats {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
}
.seat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.04);
}
.seat--vs {
  font-family: var(--display);
  color: var(--ink-faint);
  font-size: 12px;
  letter-spacing: 0.2em;
  background: none;
  border: none;
  text-align: center;
  padding: 0;
}
.seat__mark {
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.18em;
  font-weight: 600;
}
.seat--x .seat__mark { color: var(--x-color); }
.seat--o .seat__mark { color: var(--o-color); }
.seat__name { color: var(--ink); font-size: 14px; }
.seat--empty .seat__name { color: var(--ink-faint); font-style: italic; }
.seat--you { box-shadow: inset 0 0 0 1px var(--gold-500); }

.table-card__meta { display: flex; gap: 10px; }
.meta-pill {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
}
.table-card__actions { display: flex; gap: 10px; }

/* ── Empty state ─────────────────────────────────────────────────────── */

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 24px;
  color: var(--ink-faint);
}
.empty-state__rune {
  font-family: var(--display);
  font-size: 48px;
  color: var(--gold-700);
  margin-bottom: 16px;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  border: 1px solid;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  transition: all 0.18s;
  font-weight: 500;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--sm { padding: 8px 14px; font-size: 12px; }
.btn__rune { font-family: var(--display); }

.btn--primary {
  background: linear-gradient(180deg, var(--gold-500), var(--gold-700));
  color: var(--bg-deepest);
  border-color: var(--gold-500);
  box-shadow: 0 4px 14px var(--gold-glow);
}
.btn--primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--gold-300), var(--gold-500));
  box-shadow: 0 8px 24px var(--gold-glow);
  transform: translateY(-1px);
}

.btn--ghost {
  color: var(--ink-dim);
  border-color: rgba(201, 161, 74, 0.25);
}
.btn--ghost:hover:not(:disabled) {
  color: var(--gold-100);
  border-color: var(--gold-500);
  background: rgba(201, 161, 74, 0.08);
}

/* ── Modal ───────────────────────────────────────────────────────────── */

.modal {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal--open { display: flex; }
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.modal__panel {
  position: relative;
  background: var(--bg-deep);
  border: 1px solid var(--gold-700);
  border-radius: var(--radius-md);
  padding: 28px 32px;
  width: min(440px, 90vw);
  box-shadow: var(--shadow-lg);
}
.modal__panel h3 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 20px;
  letter-spacing: 0.1em;
  color: var(--gold-100);
  text-transform: uppercase;
}
.modal__hint { color: var(--ink-faint); font-style: italic; margin: 0 0 18px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  border: 1px solid rgba(201, 161, 74, 0.2);
  border-radius: var(--radius-sm);
  font-family: var(--serif);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.input:focus { border-color: var(--gold-500); }

/* ── Play page ───────────────────────────────────────────────────────── */

.play-main {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 48px 80px;
  display: flex; flex-direction: column; gap: 28px;
}

.players {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-items: stretch;
}
.player-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 16px 22px;
  background: linear-gradient(135deg, var(--bg-mid), var(--bg-deep));
  border: 1px solid rgba(201, 161, 74, 0.12);
  border-radius: var(--radius-md);
  transition: border-color 0.3s, box-shadow 0.3s;
}
.player-card__mark {
  font-family: var(--display);
  font-size: 36px;
  font-weight: 700;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
}
#player-x .player-card__mark { color: var(--x-color); }
#player-o .player-card__mark { color: var(--o-color); }
.player-card__info { display: flex; flex-direction: column; }
.player-card__name { font-size: 18px; color: var(--ink); }
.player-card__role {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.player-card__indicator {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.3s, box-shadow 0.3s;
}
.player-card__indicator.active {
  background: var(--gold-300);
  box-shadow: 0 0 14px var(--gold-glow);
  animation: pulseDot 1.4s infinite;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.players__divider {
  display: grid; place-items: center;
  width: 56px;
  font-family: var(--display);
  color: var(--gold-700);
}
.vs-rune { font-size: 32px; }

/* ── The board ───────────────────────────────────────────────────────── */

.board-frame {
  position: relative;
  margin: 0 auto;
  width: min(520px, 92vw);
  aspect-ratio: 1 / 1;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(201, 161, 74, 0.1), transparent 70%),
    linear-gradient(160deg, var(--bg-elev), var(--bg-deepest));
  border: 1px solid var(--gold-700);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), inset 0 0 60px rgba(0, 0, 0, 0.5);
}
.board-frame::before, .board-frame::after {
  /* Decorative corner runes */
  content: "✦";
  position: absolute;
  font-family: var(--display);
  color: var(--gold-700);
  font-size: 16px;
  pointer-events: none;
}
.board-frame::before { top: 8px; left: 12px; }
.board-frame::after  { bottom: 8px; right: 12px; }

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  height: 100%;
}
.cell {
  position: relative;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(201, 161, 74, 0.15);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--display);
  font-size: clamp(48px, 12vw, 100px);
  font-weight: 700;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  display: grid; place-items: center;
}
.cell:disabled { cursor: default; }
.cell:not(:disabled):hover {
  background: rgba(201, 161, 74, 0.08);
  border-color: var(--gold-500);
}
.cell:not(:disabled):active { transform: scale(0.97); }

.cell--x { color: var(--x-color); text-shadow: 0 4px 16px rgba(232, 201, 126, 0.35); }
.cell--o { color: var(--o-color); text-shadow: 0 4px 16px rgba(127, 182, 212, 0.35); }
.cell--filled { cursor: default; }
.cell--filled:hover { background: rgba(0, 0, 0, 0.4); }

.cell--x, .cell--o {
  animation: stamp 0.4s ease-out;
}
@keyframes stamp {
  0%   { transform: scale(0.4) rotate(-12deg); opacity: 0; }
  60%  { transform: scale(1.15) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

/* Overlay (waiting / completed) */
.board-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(10, 16, 32, 0.82);
  backdrop-filter: blur(6px);
  border-radius: var(--radius-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.board-overlay--visible { opacity: 1; pointer-events: auto; }
.board-overlay__panel { text-align: center; padding: 24px; max-width: 80%; }
.board-overlay__rune {
  font-family: var(--display);
  font-size: 56px;
  color: var(--gold-300);
  margin-bottom: 8px;
}
.board-overlay__panel h2 {
  font-family: var(--display);
  letter-spacing: 0.12em;
  color: var(--gold-100);
  margin: 0 0 8px;
  font-size: 24px;
  text-transform: uppercase;
}
.board-overlay__panel p {
  color: var(--ink-dim);
  font-style: italic;
  margin: 0 0 18px;
}
.board-overlay__actions { display: flex; gap: 10px; justify-content: center; }

/* ── Match actions / connection status ──────────────────────────────── */

.match-actions {
  display: flex; align-items: center; justify-content: center;
  gap: 16px;
  padding-top: 8px;
}
.connection-status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.connection-status[data-state="ok"]   { color: var(--ok); }
.connection-status[data-state="warn"] { color: var(--warn); }
.connection-status[data-state="err"]  { color: var(--err); }

/* ── Toast ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translate(-50%, 60px);
  background: var(--bg-elev);
  color: var(--ink);
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gold-700);
  box-shadow: var(--shadow-md);
  font-family: var(--serif);
  font-size: 15px;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 1000;
}
.toast--visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { border-color: var(--err); color: #f1b1ad; }

/* ── Mobile ──────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .hall-header, .play-header { padding: 24px 20px 16px; gap: 14px; }
  .hall-main, .play-main { padding: 20px; }
  .hall-title { font-size: 26px; }
  .hall-actions { gap: 10px; }
  .hall-stats { padding: 10px 16px; gap: 18px; }
  .tables__heading { flex-direction: column; align-items: flex-start; gap: 4px; }
  .players { grid-template-columns: 1fr; }
  .players__divider { display: none; }
  .player-card { padding: 12px 16px; }
  .player-card__mark { width: 44px; height: 44px; font-size: 28px; }
  .play-header__title h1 { font-size: 20px; }
  .timer { width: 64px; height: 64px; }
  .timer__num { font-size: 22px; }
}
