﻿:root {
  --navy: #0f3057;
  --blue: #1d6fa5;
  --accent: #ff9f1c;
  --green: #2a9d8f;
  --red: #e63946;
  --bg: #f4f7fa;
  --card: #ffffff;
  --text: #1c2b36;
  --muted: #6b7c8c;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  display: flex;
  flex-direction: column;
}

.app-header {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff;
  padding: 20px 20px 16px;
  padding-top: calc(20px + env(safe-area-inset-top, 0));
}
.app-header h1 { margin: 0; font-size: 20px; }
.app-sub { margin: 4px 0 0; font-size: 12px; opacity: 0.85; }

.screen { display: none; padding: 16px; flex: 1; flex-direction: column; }
.screen.active { display: flex; }

.lead { font-size: 14px; color: var(--muted); margin: 4px 0 16px; }

/* 夢・目標バナー（ホーム最上部・壁に貼る夢のように大きく表示） */
.goal-banner {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff; border-radius: 14px; padding: 16px 18px; margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(15, 48, 87, 0.2);
}
.goal-banner.goal-empty { padding: 8px; }
.goal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.goal-kicker { font-size: 11px; font-weight: bold; letter-spacing: 0.04em; opacity: 0.9; }
.goal-text {
  font-size: 18px; font-weight: bold; line-height: 1.4; word-break: break-word;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
.goal-edit-btn {
  background: rgba(255, 255, 255, 0.22); border: none; color: #fff;
  border-radius: 8px; width: 30px; height: 30px; font-size: 14px; cursor: pointer; flex-shrink: 0;
}
.goal-edit-btn:active { background: rgba(255, 255, 255, 0.35); }
.goal-set-btn {
  width: 100%; background: transparent; border: 1.5px dashed rgba(255, 255, 255, 0.65);
  color: #fff; border-radius: 10px; padding: 12px; font-size: 14px; font-weight: bold; cursor: pointer;
}
.goal-banner.editing .goal-kicker { margin-bottom: 8px; }
#goalInput {
  width: 100%; box-sizing: border-box; border: none; border-radius: 8px;
  padding: 11px 12px; font-size: 15px; color: var(--navy); margin-bottom: 8px;
}
.goal-edit-actions { display: flex; gap: 8px; }
.btn-goal-save, .btn-goal-cancel {
  flex: 1; border: none; border-radius: 8px; padding: 10px; font-size: 13px; font-weight: bold; cursor: pointer;
}
.btn-goal-save { background: #fff; color: var(--navy); }
.btn-goal-cancel { background: rgba(255, 255, 255, 0.22); color: #fff; }

.level-toggle {
  display: flex;
  background: #e8eef3;
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 16px;
}
.level-btn {
  flex: 1;
  border: none;
  background: transparent;
  /* 指で押す部品は高さ44pxを確保する。文字サイズは変えず上下の余白だけで稼ぐ。 */
  padding: 12.5px 8px;
  font-size: 13px;
  font-weight: bold;
  color: var(--muted);
  border-radius: 999px;
  cursor: pointer;
}
.level-btn.active { background: var(--navy); color: #fff; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 16px; flex-wrap: wrap;
}
.setting-label { font-size: 13px; font-weight: bold; color: var(--navy); white-space: nowrap; }
.seg-toggle { display: flex; background: #e8eef3; border-radius: 999px; padding: 4px; gap: 2px; }
.seg-btn {
  border: none; background: transparent; padding: 7px 12px;
  font-size: 12px; font-weight: bold; color: var(--muted);
  border-radius: 999px; cursor: pointer; line-height: 1.15;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.seg-btn.active { background: var(--navy); color: #fff; }
.seg-hint { font-size: 9px; font-weight: normal; opacity: 0.85; }

.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.subject-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  border: none;
  box-shadow: 0 2px 8px rgba(15,48,87,0.08);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.subject-card .subject-name { font-size: 16px; font-weight: bold; }
.subject-card .subject-stat { font-size: 12px; color: var(--muted); }
.subject-card .subject-dot {
  width: 10px; height: 10px; border-radius: 50%;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}
/* 縦積みボタンの間隔は、色ではなく「横幅いっぱいに置く」という役割の側で決める。
   以前は .btn-mock / .btn-secondary など色ごとに margin-bottom を書いていたため、
   指定の無い .btn-primary の下だけ隙間が消えて並びが崩れていた。
   ここに集約したので、今後どの色のボタンを追加しても間隔は揃う。 */
.btn-block { width: 100%; margin-bottom: 10px; }
.btn-block:last-child { margin-bottom: 0; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #e8eef3; color: var(--navy); }
.btn-primary:disabled { background: #cfd8e0; color: #8fa0ac; }
.btn-mock { background: var(--navy); color: #fff; }
.btn-trial { background: var(--accent); color: #3a2600; font-weight: bold; }
.btn-analysis { background: var(--green); color: #fff; font-weight: bold; }

/* 自己分析画面 */
.analysis-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.analysis-head h2 { font-size: 18px; color: var(--navy); margin: 0; }
.analysis-target { background: var(--card); border: 1px solid #e2e8ee; border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.analysis-target-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.analysis-target-val { font-size: 22px; font-weight: 800; color: var(--navy); }
/* 目標スライダー。ブラウザ標準のままだと高さ16pxで、スマホの指では掴みにくく、
   アプリ内で唯一スタイルの当たっていない部品になっていた。
   見えるバーは細いまま、当たり判定だけを44pxに広げてつまみを大きくする。 */
.analysis-target input[type="range"] {
  width: 100%;
  height: 44px;              /* 指で掴める高さ。バー自体は下で細く描く */
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
.analysis-target input[type="range"]:focus { outline: none; }

.analysis-target input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: #e2e8ee;
}
.analysis-target input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--blue); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(15, 48, 87, .3);
  margin-top: -9px;          /* 6pxのバーの中心につまみを合わせる */
}
.analysis-target input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 3px; background: #e2e8ee;
}
.analysis-target input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--blue); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(15, 48, 87, .3);
}
.analysis-note { font-size: 11px; color: var(--muted); line-height: 1.6; margin-top: 8px; }

.an-card { background: var(--card); border: 1px solid #e2e8ee; border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.an-card-title { font-size: 13px; font-weight: bold; color: var(--navy); margin-bottom: 8px; }
.an-empty { font-size: 13px; color: var(--muted); line-height: 1.6; }
.an-big { font-size: 40px; font-weight: 800; line-height: 1.1; }
.an-big.ok { color: var(--green); }
.an-big.ng { color: var(--navy); }
.an-unit { font-size: 15px; font-weight: bold; color: var(--muted); margin-left: 2px; }
.an-sub { font-size: 12.5px; color: var(--text); line-height: 1.6; margin-top: 4px; }
.an-sub .ok { color: var(--green); }
.an-sub .ng { color: var(--red); }
.an-total { font-size: 11px; color: var(--muted); margin-top: 6px; }

.an-bar-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.an-bar-label { width: 40px; font-size: 12px; color: var(--navy); font-weight: bold; }
.an-bar { position: relative; flex: 1; height: 14px; background: #eef2f6; border-radius: 7px; overflow: hidden; }
.an-bar-fill { display: block; height: 100%; border-radius: 7px; }
.an-bar-fill.ok { background: var(--green); }
.an-bar-fill.ng { background: var(--blue); }
.an-bar-target { position: absolute; top: -2px; width: 2px; height: 18px; background: var(--red); }
.an-bar-pct { width: 40px; text-align: right; font-size: 12px; font-weight: bold; color: var(--navy); }
.an-legend { font-size: 10.5px; color: var(--muted); margin-top: 8px; }

.an-rank-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid #f0f3f6; }
.an-rank-row:last-child { border-bottom: none; }
.an-rank-no { width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 12px; font-weight: bold; display: flex; align-items: center; justify-content: center; }
.an-rank-name { flex: 1; font-size: 14px; color: var(--navy); }
.an-rank-rate { font-size: 15px; font-weight: bold; }
.an-rank-rate.ok { color: var(--green); }
.an-rank-rate.ng { color: var(--red); }

.an-two { display: flex; gap: 24px; }
.an-k { font-size: 11px; color: var(--muted); }
.an-v { font-size: 24px; font-weight: 800; color: var(--navy); }
.an-v.ok { color: var(--green); }
.an-v.ng { color: var(--red); }

/* ヒーロー（総合達成度） */
.an-hero { display: flex; align-items: center; gap: 16px; background: linear-gradient(135deg, var(--navy), var(--blue)); color: #fff; border-radius: 14px; padding: 18px; margin-bottom: 12px; }
.an-hero-num { font-size: 46px; font-weight: 800; line-height: 1; }
.an-hero-num .an-unit { font-size: 16px; color: rgba(255,255,255,.85); }
.an-hero-num.ok { color: #a8f0c9; }
.an-hero-sub { font-size: 13px; line-height: 1.7; }
.an-hero-sub .ok { color: #a8f0c9; }
.an-hero-sub .ng { color: #ffd7a8; }
.an-hero-sub .an-total { color: rgba(255,255,255,.8); font-size: 11.5px; }

/* ミニタイル */
.an-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.an-tile { background: var(--card); border: 1px solid #e2e8ee; border-radius: 12px; padding: 12px; }
.an-tile-k { font-size: 11px; color: var(--muted); }
.an-tile-v { font-size: 26px; font-weight: 800; color: var(--navy); line-height: 1.15; }
.an-tile-v.ok { color: var(--green); }
.an-tile-v.ng {
  /* 赤は「失敗・エラー」に見えてしまう。ここは目安より遅いという注意なので、
     一段やわらかいオレンジにする。同じ画面の「達成！」の緑とも競合しない。 */
  color: var(--accent);
}
.an-tile-unit { font-size: 13px; font-weight: bold; color: var(--muted); margin-left: 1px; }
.an-tile-s { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.btn-link { display: block; text-align: center; text-decoration: none; box-sizing: border-box; margin-bottom: 10px; }

.note { font-size: 11px; color: var(--muted); margin-top: auto; padding-top: 16px; line-height: 1.6; }
.version-note { font-size: 11px; color: var(--muted); text-align: center; margin: 8px 0 4px; }
.version-note.expired { color: var(--red); font-weight: bold; }

/* ホーム下部：日替わりのひとこと */
.daily-tip {
  margin: 14px 0 4px;
  padding: 12px 14px;
  background: #eef4f9;
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--navy);
  font-weight: 600;
}

/* 利用期間の更新ボタン（更新用パスコードの入力） */
.btn-renew {
  display: block;
  width: 100%;
  margin: 6px 0 4px;
  padding: 10px;
  background: transparent;
  color: var(--blue);
  border: 1px dashed #b9c8d4;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: bold;
  cursor: pointer;
}
.btn-renew:active { background: #eef4f9; }

/* 解除モーダルの価格表示（更新ボタンを押すと目立つように出す） */
.unlock-price {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 12px;
  padding: 12px;
  background: linear-gradient(135deg, var(--navy), var(--blue));
  border-radius: 12px;
  color: #fff;
}
.unlock-price-label { font-size: 13px; font-weight: bold; opacity: .95; }
.unlock-price-amt { font-size: 26px; font-weight: 800; letter-spacing: .5px; }

/* クイズ画面 */
.quiz-top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
.btn-icon {
  background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; padding: 4px 8px;
}
.btn-quit {
  background: #fdeaec; border: 1.5px solid #f0a9b0; border-radius: 999px;
  font-size: 13px; font-weight: bold; color: #c0392b;
  cursor: pointer; padding: 11.5px 16px; white-space: nowrap; flex-shrink: 0;  /* 高さ44pxを確保 */
}
.btn-quit:active { background: #f8d0d5; }
.progress-bar { flex: 1; height: 8px; background: #e2e8ee; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--blue); width: 0%; transition: width 0.25s ease; }
.quiz-counter { font-size: 12px; color: var(--muted); white-space: nowrap; }
.quiz-timer { font-size: 13px; color: var(--navy); font-weight: bold; white-space: nowrap; min-width: 58px; text-align: right; }
.quiz-timer.timer-warning { color: var(--red); }

.quiz-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(15,48,87,0.08);
  flex: 1;
}
.question-subject {
  display: inline-block;
  font-size: 11px;
  font-weight: bold;
  color: #fff;
  background: var(--blue);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.question-text { font-size: 17px; line-height: 1.6; margin-bottom: 18px; font-weight: 600; }
.question-image {
  display: none;
  max-width: 100%;
  max-height: 45vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border: 1px solid #e2e8ee;
  border-radius: 12px;
  margin: 0 auto 18px;
  pointer-events: none;
}
.question-image.visible { display: block; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  text-align: left;
  background: #f4f7fa;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  line-height: 1.5;
}
.choice-btn.correct { background: #e4f7f2; border-color: var(--green); color: #146c5f; font-weight: bold; }
.choice-btn.wrong { background: #fdeaec; border-color: var(--red); color: #a4232f; font-weight: bold; }
.choice-mark { display: inline-block; margin-right: 8px; font-weight: bold; color: var(--blue); }
.choice-btn.correct .choice-mark { color: #146c5f; }
.choice-btn.wrong .choice-mark { color: #a4232f; }
.choice-btn.disabled { pointer-events: none; opacity: 0.85; }

.explanation {
  margin-top: 16px;
  background: #fff9ec;
  border: 1px solid #f0dca0;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  color: #7a5c14;
  line-height: 1.7;
  display: none;
}
.explanation.visible { display: block; }

.quiz-bottom {
  margin-top: 16px;
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid #e2e8ee;
}

/* 計算メモ（指で書ける自由スペース） */
.btn-scratch {
  position: fixed; right: 14px; bottom: 84px; z-index: 20;
  background: var(--navy); color: #fff; border: none; border-radius: 999px;
  padding: 10px 16px; font-size: 13px; font-weight: bold; cursor: pointer;
  box-shadow: 0 3px 10px rgba(15, 48, 87, 0.3);
}
.btn-scratch:active { background: #0a2540; }
.scratch-drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 480px; margin: 0 auto;
  background: #fff;
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  display: none; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.scratch-drawer.open { display: flex; }
.scratch-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid #e2e8ee;
}
.scratch-title { flex: 1; font-size: 13px; font-weight: bold; color: var(--navy); }
.scratch-btn {
  border: none; background: #eef2f6; color: var(--navy);
  border-radius: 8px; padding: 8px 14px; font-size: 12px; font-weight: bold; cursor: pointer;
}
#scratchCanvas {
  width: 100%; height: 44vh; background: #fff;
  touch-action: none; display: block; cursor: crosshair;
}

/* 結果画面 */
.result-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(15,48,87,0.08);
  margin-bottom: 16px;
}
.result-score { font-size: 40px; font-weight: bold; color: var(--navy); margin: 12px 0 4px; }
.result-time { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.weakpoint-box { text-align: left; margin-top: 16px; }
.weakpoint-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.weakpoint-label { font-size: 12px; font-weight: bold; width: 44px; flex-shrink: 0; }
.weakpoint-bar { flex: 1; height: 10px; background: #e2e8ee; border-radius: 999px; overflow: hidden; }
.weakpoint-bar-fill { display: block; height: 100%; background: var(--blue); border-radius: 999px; }
.weakpoint-bar-fill.weakest { background: var(--red); }
.weakpoint-pct { font-size: 12px; color: var(--muted); width: 36px; text-align: right; flex-shrink: 0; }
.weakpoint-note {
  font-size: 12px; color: #a4232f; background: #fdeaec; border-radius: 10px;
  padding: 10px 12px; margin-top: 4px; margin-bottom: 4px; line-height: 1.6;
}

.result-list { text-align: left; margin-top: 16px; display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.result-item {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f4f7fa;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.result-item.wrong { background: #fdeaec; }
.result-item.unanswered { background: #eef1f4; color: var(--muted); }
.result-item .mark { font-weight: bold; }
.result-item.correct .mark { color: var(--green); }
.result-item.wrong .mark { color: var(--red); }
.result-item.unanswered .mark { color: var(--muted); }

.result-actions { margin-top: auto; }

/* レベルロック表示 */
.level-btn { position: relative; }
.level-lock { margin-left: 4px; font-size: 11px; }

/* 購入・解除モーダル */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 48, 87, 0.55);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.visible { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  max-width: 400px;
  width: 100%;
  position: relative;
  box-shadow: 0 10px 30px rgba(15,48,87,0.25);
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  font-size: 20px; color: var(--muted);
  cursor: pointer;
}
.modal-box h3 { margin: 0 0 8px; font-size: 17px; color: var(--navy); padding-right: 24px; }
.modal-price { font-size: 28px; font-weight: bold; color: var(--accent); margin: 4px 0; }
.modal-desc { font-size: 13px; color: var(--text); line-height: 1.6; margin: 4px 0 12px; }
#quitModal .btn-primary { margin-bottom: 10px; }
.btn-quit-cancel {
  display: block; width: 100%; margin-top: 4px;
  background: none; border: none; color: var(--muted);
  font-size: 14px; font-weight: bold; padding: 10px; cursor: pointer;
}
.btn-quit-cancel:active { color: var(--navy); }
.modal-note { font-size: 12px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }
.unlock-form { display: flex; gap: 8px; }
.unlock-form input {
  flex: 1;
  border: 1px solid #d6dee5;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}
.unlock-form .btn { padding: 10px 16px; font-size: 13px; white-space: nowrap; }
.unlock-error { font-size: 12px; color: var(--red); margin-top: 8px; min-height: 14px; }

/* ===== サンプル問題パネル ===== */
#trialPanel .lead { text-align: center; }
.trial-box {
  background: linear-gradient(180deg, #f4f8fb 0%, #eef3f7 100%);
  border: 1px solid #dce6ee;
  border-radius: 16px;
  padding: 18px 16px 16px;
  margin-top: 8px;
  box-shadow: 0 2px 10px rgba(15, 48, 87, 0.06);
}
.trial-remain {
  text-align: center;
  font-size: 15px;
  color: var(--navy);
  margin-bottom: 14px;
}
.trial-remain strong { font-size: 20px; color: var(--accent); }
.trial-box .btn { margin-bottom: 10px; }
.trial-box .note { margin-top: 6px; }
.trial-done {
  text-align: center; font-size: 14px; font-weight: bold;
  color: var(--navy); line-height: 1.7; margin: 4px 0 14px;
}
#trialEndNudge { margin-bottom: 10px; }

