/* style.css */
/* このファイルでページ全体の見た目を管理します */
/* 色・フォント・余白・角丸を変えたいときは、いちばん上の :root だけを編集してください */

/* =====================
   テーマ変数（ライト）
   ===================== */
:root {
  /* 面と文字 */
  --bg:          #FAFAF7;
  --surface:     #FFFFFF;
  --surface-2:   #F2F2ED;
  --text:        #16181C;
  --text-muted:  #666C75;
  --border:      #E3E3DC;

  /* アクセント（夜空の青） */
  --accent:      #1B4B73;
  --accent-hover:#15395A;
  --accent-ink:  #FFFFFF;

  /* 状態色 */
  --correct:     #14855F;
  --wrong:       #B4462F;

  /* 星図パネル（ライト・ダーク共通の濃色） */
  --sky:         #0B1622;
  --sky-line:    #24384F;
  --sky-text:    #8FA3BD;
  --sky-title:   #F0F4F9;
  --star-0:      #1B2735;
  --star-1:      #C15F4A;
  --star-2:      #3F6089;
  --star-3:      #9FC4E8;
  --star-4:      #F0C674;

  /* かたち */
  --radius:      12px;
  --radius-sm:   8px;
  --radius-lg:   18px;
  --gap:         12px;
  --page-w:      420px;

  /* 文字 */
  --font-base: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP",
               system-ui, -apple-system, "Segoe UI", sans-serif;

  /* うごき */
  --dur-fast: 120ms;
  --dur:      240ms;
  --ease:     cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* =====================
   テーマ変数（ダーク）
   ===================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0F1419;
    --surface:     #161C23;
    --surface-2:   #1E262F;
    --text:        #E8EBEF;
    --text-muted:  #98A1AD;
    --border:      #2A343F;
    --accent:      #7FB3E0;
    --accent-hover:#9AC5EA;
    --accent-ink:  #0B1622;
    --correct:     #4FBF95;
    --wrong:       #E0836B;
  }
}
:root[data-theme="dark"] {
  --bg:          #0F1419;
  --surface:     #161C23;
  --surface-2:   #1E262F;
  --text:        #E8EBEF;
  --text-muted:  #98A1AD;
  --border:      #2A343F;
  --accent:      #7FB3E0;
  --accent-hover:#9AC5EA;
  --accent-ink:  #0B1622;
  --correct:     #4FBF95;
  --wrong:       #E0836B;
}

/* =====================
   リセットと土台
   ===================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

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

body {
  font-family: var(--font-base);
  font-size: 16px;
  line-height: 1.7;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
ul, ol { list-style: none; }
a { color: var(--accent); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* =====================
   共通クラス
   ===================== */
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.is-hidden { display: none !important; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 20;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: var(--radius-sm);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 8px; }

.btn {
  display: block; width: 100%;
  padding: 15px 18px;
  border-radius: var(--radius);
  font-size: 17px; font-weight: 700;
  text-align: center;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn + .btn { margin-top: 8px; }
.btn:active { transform: scale(0.985); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--surface-2); color: var(--text-muted); cursor: default; transform: none; }

.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-quiet { color: var(--text-muted); font-weight: 600; font-size: 15px; padding: 12px; }
.btn-quiet:hover { color: var(--text); }

.btn-hero { padding: 20px; font-size: 20px; margin-top: 20px; }

.btn-text {
  color: var(--text-muted); font-size: 14px; font-weight: 600;
  padding: 6px 10px; border-radius: var(--radius-sm);
}
.btn-text:hover { background: var(--surface-2); color: var(--text); }

.panel {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 12px;
}
.panel h3 { font-size: 14px; color: var(--text-muted); font-weight: 700; margin-bottom: 8px; }

h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.hint { color: var(--text-muted); font-size: 14px; margin-bottom: 12px; }

/* =====================
   ヘッダー
   ===================== */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  max-width: var(--page-w); width: 100%; margin: 0 auto;
  padding: 10px 16px;
}
.appbar-title { font-size: 15px; font-weight: 700; letter-spacing: 0.02em; }
.appbar-actions { display: flex; gap: 6px; }

.icon-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  font-size: 12px; font-weight: 700;
  color: var(--text-muted);
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--text-muted); }
.icon-btn[aria-pressed="false"] { opacity: 0.55; }
.icon-btn-glyph { font-size: 14px; line-height: 1; }

/* =====================
   画面
   ===================== */
main { flex: 1; width: 100%; }

.screen { display: none; }
.screen:not([hidden]) { display: block; }
.screen {
  max-width: var(--page-w); width: 100%; margin: 0 auto;
  padding: 4px 16px 28px;
}

/* =====================
   星図パネル
   ===================== */
