/* ============================================================
   けいさんカード — 絵本 × さんすうノート(方眼紙)テーマ
   ============================================================ */

:root {
  --paper: #fff6e9;
  --ink: #453a2f;
  --grid: rgba(69, 58, 47, 0.08);
  --white: #fffdf8;
  --add: #ff8a5c;
  --add-soft: #ffe3d6;
  --sub: #62b6e8;
  --sub-soft: #ddf0fc;
  --sun: #ffd34e;
  --sun-soft: #fff3c4;
  --sun-deep: #c99a2e;
  --maru: #ff5252;
  --batsu: #5a8fd0;
  --shadow: 0 5px 0 var(--ink);
  --font-ui: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', sans-serif;
  --font-num: 'M PLUS Rounded 1c', 'Zen Maru Gothic', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* hidden属性は、要素側でdisplayを明示指定していても常に優先する
   (CSSの仕様上、同じ詳細度なら後勝ちになりhidden属性が無視されてしまうため) */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--ink);
  background-color: var(--paper);
  /* さんすうノートの方眼 */
  background-image:
    linear-gradient(var(--grid) 1.5px, transparent 1.5px),
    linear-gradient(90deg, var(--grid) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.num {
  font-family: var(--font-num);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

main {
  height: 100dvh;
  max-width: 460px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

/* ---------- 画面切替 ---------- */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}
.screen.active {
  display: flex;
  animation: screen-in 0.25s ease-out;
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- ステッカー(共通部品) ---------- */
.sticker {
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
button.sticker:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
}

/* ---------- ホーム ---------- */
#screen-home {
  justify-content: flex-start;
}

/* ヘッダー: 左のなまえシールと右のメニューが左右で釣り合う */
.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  flex-shrink: 0;
  min-height: 56px;
}

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  text-align: center;
  padding-bottom: 40px;
}

/* なまえシール: 学校のノートの名前欄。少し傾けて「貼った」感を出す */
.name-label {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 7px 14px;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-1.5deg);
  margin-top: 2px;
}
.name-label-caption {
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.45;
  letter-spacing: 0.08em;
}
.name-label-value {
  font-size: 1.05rem;
  font-weight: 900;
}

/* ---------- メニュー ---------- */
.menu-wrap {
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

.menu-btn {
  width: 52px;
  height: 52px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.15s ease;
}
.menu-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
}
.menu-btn[aria-expanded="true"] {
  background: var(--sun);
}

