:root {
  --bg-top: #f1efe7;
  --bg-bottom: #e1eaf0;
  --panel: #fcfbf8;
  --line: rgba(49, 66, 77, 0.14);
  --text: #21303a;
  --muted: #5d6b75;
  --accent: #236b9a;
  --accent-dark: #184e73;
  --board-bg: #f6fafc;
  --x-color: #1c638d;
  --o-color: #b35a2b;
  --win: #ffe28a;
  --shadow: 0 14px 34px rgba(33, 48, 58, 0.1);
  --radius: 26px;
  --board-radius: 32px;
  --cell-size: min(16.5vh, 174px);
  --font-main: "Trebuchet MS", "Segoe UI", Tahoma, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
  min-height: 100vh;
  overflow: hidden;
}

.reload-hotspot {
  position: fixed;
  top: 0;
  right: 0;
  width: 96px;
  height: 96px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  opacity: 0.01;
  z-index: 20;
}

.page-shell {
  width: min(1920px, 100vw);
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 10px 82px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(315px, 390px) minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 32px);
}

.panel-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.side-main {
  display: grid;
  gap: 12px;
  align-content: start;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-dark);
  font-size: 0.85rem;
  font-weight: 700;
}

.brand-block h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.25rem, 3.4vw, 4rem);
  line-height: 0.92;
}

button {
  border: none;
  border-radius: 18px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  padding: 15px 16px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.02);
  outline: none;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  color: #fff;
  box-shadow: 0 16px 26px rgba(25, 114, 120, 0.25);
}

.secondary-button {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(33, 48, 58, 0.06);
}

.exit-link {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  min-height: 66px;
  border-radius: 18px;
  background: linear-gradient(180deg, #455560, #29353d);
  color: #ffffff;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: 0 12px 22px rgba(33, 48, 58, 0.2);
}

.exit-link:hover,
.exit-link:focus-visible {
  filter: brightness(1.04);
  outline: none;
}

.actions-block {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.action-wide {
  grid-column: 1 / -1;
}

.stats-card h2,
.info-card h2 {
  font-size: 1.1rem;
  margin: 0 0 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  padding: 10px 12px;
  min-width: 0;
}

.stat-label {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-box strong {
  font-size: 1.45rem;
  line-height: 1;
}

.info-card p,
.status-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.info-card p + p {
  margin-top: 8px;
}

.board-panel {
  display: grid;
  place-items: center;
  overflow: hidden;
}

.board-wrap {
  display: grid;
  place-items: center;
  gap: 14px;
  width: 100%;
  min-height: 100%;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, var(--cell-size));
  grid-template-rows: repeat(3, var(--cell-size));
  gap: 12px;
  padding: 18px;
  border-radius: var(--board-radius);
  background: linear-gradient(180deg, #d9eaf4, var(--board-bg));
  border: 4px solid rgba(35, 107, 154, 0.2);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.board.size-4 {
  grid-template-columns: repeat(4, var(--cell-size));
  grid-template-rows: repeat(4, var(--cell-size));
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: #ffffff;
  border: 1px solid rgba(49, 66, 77, 0.15);
  box-shadow: 0 12px 22px rgba(33, 48, 58, 0.12);
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(4rem, 11vh, 8rem);
  line-height: 1;
  padding: 0;
}

.cell.x {
  color: var(--x-color);
}

.cell.o {
  color: var(--o-color);
}

.cell.win {
  background: linear-gradient(180deg, #fff2b9, var(--win));
}

.cell.selected {
  outline: 5px solid #ffe28a;
  outline-offset: 3px;
}

.cell.open-target {
  background: #edf6fb;
}

.cell:disabled {
  cursor: default;
}

.turn-banner {
  min-width: min(100%, 520px);
  padding: 16px 22px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff, #edf4f8);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: 0 10px 22px rgba(33, 48, 58, 0.08);
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 1280px) {
  :root {
    --cell-size: min(14vh, 138px);
  }
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .actions-block,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  :root {
    --cell-size: min(21vw, 128px);
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100%, calc(100% - 16px));
    padding: 10px 8px;
  }

  .panel-card {
    padding: 16px;
  }

  .board {
    gap: 8px;
    padding: 12px;
  }
}
