/* Reversi, calm and classic: a deep green felt board on warm paper, dark and light discs. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f1efe8;
  --card: #fffdf8;
  --ink: #1e2126;
  --muted: #747882;
  --line: #e0dbcf;
  --felt: #2f7457;
  --felt-2: #2a684e;
  --felt-line: rgba(10, 40, 28, .38);
  --frame: #1d3f31;
  --dark: #25272d;
  --dark-2: #3b3e46;
  --light: #f7f3ea;
  --light-2: #d9d3c6;
  --mark: #ff5c47;
  --gold: #ffc94d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffc94d;
  --tut-accent-ink: #1e2126;
  --tut-bubble: #fffdf8;
  --tut-ink: #1e2126;
  --tut-muted: #747882;
  --tut-dim: rgba(16, 28, 22, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--card); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(30, 33, 38, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .sq:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px; padding-bottom: 14px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.tally {
  display: inline-flex; align-items: center; gap: 5px; margin-left: 2px;
  padding: 3px 10px; border-radius: 999px; background: var(--bg);
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px;
}
.tally .sep { color: var(--muted); font-weight: 400; }
.n0 { color: var(--dark); }
.n1 { color: #8b8578; }
.toast {
  justify-self: center; min-height: 24px; font-size: 15px; color: var(--muted); text-align: center;
  opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }

/* ---------- discs ---------- */
.disc-icon { display: inline-block; flex: none; width: 20px; height: 20px; border-radius: 50%; }
.disc-icon.d0 { background: radial-gradient(circle at 35% 30%, var(--dark-2), var(--dark) 65%); }
.disc-icon.d1 { background: radial-gradient(circle at 35% 30%, #fff, var(--light) 60%); box-shadow: inset 0 0 0 1.5px var(--light-2); }
.disc-icon.none { background: var(--line); }

/* ---------- board ---------- */
.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board-frame {
  width: min(100%, calc(100vh - 190px), 600px);
  padding: 2.4%;
  background: var(--frame);
  border-radius: 18px;
  box-shadow: 0 8px 0 #142c22, 0 18px 34px rgba(30, 33, 38, .22);
}
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board-frame { width: min(100cqw, calc(100cqh - 12px), 600px); }
}
.board {
  position: relative;
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr));
  background: linear-gradient(160deg, var(--felt), var(--felt-2));
  border-radius: 6px; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--felt-line);
}
/* The four small guide points where the centre 4 × 4 meets the rest. */
.board::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background:
    radial-gradient(circle at 25% 25%, var(--felt-line) 0 3px, transparent 3.5px),
    radial-gradient(circle at 75% 25%, var(--felt-line) 0 3px, transparent 3.5px),
    radial-gradient(circle at 25% 75%, var(--felt-line) 0 3px, transparent 3.5px),
    radial-gradient(circle at 75% 75%, var(--felt-line) 0 3px, transparent 3.5px);
}
.sq {
  position: relative; display: grid; place-items: center; aspect-ratio: 1; min-width: 0;
  border: 0; margin: 0; padding: 0; background: transparent; cursor: default;
  box-shadow: inset -1px -1px 0 var(--felt-line);
}
.sq:nth-child(8n) { box-shadow: inset 0 -1px 0 var(--felt-line); }
.sq:nth-child(n+57) { box-shadow: inset -1px 0 0 var(--felt-line); }
.sq:nth-child(64) { box-shadow: none; }
.sq.legal { cursor: pointer; }
.sq.legal::before {
  content: ''; width: 24%; height: 24%; border-radius: 50%;
  background: rgba(8, 30, 20, .3);
  transition: transform .15s;
}
.sq.legal.p1::before { background: rgba(255, 253, 245, .38); }
@media (hover: hover) { .sq.legal:hover::before { transform: scale(1.35); } }
.sq.legal:active::before { transform: scale(1.5); }

.disc {
  position: relative; z-index: 1; width: 82%; height: 82%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.3, .1, .3, 1);
}
.disc .f {
  position: absolute; inset: 0; border-radius: 50%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.disc .f0 { background: radial-gradient(circle at 34% 30%, var(--dark-2), var(--dark) 62%); box-shadow: 0 2px 2px rgba(0, 0, 0, .35); }
.disc .f1 { background: radial-gradient(circle at 34% 30%, #fff, var(--light) 58%, var(--light-2)); box-shadow: 0 2px 2px rgba(0, 0, 0, .3); transform: rotateY(180deg); }
.disc.c1 { transform: perspective(300px) rotateY(180deg); }
.disc.flip.c1 { animation: to1 .5s cubic-bezier(.3, .1, .3, 1) both; animation-delay: var(--d, 0ms); }
.disc.flip.c0 { animation: to0 .5s cubic-bezier(.3, .1, .3, 1) both; animation-delay: var(--d, 0ms); }
@keyframes to1 { 0% { transform: perspective(300px) rotateY(0) scale(1); } 50% { transform: perspective(300px) rotateY(90deg) scale(1.12); } 100% { transform: perspective(300px) rotateY(180deg) scale(1); } }
@keyframes to0 { 0% { transform: perspective(300px) rotateY(180deg) scale(1); } 50% { transform: perspective(300px) rotateY(90deg) scale(1.12); } 100% { transform: perspective(300px) rotateY(0) scale(1); } }
.disc.place { animation: place .28s cubic-bezier(.2, .9, .3, 1.3) both; }
.disc.c1.place { animation-name: place1; }
@keyframes place { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes place1 { from { transform: perspective(300px) rotateY(180deg) scale(.4); opacity: 0; } to { transform: perspective(300px) rotateY(180deg) scale(1); opacity: 1; } }
/* Last-move mark: a small red dot drawn on both faces of the last disc placed. */
.disc.last .f::after {
  content: ''; position: absolute; left: 41%; top: 41%; width: 18%; height: 18%; border-radius: 50%;
  background: var(--mark); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .5);
}
.sq.hot { background: rgba(255, 201, 77, .22); transition: background .6s; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(30, 33, 38, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(241, 239, 232, .5); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(30, 33, 38, .22);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(30, 33, 38, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.over-mark .disc-icon { width: 52px; height: 52px; }
.over-title { font-size: 28px; font-weight: 800; }
.over-sub { color: var(--muted); margin: 4px 0 20px; font-variant-numeric: tabular-nums; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- small and landscape screens ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 480px) {
  .bar { min-height: 50px; }
  .game { gap: 6px; padding-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* Online play (online.js): no New game while a friend is playing; a presence line under the turn. */
body.is-online #btn-new { display: none; }
.top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.net { color: var(--muted); }
/* The online rows take the divider above How to play (one line, not two). */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-online ~ #menu-help { margin-top: 0; border-top: 0; }
#over-leave { margin-top: 8px; }
