:root {
  --page: #15181e;
  --panel: #202329;
  --panel-2: #262a31;
  --line: #3a3f47;
  --muted: #a6a8ad;
  --text: #f5f6f7;
  --teal: #19c1ad;
  --teal-dark: #0f8f83;
  --x: #4d525a;
  --o: #f7efd2;
  --focus: #ffffff;
  --danger: #ffdb79;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow: hidden;
  overflow-x: hidden;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 6%, rgba(25, 193, 173, 0.16), transparent 18rem),
    linear-gradient(180deg, #181b21, #111318);
}

button,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 28px);
}

.game-panel {
  width: min(100%, 980px);
  min-width: 0;
  height: min(980px, calc(100vh - clamp(24px, 6vw, 56px)));
  height: min(980px, calc(100svh - clamp(24px, 6vw, 56px)));
  max-height: calc(100vh - clamp(24px, 6vw, 56px));
  max-height: calc(100svh - clamp(24px, 6vw, 56px));
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto minmax(260px, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.42);
}

.top-bar {
  min-height: 72px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 34px) 10px;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

h1 {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  font-weight: 800;
  line-height: 1;
}

.difficulty-control {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.difficulty-control span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.difficulty-control select {
  max-width: min(48vw, 180px);
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  font-weight: 850;
}

.difficulty-control select:focus-visible,
.restart-button:focus-visible,
.secondary-button:focus-visible,
.cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 0 clamp(18px, 4vw, 34px) 22px;
}

.score-card {
  min-width: 0;
  min-height: 62px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #202329;
}

.score-card.is-human {
  border-bottom-color: var(--teal);
}

.score-card.is-computer {
  border-bottom-color: var(--o);
}

.score-label {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(0.74rem, 2vw, 0.92rem);
  font-weight: 850;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.score-card strong {
  justify-self: end;
  color: var(--muted);
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 500;
  line-height: 1;
}

.status-strip {
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 20px 18px;
  color: var(--muted);
  font-size: clamp(1rem, 2.5vw, 1.22rem);
  font-weight: 800;
}

.status-strip #status-message {
  grid-column: 2;
}

.status-undo-button {
  grid-column: 3;
  justify-self: end;
}

.playfield {
  width: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: clamp(20px, 4vw, 34px);
  background: var(--teal);
}

.board {
  position: relative;
  grid-area: 1 / 1;
  align-self: center;
  justify-self: center;
  width: min(100%, 420px, calc(100vh - 370px));
  width: min(100%, 420px, calc(100svh - 370px));
  min-width: 260px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0;
  background:
    linear-gradient(90deg, transparent calc(33.333% - 6px), var(--teal-dark) calc(33.333% - 6px), var(--teal-dark) calc(33.333% + 6px), transparent calc(33.333% + 6px)),
    linear-gradient(90deg, transparent calc(66.666% - 6px), var(--teal-dark) calc(66.666% - 6px), var(--teal-dark) calc(66.666% + 6px), transparent calc(66.666% + 6px)),
    linear-gradient(0deg, transparent calc(33.333% - 6px), var(--teal-dark) calc(33.333% - 6px), var(--teal-dark) calc(33.333% + 6px), transparent calc(33.333% + 6px)),
    linear-gradient(0deg, transparent calc(66.666% - 6px), var(--teal-dark) calc(66.666% - 6px), var(--teal-dark) calc(66.666% + 6px), transparent calc(66.666% + 6px));
}

.cell {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--x);
  background: transparent;
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 300;
  line-height: 1;
  text-align: center;
  transition:
    background-color 140ms ease,
    transform 140ms ease;
}

.cell:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(0.97);
}

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

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

.cell.is-win {
  color: var(--danger);
}

.winning-strike {
  position: absolute;
  left: var(--strike-x, 50%);
  top: var(--strike-y, 50%);
  z-index: 2;
  width: var(--strike-width, 0%);
  height: 14px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 18px rgba(255, 219, 121, 0.34);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) rotate(var(--strike-angle, 0deg)) scaleX(0);
  transform-origin: left center;
}

.board.is-striking .winning-strike {
  animation: strike-line 1500ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.playfield.is-result .board {
  pointer-events: none;
  visibility: hidden;
}

.result-panel {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 24px;
  text-align: center;
}

.result-panel[hidden] {
  display: none;
}

.result-mark {
  color: var(--o);
  font-size: clamp(7rem, 22vw, 12rem);
  font-weight: 250;
  line-height: 0.78;
  letter-spacing: 0;
}

.result-message {
  color: var(--x);
  font-size: clamp(2.4rem, 8vw, 4.5rem);
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

@keyframes strike-line {
  0% {
    opacity: 0;
    transform: translateY(-50%) rotate(var(--strike-angle, 0deg)) scaleX(0);
  }

  10% {
    opacity: 1;
  }

  100% {
    opacity: 1;
    transform: translateY(-50%) rotate(var(--strike-angle, 0deg)) scaleX(1);
  }
}

.controls {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.restart-button,
.secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-weight: 850;
}

.restart-button {
  color: var(--teal);
  font-size: clamp(1.1rem, 2.7vw, 1.45rem);
}

.secondary-button {
  padding: 0 14px;
  color: var(--muted);
  border: 1px solid var(--line);
}

.restart-button:hover,
.secondary-button:hover:not(:disabled) {
  color: var(--text);
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
    align-items: stretch;
    justify-items: start;
  }

  .game-panel {
    width: min(100vw, 390px);
    max-width: min(100vw, 390px);
    min-height: 100vh;
    min-height: 100svh;
    height: 100vh;
    height: 100svh;
    max-height: 100vh;
    max-height: 100svh;
    grid-template-rows: auto auto auto minmax(240px, 1fr) auto;
    border: 0;
    border-radius: 0;
  }

  .top-bar {
    width: min(100vw, 390px);
    max-width: min(100vw, 390px);
    display: grid;
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 16px 8px;
  }

  .title-group {
    display: grid;
    gap: 6px;
  }

  .difficulty-control {
    justify-self: start;
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .scoreboard {
    width: min(100vw, 390px);
    max-width: min(100vw, 390px);
    gap: 8px;
    padding: 0 12px 16px;
  }

  .score-card {
    min-height: 62px;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 4px;
    padding: 8px 6px;
  }

  .score-label {
    font-size: 0.62rem;
  }

  .score-card strong {
    font-size: 1.8rem;
    justify-self: center;
  }

  .playfield {
    width: min(100vw, 390px);
    max-width: min(100vw, 390px);
    overflow: hidden;
    min-height: 0;
    padding: 18px;
  }

  .board {
    width: min(70vw, 280px, calc(100svh - 370px));
    min-width: 220px;
  }

  .controls {
    align-content: center;
  }

  .restart-button {
    flex: 1 1 150px;
  }

  .status-strip {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 0 12px 14px;
  }

  .status-strip #status-message,
  .status-undo-button {
    grid-column: 1;
  }

  .status-undo-button {
    justify-self: center;
  }
}
