/* 虫食い算・覆面算 固有の見た目（共通は ../common/base.css） */
[hidden] { display: none !important; }

.board-wrap { min-height: 200px; }

/* ---------- 筆算（方眼のノートのような地に、数字を1マスずつ） ---------- */
.hissan-wrap { container-type: inline-size; display: flex; justify-content: center; padding: 8px 0 4px; }
.hissan {
  --cols: 5; --rows: 3;
  --cw: min(58px, calc((100cqw - 24px) / var(--cols)));
  --rh: calc(var(--cw) * 1.1);
  display: grid; grid-template-columns: repeat(var(--cols), var(--cw)); grid-template-rows: repeat(var(--rows), var(--rh));
  padding: 8px 12px; border-radius: var(--radius);
  background-color: var(--surface);
  background-image: linear-gradient(to right, var(--grid-line) 1px, transparent 1px), linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cw) var(--rh); background-position: 12px 8px;
  font-size: calc(var(--cw) * .6); line-height: 1; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
:root { --grid-line: #ECE9E1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --grid-line: #303237; } }
:root[data-theme="dark"] { --grid-line: #303237; }

.hs-cell { position: relative; display: flex; align-items: center; justify-content: center; font-weight: 700; z-index: 1; min-width: 0; }
.hs-cell.given { color: var(--ink); }
.hs-sign { display: flex; align-items: center; justify-content: center; font-size: .9em; color: var(--ink); z-index: 1; }
.hs-line { align-self: start; border-top: 3px solid var(--ink); margin-top: -1.5px; z-index: 2; pointer-events: none; }
.hs-over { margin-left: 30%; }
.hs-bracket { display: flex; justify-content: flex-start; color: var(--ink); z-index: 1; pointer-events: none; margin-left: 30%; margin-top: -1px; }
.hs-bracket svg { width: 45%; height: 100%; display: block; overflow: visible; }

/* □（入れるマス） */
.hs-cell.box {
  appearance: none; font: inherit; font-weight: 700; margin: 3px; padding: 0; cursor: pointer; touch-action: manipulation;
  border: 2px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--accent);
}
.hs-cell.box:disabled { cursor: default; opacity: 1; }
.hs-cell.box.sel { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); }
.hs-cell.box.same { background: var(--accent-soft); border-color: var(--accent); }
.hs-cell.box.wrong { color: var(--ng); border-color: var(--ng); }
.hs-cell.box.dup .v { text-decoration: underline wavy var(--warn); text-underline-offset: 4px; text-decoration-thickness: 2px; }
.hs-cell.box.hinted { color: var(--ok); border-style: dashed; }
.hs-cell.box.shown { color: var(--ink-sub); font-style: italic; }
.hs-cell.box:focus-visible { outline: 3px solid var(--warn); outline-offset: 1px; }
.hs-cell.pop .v { animation: pop-in .2s ease-out; display: inline-block; }
.hs-cell.win { animation: flash .7s ease-out; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes pop-in { from { transform: scale(.6); } to { transform: none; } }
@keyframes flash { 0%, 100% { background-color: transparent; } 40% { background-color: color-mix(in srgb, var(--ok) 28%, transparent); } }

/* 覆面算の文字のマス: 空きは文字を大きく、数字が入ったら数字を大きく・文字を左上に小さく */
.letter .sym { font-weight: 700; color: var(--ink); font-size: .9em; }
.letter .v:empty { display: none; }
.letter.filled .sym, .letter.given .sym { position: absolute; top: 2px; left: 4px; font-size: max(.3em, 11px); line-height: 1; color: var(--ink-sub); font-weight: 600; }
.hs-cell.letter.given { color: var(--ink); }
.hs-cell.box.letter { color: var(--accent); }
.hs-cell.box.letter.wrong .v { color: var(--ng); }
.hs-cell.box.letter.hinted .v { color: var(--ok); }

/* ---------- 覆面算: 文字の表 ---------- */
.keytable { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 8px auto 0; max-width: 560px; }
.kt {
  appearance: none; font: inherit; display: inline-flex; align-items: center; gap: 4px; min-height: 44px; min-width: 76px; justify-content: center; padding: 0 10px;
  border: 2px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: 20px; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.kt.given { border-color: var(--line); color: var(--ink-sub); cursor: default; }
.kt .eq { color: var(--ink-sub); font-weight: 400; }
.kt .kv { color: var(--accent); min-width: .7em; text-align: center; font-variant-numeric: tabular-nums; }
.kt.given .kv { color: var(--ink); }
.kt.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.kt.wrong .kv { color: var(--ng); }
.kt.dup .kv { text-decoration: underline wavy var(--warn); text-underline-offset: 3px; }
.kt:disabled { cursor: default; }
.kt:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; }

/* ---------- 道具・数字パッド ---------- */
.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px auto 0; max-width: 540px; }
.tool { display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; font-size: 16px; flex: 1 1 0; justify-content: center; white-space: nowrap; }
.tool svg { width: 20px; height: 20px; flex: none; }
.tools .softkb-btn { flex: 1 1 0; justify-content: center; }
.pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-width: 540px; margin: 10px auto 0; }
.key {
  appearance: none; font: inherit; position: relative; font-size: 26px; font-weight: 700; min-height: 54px; padding: 0 2px; font-variant-numeric: tabular-nums;
  border-radius: var(--radius); border: 2px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; touch-action: manipulation;
}
.key small { position: absolute; right: 4px; bottom: 2px; font-size: 14px; line-height: 1.1; font-weight: 600; color: var(--ink-sub); }
.key.used { color: var(--ink-sub); }
.key.here { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.key.erase { font-size: 17px; color: var(--accent); grid-column: span 2; }
.key:active:not(:disabled) { transform: translateY(1px); }
.key:disabled { cursor: not-allowed; opacity: .4; }
.key:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; }
.after { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.status { flex-wrap: wrap; row-gap: 0; }
.st-left { flex: 1 1 auto; }
.timer { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 18px; min-width: 56px; text-align: right; margin-left: auto; }
.linkbtn { display: inline-flex; align-items: center; text-decoration: none; }

/* ---------- ヒント・記録 ---------- */
.think { margin: 10px auto 0; max-width: 640px; border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 14px; background: var(--surface); }
.think h3 { margin: 0 0 4px; font-size: 16px; }
.think p { margin: 0 0 6px; }
.think p:last-child { margin-bottom: 0; }
.think .eqline { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.lv { display: inline-block; white-space: nowrap; font-size: 14px; font-weight: 700; padding: 0 8px; border-radius: 999px; border: 1.5px solid currentColor; margin-left: 6px; vertical-align: middle; }
.lv.l1 { color: var(--ok); } .lv.l2 { color: var(--accent); } .lv.l3 { color: var(--warn); } .lv.l4 { color: var(--ng); }

.loading { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); background: var(--surface); color: var(--ink); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 18px; font-weight: 700; z-index: 2; }
.callout { z-index: 3; top: calc(100% + 34px); } /* 筆算に重ねない（道具の列の上に出す。ここは正解のあと押せない） */

@media (max-width: 480px) {
  .stage { padding: 8px; }
  .key { min-height: 50px; font-size: 24px; }
  .pad { gap: 5px; }
  .tools { gap: 6px; }
  .tool, .tools .softkb-btn { padding: 0 4px; font-size: 14px; gap: 3px; min-width: 0; }
  .tools svg { display: none; }
  .controls .btn.icon { padding: 0 9px; }
  .kt { min-width: 64px; font-size: 18px; padding: 0 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .hs-cell.pop .v, .hs-cell.win { animation: none; }
}
/* 上のバーの高さを一定に（No.93。数字は一番長い文が画面の幅（360px・375px 以上・641px 以上）で何行になるか。--tb-rt はふりがなの分。base.css・turnbar.js） */
.turnbar { --tb-msg-lines: 2; --tb-st-lines: 2.25; --tb-rt: 0px; --tb-st-rt: 0px; }
@media (min-width: 375px) { .turnbar { --tb-msg-lines: 2; --tb-st-lines: 1; } }
@media (min-width: 641px) { .turnbar { --tb-msg-lines: 1; --tb-st-lines: 1; } }
:root:lang(en) .turnbar { --tb-msg-lines: 2; --tb-st-lines: 3.25; --tb-rt: 0px; --tb-st-rt: 0px; }
@media (min-width: 375px) { :root:lang(en) .turnbar { --tb-msg-lines: 2; --tb-st-lines: 2.25; } }
@media (min-width: 641px) { :root:lang(en) .turnbar { --tb-msg-lines: 1; --tb-st-lines: 1; } }
/* 上のバーの高さ ここまで */
