:root {
  --bg: #ffffff;
  --fg: #1d1d1f;
  --muted: #86868b;
  --line: #e5e5ea;
  --cell: #f5f5f7;
  --cell-hover: #ebebf0;
  --done: #d2d2d7;
  --accent: #0071e3;
  --wrong: #ff3b30;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --fg: #f5f5f7;
    --muted: #86868b;
    --line: #2c2c2e;
    --cell: #1c1c1e;
    --cell-hover: #2c2c2e;
    --done: #48484a;
    --accent: #2997ff;
    --wrong: #ff453a;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --fg: #f5f5f7;
  --muted: #86868b;
  --line: #2c2c2e;
  --cell: #1c1c1e;
  --cell-hover: #2c2c2e;
  --done: #48484a;
  --accent: #2997ff;
  --wrong: #ff453a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 0;
}

.brand { font-weight: 600; letter-spacing: -.01em; }

.tools { display: flex; gap: 16px; }

.link {
  background: none;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
  color: var(--muted);
}
.link:hover { color: var(--fg); }
.small { font-size: 13px; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.sizes {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 24px;
}
.sizes button {
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.sizes button[aria-checked="true"] {
  background: var(--cell);
  color: var(--fg);
  font-weight: 600;
}

.status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  margin-bottom: 20px;
}
.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.mono { font-variant-numeric: tabular-nums; }

.grid {
  display: grid;
  gap: 6px;
  width: 100%;
  aspect-ratio: 1;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: var(--cell);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .12s, color .12s;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .cell:hover { background: var(--cell-hover); }
}
.cell.done { color: var(--done); }
.cell.wrong { background: var(--wrong); color: #fff; }
.grid.finished .cell { cursor: default; }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  min-height: 1.4em;
  margin: 16px 0 8px;
}
.hint.win { color: var(--accent); font-weight: 600; }

.actions { display: flex; justify-content: center; gap: 12px; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 28px;
  background: var(--fg);
  color: var(--bg);
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { opacity: .85; }
.btn.ghost-btn {
  background: transparent;
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn:disabled { opacity: .35; cursor: default; }

.records {
  margin-top: 40px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.records-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.records h2 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}
.history li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.history li .when { color: var(--muted); }
.history li.top .t { color: var(--accent); font-weight: 600; }

.muted { color: var(--muted); }
.history:empty { display: none; }

.foot {
  text-align: center;
  padding: 0 16px 32px;
  font-size: 13px;
  color: var(--muted);
}
.foot p { margin: 0 0 6px; }
.foot span { margin: 0 6px; }

.lang select {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: 0;
  padding: 4px 16px 4px 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 5px center, right 1px center;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.lang select:hover { color: var(--fg); }
.lang select option { color: #1d1d1f; background: #fff; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--fg); }

.lit {
  margin-top: 32px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  font-size: 14px;
  line-height: 1.6;
}
.lit summary {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.lit summary::-webkit-details-marker { display: none; }
.lit summary::after { content: "+"; float: right; color: var(--muted); font-weight: 400; }
.lit[open] summary::after { content: "−"; }
.lit p { margin: 12px 0; }
.lit ul { padding-left: 18px; margin: 8px 0; }
.lit li { margin: 6px 0; }
.lit a { color: var(--accent); text-decoration: none; word-break: break-all; }
.lit a:hover { text-decoration: underline; }
.refs-title { font-weight: 600; margin-top: 20px !important; }
.refs { padding-left: 20px; font-size: 12.5px; color: var(--muted); }
.refs i { font-style: italic; }

html[lang="en"] .zh-only, html[lang="zh-CN"] .en-only { display: none; }

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

/* Gomoku */
:root {
  --board: #f5f5f7;
  --grid-line: #c7c7cc;
  --black: #1d1d1f;
  --black-ring: #1d1d1f;
  --white: #ffffff;
  --white-ring: #c7c7cc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --board: #1c1c1e;
    --grid-line: #48484a;
    --black: #000000;
    --black-ring: #8e8e93;
    --white: #f5f5f7;
    --white-ring: #f5f5f7;
  }
}
:root[data-theme="dark"] {
  --board: #1c1c1e;
  --grid-line: #48484a;
  --black: #000000;
  --black-ring: #8e8e93;
  --white: #f5f5f7;
  --white-ring: #f5f5f7;
}

.goban {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-template-rows: repeat(15, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  padding: 2%;
  border-radius: 12px;
  background: var(--board);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.pt {
  position: relative;
  min-width: 0;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Grid lines run through the centre of each point and stop at the edges. */
.pt::before, .pt::after {
  content: "";
  position: absolute;
  background: var(--grid-line);
}
.pt::before { left: 0; right: 0; top: 50%; height: 1px; }
.pt::after { top: 0; bottom: 0; left: 50%; width: 1px; }
.pt.l::before { left: 50%; }
.pt.r::before { right: 50%; }
.pt.t::after { top: 50%; }
.pt.b::after { bottom: 50%; }
.pt.star .dot {
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--grid-line);
}
.stone {
  position: absolute;
  inset: 7%;
  z-index: 1;
  border-radius: 50%;
}
.stone.black { background: var(--black); box-shadow: inset 0 0 0 1px var(--black-ring); }
.stone.white { background: var(--white); box-shadow: inset 0 0 0 1px var(--white-ring); }
.stone.last::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 26%; height: 26%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent);
}
.stone.win { box-shadow: 0 0 0 2px var(--accent); }
@media (hover: hover) {
  .goban:not(.busy):not(.finished) .pt.free:hover .ghost { opacity: .35; }
}
.ghost {
  position: absolute;
  inset: 7%;
  z-index: 1;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.goban.finished .pt, .goban.busy .pt { cursor: default; }

.turn-stone {
  display: inline-block;
  width: 20px; height: 20px;
  border-radius: 50%;
  vertical-align: -2px;
}
.turn-stone.black { background: var(--black); box-shadow: inset 0 0 0 1px var(--black-ring); }
.turn-stone.white { background: var(--white); box-shadow: inset 0 0 0 1px var(--white-ring); }
.turn-text { font-size: 17px; font-weight: 600; margin-left: 4px; }
.history li.win-row .t { color: var(--accent); font-weight: 600; }