/* クレヨンで描いた3本線。長さを不揃いにして手描き感を出す */
.menu-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 24px;
}
.menu-bars span {
  height: 4px;
  border-radius: 999px;
  transition: width 0.18s ease;
}
.menu-bars span:nth-child(1) { width: 100%; background: var(--add); }
.menu-bars span:nth-child(2) { width: 76%;  background: #e8a33d; }
.menu-bars span:nth-child(3) { width: 92%;  background: var(--sub); }
.menu-btn[aria-expanded="true"] .menu-bars span:nth-child(2) { width: 100%; }

.menu-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  min-width: 210px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: flex;
  flex-direction: column;
  transform-origin: top right;
  animation: menu-pop 0.16s ease-out;
}
@keyframes menu-pop {
  from { opacity: 0; transform: scale(0.88) translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
/* メニューボタンを指す吹き出しの角 */
.menu-dropdown::before {
  content: '';
  position: absolute;
  top: -9px;
  right: 17px;
  width: 15px;
  height: 15px;
  background: var(--white);
  border-left: 3px solid var(--ink);
  border-top: 3px solid var(--ink);
  border-radius: 3px 0 0 0;
  transform: rotate(45deg);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 8px 12px;
  font-family: inherit;
  font-weight: 900;
  font-size: 1.05rem;
  color: var(--ink);
  background: none;
  border: none;
  border-radius: 14px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.menu-item:active {
  background: var(--paper);
}
/* ノートの点線のような区切り */
.menu-item-last {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 2px dashed rgba(69, 58, 47, 0.2);
  border-radius: 0 0 14px 14px;
}

/* モードボタンの丸アイコンを小さくしたもの。画面間で語彙を共有する */
.menu-chip {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
}
.chip-records  { background: var(--add-soft); }
.chip-graph    { background: var(--sub-soft); }
.chip-password { background: var(--sun); }
.chip-logout   { background: #f3ece4; }

.title {
  font-size: clamp(2.2rem, 11vw, 3rem);
  letter-spacing: 0.04em;
  line-height: 1.1;
}
.title span {
  display: inline-block;
  animation: bob 2.4s ease-in-out infinite;
}
.title span:nth-child(1) { color: var(--add);  animation-delay: 0s;    }
.title span:nth-child(2) { color: var(--sub);  animation-delay: 0.12s; }
.title span:nth-child(3) { color: #e8a33d;     animation-delay: 0.24s; }
.title span:nth-child(4) { color: #7ed957;     animation-delay: 0.36s; }
.title span:nth-child(5) { color: var(--maru); animation-delay: 0.48s; }
.title span:nth-child(6) { color: var(--sub);  animation-delay: 0.6s;  }
.title span:nth-child(7) { color: var(--add);  animation-delay: 0.72s; }
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-6px) rotate(2deg); }
}

.tagline {
  font-size: 1.05rem;
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 18px;
  align-self: center;
  transform: rotate(-2deg);
  box-shadow: 0 3px 0 var(--ink);
}

.mode-carousel-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 横スクロール+スナップのみで実現し、独自のタッチイベント処理は書かない。
   カードは幅いっぱいにし、隣のカードは完全に隠す(peekさせない)。
   初期表示はscrollLeft:0のままで、スワイプするまでscroll-snapによる
   中央寄せが効かないため、peekさせると初回表示時に右端だけ中途半端に
   見切れて見えてしまっていた */
.mode-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  gap: 14px;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.mode-carousel::-webkit-scrollbar {
  display: none;
}

.mode-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(69, 58, 47, 0.25);
  transition: background 0.2s ease, transform 0.2s ease;
}
.mode-dot.active {
  background: var(--ink);
  transform: scale(1.3);
}

/* カルーセルの1ページ。同じ系統のモード(通常・あなうめ)を縦に並べる単位で、
   スクロール・スナップもページ単位で行う */
.mode-page {
  flex: 0 0 100%;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mode-btn {
  position: relative;
  display: grid;
  grid-template-columns: 76px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  text-align: left;
  padding: 18px 22px;
  gap: 2px 14px;
}
/* +/− は文字ではなくCSSの図形で描く。
   フォントの +/− はベースライン基準で配置されるため、行ボックスを中央寄せしても
   インクが約6px上にずれる。図形なら構造的に必ず中央に来る。
   線の端を丸めてメニューのクレヨン線と同じ語彙にしている。 */
.mode-btn .mode-icon {
  grid-row: 1 / 3;
  position: relative;
  width: 72px;
  height: 72px;
  border: 3px solid var(--ink);
  border-radius: 50%;
}
.mode-btn .mode-icon::before,
.mode-btn .mode-icon::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  background: var(--white);
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}
/* 横棒: たしざん・ひきざん共通(通常・あなうめ問わず) */
.mode-btn .mode-icon::before {
  width: 32px;
  height: 7px;
  transform: translate(-50%, -50%);
}
/* 縦棒: たしざん系(通常・あなうめ)のみ */
.mode-add10 .mode-icon::after,
.mode-add10blank .mode-icon::after {
  width: 7px;
  height: 32px;
  transform: translate(-50%, -50%);
}
.mode-add10 .mode-icon,
.mode-add10blank .mode-icon { background: var(--add); }
.mode-sub10 .mode-icon,
.mode-sub10blank .mode-icon { background: var(--sub); }
.mode-add10,
.mode-add10blank { background: var(--add-soft); }
.mode-sub10,
.mode-sub10blank { background: var(--sub-soft); }
.mode-clock30,
.mode-clock5 { background: var(--sun-soft); }
/* あなうめモードは通常モードと同系色のまま、右上に「○」バッジを重ねて見分けられるようにする */
.mode-btn[data-mode$="blank"]::after {
  content: '○';
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--ink);
  opacity: 0.45;
}
/* とけいモードのアイコン: 円の中に短針・長針の2本を異なる角度・長さで描く */
.mode-clock30 .mode-icon,
.mode-clock5 .mode-icon {
  background: var(--sun);
}
.mode-clock30 .mode-icon::before,
.mode-clock5 .mode-icon::before {
  width: 5px;
  height: 16px;
  top: 50%;
  left: 50%;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(20deg);
  border-radius: 999px;
}
.mode-clock30 .mode-icon::after,
.mode-clock5 .mode-icon::after {
  width: 4px;
  height: 24px;
  top: 50%;
  left: 50%;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(110deg);
  border-radius: 999px;
}
.mode-btn .mode-label { font-size: clamp(1.55rem, 8vw - 4px, 1.7rem); }
.mode-btn .mode-best {
  font-size: 0.95rem;
  opacity: 0.75;
  font-weight: 700;
}

.link-btn {
  align-self: center;
  font-size: 1rem;
  padding: 12px 26px;
  border-radius: 999px;
}

/* ---------- 確認モーダル(ログアウト等) ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(69, 58, 47, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.confirm-card {
  width: 100%;
  max-width: 320px;
  padding: 26px 24px 24px;
  text-align: center;
  cursor: default;
  animation: confirm-pop 0.22s ease-out;
}
@keyframes confirm-pop {
  0%   { opacity: 0; transform: scale(0.85) translateY(12px); }
  60%  { transform: scale(1.02); }
  100% { opacity: 1; transform: none; }
}
.confirm-emoji {
  font-size: 2.4rem;
  line-height: 1;
  margin-bottom: 10px;
}
.confirm-message {
  font-size: 1.2rem;
}
.confirm-note {
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0.55;
  margin-top: 8px;
  line-height: 1.5;
}
.confirm-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}
.confirm-buttons .big-btn {
  font-size: 1.15rem;
  padding: 14px 0;
}

/* ---------- 読み込み中 ---------- */
#screen-loading {
  background-color: var(--paper);
}

