/* style.css … iPhone・iPad を優先したスマホ向けのレイアウト */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1f2330;
  --muted: #667085;
  --border: #dde1ea;
  --primary: #2f6fed;
  --primary-text: #ffffff;
  --a-bubble: #eef2ff;
  --b-bubble: #e8f7ee;
  --ok: #1a7f37;
  --ok-bg: #e3f5e8;
  --sub: #b45309;
  --sub-bg: #fff1dc;
  --ng: #c62828;
  --ng-bg: #fde8e8;
  --warn-bg: #fff7e0;
  --info-bg: #e8f1ff;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1e2129;
    --text: #e8eaf0;
    --muted: #9aa3b5;
    --border: #333845;
    --primary: #5b8dff;
    --a-bubble: #252c45;
    --b-bubble: #1f3a2b;
    --ok: #5fd07e;
    --ok-bg: #1d3526;
    --sub: #f5a524;
    --sub-bg: #3a2c14;
    --ng: #ff7a7a;
    --ng-bg: #3d1f22;
    --warn-bg: #3a3218;
    --info-bg: #1c2a44;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 16px;
  padding: 6px 4px;
  min-width: 64px;
  cursor: pointer;
}
#back { text-align: left; }
#settings-btn { text-align: right; margin-left: auto; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

/* ---------- 部品 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-large { width: 100%; min-height: 56px; font-size: 18px; margin: 16px 0 8px; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); font-weight: 600; }
.btn-ng { background: var(--ng-bg); color: var(--ng); border-color: var(--ng); font-weight: 600; }

.row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; align-items: center; }
.row .btn { flex: 1 1 auto; }

.note { color: var(--muted); font-size: 14px; }
.tag {
  display: inline-block;
  padding: 1px 10px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--info-bg);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}

.notice {
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 15px;
}
.notice-warn { background: var(--warn-bg); }
.notice-info { background: var(--info-bg); }
.notice .btn { margin-top: 8px; display: flex; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 12px 0;
}
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.panel summary { cursor: pointer; font-weight: 600; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.choice input { width: 20px; height: 20px; flex-shrink: 0; }
.choice-block { align-items: flex-start; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--border); }
.choice-block:last-child { border-bottom: 0; }
.choice-block input { margin-top: 4px; }
.choice-block .note { flex-basis: 100%; padding-left: 28px; }
.choice.disabled { opacity: 0.5; }

.select { width: 100%; min-height: 44px; font-size: 16px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); margin-bottom: 8px; }

/* ---------- ホーム ---------- */
.tabs { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; margin-bottom: 12px; }
.tab { flex: 1; border: 0; background: none; padding: 10px; border-radius: 999px; font-size: 16px; font-family: inherit; color: var(--text); cursor: pointer; }
.tab.active { background: var(--primary); color: var(--primary-text); font-weight: 600; }
.section-note { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.grade-head { font-size: 15px; color: var(--muted); margin: 18px 0 6px; }

.card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.card:active { transform: scale(0.99); }
.card-title { font-size: 18px; font-weight: 700; }
.card-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card-score { font-size: 14px; margin-top: 6px; }
.trademark { color: var(--muted); font-size: 12px; margin-top: 24px; }

.detail-head { color: var(--muted); margin-bottom: 4px; }

/* ---------- 練習画面 ---------- */
.practice-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.progress { margin-left: auto; font-variant-numeric: tabular-nums; }
.toggles { display: flex; gap: 16px; margin-bottom: 8px; }

.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--a-bubble);
  border: 2px solid transparent;
  cursor: default;
}
.bubble.role-b { align-self: flex-end; background: var(--b-bubble); }
.bubble.current { border-color: var(--primary); }
.bubble .who { font-size: 12px; color: var(--muted); }
.bubble .en { font-size: 18px; }
.bubble .ja { font-size: 14px; color: var(--muted); }
.chat.hide-en .en { display: none; }
.chat.hide-ja .ja { display: none; }
.hint-text { letter-spacing: 0.04em; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.95em; }
.hidden-text { color: var(--muted); font-size: 14px; }

.controls { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.status { text-align: center; color: var(--muted); margin: 4px 0; }

/* マイク */
.mic-panel { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 8px 0; }
.mic-btn {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.mic-btn:disabled { opacity: 0.6; }
.mic-btn.listening { background: var(--ng); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.45); } 50% { box-shadow: 0 0 0 10px rgba(198, 40, 40, 0); } }
.mic-icon { font-size: 22px; }
.mic-status { font-size: 14px; color: var(--muted); text-align: center; }
.mic-live { font-size: 16px; min-height: 1.4em; text-align: center; }
.self-check { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; }
.self-check .note { flex-basis: 100%; text-align: center; margin: 0; }
.self-check .btn { flex: 1; }

