:root {
  --canvas: #f8f7f5;
  --surface: #ffffff;
  --surface-soft: #fbfaf8;

  --text: #181719;
  --muted: #67636a;

  --border: #dfdcda;
  --border-strong: #cfc9c6;

  --accent: #7f1838;
  --accent-dark: #64122b;
  --accent-soft: #f7edf1;

  --player-one: #7f1838;
  --player-two: #27333a;

  --board-background: #d5aa73;
  --board-line: rgb(82 52 34 / 58%);

  --shadow: 0 8px 28px rgb(26 20 22 / 5%);
  --result-shadow: 0 28px 80px rgb(24 18 20 / 28%);

  --radius: 14px;
  --max-width: 1440px;

  color-scheme: light;
}

[hidden] {
  display: none !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */

.site-header {
  border-bottom: 1px solid var(--border);
  background: rgb(248 247 245 / 94%);
  backdrop-filter: blur(12px);
}

.header-inner {
  width: min(calc(100% - 40px), var(--max-width));
  min-height: 98px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}

.brand {
  display: inline-flex;
  flex-direction: column;
  text-decoration: none;
}

.brand strong {
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  letter-spacing: -0.025em;
}

.brand span {
  color: var(--muted);
  font-size: 0.94rem;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(20px, 4vw, 52px);
}

.site-nav a {
  position: relative;
  padding: 36px 0 31px;
  text-decoration: none;
  font-weight: 520;
}

.site-nav a::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 17px;
  left: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 160ms ease;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.site-nav a.active {
  color: var(--accent);
}

.site-nav a:hover::after,
.site-nav a:focus-visible::after,
.site-nav a.active::after {
  transform: scaleX(1);
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgb(127 24 56 / 18%);
  outline-offset: 2px;
}

input:focus-visible {
  border-color: var(--accent);
}

/* Layout */

.page-shell {
  width: min(calc(100% - 40px), var(--max-width));
  margin: 0 auto;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(280px, 350px) minmax(0, 1fr);
  gap: 28px;
  padding: 30px 0 52px;
}

.sidebar,
.game-column {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.game-column {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Panels */

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.setup-panel,
.info-panel,
.log-panel {
  padding: 22px;
}

.panel h2 {
  margin: 0;
  color: var(--accent-dark);
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}

/* Setup */

.setup-panel form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.setup-panel label,
.setup-panel legend {
  font-size: 0.93rem;
  font-weight: 620;
}

.setup-panel fieldset {
  min-width: 0;
  margin: 0 0 5px;
  padding: 0;
  border: 0;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 8px;
}

.radio-option {
  position: relative;
}

.radio-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.radio-option span {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.radio-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.radio-option input:focus-visible + span {
  outline: 3px solid rgb(127 24 56 / 18%);
  outline-offset: 2px;
}

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

.setup-panel input[type="text"],
.setup-panel input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.player-fields {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.player-form-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
}

.player-form-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}

.player-form-heading strong {
  font-size: 0.95rem;
}

.symbol-input {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 750;
  text-transform: uppercase;
}

.setup-error {
  margin: 5px 0 0;
  padding: 11px 12px;
  border: 1px solid rgb(164 52 66 / 30%);
  border-radius: 8px;
  background: #fbedef;
  color: #8b2735;
  font-size: 0.88rem;
  font-weight: 620;
}

/* Buttons */

.primary-button,
.action-grid button,
.repository-button {
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 620;
}

.primary-button {
  margin-top: 8px;
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 16px;
}

.action-grid button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.wide-button {
  width: 100%;
}

/* Game info */

.info-panel {
  display: grid;
  gap: 17px;
}

.current-player-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 12px;
}

.current-player-row > div {
  display: flex;
  flex-direction: column;
}

.current-player-row > div span {
  color: var(--muted);
  font-size: 0.88rem;
}

.current-player-row strong {
  font-size: 1rem;
}

.mini-piece {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #ffffff;
  font-weight: 760;
}

.player-one-mini {
  background: var(--player-one);
}

.player-two-mini,
.current-symbol {
  background: var(--player-two);
}

.game-meta {
  display: grid;
  gap: 14px;
  margin: 5px 0 0;
  padding-top: 17px;
  border-top: 1px solid var(--border);
}

.game-meta div {
  display: grid;
  gap: 3px;
}

.game-meta dt {
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 760;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.game-meta dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Board */

.board-panel {
  padding: clamp(20px, 3vw, 32px);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.compact-heading {
  align-items: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 760;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.board-panel h2,
.content-section h2,
.result-banner h2 {
  margin: 0;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  font-weight: 500;
  letter-spacing: -0.025em;
}

.turn-pill {
  flex: 0 0 auto;
  padding: 7px 13px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: 0.9rem;
  font-weight: 650;
}

.status-strip {
  margin: 22px 0;
  padding: 13px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-soft);
}

.status-strip p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
}

.board-stage {
  position: relative;
}

.board-scroll {
  width: 100%;
  min-height: 560px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background:
    linear-gradient(
      rgb(127 24 56 / 2%) 1px,
      transparent 1px
    ),
    linear-gradient(
      90deg,
      rgb(127 24 56 / 2%) 1px,
      transparent 1px
    ),
    var(--surface-soft);
  background-size: 28px 28px;
}

.gomoku-board {
  width: max-content;
  min-width: min(100%, 560px);
  display: grid;
  place-content: center;
  padding: clamp(20px, 3vw, 34px);
}

.empty-board {
  width: 100%;
  min-height: 558px;
  place-items: center;
}

.empty-board-message {
  max-width: 310px;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.empty-board-message strong {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.4rem;
  font-weight: 500;
}

.empty-board-message p {
  margin: 0;
}

.empty-board-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 5px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.6rem;
}

.board-cell {
  position: relative;
  width: clamp(25px, 3.15vw, 40px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(
      var(--board-line),
      var(--board-line)
    ) center / 100% 1px no-repeat,
    linear-gradient(
      90deg,
      var(--board-line),
      var(--board-line)
    ) center / 1px 100% no-repeat,
    var(--board-background);
}

.board-cell::after {
  content: "";
  position: absolute;
  inset: 14%;
  z-index: 1;
  border-radius: 50%;
  transform: scale(0);
  transition:
    transform 130ms ease,
    background 130ms ease,
    box-shadow 130ms ease;
}

.board-cell[data-player="0"]::after {
  background: var(--player-one);
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 16%),
    0 3px 7px rgb(59 18 31 / 22%);
  transform: scale(1);
}

.board-cell[data-player="1"]::after {
  background: var(--player-two);
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 10%),
    0 3px 7px rgb(24 26 30 / 24%);
  transform: scale(1);
}

.board-cell:hover:not(:disabled)::after,
.board-cell:focus-visible:not(:disabled)::after {
  background: rgb(127 24 56 / 35%);
  transform: scale(0.62);
}

.board-cell:focus-visible {
  z-index: 3;
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.board-cell.winning::after {
  animation: winning-stone 700ms ease-in-out infinite alternate;
  box-shadow:
    0 0 0 3px #ffffff,
    0 0 0 6px var(--accent),
    0 0 20px rgb(127 24 56 / 48%);
}

@keyframes winning-stone {
  from {
    transform: scale(0.88);
  }

  to {
    transform: scale(1.08);
  }
}

.move-help {
  max-width: 760px;
  margin: 17px auto 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Result popup */

.board-stage:has(.result-banner:not([hidden]))::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 10;
  border-radius: 12px;
  background: rgb(24 18 20 / 50%);
  backdrop-filter: blur(2px);
}

.result-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 20;
  width: min(calc(100% - 32px), 430px);
  padding: 30px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--result-shadow);
  text-align: center;
  transform: translate(-50%, -50%);
  animation: result-enter 200ms ease-out;
}

.result-banner .eyebrow {
  margin-top: 14px;
}

.result-banner h2 {
  font-size: clamp(2rem, 5vw, 3rem);
}

.result-banner > p:not(.eyebrow) {
  margin: 12px 0 0;
  color: var(--muted);
}

.result-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 1.45rem;
  font-weight: 800;
}