/* ---------- ログイン・サインアップ・パスワード変更 ---------- */
#screen-login,
#screen-signup,
#screen-change-password {
  justify-content: center;
  align-items: center;
  gap: 22px;
  text-align: center;
}
.auth-title {
  margin-bottom: 4px;
}
.auth-form {
  width: 100%;
  max-width: 320px;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: default;
}
.auth-heading {
  font-size: 1.4rem;
  margin-bottom: 4px;
}
.auth-input {
  font-family: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 12px 16px;
  outline: none;
}
.auth-input:focus {
  background: var(--white);
  box-shadow: 0 0 0 3px var(--sun);
}
.auth-input::placeholder {
  color: var(--ink);
  opacity: 0.4;
}
.auth-submit {
  font-size: 1.2rem;
  padding: 14px 0;
  border-radius: 999px;
  background: var(--sun);
  margin-top: 4px;
}
.auth-error {
  font-size: 0.9rem;
  color: var(--maru);
  background: var(--white);
  border: 2px solid var(--maru);
  border-radius: 12px;
  padding: 8px 12px;
}
.auth-success {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--sun);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 12px;
}

/* ---------- プレイ ---------- */
#screen-play {
  gap: 10px;
  padding-top: 10px;
}

.play-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.quit-btn {
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
}
.progress {
  font-size: 1rem;
  opacity: 0.8;
}
.timer {
  margin-left: auto;
  font-size: 1.5rem;
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 2px 12px;
  box-shadow: 0 3px 0 var(--ink);
}

.card-area {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}

.card {
  position: relative; /* .judge を内側にぴったり重ねる基準にする */
  width: 100%;
  min-width: 0; /* grid item のデフォルトmin-width:autoがnowrapテキストの幅に
                   引っ張られて100%を超えて広がってしまうのを防ぐ */
  padding: clamp(20px, 6vh, 48px) 12px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35em;
  font-size: clamp(2.5rem, 12.5vw, 3.6rem);
  background:
    linear-gradient(var(--white), var(--white)) padding-box,
    var(--white);
  border-radius: 30px;
  cursor: default;
}
.card-text {
  white-space: nowrap; /* "10 − 10" のような幅の広い式が2行に折り返さないようにする */
}
/* 通常の計算式(a op b = ?)の行。以前は.card自体がこのレイアウトだったが、
   .card-clockと共存させるため独立した要素に切り出した */
.card-arith {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35em;
  width: 100%;
}
.card-answer {
  color: #c9bfae;
}

