@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  color-scheme: light;
  --paper: #f7f4ed;
  --surface: #ffffff;
  --ink: #292521;
  --muted: #756e65;
  --line: #e6ded2;
  --rust: #a74631;
  --gold: #f1d18a;
  --gold-ink: #9a641e;
  --orange: #c56b55;
  font-family: "DM Sans", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(
      circle at 88% 7%,
      rgba(167, 70, 49, 0.1),
      transparent 22rem
    ),
    var(--paper);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100% - 48px, 1040px);
  min-height: 72px;
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  text-decoration: none;
}

.portfolio-link {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s ease;
}

.portfolio-link:hover {
  color: var(--rust);
}

.page-shell {
  width: min(100% - 48px, 1040px);
  margin: 54px auto 0;
}

.game-intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  padding: 24px 28px;
  border-radius: 8px;
  background: var(--rust);
  box-shadow: 0 12px 28px rgba(87, 44, 32, 0.16);
  color: white;
}

.game-intro .eyebrow {
  color: var(--gold);
}

.eyebrow {
  margin: 0;
  color: var(--rust);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
}

.game-intro h1 {
  margin: 8px 0 6px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 40px;
  line-height: 1.1;
}

.game-intro > div > p:last-child {
  margin: 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: 15px;
}

.round-label {
  padding: 10px 15px;
  border-radius: 8px;
  background: var(--gold);
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.round-label span {
  margin: 0 5px;
  color: #766248;
  font-family: "DM Sans", sans-serif;
  font-size: 10px;
  text-transform: uppercase;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 24px;
  align-items: stretch;
}

.play-area {
  display: grid;
  justify-items: center;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(59, 44, 38, 0.08);
}

.opponent-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.opponent-control select {
  min-height: 38px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.game-status {
  min-height: 24px;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: min(100%, 420px);
  aspect-ratio: 1;
  padding: 12px;
  border-radius: 12px;
  background: var(--rust);
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.04);
}

.mobile-game-actions {
  display: none;
}

.cell {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid rgba(167, 70, 49, 0.15);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--ink);
  cursor: pointer;
  font-family: "Space Grotesk", sans-serif;
  font-size: 64px;
  font-weight: 700;
  line-height: 1;
  transition:
    background 0.16s ease,
    transform 0.16s ease;
}

.cell:not(:disabled):hover {
  transform: translateY(-2px);
  background: #fbf0e8;
}

.cell[data-mark="X"] {
  color: var(--rust);
}

.cell[data-mark="O"] {
  color: var(--gold-ink);
}

.cell.is-winner {
  background: #fbebc6;
}

.cell:disabled {
  cursor: default;
}

.score-panel {
  display: flex;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 12px 28px rgba(59, 44, 38, 0.08);
}

.timer-block {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.score-panel .eyebrow {
  color: var(--rust);
}

#round-time {
  display: block;
  margin-top: 7px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 36px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1;
}

.score-block {
  padding: 20px 0;
}

.score-block > .eyebrow {
  margin-bottom: 10px;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.score-row strong {
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  font-size: 18px;
}

#score-x {
  color: var(--rust);
}

#score-o {
  color: var(--gold-ink);
}

.score-row.draws {
  border-bottom: 0;
}

.new-round,
.reset-score {
  min-height: 42px;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease;
}

.new-round {
  margin-top: auto;
  border: 0;
  background: var(--gold);
  color: var(--ink);
}

.new-round:hover {
  transform: translateY(-1px);
  background: #f7dfa8;
}

.reset-score {
  margin-top: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.reset-score:hover {
  background: #f7f2e9;
}

.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100% - 48px, 1040px);
  margin: 30px auto 0;
  padding: 18px 0 24px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: center;
}

@media (max-width: 700px) {
  .topbar,
  .page-shell,
  .page-footer {
    width: min(100% - 32px, 520px);
  }

  .page-shell {
    margin-top: 34px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    row-gap: 26px;
  }

  .mobile-game-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: min(100%, 420px);
    margin-top: 14px;
  }

  .mobile-game-action {
    display: flex;
    min-width: 0;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-game-action.new-round-action {
    border-color: var(--gold);
    background: var(--gold);
  }

  .mobile-game-action.reset-score-action {
    border-color: var(--rust);
    background: var(--rust);
    color: #fff;
  }

  .mobile-game-action .action-icon {
    flex: 0 0 auto;
    font-size: 20px;
    line-height: 1;
  }

  .score-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px 24px;
  }

  .timer-block {
    grid-row: span 2;
    align-self: center;
    border: 0;
  }

  .score-block {
    padding: 0 0 8px;
  }

  .score-panel > .new-round,
  .score-panel > .reset-score {
    display: none;
  }

  .new-round,
  .reset-score {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .topbar,
  .page-shell,
  .page-footer {
    width: calc(100% - 24px);
  }

  .brand {
    font-size: 22px;
  }

  .portfolio-link {
    font-size: 12px;
  }

  .page-shell {
    margin-top: 28px;
  }

  .game-intro {
    align-items: flex-start;
    padding: 20px 16px;
  }

  .game-intro h1 {
    font-size: 34px;
  }

  .game-intro > div > p:last-child {
    max-width: 260px;
    font-size: 13px;
  }

  .round-label {
    padding: 8px 10px;
    font-size: 12px;
  }

  .play-area {
    padding: 14px;
  }

  .board {
    gap: 8px;
    padding: 8px;
  }

  .cell {
    border-width: 1px;
    font-size: 56px;
  }

  .score-panel {
    padding: 18px;
  }

  .page-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