.sky {
  background: var(--sky);
  border-radius: var(--radius-lg);
  padding: 18px 16px 14px;
  border: 1px solid var(--sky-line);
}
.sky-progress {
  color: var(--sky-text); font-size: 13px; margin-bottom: 12px;
}
.sky-progress strong { color: var(--sky-title); font-size: 20px; font-weight: 700; }

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  /* JSが81マスを描き終えるまで .board は空で高さ0になり、描画完了の瞬間に
     下の凡例・ボタン類が一気に押し下げられるレイアウトシフト（CLS）が発生していた。
     10列×10行の正方形グリッドなので、幅から高さを先に確定させて防ぐ（Lighthouse実測で確認）。 */
  aspect-ratio: 1;
}
/* 行の div は ARIA の role="row" のために必要だが、レイアウト上は箱を作らせない */
.board-row { display: contents; }

.board-head {
  display: flex; align-items: center; justify-content: center;
  color: var(--sky-text); font-size: 11px; font-weight: 700;
  aspect-ratio: 1;
}
.board-corner { aspect-ratio: 1; }

.cell {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1;
  border-radius: 4px;
  transition: background var(--dur-fast) var(--ease);
}
.cell:hover { background: rgba(255, 255, 255, 0.07); }
.cell[aria-selected="true"] { background: rgba(255, 255, 255, 0.13); }

/* 星本体：レベルごとに色・大きさ・かたちを変える（色だけに頼らない） */
.star {
  display: block;
  background: var(--star-0);
  width: 5px; height: 5px;
  border-radius: 50%;
  transition: width var(--dur) var(--ease), height var(--dur) var(--ease),
              background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.cell[data-lv="1"] .star {
  background: var(--star-1); width: 8px; height: 8px;
  border-radius: 1px; transform: rotate(45deg);
}
.cell[data-lv="2"] .star { background: var(--star-2); width: 8px;  height: 8px; }
.cell[data-lv="3"] .star { background: var(--star-3); width: 10px; height: 10px; }
.cell[data-lv="4"] .star {
  background: var(--star-4); width: 15px; height: 15px;
  border-radius: 0;
  clip-path: polygon(50% 0%, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0% 50%, 40% 40%);
}

/* 星座の線（Lv4どうしが たて・よこで となりあうと つながる） */
/* SVG は既定の 300x150 という固有サイズを持つため、幅・高さを明示して盤面を覆わせる */
.constellation {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.constellation line {
  stroke: var(--star-4);
  stroke-width: 1.5;
  stroke-linecap: round;
  opacity: 0.45;
}

/* レベルが上がったときの演出 */
@keyframes star-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(2.1); }
  100% { transform: scale(1); }
}
@keyframes star-pop-rot {
  0%   { transform: rotate(45deg) scale(1); }
  45%  { transform: rotate(45deg) scale(2.1); }
  100% { transform: rotate(45deg) scale(1); }
}
.cell.is-celebrating .star { animation: star-pop 620ms var(--ease) both; }
.cell.is-celebrating[data-lv="1"] .star { animation-name: star-pop-rot; }

/* 凡例 */
.legend {
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--sky-line);
  min-height: 30px; /* JS描画前後の高さジャンプ（CLS）防止。凡例アイテムの実測高さぶんを先に予約 */
}
.legend li { display: flex; align-items: center; gap: 6px; color: var(--sky-text); font-size: 11px; }
.legend .cell { flex: none; width: 18px; height: 18px; aspect-ratio: auto; }
.legend .cell:hover { background: none; }
.legend .star { flex: none; }

/* マスの詳細 */
.cell-detail {
  min-height: 1.7em;
  margin-top: 12px;
  font-size: 14px; color: var(--text-muted); text-align: center;
}
.cell-detail strong { color: var(--text); font-weight: 700; }

.storage-warning {
  margin-top: 16px; padding: 10px 14px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13px; text-align: center;
}

.install-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 16px; padding: 10px 14px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13px; text-align: left;
}
.install-hint .btn-text { flex: none; padding: 4px 8px; }

/* =====================
   モード選択
   ===================== */
.mode-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.mode-card {
  display: block; width: 100%; text-align: left;
  padding: 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.mode-card:hover { border-color: var(--accent); background: var(--surface-2); }
.mode-name { display: block; font-size: 17px; font-weight: 700; }
.mode-desc { display: block; font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* =====================
   段えらび
   ===================== */
.dan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.dan-btn {
  padding: 14px 4px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700;
  transition: all var(--dur-fast) var(--ease);
}
.dan-btn[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

.switch { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 18px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  flex: none; position: relative; width: 44px; height: 26px; margin-top: 2px;
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: 999px; transition: background var(--dur) var(--ease);
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-muted);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); background: var(--accent-ink); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--accent); outline-offset: 2px; }
.switch-text { font-size: 15px; font-weight: 600; }
.switch-text small { display: block; font-size: 12px; font-weight: 400; color: var(--text-muted); }

/* =====================
   出題
   ===================== */
.quiz-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.quiz-progress { font-size: 13px; font-weight: 700; color: var(--text-muted); }

