:root {
  --background: #F6F3EC;
  --surface: #FFFEFA;
  --text: #202C29;
  --muted: #52625A;
  --accent: #285B49;
  --accent-hover: #1C4436;
  --on-accent: #FFFFFF;
  --border: #ADB8AD;
  --line: #52625A;
  --board-light: #E6DDC8;
  --board-dark: #63786E;
  --focus: #174FAD;
  --danger: #A52A32;
  --radius-panel: 12px;
  --radius-button: 8px;
  --radius-board: 4px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 650; line-height: 1.12; margin: 0 0 12px; }

h1 { font-size: clamp(28px, 4vw, 44px); }

h2 { font-size: clamp(22px, 3vw, 28px); }

h3 { font-size: 20px; }

p { margin: 0 0 12px; }

a { color: var(--accent); text-underline-offset: 3px; }

a:hover { color: var(--accent-hover); }

.skip {
  position: absolute;
  left: 16px;
  top: -48px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-button);
  z-index: 5;
}

.skip:focus { top: 12px; }

.site-header, .site-footer, main {
  padding-left: 16px;
  padding-right: 16px;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding-top: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  color: var(--text);
  font-weight: 650;
  font-size: 20px;
  text-decoration: none;
}

nav { display: flex; flex-wrap: wrap; gap: 8px 16px; }

nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text);
}

.site-footer {
  padding-top: 24px;
  padding-bottom: 32px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

main { padding-top: 24px; padding-bottom: 24px; max-width: 1180px; }

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

.home-panel, .games-panel { max-width: 44rem; }

.field { margin-bottom: 16px; }

label { display: block; font-weight: 600; margin-bottom: 8px; }

input[type="text"], input:not([type]), input[type="search"] {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  padding: 8px 12px;
}

.field-error { color: var(--danger); min-height: 1.45em; font-size: 14px; line-height: 1.45; margin: 8px 0 0; }

.note, .muted, .help { color: var(--muted); font-size: 14px; line-height: 1.45; }

button, .filters a, a.secondary, #enter-board {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 44px;
  padding: 8px 16px;
  border-radius: var(--radius-button);
  border: 2px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .filters a:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }

button.secondary, a.secondary, .filters a {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.filters a[aria-current="page"] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.links { display: grid; gap: 16px; margin-top: 24px; max-width: 44rem; }

.secret-url { overflow-wrap: anywhere; font-weight: 600; }

.copy-fallback { margin-top: 8px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

.games { width: 100%; border-collapse: collapse; }

.games th, .games td {
  text-align: left;
  vertical-align: top;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.games th { font-size: 14px; line-height: 1.45; }

.cell-label { display: none; }

.col-date, .games td:last-child { min-width: 12rem; }

.play-page { max-width: 1180px; }

.play-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.player {
  margin: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  overflow-wrap: anywhere;
}

.player.is-turn { border-color: var(--accent); border-width: 2px; }

.board-wrap { width: 100%; max-width: 640px; }

.board {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: var(--radius-board);
  background: var(--background);
  touch-action: manipulation;
  overflow: hidden;
}

.board > [role="row"] {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  min-width: 0;
  min-height: 0;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: var(--board-light);
  color: var(--text);
  cursor: pointer;
}

.cell.dark { background: var(--board-dark); }

.cell:focus { outline: none; }

.cell .coord {
  position: absolute;
  left: 2px;
  top: 1px;
  font-size: 10px;
  line-height: 1;
  opacity: 0.85;
  pointer-events: none;
}

.cell.light .coord { color: var(--text); }
.cell.dark .coord { color: #FFFFFF; }

.cell .piece { width: 82%; height: 82%; display: block; pointer-events: none; }

.cell.is-last { box-shadow: inset 0 0 0 2px var(--accent); }

.cell.is-selected { box-shadow: inset 0 0 0 3px #202C29; }
.cell.dark.is-selected { box-shadow: inset 0 0 0 3px #F6F3EC; }

.cell.is-cursor { outline: 3px solid var(--focus); outline-offset: -3px; z-index: 1; }

.cell.is-check { box-shadow: inset 0 0 0 2px var(--danger), inset 0 0 0 6px var(--background); }

.cell.is-target::after,
.cell.is-capture::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.cell.is-target::after {
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: #202C29;
  border: 2px solid #FFF8E8;
}

.cell.dark.is-target::after {
  background: #FFF8E8;
  border-color: #202C29;
}

.cell.is-capture::after {
  width: 70%;
  height: 70%;
  background:
    linear-gradient(#202C29, #202C29) left top / 12px 3px no-repeat,
    linear-gradient(#202C29, #202C29) left top / 3px 12px no-repeat,
    linear-gradient(#202C29, #202C29) right top / 12px 3px no-repeat,
    linear-gradient(#202C29, #202C29) right top / 3px 12px no-repeat,
    linear-gradient(#202C29, #202C29) left bottom / 12px 3px no-repeat,
    linear-gradient(#202C29, #202C29) left bottom / 3px 12px no-repeat,
    linear-gradient(#202C29, #202C29) right bottom / 12px 3px no-repeat,
    linear-gradient(#202C29, #202C29) right bottom / 3px 12px no-repeat;
}

.cell.dark.is-capture::after {
  background:
    linear-gradient(#FFF8E8, #FFF8E8) left top / 12px 3px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) left top / 3px 12px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) right top / 12px 3px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) right top / 3px 12px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) left bottom / 12px 3px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) left bottom / 3px 12px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) right bottom / 12px 3px no-repeat,
    linear-gradient(#FFF8E8, #FFF8E8) right bottom / 3px 12px no-repeat;
}

.check-mark {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0;
  pointer-events: none;
}

.cell.light .check-mark { color: var(--danger); }
.cell.dark .check-mark { color: #FFFFFF; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.history { margin: 0; padding-left: 1.2rem; }

.history li { margin: 0 0 4px; }

.status { min-height: 1.5em; font-weight: 650; margin: 0; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(32, 44, 41, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 4;
}

.modal[hidden] { display: none; }

.modal-card {
  width: min(100%, 28rem);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-panel);
  padding: 16px;
}

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

.choice-row button {
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  min-height: 88px;
}

.choice-row svg { width: 48px; height: 48px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

#alert:empty { margin: 0; }

#alert:not(:empty) {
  background: var(--surface);
  border: 2px solid var(--danger);
  border-radius: var(--radius-button);
  padding: 12px;
  margin-bottom: 16px;
}

@media (max-width: 719px) {
  .games thead { display: none; }
  .games, .games tbody, .games tr, .games td { display: block; width: 100%; }
  .games tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-panel);
    margin-bottom: 12px;
    padding: 8px 12px;
  }
  .games td { border: 0; padding: 6px 0; display: flex; justify-content: space-between; gap: 12px; }
  .cell-label { display: inline; color: var(--muted); font-size: 14px; }
  .games td:last-child { min-width: 0; }
}

@media (min-width: 960px) {
  .site-header, .site-footer, main { padding-left: 24px; padding-right: 24px; }
  .play-stack {
    display: grid;
    grid-template-columns: minmax(0, 640px) minmax(300px, 340px);
    column-gap: 32px;
    row-gap: 12px;
    align-items: start;
  }
  .opponent { grid-column: 1; grid-row: 1; }
  .status { grid-column: 2; grid-row: 1; }
  .board-wrap { grid-column: 1; grid-row: 2 / span 3; }
  .updated { grid-column: 2; grid-row: 2; align-self: start; }
  .actions { grid-column: 2; grid-row: 3; align-self: start; }
  .history-wrap {
    grid-column: 2;
    grid-row: 4;
    align-self: start;
    max-height: 420px;
    overflow: auto;
  }
  .self { grid-column: 1; grid-row: 5; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

