: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-red: #7f1838;
  --player-blue: #27333a;
  --shadow: 0 8px 28px rgb(26 20 22 / 5%);
  --result-shadow: 0 30px 80px rgb(25 15 18 / 28%);
  --radius: 14px;
  --max-width: 1440px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 112px;
}

body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  transform: translateY(-150%);
  border-radius: 7px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: sticky;
  z-index: 30;
  top: 0;
  border-bottom: 1px solid rgb(223 220 218 / 88%);
  background: rgb(248 247 245 / 94%);
  backdrop-filter: blur(12px);
}

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

.header-inner {
  min-height: 98px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}

.brand {
  display: grid;
  gap: 2px;
  flex: 0 0 auto;
  text-decoration: none;
}

.brand strong {
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 600;
  line-height: 1.2;
}

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

.site-nav {
  display: flex;
  gap: clamp(20px, 3vw, 38px);
  overflow-x: auto;
  scrollbar-width: none;
}

.site-nav::-webkit-scrollbar {
  display: none;
}

.site-nav a {
  position: relative;
  flex: 0 0 auto;
  padding: 38px 0 35px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 600;
  text-decoration: none;
}

.site-nav a::after {
  position: absolute;
  right: 0;
  bottom: 29px;
  left: 0;
  height: 2px;
  transform: scaleX(0);
  transform-origin: right;
  background: var(--accent);
  content: "";
  transition: transform 180ms 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);
  transform-origin: left;
}

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

.sidebar,
.game-column {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.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;
}

.compact-heading {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.96rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.setup-summary {
  margin: 16px 0 0;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
}

.setup-note {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 0.79rem;
}

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button-primary:hover:not(:disabled),
.button-primary:focus-visible:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.button-secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.button-secondary:hover:not(:disabled),
.button-secondary:focus-visible:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.start-button {
  width: 100%;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 9px;
}

.save-status {
  min-height: 19px;
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.player-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.player-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
  background: var(--surface-soft);
}

.player-marker {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.player-red {
  background: var(--player-red);
}

.player-blue {
  background: var(--player-blue);
}

.player-row span:nth-child(2) {
  display: grid;
}

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

.player-row small {
  color: var(--muted);
  font-size: 0.69rem;
}

.game-details {
  margin: 18px 0 0;
}

.game-details div {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.game-details dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.game-details dd {
  margin: 0;
  font-size: 0.76rem;
}

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

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

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

.panel-heading h2,
.content-section h2,
.result-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.025em;
}

.panel-heading h2 {
  font-size: clamp(1.7rem, 3vw, 2.25rem);
}

.turn-pill {
  flex: 0 0 auto;
  border: 1px solid #e3cbd4;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 7px 12px;
  font-size: 0.73rem;
  font-weight: 750;
}

.turn-pill.blue-turn {
  border-color: #ccd3d7;
  background: #eef1f2;
  color: var(--player-blue);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 22px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-soft);
}

.status-strip div {
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 11px 8px;
  text-align: center;
}

.status-strip div + div {
  border-left: 1px solid var(--border);
}

.status-strip span {
  color: var(--muted);
  font-size: 0.66rem;
}

.status-strip strong {
  font-size: 1rem;
}

.board-stage {
  position: relative;
  width: 100%;
  min-height: 0;
}

.board-frame {
  width: min(100%, 600px);
  margin-inline: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: clamp(10px, 2vw, 18px);
}

.column-labels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin-left: 24px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
}

.board-row-layout {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 6px;
}

.row-labels {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.row-labels span {
  display: grid;
  place-items: center;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(4px, 1vw, 8px);
  aspect-ratio: 1;
}

.cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: clamp(7px, 1.4vw, 11px);
  background: #f2f0ed;
  color: var(--text);
  padding: 0;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.cell::after {
  position: absolute;
  inset: 4px;
  border: 1px solid transparent;
  border-radius: inherit;
  content: "";
  pointer-events: none;
}

.cell-valid:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 5px 16px rgb(127 24 56 / 12%);
  transform: translateY(-1px);
}

.cell-red {
  border-color: #6b112e;
  background: var(--player-red);
}

.cell-blue {
  border-color: #182329;
  background: var(--player-blue);
}

.cell-red::after,
.cell-blue::after {
  border-color: rgb(255 255 255 / 18%);
}

.beads {
  position: absolute;
  inset: 24%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 10%;
  place-items: center;
}

.bead {
  width: 76%;
  aspect-ratio: 1;
  border: 1px solid rgb(255 255 255 / 62%);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgb(0 0 0 / 25%);
}

.beads-1 .bead {
  grid-area: 1 / 1 / 3 / 3;
  width: 38%;
}

.beads-2 .bead:first-child {
  grid-area: 1 / 1;
}

.beads-2 .bead:last-child {
  grid-area: 2 / 2;
}

