/* 計算マス固有の見た目（共通は ../common/base.css） */
[hidden] { display: none !important; }

.board-wrap { min-height: 240px; }

/* ---------- マス目 ---------- */
/* 上の端（上の数）は藍、左の端（左の数）は黄土。下の式の数も同じ色にして、どちらの数かを見せる */
.grid-wrap {
  --top-bg: #E3ECF5; --top-ink: #24486B; --left-bg: #F5E9D4; --left-ink: #7A4E0E;
  background: var(--board); color: #1F2328; border: 2px solid var(--line); border-radius: var(--radius); padding: 8px;
  container-type: inline-size;
}
.grid {
  display: grid; grid-template-columns: repeat(calc(var(--n, 10) + 1), 1fr); gap: 3px; margin: 0 auto;
  width: min(100%, 540px); font-variant-numeric: tabular-nums; --fs: min(4.3cqw, 24px);
}
.grid[data-n="5"] { width: min(100%, 420px); gap: 4px; --fs: min(8cqw, 38px); }
.grid[data-n="3"] { width: min(100%, 320px); gap: 5px; --fs: min(11cqw, 46px); }
.grid .h, .grid .c {
  appearance: none; font: inherit; aspect-ratio: 1; min-width: 0; padding: 0; border-radius: 5px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs); line-height: 1;
}
.grid .h.top { background: var(--top-bg); color: var(--top-ink); }
.grid .h.left { background: var(--left-bg); color: var(--left-ink); }
.grid .h.corner { background: #1F2328; color: #FFFFFF; }
.grid .h.top.now { background: #2F5D8A; color: #FFFFFF; }
.grid .h.left.now { background: #9A6414; color: #FFFFFF; }
.grid .c {
  border: 2px solid #D9D6CE; background: #FFFFFF; color: #1F2328; cursor: pointer; position: relative; touch-action: manipulation;
}
.grid .c.rel { background: #F1F4F8; }
.grid .c.sel { border: 3px solid #2F5D8A; background: #FFFFFF; color: #2F5D8A; z-index: 1; }
.grid .c.sel:not(.typing):empty::after { content: ''; width: 2px; height: 55%; background: #2F5D8A; animation: blink 1s steps(1) infinite; }
.grid .c.done { background: #EDF6F0; color: #1F2328; }
.grid .c.ok { background: #EDF6F0; }
.grid .c.ng { background: #FBE9E7; border-color: #B23A3A; color: #B23A3A; }
.grid .c.ng::before {
  content: '×'; position: absolute; right: 1px; top: -1px; font-size: max(10px, calc(var(--fs) * .5)); line-height: 1; color: #B23A3A;
}
.grid .c.ng.sel { border-color: #2F5D8A; }
.grid .c.sel.retry { background: #FBE9E7; }
.grid .c.fixed { background: #FFF7E0; border-color: #B7791F; }
.grid .c.miss:not(.sel)::after {
  content: ''; position: absolute; right: 2px; top: 2px; width: 6px; height: 6px; border-radius: 50%; background: #B23A3A;
}
.grid .c:focus-visible { outline: 3px solid var(--warn); outline-offset: 1px; }
.grid .c.pop { animation: pop-in .18s ease-out; }
.grid .c.shake { animation: shake .35s ease-out; }
.grid .c.reveal { animation: pop-in .25s ease-out both; animation-delay: calc(var(--k, 0) * 6ms); }
.grid .c.win { animation: jump .5s ease-out; animation-delay: calc(var(--k, 0) * 8ms); }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pop-in { from { transform: scale(.8); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes shake { 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } 100% { transform: none; } }
@keyframes jump { 0%, 100% { transform: none; } 40% { transform: translateY(-4px); } }

/* ---------- 下の式 ---------- */
.expr {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; min-height: 52px;
  font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1;
}
.expr .num { display: inline-flex; align-items: center; justify-content: center; min-width: 1.5em; height: 1.4em; padding: 0 .2em; border-radius: 6px; }
.expr .num.top { background: var(--top-bg); color: var(--top-ink); }
.expr .num.left { background: var(--left-bg); color: var(--left-ink); }
.expr .op { color: #5B616B; }
.expr .ans {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.8em; height: 1.4em; padding: 0 .1em;
  border: 3px solid #2F5D8A; border-radius: 8px; background: #FFFFFF; color: #2F5D8A;
}
.expr .ans.caret::after { content: ''; width: 3px; height: .8em; background: #2F5D8A; animation: blink 1s steps(1) infinite; }

/* ---------- 数字ボタン ---------- */
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 480px; margin: 10px auto 0; }
.key {
  appearance: none; font: inherit; font-size: 28px; font-weight: 700; min-height: 54px; padding: 0; 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.erase { grid-column: span 2; font-size: 19px; color: var(--accent); }
.key.enter { grid-column: span 3; font-size: 21px; background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
.key:active:not(:disabled) { transform: translateY(1px); }
.key:disabled { opacity: .4; cursor: not-allowed; }
.key:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; }
.linkbtn { display: inline-flex; align-items: center; text-decoration: none; }
.timer { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 18px; min-width: 64px; text-align: right; margin-left: auto; }
.tag { 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; color: var(--accent); }
.tag.retry { color: var(--ng); }

/* ---------- 設定 ---------- */
.ops .choice span b { font-size: 20px; margin-right: 4px; }
.choice .arr { width: 16px; height: 16px; margin-right: 4px; flex: none; display: inline-block; vertical-align: -2px; }

/* ---------- 結果 ---------- */
.result-box { position: static; margin: 12px auto 0; max-width: 560px; }
.result-box .big { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.result-box .weak { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 4px 0 10px; }
.result-box .weak span { border: 2px solid var(--ng); color: var(--ng); border-radius: 6px; padding: 0 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-box .best { display: inline-block; margin-left: 6px; font-size: 14px; color: var(--ok); border: 1.5px solid var(--ok); border-radius: 999px; padding: 0 8px; vertical-align: middle; }
.callout { z-index: 5; }

@media (max-width: 420px) {
  .stage { padding: 8px; }
  .grid-wrap { padding: 4px; }
  .grid { gap: 2px; }
  .grid .c { border-width: 1.5px; }
  .grid .c.sel { border-width: 2.5px; }
  .expr { font-size: 26px; margin-top: 6px; min-height: 44px; }
  .key { min-height: 50px; font-size: 26px; }
  .pad { gap: 5px; margin-top: 8px; }
  .controls .btn.icon { padding: 0 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .grid .c.sel:not(.typing):empty::after, .expr .ans.caret::after, .grid .c.pop, .grid .c.shake, .grid .c.reveal, .grid .c.win { animation: none; }
}
.howto img.narrow { max-width: 560px; }
/* 上のバーの高さを一定に（No.93。数字は一番長い文が画面の幅（360px・375px 以上・641px 以上）で何行になるか。--tb-rt はふりがなの分。base.css・turnbar.js） */
.turnbar { --tb-msg-lines: 2; --tb-st-lines: 1; --tb-rt: 11px; --tb-st-rt: 11px; }
@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; } }
/* 上のバーの高さ ここまで */
