/* =========================================================================
   電話応対練習システム 共通スタイル
   ・スマホ（幅360px〜）で使うことを第一に考えたレイアウト
   ・色は :root の変数にまとめているので、ここを変えれば全体の色が変わる
   ========================================================================= */

:root {
  --bg: #f4f5f7;          /* ページの背景 */
  --surface: #ffffff;     /* カードの背景 */
  --text: #1d2433;        /* 本文 */
  --muted: #5d6677;       /* 補足の文字 */
  --line: #dfe3ea;        /* 罫線 */
  --primary: #1f5f8b;     /* メインの色（ボタン・リンク） */
  --primary-weak: #e5f0f7;
  --good: #1e8e5a;        /* 正解・応答ボタン */
  --good-weak: #e3f4ec;
  --warn: #b7791f;        /* 部分点 */
  --warn-weak: #fbf1df;
  --bad: #c0392b;         /* 不足・終話ボタン */
  --bad-weak: #fbe6e3;
  --radius: 12px;
  --call-bg1: #14202e;    /* 通話画面の背景（上） */
  --call-bg2: #0b1119;    /* 通話画面の背景（下） */
  font-size: 16px;
}

* { box-sizing: border-box; }
/* hidden 属性を付けた要素は、display を指定したクラスが付いていても隠す */
[hidden] { display: none !important; }

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;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); }

/* ---- ヘッダー ---- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.site-header .inner {
  max-width: 960px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); margin-right: auto; }
.nav { display: flex; gap: 14px; align-items: center; font-size: .92rem; flex-wrap: wrap; }
.nav a { text-decoration: none; }
.nav form { margin: 0; }
.linklike { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }

/* ---- ページ本体 ---- */
.container { max-width: 960px; margin: 0 auto; padding: 20px 16px 60px; }
.narrow { max-width: 480px; }
h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
.lead { color: var(--muted); margin-top: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}

/* ---- メッセージ（登録完了など） ---- */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 8px; background: var(--good-weak); color: var(--good); }
.messages li.error { background: var(--bad-weak); color: var(--bad); }

/* ---- ボタン ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; min-height: 44px; /* 指で押しやすい高さ */
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn.block { display: flex; width: 100%; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: .9rem; }

