/* ==========================================================
   九九カード - スタイルシート
   ========================================================== */
:root {
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-200: #fde68a;
  --amber-300: #fcd34d;
  --amber-400: #fbbf24;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --amber-800: #92400e;
  --amber-900: #78350f;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --sky-500: #0ea5e9;
  --sky-700: #0369a1;
  --indigo-500: #6366f1;
  --rose-500: #f43f5e;
  --rose-600: #e11d48;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;

  /* 明るい色をそのまま文字色に使わない。「面用」と「文字用」を2段階に分ける。
     ─ 面・帯・アイコンの下地 …… amber-100〜400 / slate-100〜300
     ─ 文字・アイコン        …… 下の2つ。淡い地でも白地でも 4.5:1 を満たす値。 */
  --ink: #1e293b;        /* 本文 */
  --ink-sub: #475569;    /* 補足・小さい字・案内文・空状態 */

  --radius: 20px;
  --shadow: 0 4px 14px rgba(146, 100, 13, .12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'BIZ UDGothic', 'Yu Gothic', system-ui, sans-serif;
  color-scheme: light;   /* 児童用アプリなので配色は固定する */
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: clamp(15px, 1.6vw + 10px, 18px);
  line-height: 1.8;
  background: linear-gradient(180deg, var(--amber-50), #fff7e6 60%, var(--amber-50));
  color: var(--ink);
  display: flex;
  flex-direction: column;
  /* 100vh はモバイルのアドレスバー分だけはみ出すので dvh を使う。
     dvh を先に書き、非対応の古い端末だけ @supports で 100vh に落とす。 */
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;   /* ダブルタップズームの300ms遅延を消す */
  /* 横向き時にノッチ側が欠けないようにする */
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
@supports not (min-height: 100dvh) { body { min-height: 100vh; } }

button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
button:disabled { opacity: .4; cursor: not-allowed; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--amber-800); outline-offset: 2px; }

/* 読み上げにだけ渡す見出し（見た目には出さない） */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ===== タップ領域 44px =====
   ボタン自身を大きくすると、詰めて組んであるツールバーで折り返しが起きて
   別の破綻を生む。疑似要素で「当たり判定だけ」を広げる。 */
.tap-44 { position: relative; }
.tap-44::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 100%; height: 100%;
  min-width: 44px; min-height: 44px;
}

/* ===== 動きの配慮 =====
   .01ms であって 0 ではない。0 にすると animation-fill-mode: forwards が効かなくなり、
   fadeIn しているカードや画面が opacity: 0 のまま消えてしまう。
   「動きを止める」つもりが「中身を消す」ことになる。 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ハイコントラストモード。背景色が無効化されても押せると分かるように枠を残す。 */
@media (forced-colors: active) {
  .mode-card, .stage-btn, .seg-btn, .key, .ctl-btn, .judge-btn, .btn-start,
  .btn-primary, .btn-secondary, .btn-back, .btn-mini, .btn-danger,
  .btn-close, .btn-sound, .chip, .toggle, .hm-cell, .update-btn {
    border: 2px solid ButtonText;
  }
}

/* ===== 更新の帯 ===== */
.update-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: var(--amber-800); color: #fff;
  font-size: 14px; font-weight: 900; text-align: center;
}
.update-text { line-height: 1.5; }
.update-btn {
  min-height: 44px; padding: 8px 18px; border-radius: 12px;
  background: #fff; color: var(--amber-800); font-weight: 900; font-size: 14px;
}
.update-btn:active { transform: scale(.95); }