.quiz-bar { height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.quiz-bar-fill {
  height: 100%; width: 0%;
  background: var(--accent); border-radius: 999px;
  transition: width var(--dur) var(--ease);
}

.question {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: 26px 0 16px;
  font-size: 46px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.question-op, .question-eq { color: var(--text-muted); font-size: 34px; }

.answer {
  display: block;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  text-align: center;
  font-size: 38px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}
.answer.has-value { color: var(--text); }

.verdict {
  min-height: 2em; margin: 8px 0 4px;
  text-align: center; font-size: 18px; font-weight: 700;
}
.verdict.is-correct { color: var(--correct); }
.verdict.is-wrong   { color: var(--wrong); }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.np {
  padding: 16px 4px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.np:hover { background: var(--surface-2); }
.np:active { transform: scale(0.94); }
.np-del { background: var(--surface-2); font-size: 18px; }
.np-enter {
  grid-column: 2 / 4;
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-size: 18px;
}
.np-enter:hover { background: var(--accent-hover); }

/* =====================
   結果
   ===================== */
.score-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px; margin: 12px 0;
  text-align: center;
}
.score-main { font-size: 15px; color: var(--text-muted); }
.score-main strong { font-size: 34px; font-weight: 700; color: var(--text); }

.ratings { display: flex; gap: 10px; margin-top: 14px; }
.rating { flex: 1; }
.rating dt { font-size: 12px; color: var(--text-muted); font-weight: 700; margin-bottom: 2px; }
.rating dd { font-size: 18px; letter-spacing: 0.14em; color: var(--star-4); }
.rating dd .off { color: var(--border); }

.lit-list, .wrong-list { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.lit-list li, .wrong-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
}
.lit-list li:last-child, .wrong-list li:last-child { border-bottom: none; }
.lit-list .lv-name { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.wrong-list .yours { font-size: 13px; color: var(--wrong); }
.wrong-list .right { font-weight: 700; }

/* =====================
   ホーム下部の追加要素（ミッション・バッジ・週の練習日数）
   ===================== */
.home-extra { margin-top: 24px; display: flex; flex-direction: column; gap: 16px; }

.mission-panel h2, .badge-panel h2 {
  font-size: 14px; color: var(--text-muted); font-weight: 700; margin-bottom: 8px;
}

.mission-list { display: flex; flex-direction: column; gap: 6px; }
.mission-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.mission-item.is-done { border-color: var(--correct); }
.mission-check {
  flex: none; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1.5px solid var(--border);
  font-size: 12px; font-weight: 700; color: var(--accent-ink);
}
.mission-item.is-done .mission-check { background: var(--correct); border-color: var(--correct); }
.mission-label { flex: 1; }
.mission-progress {
  flex: none; font-variant-numeric: tabular-nums;
  color: var(--text-muted); font-weight: 700; font-size: 13px;
}

.week-progress { font-size: 14px; color: var(--text-muted); text-align: center; }

.challenge-best-home, .challenge-best-result {
  text-align: center; font-size: 14px; font-weight: 700;
  padding: 10px 14px;
  background: var(--surface-2); border-radius: var(--radius-sm);
}
.challenge-best-result { margin: 12px 0; }

.badge-list { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-chip {
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1.5px solid var(--border);
  font-size: 12px; font-weight: 700; color: var(--text);
}
.badge-chip-new { background: var(--star-4); border-color: var(--star-4); color: var(--sky); }

.new-badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 12px 0; }

.share-status {
  margin-top: 6px; text-align: center; font-size: 13px;
  color: var(--text-muted); word-break: break-all;
}

/* =====================
   にがて特訓の案内
   ===================== */
.weak-guide {
  margin: 14px 0; padding: 16px; text-align: center;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius);
}
.weak-guide p { margin-bottom: 12px; color: var(--text-muted); font-size: 14px; }

/* =====================
   コンボ演出
   ===================== */
.quiz-combo {
  text-align: center; font-size: 16px; font-weight: 700;
  color: var(--star-4); min-height: 1.4em; margin: 4px 0;
}
@keyframes combo-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.quiz-combo.is-pop { animation: combo-pop 260ms var(--ease); }

/* =====================
   せってい
   ===================== */
.settings-group { margin-bottom: 24px; }
.settings-group h3 { font-size: 14px; color: var(--text-muted); font-weight: 700; margin-bottom: 10px; }

.btn-danger { background: var(--wrong); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.settings-confirm {
  margin-top: 10px; padding: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm); border: 1.5px solid var(--wrong);
}
.settings-confirm p { margin-bottom: 10px; font-size: 14px; }

.settings-status { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

/* =====================
   フッター
   ===================== */
.appfoot {
  max-width: var(--page-w); width: 100%; margin: 0 auto;
  padding: 20px 16px 28px;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px; text-align: center;
}
.privacy-note { margin-bottom: 6px; }

/* =====================
   うごきを減らす設定への対応（必須）
   ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* =====================
   広い画面
   ===================== */
@media (min-width: 700px) {
  :root { --page-w: 460px; }
  .question { font-size: 54px; }
}