/* ---- フォーム ---- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
input[type=text], input[type=password], input[type=search], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
.helptext, .form-row .help { color: var(--muted); font-size: .85rem; }
.errorlist { color: var(--bad); list-style: none; padding: 0; margin: 4px 0 0; font-size: .9rem; }

/* ---- シナリオ一覧 ---- */
.scenario-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.scenario-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.scenario-card:hover { border-color: var(--primary); }
.scenario-card .no { font-size: .8rem; color: var(--primary); font-weight: 700; }
.scenario-card .title { font-weight: 700; font-size: 1.05rem; }
.scenario-card .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; }
.stars { color: #d69e2e; letter-spacing: 1px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .8rem; background: var(--primary-weak); color: var(--primary); }
.badge.good { background: var(--good-weak); color: var(--good); }
.badge.oni { background: var(--bad-weak); color: var(--bad); font-weight: 700; }

/* 鬼モード */
.oni-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-color: var(--bad); }
.btn.oni { background: var(--bad); border-color: var(--bad); color: #fff; white-space: nowrap; }
.oni-note { color: #fca5a5; font-size: .9rem; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }

/* ---- 表 ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8f9fb; white-space: nowrap; font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-items: end; }
.pager { display: flex; gap: 12px; justify-content: center; margin: 16px 0; }

/* =========================================================================
   採点結果
   ========================================================================= */
.score-hero { text-align: center; padding: 24px 16px; }
.score-hero .total { font-size: 3rem; font-weight: 800; line-height: 1; }
.score-hero .total small { font-size: 1.1rem; color: var(--muted); font-weight: 600; }
.score-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.score-item:last-child { border-bottom: 0; }
.score-item .head { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.bar { height: 8px; background: #edf0f4; border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar > span { display: block; height: 100%; background: var(--good); }
.bar.mid > span { background: var(--warn); }
.bar.low > span { background: var(--bad); }
.score-item .comment { font-size: .92rem; color: var(--text); margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: .78rem; padding: 1px 8px; border-radius: 99px; }
.chip.ok { background: var(--good-weak); color: var(--good); }
.chip.ng { background: var(--bad-weak); color: var(--bad); }
.chip.part { background: var(--warn-weak); color: var(--warn); }
.chip.measure { background: var(--primary-weak); color: var(--primary); }

.compare { display: grid; gap: 6px; }
.compare .line { padding: 8px 12px; border-radius: 10px; font-size: .95rem; }
.compare .caller { background: #eef1f5; }
.compare .mine { background: var(--primary-weak); }
.compare .model { background: var(--good-weak); }
.compare .who { display: block; font-size: .75rem; color: var(--muted); font-weight: 700; }
.point-box { background: var(--warn-weak); border-left: 4px solid var(--warn); padding: 12px 14px; border-radius: 8px; }

/* =========================================================================
   通話画面（電話アプリ風）
   ========================================================================= */
.call-page { background: linear-gradient(var(--call-bg1), var(--call-bg2)); min-height: 100vh; color: #f1f5f9; }
.call-page .site-header { display: none; } /* 通話中はヘッダーを隠して全画面に */
.call-wrap { max-width: 480px; margin: 0 auto; padding: 16px 16px 120px; min-height: 100vh; display: flex; flex-direction: column; }

.phase { display: none; }
.phase.active { display: flex; flex-direction: column; flex: 1; }

/* 練習前の説明 */
.briefing { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); padding: 16px; }
.briefing h1 { color: #fff; }
.briefing p { color: #cbd5e1; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid rgba(255,255,255,.1); }
.toggle span small { display: block; color: #94a3b8; font-size: .8rem; }
.toggle input { width: 22px; height: 22px; accent-color: var(--good); }
.back-link { color: #94a3b8; font-size: .9rem; margin-top: 12px; display: inline-block; }

/* 着信・通話中の相手表示 */
.caller-info { text-align: center; margin-top: 28px; }
.avatar {
  width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 12px; background: #334155;
  display: grid; place-items: center; font-size: 2.4rem;
}
.avatar.speaking { box-shadow: 0 0 0 6px rgba(59,130,246,.35); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(59,130,246,.12); } }
.caller-name { font-size: 1.4rem; font-weight: 700; }
.caller-sub { color: #94a3b8; font-size: .95rem; }
.ringing .caller-sub::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.answer-row { margin-top: auto; display: flex; justify-content: space-around; padding: 40px 0 20px; }
.round-btn {
  width: 72px; height: 72px; border-radius: 50%; border: 0; color: #fff; font-size: 1.8rem; cursor: pointer;
  display: grid; place-items: center;
}
.round-btn.accept { background: #22c55e; animation: bounce 1s infinite; }
.round-btn.decline, .round-btn.hangup { background: #ef4444; }
@keyframes bounce { 50% { transform: translateY(-6px); } }
.round-label { text-align: center; font-size: .85rem; color: #cbd5e1; margin-top: 6px; }

/* 通話中の状態表示 */
.status-pill {
  margin: 14px auto 0; padding: 6px 14px; border-radius: 99px; background: rgba(255,255,255,.1);
  font-size: .9rem; text-align: center; max-width: 100%;
}
.status-pill.listening { background: rgba(34,197,94,.2); color: #bbf7d0; }
.status-pill.busy { background: rgba(234,179,8,.2); color: #fde68a; }
.level { height: 6px; background: rgba(255,255,255,.12); border-radius: 99px; overflow: hidden; margin: 10px 20px 0; }
.level > span { display: block; height: 100%; width: 0; background: #22c55e; transition: width .08s; }

/* 会話ログ（吹き出し） */
.log { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 14px; font-size: .95rem; line-height: 1.6; }
.bubble.caller { background: #273449; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.student { background: #1f5f8b; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.student.empty { background: #7f1d1d; }
.bubble.interim { opacity: .7; font-style: italic; }
.bubble small { display: block; color: #94a3b8; font-size: .72rem; }

.hint-box {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(250,204,21,.12);
  border: 1px solid rgba(250,204,21,.3); color: #fef3c7; font-size: .9rem;
}
.hint-box .model { display: block; margin-top: 4px; color: #fff; }

/* 通話中の操作ボタン（画面下に固定） */
.call-controls {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(11,17,25,.92); backdrop-filter: blur(6px); border-top: 1px solid rgba(255,255,255,.08);
}
.call-controls .inner { max-width: 480px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ctrl {
  display: flex; flex-direction: column; align-items: center; gap: 2px; background: rgba(255,255,255,.08);
  border: 0; border-radius: 12px; color: #e2e8f0; padding: 8px 4px; font: inherit; font-size: .75rem; cursor: pointer; min-height: 56px;
}
.ctrl .ico { font-size: 1.3rem; line-height: 1; }
.ctrl:disabled { opacity: .35; cursor: default; }
.ctrl.primary { background: #22c55e; color: #052e16; font-weight: 700; }
.ctrl.danger { background: #ef4444; color: #fff; }

.toast {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; max-width: 92%;
  background: #fef3c7; color: #78350f; padding: 10px 14px; border-radius: 10px; font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.3); display: none;
}
.toast.show { display: block; }

.loading { text-align: center; padding: 40px 0; color: #cbd5e1; }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%; margin: 0 auto 12px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 履歴のグラフ */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart .lbl { fill: var(--muted); font-size: 10px; }
.chart .ln { fill: none; stroke: var(--primary); stroke-width: 2; }
.chart .pt { fill: var(--primary); }

/* 学生×パターン表 */
.cell-best { font-weight: 700; }
.cell-count { color: var(--muted); font-size: .78rem; }
.cell-full { background: var(--good-weak); }
.cell-none { color: #b8c0cc; }

@media (max-width: 480px) {
  h1 { font-size: 1.25rem; }
  .score-hero .total { font-size: 2.6rem; }
}
