: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;
  --ladder: #337454;
  --ladder-soft: #e7f2eb;
  --snake: #a43442;
  --snake-soft: #f8e9eb;
  --finish: #c18d31;
  --board-a: #fffdf9;
  --board-b: #f1e7df;
  --shadow: 0 8px 28px rgb(26 20 22 / 5%);
  --result-shadow: 0 30px 80px rgb(25 15 18 / 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, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
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;
}

.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;
  left: 0;
  right: 0;
  bottom: 17px;
  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, select:focus-visible {
  outline: 3px solid rgb(127 24 56 / 18%);
  outline-offset: 2px;
}

.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; }
.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-panel form { display: grid; gap: 10px; margin-top: 20px; }
.setup-panel label { font-size: 0.93rem; font-weight: 620; }
.setup-panel input, .setup-panel select {
  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: 5px; }
.player-name-field { display: grid; gap: 7px; }
.name-input-row { display: grid; grid-template-columns: 38px 1fr; gap: 9px; align-items: center; }
.mini-token, .player-token {
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 3px 8px rgb(0 0 0 / 16%);
}
.mini-token { width: 36px; height: 36px; }
.token-a { background: #7f1838; }
.token-b { background: #27333a; }
.token-c { background: #a46b18; }
.token-d { background: #276b78; }
.setup-error {
  margin: 4px 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;
}

.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: #fff; }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.action-grid button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.roll-button:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.info-panel { display: grid; gap: 17px; }
.dice-card {
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
}
.dice-label { color: var(--muted); font-size: 0.9rem; }
.dice-face {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 11px;
  color: var(--accent-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.75rem;
}
.dice-face.rolling { animation: dice-pulse 140ms ease-in-out infinite alternate; }
@keyframes dice-pulse { to { transform: rotate(4deg) scale(1.06); } }
.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; text-transform: uppercase; letter-spacing: 0.07em; }
.game-meta dd { margin: 0; color: var(--muted); font-size: 0.92rem; }
.player-list { display: grid; gap: 9px; padding-top: 16px; border-top: 1px solid var(--border); }
.player-info-row { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; }
.player-info-row .mini-token { width: 30px; height: 30px; font-size: 0.8rem; }
.player-info-row span { color: var(--muted); font-size: 0.88rem; }
.player-info-row.current { color: var(--accent-dark); }
.player-info-row.current strong { color: var(--accent-dark); }

.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; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); }
.status-strip p { margin: 0; color: var(--accent-dark); font-weight: 650; }
.board-stage { position: relative; }
.board-frame {
  display: flex;
  justify-content: center;
  padding: clamp(10px, 2vw, 20px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}
.snakes-board {
  width: min(100%, 780px);
  min-width: 620px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  overflow: hidden;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--border);
  gap: 1px;
}
.board-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 5px;
  overflow: hidden;
  background: var(--board-a);
}
.board-cell.alt { background: var(--board-b); }
.board-cell.ladder-start { background: var(--ladder-soft); }
.board-cell.snake-start { background: var(--snake-soft); }
.board-cell.finish-cell { background: #fbf1d8; }
.cell-number { position: absolute; top: 4px; left: 5px; color: var(--muted); font-size: clamp(0.62rem, 1.1vw, 0.82rem); font-weight: 760; }
.jump-badge {
  position: absolute;
  right: 4px;
  top: 4px;
  padding: 1px 4px;
  border-radius: 999px;
  font-size: clamp(0.46rem, 0.75vw, 0.66rem);
  font-weight: 800;
}
.ladder-start .jump-badge { background: var(--ladder); color: #fff; }
.snake-start .jump-badge { background: var(--snake); color: #fff; }
.finish-cell .jump-badge { background: var(--finish); color: #fff; }
.cell-tokens {
  position: absolute;
  right: 5px;
  bottom: 5px;
  left: 5px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
}
.player-token { width: clamp(17px, 2.2vw, 26px); height: clamp(17px, 2.2vw, 26px); font-size: clamp(0.48rem, 0.9vw, 0.72rem); }
.board-cell.active-player-cell { box-shadow: inset 0 0 0 3px rgb(127 24 56 / 44%); }
.board-legend { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 16px; color: var(--muted); font-size: 0.87rem; }
.board-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.ladder-dot { background: var(--ladder); }
.snake-dot { background: var(--snake); }
.finish-dot { background: var(--finish); }
.move-help { max-width: 780px; margin: 12px auto 0; color: var(--muted); font-size: 0.92rem; }

.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-mark { width: 56px; height: 56px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--finish); color: #fff; font-size: 1.5rem; }
.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-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); } }

.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; left: 4px; top: 18px; 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-section { padding: clamp(48px, 8vw, 86px) 0; border-top: 1px solid var(--border); }
.content-section > h2, .repository-section h2 { max-width: 840px; }
.content-grid { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(26px, 6vw, 72px); max-width: 1050px; margin-top: 24px; }
.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 { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; padding: 0 18px; border-color: var(--accent); color: var(--accent); text-decoration: none; }
.repository-button:hover { background: var(--accent); color: #fff; }
.site-footer { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 38px 20px; background: #202329; color: #fff; text-align: center; }
.site-footer span { color: #c4c7cb; font-size: 0.91rem; }

@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; }
  .content-grid { grid-template-columns: 1fr; }
  .repository-section { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 520px) {
  .action-grid { grid-template-columns: 1fr; }
  .board-panel, .setup-panel, .info-panel, .log-panel { padding: 17px; }
  .board-frame { justify-content: flex-start; padding: 8px; }
  .snakes-board { min-width: 560px; }
  .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; }
}
