:root {
  --bg: #0b1220;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: rgba(0, 0, 0, 0.35);
  --accent: #7c5cff;
  --good: #12b981;
  --danger: #fb7185;
  --p0: #ff5c7a;
  --p1: #5bf0b2;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(124, 92, 255, 0.16), transparent 60%),
    radial-gradient(1000px 700px at 90% 20%, rgba(18, 185, 129, 0.12), transparent 55%),
    radial-gradient(900px 650px at 45% 90%, rgba(255, 172, 79, 0.08), transparent 55%),
    var(--bg);
  min-height: 100svh;
}

body.matchFullscreen {
  overflow: hidden;
  overscroll-behavior: none;
}

body.matchFullscreen .legalBar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
}

body.matchFullscreen .app-root {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--legalbar-h, 0px);
  bottom: 0;
  padding: 10px;
  display: grid;
  place-items: stretch;
}

body.matchFullscreen .card {
  width: 100%;
  max-width: none;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
}

body.matchFullscreen .card.cardGame {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.matchFullscreen .card.cardGame > .row.space,
body.matchFullscreen .card.cardGame > .modebar,
body.matchFullscreen .card.cardGame > .muted.small {
  display: none;
}

body.matchFullscreen .card.cardGame > .section {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.matchFullscreen .card.cardGame > .section > :not(.gameScreen) {
  display: none;
}

body.matchFullscreen .card.cardGame > .section > .gameScreen {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.matchFullscreen .card.cardGame > .section > .gameScreen > .grid2 {
  flex: 1 1 auto;
  min-height: 0;
}

body.matchFullscreen .card.cardGame > .section > .gameScreen > .grid2 > .section {
  display: none;
}

body.matchFullscreen .card.cardGame .boardWrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.matchFullscreen .card.cardGame .tttGrid {
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  max-width: min(100%, max(
    220px,
    calc(100dvh - var(--legalbar-h, 0px) - var(--game-status-h, 0px) - var(--game-controls-h, 0px) - 64px)
  ));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

body.matchFullscreen .card.cardGame .tttCell {
  font-size: clamp(28px, 4.5vw, 54px);
}

.legalBar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  backdrop-filter: blur(10px);
}
.legalBar a { color: rgba(255, 255, 255, 0.90); text-decoration: none; }
.legalBar a:hover { text-decoration: underline; }
.legalBar .sep { opacity: 0.55; }

.app-root {
  padding: 16px;
  display: grid;
  place-items: center;
}

.card {
  width: min(1200px, 100%);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.title {
  font-weight: 900;
  letter-spacing: 0.2px;
  font-size: clamp(22px, 3.6vw, 34px);
}
.subtitle { color: rgba(255, 255, 255, 0.72); font-size: 13px; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.space { justify-content: space-between; }

.btn {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 800;
}
.btn:hover:enabled { background: rgba(255, 255, 255, 0.11); }
.btn.primary { background: rgba(124, 92, 255, 0.32); border-color: rgba(124, 92, 255, 0.55); }
.btn.good { background: rgba(18, 185, 129, 0.22); border-color: rgba(18, 185, 129, 0.55); }
.btn.danger { background: rgba(251, 113, 133, 0.20); border-color: rgba(251, 113, 133, 0.50); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.field { display: grid; gap: 6px; min-width: 240px; }
.field.inline { min-width: 280px; }
.field span { color: var(--muted); font-size: 12px; }

input, select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
}

.modebar {
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}
.modebar .btn { flex: 1 1 0; justify-content: center; text-align: center; }
.modebar .btn[aria-selected="true"] { background: rgba(124, 92, 255, 0.32); border-color: rgba(124, 92, 255, 0.55); }

.section {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
  display: grid;
  gap: 10px;
}
.h { font-weight: 900; font-size: 13px; }

.players { display: grid; gap: 8px; }
.player-row {
  display: grid;
  grid-template-columns: 1fr 170px 170px;
  gap: 8px;
  align-items: end;
}
@media (max-width: 820px) {
  .player-row { grid-template-columns: 1fr; }
  .field, .field.inline { min-width: 0; width: 100%; }
}

.grid2 {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 360px;
  gap: 12px;
  align-items: start;
}
@media (max-width: 980px) {
  .grid2 { grid-template-columns: 1fr; }
}

.boardWrap {
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
  padding: 12px;
}

.boardSvg {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 1 / 1;
}

.chat-log {
  max-height: 260px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
  padding: 10px;
}
.chat-line { margin-bottom: 6px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.16);
}
.dot.p0 { background: var(--p0); }
.dot.p1 { background: var(--p1); }

.overlay {
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  padding: 12px;
}

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

.tttCell {
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  font-size: clamp(34px, 6vw, 64px);
  font-weight: 1000;
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
  user-select: none;
}
.tttCell:hover:enabled { background: rgba(255, 255, 255, 0.10); }
.tttCell:disabled { opacity: 0.70; cursor: not-allowed; }
.tttCell.p0 { color: var(--p0); }
.tttCell.p1 { color: var(--p1); }

.tttLine {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
}