/* とけいモードのカード内レイアウト: 時計盤面の下に「?じ ?ふん」の回答スロット */
.card-clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}
.clock-face {
  width: min(48vw, 200px);
  height: min(48vw, 200px);
}
.clock-number {
  font-family: var(--font-num);
  font-size: 15px;
  font-weight: 800;
  fill: var(--ink);
}
.clock-answer {
  display: flex;
  align-items: baseline;
  gap: 0.15em;
  font-size: clamp(1.6rem, 8vw, 2.2rem);
  font-family: var(--font-num);
  font-weight: 800;
}
.clock-slot {
  display: inline-block;
  min-width: 1.3em;
  text-align: center;
  color: #c9bfae;
  opacity: 0.4;
}
/* 今問われている方だけを大きく・色をつけて不透明度も上げ、それ以外(未回答・
   答え終えた方)は薄くする。ラベル文字を増やさず、見た目のコントラストだけで
   「なんじ?」「なんぷん?」のどちらが今の質問かを伝える */
.clock-slot.answered {
  color: var(--ink);
  opacity: 0.4;
}
.clock-slot.active {
  color: var(--sun-deep);
  font-size: 1.3em;
  transform: scale(1.08);
  opacity: 1;
}
.clock-unit {
  margin-right: 0.3em;
  opacity: 0.4;
}
.clock-unit.active {
  opacity: 1;
}

/* ○ / × / カウントダウン のオーバーレイ */
.judge {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 10;
}
/* とけいモードは時計盤面が縦に大きく場所を取り、中央に表示すると盤面(針・
   数字)に○×の判定表示が重なって読みにくくなる。回答スロットに近い下寄りに
   表示することで盤面を隠さないようにする(スタート前のカウントダウン表示
   (.judge.cover)はカード全体を覆うものなので対象外、従来通り中央のまま) */
#card-clock:not([hidden]) ~ .judge.maru {
  align-items: end;
}
#card-clock:not([hidden]) ~ .judge.batsu {
  /* .judge.batsuはflex-direction:columnなのでjustify-contentが縦方向を制御する */
  justify-content: flex-end;
}
.judge.maru::before {
  content: '';
  width: min(46vw, 210px);
  height: min(46vw, 210px);
  border: 14px solid var(--maru);
  border-radius: 50%;
  animation: maru-pop 0.55s ease-out forwards;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.12));
}
@keyframes maru-pop {
  0%   { transform: scale(0.3); opacity: 0; }
  35%  { transform: scale(1.08); opacity: 1; }
  70%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

.judge.batsu {
  flex-direction: column;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  animation: batsu-shake 0.4s ease;
}
.batsu-mark {
  font-size: min(22vw, 96px);
  line-height: 1;
  color: var(--batsu);
  font-weight: 900;
  opacity: 0.4; /* 問題の数字が透けて見えるようにし、問題が読めなくなるのを防ぐ */
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.12));
}
.batsu-text {
  font-size: 1.4rem;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 4px 18px;
  box-shadow: 0 3px 0 var(--ink);
}
@keyframes batsu-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  50% { transform: translateX(10px); }
  75% { transform: translateX(-6px); }
}

/* スタート待ち・カウントダウンの間、カード自体の数字(例: 3+2=?)が
   先読みできてしまったり重なって読みにくくならないよう完全に覆い隠す。
   .judge は .card の内側の要素になったので(index.html参照)、.card と
   別々にサイズを計算する必要がなく、常にぴったり同じ大きさになる。
   (以前は .card-area 基準の別要素だったため、フォントサイズの違いで
   高さがずれ、カードの縁が透けて見えてしまっていた) */
.judge.cover {
  pointer-events: auto; /* スタートボタンをタップできるようにする */
  background: var(--white);
  border-radius: 27px; /* .card の30pxから枠線3px分小さくし、内側にぴったり収める */
}
.judge.cover.count {
  font-family: var(--font-num);
  font-size: clamp(3rem, 20vw, 7rem);
  line-height: 1;
  color: var(--ink);
  background: var(--sun); /* 「カウント中」だと分かるよう問題カードの白と区別する */
}
/* 「スタート!」は数字より文字数が多いので、1行に収まるよう小さくする */
.judge.cover.count.start {
  font-size: clamp(2rem, 13vw, 4.2rem);
  white-space: nowrap;
}
/* ポップ演出は文字(.count-text)だけにかける。#judge自体にかけると
   アニメーション開始時のopacity:0で背景ごと透明になり、後ろの問題が
   一瞬見えてしまうため、常に不透明な背景(覆い)とは切り離す */
.count-text {
  display: inline-block; /* transformが効くように */
}
.count-text.pop {
  animation: count-pop 0.6s ease-out;
}

