:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #23211d;
  --muted: #6d675c;
  --line: #2b2925;
  --thin: #c9c2b4;
  --accent: #2f6f5e;
  --accent-soft: #dcebe5;
  --given: #23211d;
  --user: #2a5bb8;
  --bad: #c0392b;
  --sel: #fbe7a6;
  --peer: #f0ebdf;
  --same: #e6dcc0;
  --cell: 44px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a18; --paper: #24221f; --ink: #ece7dc; --muted: #a39d90; --line: #ece7dc;
    --thin: #4a463f; --accent: #7cc4ad; --accent-soft: #2b3d37; --given: #ece7dc; --user: #8fb4ff;
    --bad: #ff7b6b; --sel: #5a4d1f; --peer: #2c2a26; --same: #4a4330;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.6; }
body.big { --cell: 58px; font-size: 19px; }
button { font: inherit; color: inherit; cursor: pointer; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px max(16px, calc((100vw - 980px) / 2)); }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { flex-shrink: 0; width: 38px; height: 38px;border: 3px solid var(--line); border-radius: 6px;
  background: linear-gradient(var(--line), var(--line)) 33% 0 / 2px 100% no-repeat,
              linear-gradient(var(--line), var(--line)) 66% 0 / 2px 100% no-repeat,
              linear-gradient(var(--line), var(--line)) 0 33% / 100% 2px no-repeat,
              linear-gradient(var(--line), var(--line)) 0 66% / 100% 2px no-repeat,
              var(--accent-soft); }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: .02em; }
.tag { margin: 0; color: var(--muted); font-size: .85rem; }
.top-actions { display: flex; gap: 8px; }

main { max-width: 980px; margin: 0 auto; padding: 0 16px 32px; }
.chip { border: 1.5px solid var(--thin); background: var(--paper); border-radius: 999px; padding: 6px 14px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--paper); border-color: var(--accent); }

.datebar { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; flex-wrap: wrap; }
.datebar input { font: inherit; padding: 6px 10px; border: 1.5px solid var(--thin); border-radius: 8px; background: var(--paper); color: var(--ink); }
.nav { width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--thin); background: var(--paper); }
.nav:disabled { opacity: .35; cursor: default; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { border: 1.5px solid var(--thin); background: var(--paper); border-radius: 10px; padding: 8px 14px; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tab .done { color: var(--accent); margin-left: 4px; }

.play { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.board-wrap { flex: 0 1 auto; }
.meta { color: var(--muted); font-size: .9rem; margin-bottom: 8px; min-height: 1.5em; }
.board { display: grid; border: 3px solid var(--line); background: var(--paper); width: max-content; user-select: none;
  touch-action: manipulation; }
.cell { width: var(--cell); height: var(--cell); display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--thin); border-bottom: 1px solid var(--thin); font-size: calc(var(--cell) * .58);
  position: relative; cursor: pointer; }
.cell.br { border-right: 2.5px solid var(--line); }
.cell.bb { border-bottom: 2.5px solid var(--line); }
.cell.lastc { border-right: none; }
.cell.lastr { border-bottom: none; }
.cell.given { font-weight: 700; color: var(--given); }
.cell.user { color: var(--user); }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.sel { background: var(--sel); }
.cell.bad { color: var(--bad); }
.cell.hint { outline: 3px solid var(--accent); outline-offset: -3px; }
.memo { position: absolute; inset: 2px; display: grid; font-size: calc(var(--cell) * .2); color: var(--muted); line-height: 1; }
.memo span { display: flex; align-items: center; justify-content: center; }

.msg { min-height: 2.6em; margin-top: 10px; font-size: .95rem; max-width: 460px; }
.msg.ok { color: var(--accent); font-weight: 700; }

.panel { flex: 1 1 240px; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pad button { height: 52px; font-size: 1.4rem; border-radius: 10px; border: 1.5px solid var(--thin); background: var(--paper); }
.pad button:active { background: var(--accent-soft); }
body.big .pad button { height: 64px; font-size: 1.7rem; }
.row { display: flex; gap: 8px; }
.btn { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--accent); background: var(--accent-soft); }
.btn.ghost { background: var(--paper); border-color: var(--thin); }
.btn.ghost[aria-pressed="true"] { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--paper); font-weight: 700; }
.print-box { border-top: 1px dashed var(--thin); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }

.howto { margin-top: 36px; background: var(--paper); border-radius: 12px; padding: 4px 20px 12px; max-width: 760px; }
.howto h2 { font-size: 1.1rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px 16px 40px; }

.print-area { display: none; }

@media (max-width: 520px) {
  :root { --cell: calc((100vw - 38px) / var(--n, 9)); }
  body.big { --cell: calc((100vw - 38px) / var(--n, 9)); }
  .panel { max-width: none; }
}

/* ---------- print ---------- */
@media print {
  @page { size: A4 portrait; margin: 14mm; }
  body { background: #fff; color: #000; }
  header, main, footer { display: none !important; }
  .print-area { display: block; }
  .pp { page-break-after: always; break-after: page; text-align: center; font-family: var(--font); color: #000; }
  .pp:last-child { page-break-after: auto; break-after: auto; }
  .pp h2 { font-size: 16pt; margin: 0 0 4mm; }
  .pp .sub { font-size: 10pt; margin: 0 0 8mm; color: #333; }
  .pgrid { display: inline-grid; border: 2.5pt solid #000; }
  .pgrid div { border-right: .6pt solid #777; border-bottom: .6pt solid #777; display: flex; align-items: center;
    justify-content: center; font-weight: 600; }
  .pgrid div.br { border-right: 2pt solid #000; }
  .pgrid div.bb { border-bottom: 2pt solid #000; }
  .pgrid div.lastc { border-right: none; }
  .pgrid div.lastr { border-bottom: none; }
  .pgrid div.a { font-weight: 400; color: #444; }
  .pfoot { font-size: 8pt; color: #555; margin-top: 6mm; }
}
