:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  --bg: #080b12;
  --surface: #101521;
  --surface-raised: #151c2b;
  --line: #293247;
  --line-strong: #3d4963;
  --text: #f5f7fb;
  --muted: #99a4ba;
  --x: #5ee7f4;
  --x-soft: rgba(94, 231, 244, 0.14);
  --o: #ff9e68;
  --o-soft: rgba(255, 158, 104, 0.14);
  --focus: #c7b8ff;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    var(--bg);
  background-size: 36px 36px;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 5px);
  gap: 3px;
  width: 30px;
  height: 30px;
  place-content: center;
  border: 1px solid var(--line-strong);
}

.brand-mark span {
  width: 5px;
  height: 5px;
  background: var(--line-strong);
}

.brand-mark span:nth-child(1),
.brand-mark span:nth-child(5),
.brand-mark span:nth-child(9) {
  background: var(--x);
}

.brand-copy strong {
  display: block;
  font-size: 0.94rem;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

.brand-copy span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.quiet-button,
.secondary-button,
.primary-button,
.mode-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease,
    transform 150ms ease;
}

.quiet-button:hover,
.secondary-button:hover,
.mode-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-raised);
}

.quiet-button {
  padding: 0 15px;
  background: rgba(16, 21, 33, 0.72);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 28px;
  align-items: start;
}

.play-area {
  min-width: 0;
}

.mobile-status {
  display: none;
  margin-bottom: 16px;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 760px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: clamp(8px, 1.5vw, 14px);
  gap: clamp(7px, 1.2vw, 12px);
  background: #06080e;
  border: 1px solid var(--line-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.mini-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-width: 0;
  padding: clamp(4px, 0.7vw, 7px);
  gap: clamp(3px, 0.45vw, 5px);
  background: var(--surface);
  border: 1px solid var(--line);
  transition:
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.mini-board::after {
  position: absolute;
  z-index: 2;
  inset: 5px;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(3.3rem, 10vw, 7.6rem);
  font-weight: 800;
  line-height: 1;
  opacity: 0;
  transform: scale(0.86);
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.mini-board[data-result="X"]::after {
  color: var(--x);
  content: "X";
  opacity: 0.82;
  transform: scale(1);
}

.mini-board[data-result="O"]::after {
  color: var(--o);
  content: "O";
  opacity: 0.82;
  transform: scale(1);
}

.mini-board[data-result="draw"]::after {
  color: var(--muted);
  content: "·";
  opacity: 0.66;
  transform: scale(1);
}

.mini-board--available {
  border-color: var(--line-strong);
  background: #141b29;
}

body[data-turn="X"] .mini-board--available {
  box-shadow: inset 0 0 0 1px var(--x-soft);
}

body[data-turn="O"] .mini-board--available {
  box-shadow: inset 0 0 0 1px var(--o-soft);
}

.mini-board--global-line {
  border-color: var(--focus);
  box-shadow: inset 0 0 0 2px rgba(199, 184, 255, 0.25);
}

.cell {
  position: relative;
  z-index: 1;
  display: grid;
  min-width: 0;
  padding: 0;
  place-items: center;
  aspect-ratio: 1;
  border: 0;
  border-radius: 3px;
  background: #0b0f19;
  color: var(--text);
  cursor: pointer;
  font-size: clamp(0.78rem, 3.1vw, 1.65rem);
  font-weight: 750;
  line-height: 1;
  transition:
    background 120ms ease,
    transform 120ms ease;
}

.cell[data-value="X"] {
  color: var(--x);
}

.cell[data-value="O"] {
  color: var(--o);
}

.cell:not(:disabled):hover {
  background: var(--surface-raised);
  transform: scale(0.94);
}

.cell:not(:disabled):active {
  transform: scale(0.86);
}

.cell:disabled {
  cursor: default;
}

.cell--last::before {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  opacity: 0.72;
}

.board-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.primary-button,
.secondary-button {
  padding: 0 18px;
}

.primary-button {
  border-color: #e4e9f4;
  background: #edf1f8;
  color: #0a0d14;
  font-weight: 720;
}

.primary-button:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.secondary-button {
  background: transparent;
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.sidebar {
  display: grid;
  gap: 14px;
}

.panel {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(16, 21, 33, 0.86);
  backdrop-filter: blur(14px);
}

.status-panel {
  min-height: 190px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.status-panel h1,
.mobile-status h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  letter-spacing: -0.04em;
  line-height: 1.04;
}

.status-detail {
  min-height: 44px;
  margin: 12px 0 18px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.target-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.target-row strong {
  color: var(--text);
  font-size: 0.88rem;
  text-align: right;
  text-transform: capitalize;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-button {
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
}

.mode-button--active {
  border-color: var(--line-strong);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--focus);
}

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

.score-item {
  min-width: 0;
  padding: 12px 8px;
  background: #0b0f19;
  text-align: center;
}

.score-item span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.74rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-item strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
}

.score-item:first-child strong {
  color: var(--x);
}

.score-item:nth-child(2) strong {
  color: var(--o);
}

.rule-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.52;
}

.rule-note strong {
  color: var(--text);
}

dialog {
  width: min(540px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.65);
}

dialog::backdrop {
  background: rgba(3, 5, 10, 0.78);
  backdrop-filter: blur(5px);
}

.dialog-content {
  padding: 28px;
}

.dialog-content h2 {
  margin: 0;
  font-size: 1.65rem;
  letter-spacing: -0.035em;
}

.dialog-content ol {
  display: grid;
  gap: 14px;
  margin: 20px 0 26px;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.55;
}

.dialog-content li::marker {
  color: var(--focus);
  font-weight: 700;
}

@media (max-width: 900px) {
  .app {
    width: min(760px, calc(100% - 28px));
    padding-top: 18px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .mobile-status {
    display: block;
  }

  .sidebar .status-panel {
    display: none;
  }

  .sidebar {
    grid-template-columns: 1fr 1fr;
  }

  .rules-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 18px, 500px);
    padding-top: 12px;
  }

  .masthead {
    margin-bottom: 18px;
  }

  .brand-copy span {
    display: none;
  }

  .game-layout {
    gap: 20px;
  }

  .mobile-status {
    margin-inline: 4px;
  }

  .status-detail {
    min-height: 0;
    margin-bottom: 12px;
  }

  .game-board {
    padding: 6px;
    gap: 5px;
  }

  .mini-board {
    padding: 3px;
    gap: 2px;
  }

  .cell {
    border-radius: 2px;
    font-size: clamp(0.72rem, 5vw, 1.2rem);
  }

  .board-actions {
    margin-top: 12px;
  }

  .primary-button,
  .secondary-button {
    flex: 1;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .rules-panel {
    grid-column: auto;
  }

  .panel {
    padding: 17px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