/* 判定結果 */
.score-result { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: 14px; }
.badge-great { background: var(--ok-bg); color: var(--ok); }
.badge-good { background: var(--sub-bg); color: var(--sub); }
.badge-retry { background: var(--ng-bg); color: var(--ng); }
.heard { font-size: 14px; color: var(--muted); margin: 4px 0; }
.aligned { font-size: 17px; line-height: 2; }
.missed { font-size: 14px; color: var(--ng); }

.w { display: inline-block; padding: 0 4px; border-radius: 6px; margin: 1px 0; line-height: 1.5; }
.w small { display: block; font-size: 11px; line-height: 1.1; opacity: 0.85; }
.w-ok { background: var(--ok-bg); color: var(--ok); }
.w-sub { background: var(--sub-bg); color: var(--sub); text-align: center; }
.w-miss { background: var(--ng-bg); color: var(--ng); text-decoration: line-through; }
.w-extra { color: var(--muted); font-style: italic; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; margin: 8px 0; align-items: flex-end; }

/* 結果画面 */
.result-summary { text-align: center; margin: 8px 0 16px; }
.big-score { font-size: 56px; font-weight: 800; line-height: 1.1; }
.big-score small { font-size: 24px; }
.big-score.small { font-size: 32px; }
.result-list { list-style: none; padding: 0; margin: 0; }
.result-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.result-top { margin-bottom: 4px; }
.result-row .ja { font-size: 14px; color: var(--muted); }

/* ---------- 面接 ---------- */
.exam-card { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.card-panel .exam-card { border: 0; padding: 8px 0 0; margin: 0; }
.exam-card-title { text-align: center; font-weight: 700; font-size: 18px; margin-bottom: 6px; }
.passage { font-size: 18px; line-height: 1.8; margin: 0 0 10px; }
.card-image { display: block; width: 100%; height: auto; border-radius: 10px; background: #fff; border: 1px solid var(--border); }
.narr-start { font-size: 15px; margin: 10px 0 0; }
.card-down { text-align: center; padding: 16px; }

.question { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.q-label { font-weight: 700; font-size: 18px; }
.q-intro { font-style: italic; margin: 6px 0 0; }
.q-en { font-size: 18px; margin: 6px 0; }
.question .ja, .result-row p.ja { color: var(--muted); font-size: 14px; margin: 0; }
.tip { background: var(--info-bg); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin-top: 8px; }
.model-box { border-top: 1px dashed var(--border); margin-top: 10px; padding-top: 10px; }
.model-tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.model-text { font-size: 18px; margin: 6px 0; }

.answer { background: var(--bg); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.answer-head, .models-head { font-size: 13px; color: var(--muted); font-weight: 700; }
.answer p { margin: 2px 0; }
.checks { list-style: none; padding: 0; margin: 8px 0; }
.checks li { padding: 6px 0 6px 28px; position: relative; border-bottom: 1px solid var(--border); font-size: 15px; }
.checks li:last-child { border-bottom: 0; }
.checks .mark { position: absolute; left: 4px; top: 6px; font-weight: 800; }
.checks .ok .mark { color: var(--ok); }
.checks .ng .mark { color: var(--sub); }
.checks .detail { font-size: 13px; color: var(--muted); }
.disclaimer { font-size: 12px; }
.models { margin: 8px 0; }
.model { padding: 6px 0; border-bottom: 1px solid var(--border); }
.models-wrap summary { cursor: pointer; color: var(--primary); margin: 6px 0; }
.evals { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.eval-btn { min-width: 56px; font-size: 20px; }
.eval-mark { font-size: 20px; font-weight: 700; }
.q-list { margin: 8px 0 0; padding-left: 20px; }

.examiner { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.examiner-icon { font-size: 34px; }
.examiner-say { color: var(--muted); font-size: 15px; }

.timer { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 10px 0; }
.timer-label { color: var(--muted); font-size: 14px; }
.timer-num { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.timer-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin: 6px 0 10px; }
.timer-bar div { height: 100%; width: 0; background: var(--primary); transition: width 1s linear; }
.rate-row span { color: var(--muted); font-size: 14px; }

/* ---------- 設定 ---------- */
.settings section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.settings h2 { font-size: 16px; margin: 0 0 8px; }

/* ---------- ダイアログ ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal { background: var(--surface); color: var(--text); border-radius: var(--radius); padding: 18px; max-width: 520px; width: 100%; max-height: 85vh; overflow: auto; }
.modal h2 { font-size: 18px; margin: 0 0 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.modal-actions .btn { flex: 1; }
.steps { padding-left: 20px; font-size: 15px; }
.steps li { margin-bottom: 6px; }
.voice-help { margin-top: 8px; font-size: 15px; }
.voice-help summary { cursor: pointer; color: var(--primary); }
