:root {
  --display-w: 600px;
  --ink: #f8fbf7;
  --muted: #9fd6c0;
  --bg: #020303;
  --panel: #07130f;
  --green: #0e8f60;
  --green-deep: #053827;
  --grid: #0fd486;
  --gold: #ffd66c;
  --coral: #ff765f;
  --blue: #77c7ff;
  --shadow: 0 0 34px rgba(15, 212, 134, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111;
  display: grid;
  place-items: center;
}

button {
  border: 0;
  font: inherit;
}

.shell {
  position: relative;
  width: min(var(--display-w), 100vw);
  height: min(var(--display-w), 100vh);
  display: grid;
  grid-template-columns: 132px 126px 1fr;
  grid-template-rows: 62px minmax(0, 1fr) 42px;
  gap: 8px;
  padding: 10px;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 16px 70px rgba(0, 0, 0, 0.55);
}

.scoreboard {
  display: contents;
}

.brand {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(90deg, #181818 0 50%, #faf7ed 50% 100%);
  border: 2px solid var(--grid);
  box-shadow: 0 0 16px rgba(15, 212, 134, 0.35);
}

.brand p,
.turn-panel p,
.score-card span {
  margin: 0;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand h1 {
  margin: 2px 0 0;
  font-size: 1.28rem;
  line-height: 1;
  letter-spacing: 0;
}

.score-cards {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  min-width: 0;
}

.score-card,
.turn-panel {
  border: 1px solid rgba(23, 32, 29, 0.11);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 0 18px rgba(15, 212, 134, 0.12);
}

.score-card {
  padding: 7px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.score-card strong {
  font-size: 1.42rem;
  line-height: 1;
}

.score-card.dark.active {
  color: #f7f4eb;
  background: #17201d;
  outline: 2px solid var(--blue);
}

.score-card.light.active {
  color: #17201d;
  background: #ffffff;
  outline: 2px solid var(--gold);
}

.score-card.dark.active span,
.score-card.light.active span {
  color: currentColor;
}

.turn-panel {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 7px 9px;
}

.turn-panel.game-ended {
  opacity: 0.72;
}

.turn-panel strong {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-size: 0.82rem;
}

.turn-disc {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #171717;
  box-shadow: inset -6px -7px 0 rgba(255, 255, 255, 0.08), 0 6px 14px rgba(23, 32, 29, 0.2);
}

.turn-disc.light {
  background: #fbf8ef;
  border: 1px solid rgba(23, 32, 29, 0.2);
  box-shadow: inset -7px -8px 0 rgba(23, 32, 29, 0.08), 0 6px 14px rgba(23, 32, 29, 0.12);
}

.controls {
  grid-column: 1 / -1;
  grid-row: 3;
  display: grid;
  grid-template-columns: 1fr 96px 96px;
  gap: 6px;
}

.controls button {
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #f8f3e8;
  border: 1px solid rgba(119, 199, 255, 0.38);
  background: #09261d;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.controls button:hover {
  transform: translateY(-1px);
  background: var(--green);
}

.focusable:focus,
.focusable.is-selected {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  z-index: 2;
}

.controls button[aria-pressed="true"] {
  color: #04100c;
  background: var(--blue);
}

.controls button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

#newGameButton {
  grid-column: auto;
}

.icon-button {
  padding: 0;
}

.button-icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.play-area {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

.board-wrap {
  position: relative;
  width: auto;
  height: 100%;
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  padding: 20px;
  border-radius: 8px;
  background: #13231d;
  box-shadow: var(--shadow);
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 4px solid var(--grid);
  background: var(--green);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  perspective: 180px;
  border-right: 1px solid var(--green-deep);
  border-bottom: 1px solid var(--green-deep);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.08), transparent 48%),
    var(--green);
  cursor: default;
}

.cell:nth-child(8n) {
  border-right: 0;
}

.cell:nth-child(n + 57) {
  border-bottom: 0;
}

.cell.legal {
  cursor: pointer;
}

.cell.legal::after {
  content: "";
  width: min(34%, 18px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: rgba(255, 214, 108, 0.22);
  box-shadow: 0 0 13px rgba(255, 214, 108, 0.65);
}

.cell.legal.hidden-hints::after {
  display: none;
}

.cell.legal:hover::after {
  background: rgba(210, 166, 66, 0.64);
}

.cell.is-selected::after {
  background: var(--gold);
}

.disc {
  width: min(74%, 38px);
  aspect-ratio: 1;
  border-radius: 50%;
  transition: transform 220ms ease, background 220ms ease;
  transform-style: preserve-3d;
}

.disc.dark {
  --disc-shadow: inset -10px -12px 0 rgba(255, 255, 255, 0.08), 0 8px 15px rgba(5, 20, 15, 0.28);
  background: #171717;
  box-shadow: var(--disc-shadow);
}

.disc.light {
  --disc-shadow: inset -10px -12px 0 rgba(23, 32, 29, 0.08), 0 8px 15px rgba(5, 20, 15, 0.18);
  background: #fbf8ef;
  border: 1px solid rgba(23, 32, 29, 0.18);
  box-shadow: var(--disc-shadow);
}

.disc.flipping {
  animation: flip-disc 720ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.disc.placed {
  animation: place-disc 620ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes flip-disc {
  0% {
    transform: rotateY(0deg) scale(1);
    filter: brightness(0.82);
  }

  48% {
    transform: rotateY(88deg) scale(1.08);
    filter: brightness(1.45);
  }

  100% {
    transform: rotateY(180deg) scale(1);
    filter: brightness(1);
  }
}

@keyframes place-disc {
  0% {
    transform: scale(0.62);
    box-shadow: 0 0 0 0 rgba(255, 214, 108, 0.92), 0 0 24px rgba(255, 214, 108, 0.7);
    filter: brightness(1.35);
  }

  45% {
    transform: scale(1.14);
    box-shadow: 0 0 0 8px rgba(255, 214, 108, 0.36), 0 0 30px rgba(255, 214, 108, 0.78);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 0 14px rgba(255, 214, 108, 0), var(--disc-shadow);
    filter: brightness(1);
  }
}

.coords {
  position: absolute;
  color: #f8f3e8;
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.coords.top,
.coords.bottom {
  left: clamp(22px, 4vw, 34px);
  right: clamp(22px, 4vw, 34px);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  text-align: center;
}

.coords.top {
  top: 8px;
}

.coords.bottom {
  bottom: 8px;
}

.coords.side {
  top: clamp(22px, 4vw, 34px);
  bottom: clamp(22px, 4vw, 34px);
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
}

.coords.left {
  left: 10px;
}

.coords.right {
  right: 10px;
}

.game-modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(0, 0, 0, 0.72);
}

.game-modal[hidden] {
  display: none;
}

.modal-card {
  width: min(360px, 100%);
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 28px;
  border: 2px solid var(--grid);
  border-radius: 8px;
  color: var(--ink);
  text-align: center;
  background: #06140f;
  box-shadow: 0 0 40px rgba(15, 212, 134, 0.42);
}

.modal-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.modal-card h2 {
  margin: 0;
  color: var(--gold);
  font-size: 2.15rem;
  line-height: 1;
  letter-spacing: 0;
}

.modal-card span {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
}

#restartButton {
  min-width: 160px;
  min-height: 46px;
  border-radius: 8px;
  color: #04100c;
  background: var(--blue);
  cursor: pointer;
  font-weight: 900;
}

@media (max-width: 560px), (max-height: 560px) {
  .shell {
    grid-template-columns: 116px 112px 1fr;
    grid-template-rows: 58px minmax(0, 1fr) 40px;
    padding: 8px;
    gap: 7px;
  }

  .brand h1 {
    font-size: 1.16rem;
  }

  .score-card {
    padding: 6px;
  }

  .board-wrap {
    padding: 18px;
  }
}