.start-prompt {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  font-family: inherit;
  font-weight: 900;
  font-size: clamp(1.6rem, 8vw, 2.6rem);
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  animation: start-pulse 1.6s ease-in-out infinite;
}
@keyframes start-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}
@keyframes count-pop {
  0%  { transform: scale(0.4); opacity: 0; }
  40% { transform: scale(1.15); opacity: 1; }
  70% { transform: scale(1); }
}

.mic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 1.6em;
  font-size: 0.95rem;
}
.mic-status { opacity: 0.75; }
.heard {
  color: var(--sub);
  font-size: 1.1rem;
}

/* すうじボタン */
.numpad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  /* 行の高さを固定し、ボタン数が少ない段階(例: clock30の分=0/30)でも
     見た目の段数によらず常に同じ高さになるようにする(内容に依存させない) */
  grid-auto-rows: 66px;
  gap: 8px;
  /* iPhoneは画面物理形状自体が角丸になっており、env(safe-area-inset-*)では
     考慮されない。左下の「6」など画面の角に一番近いボタンが角の丸みに
     少しかかって見切れて見えるため、下側に余分な余白を足して避ける */
  padding-bottom: 20px;
}
.num-btn {
  font-size: 1.5rem;
  padding: 12px 0;
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
}
.num-btn:nth-child(odd) { background: #fff1de; }
/* ボタン数が少ない段階でもグリッドの段数(高さ)を保つための見えない埋め要素。
   .num-btnと同じ箱の大きさを保ちつつ、見た目・操作を完全に消す */
.num-btn-filler {
  visibility: hidden;
  pointer-events: none;
}

/* ---------- 結果 ---------- */
#screen-result {
  justify-content: center;
  gap: 24px;
  text-align: center;
}
.result-title {
  font-size: 2.2rem;
}
.result-card {
  padding: 28px 20px;
  cursor: default;
  border-radius: 30px;
}
.result-time {
  font-size: 3.6rem;
  line-height: 1.1;
}
.newbest {
  margin-top: 8px;
  display: inline-block;
  font-size: 1.2rem;
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 4px 18px;
  transform: rotate(-2deg);
  animation: bob 1.6s ease-in-out infinite;
}
.result-detail {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: 28px;
}
.result-detail div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result-detail dt {
  font-size: 0.9rem;
  opacity: 0.7;
}
.result-detail dd {
  font-size: 1.3rem;
}
.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.big-btn {
  font-size: 1.5rem;
  padding: 16px 44px;
  border-radius: 999px;
  background: var(--sun);
}
/* 取り消しにくい操作のボタン。.big-btn の背景色を上書きするため後ろに置く */
.btn-danger {
  background: var(--maru);
  color: var(--white);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

/* ---------- きろく ---------- */
#screen-records {
  padding-top: 24px;
  gap: 18px;
  overflow-y: auto;
}
.records-title {
  text-align: center;
  font-size: 1.8rem;
}
#records-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.records-block {
  padding: 16px 18px;
  cursor: default;
}
.records-add10,
.records-add10blank { background: var(--add-soft); }
.records-sub10,
.records-sub10blank { background: var(--sub-soft); }
.records-clock30,
.records-clock5 { background: var(--sun-soft); }
.records-block h3 {
  font-size: 1.3rem;
}
.records-best {
  font-size: 1.05rem;
  margin: 4px 0 10px;
}
.records-history {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.records-history li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 0.95rem;
  font-weight: 700;
}
.rec-time { margin-left: auto; }
.rec-miss { opacity: 0.7; font-size: 0.85rem; }
.rec-empty { justify-content: center; opacity: 0.6; }
#screen-records .link-btn { margin: 4px auto 20px; flex-shrink: 0; }

/* ---------- グラフ ---------- */
#screen-graph {
  padding-top: 24px;
  gap: 18px;
  align-items: center;
}
.graph-title {
  text-align: center;
  font-size: 1.8rem;
}
.graph-card {
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: default;
}
.graph-legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}
.graph-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}
.graph-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: inline-block;
}
.graph-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}
#graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.graph-tooltip {
  position: absolute;
  transform: translate(-50%, -130%);
  background: var(--ink);
  color: var(--white);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  pointer-events: none;
  white-space: nowrap;
}
.graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
}
#screen-graph .link-btn { margin: 4px auto 20px; flex-shrink: 0; }

/* ---------- アニメーション弱者への配慮 ---------- */
@media (prefers-reduced-motion: reduce) {
  .title span,
  .newbest {
    animation: none;
  }
}