/* ===== SVGアイコン共通 ===== */
.icon {
  width: 1em; height: 1em;
  display: inline-block;
  vertical-align: -0.14em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.icon-fill { fill: currentColor; stroke: none; }

/* ===== ヘッダー ===== */
.app-header {
  padding: calc(var(--safe-top) + 8px) 14px 8px;
  background: #fff;
  border-bottom: 3px solid var(--amber-400);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(146, 100, 13, .06);
  z-index: 20;
  flex-shrink: 0;
}
body.playing .app-header { display: none; }

.brand { display: flex; align-items: center; gap: 9px; }
.brand-icon {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(165deg, var(--amber-400), var(--amber-600));
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(217, 119, 6, .3);
}
.brand-icon .icon { width: 20px; height: 20px; }
.brand-name { font-weight: 900; font-size: 19px; letter-spacing: .04em; color: var(--slate-800); }

.header-right { display: flex; gap: 8px; align-items: center; }
.chip {
  font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 999px;
  background: var(--amber-100); color: var(--amber-800); border: 1.5px solid var(--amber-300);
  display: inline-flex; align-items: center; gap: 5px;
}
.chip-install { background: var(--amber-700); color: #fff; border-color: var(--amber-900); transition: transform .15s; }
.chip-install:active { transform: scale(.94); }

/* ===== 画面共通 ===== */
#app { flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 640px; margin: 0 auto; position: relative; }

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 16px 16px calc(var(--safe-bottom) + 20px);
  animation: fadeIn .25s ease;
}
.screen.active { display: flex; }
.screen { overscroll-behavior: contain; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-play { padding: calc(var(--safe-top) + 10px) 14px calc(var(--safe-bottom) + 14px); max-height: 100dvh; }
@supports not (max-height: 100dvh) { .screen-play { max-height: 100vh; } }

/* ===== ホーム ===== */
.home-hero { text-align: center; padding: 10px 0 16px; }
.home-greet { font-weight: 900; font-size: clamp(17px, 4.5vw, 21px); color: var(--amber-800); }
.home-today { margin-top: 8px; font-size: 13px; font-weight: 700; color: var(--ink-sub); }
.home-today b { color: var(--amber-700); font-size: 16px; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode-card {
  background: #fff; border-radius: var(--radius); padding: 20px 12px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: var(--shadow); border: 3px solid transparent;
  transition: transform .12s ease;
}
.mode-card:active { transform: scale(.955); }
.mode-flash { border-color: var(--amber-300); }
.mode-quiz { border-color: #a5d8f5; }
.mode-pair { border-color: #c4b5fd; }
.mode-records { border-color: #bbe8c5; }
.mode-icon {
  width: 62px; height: 62px; border-radius: 20px;
  display: grid; place-items: center; margin-bottom: 4px;
}
.mode-icon .icon { width: 32px; height: 32px; }
.mode-flash .mode-icon { background: var(--amber-100); color: var(--amber-800); }
.mode-quiz .mode-icon { background: #e0f2fe; color: #0284c7; }
.mode-pair .mode-icon { background: #ede9fe; color: #7c3aed; }
.mode-records .mode-icon { background: #dcfce7; color: var(--green-700); }
.mode-title { font-weight: 900; font-size: clamp(15px, 4vw, 18px); text-align: center; line-height: 1.35; }
.mode-desc { font-size: 11px; font-weight: 700; color: var(--ink-sub); }

.weak-banner {
  margin-top: 16px; width: 100%;
  background: #fff; border: 2.5px dashed var(--rose-500); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 10px;
  font-weight: 700; color: var(--slate-700); font-size: 13.5px; text-align: left;
  transition: transform .12s;
}
.weak-banner:active { transform: scale(.97); }
.weak-icon {
  width: 42px; height: 42px; border-radius: 14px; flex-shrink: 0;
  background: #fff1f2; color: var(--rose-600);
  display: grid; place-items: center;
}
.weak-icon .icon { width: 24px; height: 24px; }
.weak-text { flex: 1; } .weak-text b { color: var(--rose-600); font-size: 17px; }
.weak-arrow { color: var(--rose-600); display: grid; place-items: center; }
.weak-arrow .icon { width: 20px; height: 20px; }

/* ===== 設定画面 ===== */
.setup-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.btn-back { font-weight: 900; font-size: 14px; color: var(--amber-800); background: var(--amber-100); padding: 8px 14px; border-radius: 12px; transition: transform .12s; }
.btn-back::before { content: '‹ '; font-weight: 900; }
.btn-back:active { transform: scale(.94); }
.setup-title { font-size: 19px; font-weight: 900; }

.panel { background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel-label { font-weight: 900; font-size: 14px; color: var(--slate-700); margin-bottom: 10px; }
.panel-label small { font-weight: 700; color: var(--ink-sub); font-size: 11px; }
.panel-label .icon { color: var(--amber-800); width: 17px; height: 17px; }
.panel-sub { color: var(--ink-sub); font-size: 11px; font-weight: 700; }

.stage-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
@media (min-width: 480px) { .stage-grid { grid-template-columns: repeat(9, 1fr); } }
.stage-btn {
  padding: 12px 0; border-radius: 14px; font-weight: 900; font-size: 15px;
  background: var(--slate-100); border: 2.5px solid var(--slate-200); color: var(--ink-sub);
  transition: all .12s;
}
.stage-btn small { display: block; font-size: 9px; }
.stage-btn.on { background: var(--amber-700); border-color: var(--amber-900); color: #fff; box-shadow: 0 3px 8px rgba(120,53,15,.3); }
.stage-btn:active { transform: scale(.92); }

.stage-tools { display: flex; gap: 8px; margin-top: 10px; }
.btn-mini { font-size: 12px; font-weight: 700; color: var(--amber-800); background: var(--amber-100); padding: 6px 12px; border-radius: 10px; }
.btn-mini:active { transform: scale(.94); }

.segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#face-segment { grid-template-columns: 1fr 1fr; }
.seg-btn {
  padding: 10px 6px; border-radius: 14px; font-weight: 900; font-size: 13.5px; line-height: 1.5;
  background: var(--slate-100); border: 2.5px solid var(--slate-200); color: var(--ink-sub);
  transition: all .12s;
}
.seg-btn small { font-weight: 700; font-size: 10px; opacity: .75; }
.seg-btn .icon { width: 15px; height: 15px; }
.seg-btn.on { background: #fff; border-color: var(--amber-700); color: var(--amber-700); box-shadow: 0 3px 8px rgba(120,53,15,.15); }
.seg-btn:active { transform: scale(.95); }

.toggle {
  width: 56px; height: 32px; border-radius: 999px; background: var(--slate-300);
  position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle .knob {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: left .2s;
}
.toggle.on { background: var(--amber-700); }
.toggle.on .knob { left: 27px; }

.pair-hint { background: #eef2ff; border: 2px solid #c7d2fe; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; font-size: 13px; font-weight: 700; color: #3730a3; }
.pair-hint ol { margin: 6px 0 0 20px; display: grid; gap: 4px; }

.btn-start {
  width: 100%; padding: 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--amber-700), var(--amber-800));
  color: #fff; font-weight: 900; font-size: 19px; letter-spacing: .06em;
  box-shadow: 0 5px 0 var(--amber-900), 0 8px 18px rgba(120,53,15,.35);
  transition: transform .1s, box-shadow .1s;
  margin-bottom: 14px;
}
.btn-start .icon { width: 20px; height: 20px; vertical-align: -0.2em; }
.btn-start:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--amber-900), 0 3px 8px rgba(120,53,15,.3); }
.start-count { display: block; font-size: 12px; font-weight: 700; opacity: .9; margin-top: 2px; }

.btn-danger { width: 100%; padding: 12px; border-radius: 14px; font-weight: 700; font-size: 13px; color: var(--rose-600); background: #fff; border: 2px solid #fecdd3; margin-top: 4px; }

/* ===== プレイ画面共通 ===== */
.play-top { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.btn-close, .btn-sound {
  width: 42px; height: 42px; border-radius: 14px; font-weight: 900;
  background: #fff; box-shadow: var(--shadow); color: var(--ink-sub); flex-shrink: 0;
  display: grid; place-items: center; transition: transform .12s;
}
.btn-close .icon, .btn-sound .icon { width: 20px; height: 20px; }
.btn-close:active, .btn-sound:active { transform: scale(.9); }
.play-progress { flex: 1; }
.progress-text { font-size: 12px; font-weight: 900; color: var(--ink-sub); margin-bottom: 4px; }
.progress-bar { height: 10px; background: var(--slate-200); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--amber-400), var(--amber-500)); border-radius: 999px; transition: width .3s ease; }
.quiz-timer { font-weight: 900; font-size: 16px; color: var(--amber-700); background: #fff; padding: 8px 12px; border-radius: 12px; box-shadow: var(--shadow); min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }

.play-hint { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--ink-sub); flex-shrink: 0; padding: 6px 0; }

/* ===== カードアリーナ ===== */
.card-arena {
  flex: 1; position: relative; display: grid; place-items: center;
  min-height: 0; padding: 12px 0;
}
.card-stack {
  position: relative;
  width: min(420px, 88vw, calc((100dvh - 300px) * .78));
  aspect-ratio: 3 / 4;
  max-height: calc(100dvh - 280px);
}
@supports not (height: 100dvh) {
  .card-stack { width: min(420px, 88vw, calc((100vh - 300px) * .78)); max-height: calc(100vh - 280px); }
}

.kcard {
  position: absolute; inset: 0;
  perspective: 1200px;
  touch-action: none;
  will-change: transform;
}
.kcard.behind1 { transform: scale(.95) translateY(24px); z-index: 1; filter: brightness(.97); pointer-events: none; }
.kcard.behind2 { transform: scale(.9) translateY(46px); z-index: 0; filter: brightness(.94); pointer-events: none; }
.kcard.current { z-index: 2; cursor: grab; }
.kcard.current:active { cursor: grabbing; }
.kcard.snap-back { transition: transform .3s cubic-bezier(.2, 1.6, .4, 1); }
.kcard.fly-out { transition: transform .35s ease-in, opacity .35s ease-in; opacity: 0; }
.kcard.deal-in { animation: dealIn .32s cubic-bezier(.2, 1.2, .4, 1); }
@keyframes dealIn { from { transform: scale(.95) translateY(24px); } to { transform: none; } }

.kcard-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.35, .9, .3, 1);
}
.kcard.flipped .kcard-inner { transform: rotateY(180deg); }

.kface {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 26px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(146, 100, 13, .18);
}
.kface-front {
  background: #fff;
  border: 5px solid var(--amber-400);
}
.kface-back {
  background: linear-gradient(165deg, var(--amber-700), var(--amber-800) 55%, var(--amber-900));
  border: 5px solid var(--amber-900);
  color: #fff;
  transform: rotateY(180deg);
}

.kface-top { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.ktag { font-size: 12px; font-weight: 900; padding: 5px 12px; border-radius: 999px; white-space: nowrap; }
.kface-front .ktag { background: var(--amber-100); color: var(--amber-800); border: 1.5px solid var(--amber-200); }
.kface-back .ktag { background: rgba(0,0,0,.22); color: #fff; border: 1.5px solid rgba(255,255,255,.45); }
.khint { font-size: 10.5px; font-weight: 700; color: var(--ink-sub); }
.kface-back .khint { color: var(--amber-50); }

.kmain { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; width: 100%; }
.kformula {
  font-weight: 900;
  font-size: 52px; /* コンテナクエリ非対応ブラウザ用フォールバック */
  font-size: clamp(44px, 16cqw, 84px);
  letter-spacing: .04em;
  color: var(--slate-800);
  white-space: nowrap;
}
.kcard { container-type: size; }
.kface-back .kformula { color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.12); }
.kanswer {
  font-weight: 900;
  font-size: 80px; /* コンテナクエリ非対応ブラウザ用フォールバック */
  font-size: clamp(64px, 26cqw, 130px);
  color: #fff;
  line-height: 1;
  text-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.kyomi {
  font-size: 17px; /* コンテナクエリ非対応ブラウザ用フォールバック */
  font-size: clamp(14px, 5cqw, 22px); font-weight: 900; letter-spacing: .1em;
  background: rgba(0,0,0,.22); border: 1.5px solid rgba(255,255,255,.45);
  padding: 8px 16px; border-radius: 999px;
}
.kspeak {
  width: 46px; height: 46px; border-radius: 50%; color: #fff;
  background: rgba(0,0,0,.22); border: 1.5px solid rgba(255,255,255,.5);
  display: grid; place-items: center; transition: transform .12s;
}
.kspeak .icon { width: 22px; height: 22px; }
.kspeak:active { transform: scale(.88); }
.kfoot { font-size: 11px; font-weight: 900; color: var(--ink-sub); }
.kface-back .kfoot { color: var(--amber-50); }

/* スワイプ中ラベル */
.swipe-label {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 17px; font-weight: 900; padding: 12px 16px; border-radius: 16px;
  opacity: 0; transition: opacity .15s; pointer-events: none; z-index: 5; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.swipe-label-left { left: 6px; }
.swipe-label-right { right: 6px; }
.swipe-label.tone-good { background: var(--green-700); color: #fff; }
.swipe-label.tone-again { background: var(--rose-600); color: #fff; }
.swipe-label.show { opacity: 1; }

/* コントローラー */
.play-controls { display: grid; grid-template-columns: 1fr 1.1fr 1fr; gap: 10px; flex-shrink: 0; }
.ctl-btn {
  padding: 12px 6px; border-radius: 18px; font-weight: 900;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #fff; box-shadow: 0 4px 0 var(--slate-200), var(--shadow);
  transition: transform .1s, box-shadow .1s;
}
.ctl-btn .icon { width: 25px; height: 25px; }
.ctl-btn span { font-size: 12px; }
.ctl-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--slate-200); }
.ctl-again { color: var(--rose-600); }
.ctl-flip { color: var(--amber-800); background: var(--amber-100); box-shadow: 0 4px 0 var(--amber-300), var(--shadow); }
.ctl-flip:active { box-shadow: 0 1px 0 var(--amber-300); }
.ctl-good { color: var(--green-700); }

/* ===== クイズ ===== */
.quiz-body { flex: 1; display: flex; flex-direction: column; min-height: 0; justify-content: space-between; gap: 8px; padding-top: 8px; }
.quiz-problem-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 0; }
.quiz-problem { font-size: clamp(40px, 11vw, 64px); font-weight: 900; letter-spacing: .04em; }
.quiz-answer-box {
  min-width: 130px; text-align: center; font-size: clamp(34px, 9vw, 48px); font-weight: 900;
  background: #fff; border: 3.5px solid var(--amber-400); border-radius: 18px; padding: 4px 20px;
  color: var(--amber-700); box-shadow: var(--shadow); font-variant-numeric: tabular-nums;
}
.quiz-answer-box.correct { border-color: var(--green-700); color: var(--green-700); animation: pop .3s; }
.quiz-answer-box.wrong { border-color: var(--rose-600); color: var(--rose-600); animation: shake .4s; }
@keyframes pop { 50% { transform: scale(1.12); } }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.quiz-feedback { min-height: 30px; font-weight: 900; font-size: 16px; text-align: center; }
.quiz-feedback .fb-ok { color: var(--green-700); display: inline-flex; align-items: center; gap: 6px; }
.quiz-feedback .fb-ok .icon { stroke-width: 2.6; }
.quiz-feedback .fb-ng { color: var(--rose-600); font-size: 14.5px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 380px; width: 100%; margin: 0 auto; flex-shrink: 0; }
.key {
  padding: clamp(10px, 2.2dvh, 18px) 0; border-radius: 16px; font-size: 24px; font-weight: 900;
  background: #fff; box-shadow: 0 3px 0 var(--slate-200), var(--shadow); color: var(--slate-700);
  transition: transform .08s, box-shadow .08s;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--slate-200); }
.key-del { color: var(--rose-600); }
.key-del .icon { width: 24px; height: 24px; }
.key-ok { background: var(--amber-700); color: #fff; box-shadow: 0 3px 0 var(--amber-900), var(--shadow); }
.key-ok:active { box-shadow: 0 1px 0 var(--amber-900); }
.btn-next-q {
  max-width: 380px; width: 100%; margin: 0 auto; padding: 16px; border-radius: 16px;
  background: var(--sky-700); color: #fff; font-weight: 900; font-size: 18px; flex-shrink: 0;
  box-shadow: 0 4px 0 #075985;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-next-q .icon { width: 17px; height: 17px; }
.btn-next-q:active { transform: translateY(3px); box-shadow: 0 1px 0 #075985; }

/* ===== ふたりで ===== */
.pair-scores { flex: 1; display: flex; gap: 8px; }
.pair-score {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff; border-radius: 14px; padding: 7px 6px; box-shadow: var(--shadow);
  font-size: 12px; font-weight: 700; color: var(--ink-sub); border: 2.5px solid transparent;
}
.pair-score.turn { border-color: var(--amber-700); background: var(--amber-100); }
.pp-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); }
.pp-dot-1 { background: var(--rose-500); }
.pp-dot-2 { background: var(--sky-500); }
.pp-pts { font-size: 18px; color: var(--amber-800); }
.pair-turn {
  text-align: center; font-weight: 900; font-size: clamp(15px, 4.5vw, 19px);
  color: var(--slate-700); padding: 10px 0 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.card-arena-pair .card-stack { max-height: calc(100dvh - 330px); }

.pair-judge { flex-shrink: 0; background: #fff; border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.judge-ask { text-align: center; font-weight: 900; font-size: 14px; margin-bottom: 8px; }
.judge-ask small { color: var(--ink-sub); font-size: 11px; }
.judge-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.judge-btn {
  padding: 14px; border-radius: 16px; font-weight: 900; font-size: 17px; color: #fff;
  transition: transform .1s; display: flex; align-items: center; justify-content: center; gap: 7px;
}
.judge-btn .icon { width: 20px; height: 20px; stroke-width: 2.6; }
.judge-btn:active { transform: scale(.95); }
.judge-ok { background: var(--green-700); box-shadow: 0 4px 0 #14532d; }
.judge-ng { background: var(--slate-600); box-shadow: 0 4px 0 var(--slate-800); }

/* ===== 結果 ===== */
#screen-result { justify-content: center; position: relative; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.result-card {
  background: #fff; border-radius: 28px; padding: 28px 22px; box-shadow: var(--shadow);
  text-align: center; border: 4px solid var(--amber-300); position: relative; z-index: 2;
}
.result-icon {
  width: 96px; height: 96px; border-radius: 50%; margin: 0 auto;
  background: var(--amber-100); color: var(--amber-800);
  display: grid; place-items: center;
  animation: bounce .8s ease infinite alternate;
}
.result-icon .icon { width: 48px; height: 48px; }
.result-icon.tone-green { background: #dcfce7; color: var(--green-700); }
.result-icon.tone-sky { background: #e0f2fe; color: #0284c7; }
.result-icon.tone-rose { background: #ffe4e6; color: var(--rose-600); }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-10px); } }
.result-title { font-size: 23px; font-weight: 900; color: var(--amber-700); margin: 8px 0 16px; }
.result-stats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.rs-item { background: var(--amber-50); border: 2px solid var(--amber-200); border-radius: 16px; padding: 10px 16px; min-width: 88px; }
.rs-num { display: block; font-size: 24px; font-weight: 900; color: var(--amber-700); font-variant-numeric: tabular-nums; }
.rs-label { font-size: 11px; font-weight: 700; color: var(--ink-sub); }
.result-wrong { text-align: left; background: #fff1f2; border: 2px solid #fecdd3; border-radius: 16px; padding: 12px 14px; margin-bottom: 16px; }
.rw-label { font-size: 12px; font-weight: 900; color: var(--rose-600); margin-bottom: 8px; }
.rw-list { display: flex; flex-wrap: wrap; gap: 6px; }
.rw-item { background: #fff; border: 1.5px solid #fecdd3; border-radius: 10px; padding: 5px 10px; font-size: 13px; font-weight: 900; color: var(--slate-700); }
.rw-item small { color: var(--ink-sub); font-weight: 700; }
.result-btns { display: flex; flex-direction: column; gap: 10px; }
.btn-primary {
  padding: 15px; border-radius: 16px; background: var(--amber-700); color: #fff;
  font-weight: 900; font-size: 16px; box-shadow: 0 4px 0 var(--amber-900);
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--amber-900); }
.btn-secondary {
  padding: 13px; border-radius: 16px; background: #fff; color: var(--amber-700);
  border: 2.5px solid var(--amber-300); font-weight: 900; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-secondary:active { transform: scale(.97); }
.btn-primary .icon, .btn-secondary .icon { width: 17px; height: 17px; }

/* ===== きろく ===== */
.records-hero { display: flex; justify-content: space-around; text-align: center; }
.rec-stat { display: flex; flex-direction: column; gap: 2px; }
.rec-num { font-size: 28px; font-weight: 900; color: var(--amber-700); font-variant-numeric: tabular-nums; }
.rec-num small { font-size: 14px; color: var(--ink-sub); }
.rec-label { font-size: 11px; font-weight: 700; color: var(--ink-sub); display: inline-flex; align-items: center; gap: 4px; justify-content: center; }
.rec-label .icon { color: var(--amber-800); width: 13px; height: 13px; }

.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 10px; font-weight: 900; color: var(--ink-sub); margin-bottom: 6px; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day {
  aspect-ratio: 1; border-radius: 12px; background: var(--slate-100);
  display: grid; place-items: center; font-size: 15px; font-weight: 700; color: var(--ink-sub);
  position: relative;
}
.cal-day.stamped { background: var(--amber-100); color: var(--amber-800); }
.cal-day.today { outline: 2.5px solid var(--amber-800); outline-offset: 1px; }
.cal-day .cal-num { position: absolute; top: 2px; left: 5px; font-size: 8.5px; }
.cal-day .icon { width: 17px; height: 17px; }
.cal-day.empty { background: transparent; }

/* 1マスを 44px 以上にすると 320px 幅では収まらないので、この枠の中だけ横に流す。
   ページ全体に横スクロールを出さないための入れ子スクロール。 */
.heatmap-scroll { overflow-x: auto; overscroll-behavior-x: contain; margin: 0 -4px; padding: 0 4px 4px; }
.heatmap { display: grid; grid-template-columns: auto repeat(9, minmax(44px, 1fr)); gap: 4px; min-width: max-content; }
.hm-head, .hm-side { display: grid; place-items: center; font-size: 10.5px; font-weight: 900; color: var(--ink-sub); }
.hm-cell {
  min-height: 44px; border-radius: 8px; display: grid; place-items: center;
  font-size: 11px; font-weight: 900; transition: transform .1s;
}
@media (min-width: 480px) { .hm-cell { font-size: 12px; } }
.hm-cell:active { transform: scale(.85); }
.hm-0 { background: var(--slate-100); color: var(--ink-sub); }
.hm-1 { background: var(--amber-100); color: var(--amber-800); }
.hm-2 { background: var(--amber-300); color: var(--amber-800); }
.hm-3 { background: var(--green-700); color: #fff; }
.hm-cell .icon { width: 13px; height: 13px; }
.heat-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; font-size: 10.5px; font-weight: 700; color: var(--ink-sub); }
.heat-legend span { display: flex; align-items: center; gap: 4px; }
.hl { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.hl-0 { background: var(--slate-100); border: 1px solid var(--slate-200); }
.hl-1 { background: var(--amber-100); }
.hl-2 { background: var(--amber-300); }
.hl-3 { background: var(--green-700); }
.heat-detail { margin-top: 10px; min-height: 22px; font-size: 13px; font-weight: 900; color: var(--amber-700); text-align: center; }

/* --- 学習ログのふりかえり --- */
.sl-week { display: flex; justify-content: space-around; text-align: center; gap: 8px; }
.sl-stat { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sl-num { font-size: 24px; font-weight: 900; color: var(--amber-700); font-variant-numeric: tabular-nums; }
.sl-num small { font-size: 13px; color: var(--ink-sub); }
/* ことばの とちゅうで 折り返さない(スペースの位置だけで改行する) */
.sl-label { font-size: 10.5px; font-weight: 700; color: var(--ink-sub); word-break: keep-all; }
.sl-sub { margin: 14px 0 6px; font-size: 11px; font-weight: 900; color: var(--ink-sub); }
.sl-list { display: flex; flex-direction: column; gap: 6px; }
.sl-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--slate-100); border-radius: 12px; padding: 8px 11px;
}
.sl-date { font-size: 11px; font-weight: 900; color: var(--ink-sub); min-width: 34px; font-variant-numeric: tabular-nums; }
.sl-body { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sl-body b { font-size: 12.5px; font-weight: 900; color: var(--slate-700); }
.sl-body small { font-size: 10.5px; font-weight: 700; color: var(--ink-sub); }
.sl-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.sl-tag {
  font-size: 9.5px; font-weight: 900;
  background: var(--slate-200); color: var(--ink-sub); border-radius: 999px; padding: 2px 7px;
}
.sl-tag-weak { background: var(--amber-100); color: var(--amber-800); }
.sl-score { text-align: right; display: flex; flex-direction: column; }
.sl-score b { font-size: 14px; font-weight: 900; color: var(--amber-700); font-variant-numeric: tabular-nums; }
.sl-score small { font-size: 9.5px; font-weight: 700; color: var(--ink-sub); }
.sl-note { margin-top: 10px; font-size: 10.5px; font-weight: 700; color: var(--ink-sub); text-align: center; }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge {
  background: var(--amber-50); border: 2px solid var(--amber-200); border-radius: 16px;
  padding: 12px 6px; text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.badge.locked { background: var(--slate-100); border-color: var(--slate-200); opacity: .55; }
.badge-icon {
  width: 42px; height: 42px; border-radius: 13px;
  background: #fff; color: var(--amber-800); border: 1.5px solid var(--amber-200);
  display: grid; place-items: center;
}
.badge.locked .badge-icon { color: var(--slate-500); border-color: var(--slate-200); }
.badge-icon .icon { width: 23px; height: 23px; }
.badge-name { font-size: 10.5px; font-weight: 900; color: var(--slate-700); }

/* ===== トースト ===== */
.toast {
  position: fixed; bottom: calc(var(--safe-bottom) + 24px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--slate-800); color: #fff; font-weight: 700; font-size: 13.5px;
  padding: 12px 20px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 50; white-space: nowrap; max-width: 92vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 横向き(ランドスケープ)対応 ===== */
@media (orientation: landscape) and (max-height: 520px) {
  .screen-play { flex-direction: row; flex-wrap: wrap; align-content: stretch; gap: 8px; }
  .play-top { width: 100%; }
  .card-arena { flex: 1 1 55%; order: 1; }
  .card-stack { width: min(300px, calc((100dvh - 120px) * .75)); max-height: calc(100dvh - 110px); }
  .play-hint { display: none; }
  .play-controls { flex: 0 0 130px; order: 2; grid-template-columns: 1fr; align-content: center; }
  .quiz-body { flex-direction: row; align-items: center; gap: 16px; }
  .keypad { max-width: 300px; }
  .card-arena-pair .card-stack { max-height: calc(100dvh - 150px); }
  .pair-judge { flex: 0 0 190px; order: 2; align-self: center; }
}

/* 大画面(タブレット) */
@media (min-width: 768px) {
  #app { max-width: 720px; }
  .brand-name { font-size: 22px; }
  .mode-emoji { font-size: 52px; }
}

/* ===== 印刷 ===== */
@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    background: #fff; font-size: 10.5pt; line-height: 1.5;
  }
  .no-print, .app-header, .update-bar, .toast, .btn-start, .btn-danger,
  .stage-tools, .play-controls, .keypad, .btn-next-q, .pair-judge, .confetti { display: none !important; }
  .panel, .badge, .result-card { break-inside: avoid; box-shadow: none; }
  .calendar, .heatmap, table { break-inside: avoid; }
  .heatmap-scroll { overflow: visible; }
  a[href]::after { content: ""; }   /* URLを併記しない */
}