.result-banner.draw-result {
  border-color: var(--player-two);
}

.result-banner.draw-result .result-mark {
  background: var(--player-two);
}

.result-button {
  width: 100%;
  margin-top: 20px;
}

@keyframes result-enter {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Game log */

.text-button {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.text-button:hover:not(:disabled) {
  color: var(--accent);
}

.game-log {
  max-height: 230px;
  margin: 18px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.game-log li {
  position: relative;
  padding: 10px 10px 10px 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.92rem;
}

.game-log li::before {
  content: "";
  position: absolute;
  top: 18px;
  left: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.game-log li:first-child {
  border-top: 0;
}

.empty-log {
  padding-left: 0 !important;
}

.empty-log::before {
  display: none;
}

/* Content */

.content-section {
  padding: clamp(48px, 8vw, 86px) 0;
  border-top: 1px solid var(--border);
}

.content-section > h2,
.repository-section h2 {
  max-width: 840px;
}

.content-grid {
  max-width: 1050px;
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(26px, 6vw, 72px);
}

.content-grid p,
.repository-section p {
  margin: 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.rules-list {
  max-width: 900px;
  margin: 28px 0 0;
  padding-left: 1.25rem;
}

.rules-list li {
  padding: 6px 0 6px 7px;
}

.rules-list li::marker {
  color: var(--accent);
  font-weight: 800;
}

.repository-section {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
}

.repository-section > div {
  max-width: 800px;
}

.repository-section p:last-child {
  margin-top: 18px;
}

.repository-button {
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.repository-button:hover {
  background: var(--accent);
  color: #ffffff;
}

/* Footer */

.site-footer {
  padding: 38px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #202329;
  color: #ffffff;
  text-align: center;
}

.site-footer span {
  color: #c4c7cb;
  font-size: 0.91rem;
}

/* Responsive */

@media (max-width: 1040px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

@media (max-width: 760px) {
  .header-inner {
    width: min(calc(100% - 28px), var(--max-width));
    min-height: auto;
    flex-direction: column;
    align-items: flex-start;
    padding: 20px 0 0;
  }

  .site-nav {
    width: 100%;
    gap: 25px;
    overflow-x: auto;
  }

  .site-nav a {
    flex: 0 0 auto;
    padding: 14px 0 18px;
  }

  .site-nav a::after {
    bottom: 8px;
  }

  .page-shell {
    width: min(calc(100% - 28px), var(--max-width));
  }

  .game-layout {
    padding-top: 20px;
  }

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

  .panel-heading {
    flex-direction: column;
  }

  .turn-pill {
    align-self: flex-start;
  }

  .board-scroll {
    min-height: 470px;
    align-items: flex-start;
    justify-content: flex-start;
  }

  .empty-board {
    min-height: 468px;
  }

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

  .repository-section {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .choice-row {
    grid-template-columns: 1fr;
  }

  .board-panel,
  .setup-panel,
  .info-panel,
  .log-panel {
    padding: 17px;
  }

  .gomoku-board {
    padding: 18px;
  }

  .board-cell {
    width: 27px;
  }

  .result-banner {
    padding: 24px 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}