.beads-3 .bead:first-child {
  grid-area: 1 / 1;
}

.beads-3 .bead:nth-child(2) {
  grid-area: 1 / 2;
}

.beads-3 .bead:nth-child(3) {
  grid-area: 2 / 1 / 3 / 3;
  width: 38%;
}

.cell-played {
  animation: cell-play 260ms ease;
}

.cell-exploding {
  z-index: 2;
  animation: cell-explode 300ms ease;
}

.cell-invalid {
  animation: cell-invalid 260ms ease;
}

.board-busy {
  pointer-events: none;
}

@keyframes cell-play {
  50% { transform: scale(0.95); }
}

@keyframes cell-explode {
  45% {
    box-shadow: 0 0 0 9px rgb(127 24 56 / 16%);
    transform: scale(1.035);
  }
}

@keyframes cell-invalid {
  25%, 75% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
}

.move-message {
  margin: 18px 0 0;
  font-size: 0.82rem;
  font-weight: 750;
  text-align: center;
}

.board-help {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.log-heading {
  align-items: baseline;
  padding-bottom: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 3px 0;
  font-size: 0.73rem;
  font-weight: 700;
}

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

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

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

.game-log .activity-blue::before {
  background: var(--player-blue);
}

.game-log .activity-warning {
  color: var(--accent);
}

.game-log .activity-empty::before {
  background: var(--border-strong);
}

.content-section {
  padding: clamp(52px, 7vw, 82px) 0;
  border-top: 1px solid var(--border);
}

.content-section h2 {
  max-width: 850px;
  font-size: clamp(2rem, 4vw, 3.25rem);
  line-height: 1.12;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(28px, 5vw, 72px);
  margin-top: 28px;
}

.content-grid p,
.repository-section > div > p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.75;
}

code {
  color: var(--text);
  font-size: 0.92em;
}

.rules-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: clamp(32px, 6vw, 88px);
  margin: 30px 0 0;
  padding-left: 24px;
}

.rules-list li {
  border-top: 1px solid var(--border);
  padding: 13px 8px 13px 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.repository-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 36px;
  align-items: end;
}

.repository-section > div > p:last-child {
  max-width: 760px;
  margin-top: 20px;
}

.repository-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.repository-button {
  min-width: 190px;
}

.site-footer {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 38px 20px;
  background: #202329;
  color: #fff;
  text-align: center;
}

.site-footer strong {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
}

.site-footer span {
  color: #aeb2b9;
  font-size: 0.73rem;
}

.result-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgb(24 23 25 / 72%);
  padding: 18px;
}

.result-card {
  width: min(100%, 390px);
  border: 2px solid var(--accent);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--result-shadow);
  padding: clamp(22px, 5vw, 34px);
  text-align: center;
}

.result-card.blue-result {
  border-color: var(--player-blue);
}

.result-mark {
  width: 34px;
  height: 34px;
  margin: 0 auto 14px;
  border: 7px solid var(--surface);
  border-radius: 50%;
  background: var(--player-red);
  box-shadow: 0 0 0 1px var(--accent);
}

.result-mark.result-blue {
  background: var(--player-blue);
  box-shadow: 0 0 0 1px var(--player-blue);
}

.result-card h2 {
  font-size: 2rem;
}

.result-card p:not(.eyebrow) {
  margin: 9px 0 20px;
  color: var(--muted);
  font-size: 0.82rem;
}

.result-card .button {
  width: 100%;
}

.button:focus-visible,
.text-button:focus-visible,
.cell:focus-visible,
.site-nav a:focus-visible,
.brand:focus-visible,
.repository-button:focus-visible {
  outline: 3px solid rgb(127 24 56 / 30%);
  outline-offset: 3px;
}

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

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  html {
    scroll-padding-top: 145px;
  }

  .header-inner {
    min-height: 0;
    display: grid;
    gap: 12px;
    padding: 20px 0 0;
  }

  .site-nav {
    width: 100%;
  }

  .site-nav a {
    padding: 8px 0 18px;
  }

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

  .sidebar,
  .content-grid,
  .rules-list,
  .repository-section {
    grid-template-columns: 1fr;
  }

  .panel-heading:not(.log-heading) {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .repository-section {
    align-items: start;
  }

  .repository-actions {
    justify-content: flex-start;
  }
}

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

  .game-layout {
    gap: 16px;
    padding-top: 18px;
  }

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

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

  .status-strip span {
    font-size: 0.6rem;
  }

  .board-frame {
    padding: 8px;
  }

  .column-labels {
    margin-left: 20px;
  }

  .board-row-layout {
    grid-template-columns: 16px minmax(0, 1fr);
    gap: 4px;
  }

  .game-board {
    gap: 4px;
  }

  .result-overlay {
    padding: 10px;
  }

  .repository-actions,
  .repository-button {
    width: 100%;
  }
}

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

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