/* =========================================================
   TOEIC Studio — スタイル
   余白は 4 の倍数（--s1..--s6）、角丸は --r、パネルは1種類に統一
   ========================================================= */
:root {
  --bg: #0e1014; --panel: #171a21; --sunken: #111318; --border: #262a33; --line: #20242c;
  --text: #e7e9ee; --muted: #8b919e; --accent: #6390ff; --accent-weak: rgba(99,144,255,.14);
  --ok: #3ecf8e; --ok-weak: rgba(62,207,142,.13); --warn: #f2b84b; --bad: #f08a6c; --bad-weak: rgba(240,138,108,.13);
  --shadow: none;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --r: 12px; --r-sm: 8px;
  --top: 56px;          /* 上部バーの高さ */
  --tabbar: 0px;        /* スマホ下部タブの高さ（スマホ時のみ設定） */
  --w: 880px; --w-wide: 1320px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f4f7; --panel: #ffffff; --sunken: #f6f7f9; --border: #e1e4ea; --line: #eceef2;
  --text: #1b1f27; --muted: #6a7180; --accent: #2f64e0; --accent-weak: rgba(47,100,224,.09);
  --ok: #12925c; --ok-weak: rgba(18,146,92,.09); --warn: #b7790a; --bad: #d14b2c; --bad-weak: rgba(209,75,44,.08);
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.04);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", sans-serif;
  transition: background-color .3s, color .3s;
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 var(--s3); letter-spacing: .01em; }
h2 .note { font-weight: 400; margin-left: var(--s1); }
.note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.err { color: var(--bad); font-size: 12px; }
.mt { margin-top: var(--s3); }
mark { background: rgba(242,184,75,.35); color: inherit; border-radius: 2px; }

/* ---------- 上部バー（PC: ロゴ｜タブ｜ユーザー、スマホ: ロゴ｜ユーザー + 下部タブ） ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.tb-inner { height: 100%; max-width: var(--w-wide); margin: 0 auto; padding: 0 var(--s5); display: flex; align-items: center; gap: var(--s4); }
.logo { display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: 15px; white-space: nowrap; }
.logo img { width: 26px; height: 26px; border-radius: 7px; }
.who { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30%; }
.tabs { display: flex; gap: var(--s1); margin: 0 auto; height: 100%; }
.tabs button {
  position: relative; display: flex; align-items: center; gap: 6px; height: 100%;
  padding: 0 var(--s3); background: none; border: 0; color: var(--muted); font-size: 14px; font-weight: 500;
}
.tabs button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--accent); }
.tabs button.on::after { content: ""; position: absolute; left: var(--s3); right: var(--s3); bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tabs button:focus-visible { outline-offset: -4px; }

/* ---------- 本文 ---------- */
main { max-width: var(--w); margin: 0 auto; padding: var(--s5) var(--s5) calc(var(--s6) * 2 + var(--tabbar)); display: flex; flex-direction: column; gap: var(--s4); }
main.wide { max-width: var(--w-wide); }
main > section:not([hidden]) { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: var(--s5); min-width: 0; box-shadow: var(--shadow); }
details.panel > summary { list-style: none; cursor: pointer; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary h2 { margin: 0; display: flex; align-items: center; gap: var(--s2); }
details.panel > summary h2::before { content: "›"; color: var(--muted); font-weight: 400; transition: transform .15s; display: inline-block; }
details.panel[open] > summary h2::before { transform: rotate(90deg); }
details.panel[open] > summary { margin-bottom: var(--s2); }

/* ---------- フォーム部品 ---------- */
select, input {
  background: var(--sunken); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0 var(--s3); height: 40px; font-size: 14px; min-width: 0;
}
select { padding-right: var(--s6); }
input[type="search"], input[type="text"], input[type="password"], input[type="date"], input[type="number"], input:not([type]) { width: 100%; }
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.bar { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.bar input, .bar select { width: auto; flex: 1 1 140px; }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  background: var(--accent); color: #fff; border: 0; border-radius: var(--r-sm);
  height: 44px; padding: 0 var(--s5); font-size: 14px; font-weight: 600; margin-top: var(--s4);
  transition: filter .15s, transform .05s;
}
.primary:hover { filter: brightness(1.07); } .primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .45; cursor: default; filter: none; }
.primary.sm { height: 40px; margin: 0; flex: 0 0 auto; }
.glink, .ubtn {
  background: var(--panel); border: 1px solid var(--border); color: var(--accent); border-radius: var(--r-sm);
  height: 32px; padding: 0 var(--s3); font-size: 12px; font-weight: 500; margin: var(--s2) var(--s2) 0 0;
}
.glink:hover, .ubtn:hover { border-color: var(--accent); }
.ubtn { height: 28px; color: var(--text); margin: 2px; }
.ubtn.danger { color: var(--bad); }
.linkbtn { background: none; border: 0; color: var(--accent); padding: 0; font-size: inherit; }
.seg { display: flex; background: var(--sunken); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg button { flex: 1; height: 34px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 14px; font-weight: 500; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
:root[data-theme="light"] .seg button.on { box-shadow: 0 1px 2px rgba(16,24,40,.12); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.stack label { display: flex; flex-direction: column; gap: 6px; }
.stack .primary { margin-top: var(--s1); }

/* ---------- クイズ ---------- */
.qbar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: var(--s2); align-items: center; margin-bottom: var(--s5); }
.qbar select { width: 100%; }
.qbar .session { grid-column: 1 / -1; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: calc(var(--s1) * -1); }
.qbar .session:empty { display: none; }
.meta { display: flex; gap: var(--s2); align-items: center; font-size: 12px; color: var(--muted); margin-bottom: var(--s3); flex-wrap: wrap; }
.pill { padding: 1px 8px; border-radius: 999px; background: var(--accent-weak); color: var(--accent); font-weight: 500; }
.pill.weak { background: var(--bad-weak); color: var(--bad); }
.pill.new { background: var(--ok-weak); color: var(--ok); }
.lvl { font-variant-numeric: tabular-nums; }
.q { font-size: 17px; line-height: 1.7; margin: 0 0 var(--s4); }
.q.word { font-size: 30px; font-weight: 700; letter-spacing: .01em; margin: var(--s2) 0 var(--s5); }
.choices { display: grid; gap: var(--s2); }
.choice {
  display: flex; align-items: center; gap: var(--s3); text-align: left; min-height: 48px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px var(--s4); font-size: 15px;
  transition: border-color .12s, background-color .12s;
}
.choice b { display: inline-grid; place-items: center; flex: 0 0 24px; height: 24px; border-radius: 6px; background: var(--sunken); color: var(--muted); font-size: 12px; font-weight: 600; }
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:disabled { cursor: default; }
.choice.sel { border-color: var(--accent); background: var(--accent-weak); }
.choice.sel b { background: var(--accent); color: #fff; }
.choice.correct { border-color: var(--ok); background: var(--ok-weak); }
.choice.correct b { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-weak); }
.choice.wrong b { background: var(--bad); color: #fff; }
.result { margin-top: var(--s4); padding: var(--s3) var(--s4); border-radius: var(--r-sm); background: var(--sunken); font-size: 13px; line-height: 1.75; }
.result .head { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.result .head.ok { color: var(--ok); } .result .head.ng { color: var(--bad); }
/* Part6/7 */
.doc { background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-sm); padding: var(--s4); margin-bottom: var(--s3); }
.doc .dl { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: var(--s2); letter-spacing: .06em; text-transform: uppercase; }
.doc .dt { white-space: pre-wrap; font-size: 15px; line-height: 1.8; overflow-wrap: anywhere; }
.doc .blank { background: var(--accent-weak); color: var(--accent); border-radius: 4px; padding: 0 5px; font-weight: 700; }
.rcq { border-top: 1px solid var(--line); padding-top: var(--s4); margin-top: var(--s4); }
.rcq .qt { font-size: 14px; line-height: 1.65; margin-bottom: var(--s2); white-space: pre-wrap; }
.rcq .qt b { color: var(--accent); margin-right: 6px; }
.rcq .choice { min-height: 42px; padding: 8px var(--s3); font-size: 14px; }
.rcq .exp { font-size: 12px; line-height: 1.75; margin-top: var(--s2); }
.rcq .exp:empty { display: none; }
.rcq .exp .ok { color: var(--ok); font-weight: 700; } .rcq .exp .ng { color: var(--bad); font-weight: 700; }

/* ---------- 成績 ---------- */
.esthead { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); }
.big { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.05; margin: var(--s1) 0 var(--s1); letter-spacing: -.01em; }
.big .pm { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.delta { text-align: right; display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta .up { color: var(--ok); font-weight: 700; font-size: 15px; } .delta .down { color: var(--bad); font-weight: 700; font-size: 15px; }
.chart { position: relative; margin-top: var(--s3); }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0,0,0,.15); border-radius: var(--r-sm); padding: 6px 10px; font-size: 12px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -100%); z-index: 2; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s3); }
.chip { background: var(--sunken); border: 1px solid var(--border); border-radius: 999px; height: 28px; padding: 0 var(--s3); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip b { color: var(--muted); font-weight: 500; margin-right: 6px; }
.chip:hover { border-color: var(--accent); }
.howto { margin-top: var(--s3); } .howto summary { cursor: pointer; } .howto ul { margin: 6px 0 0; padding-left: 1.2em; line-height: 1.75; }
.h3 { font-size: 12px; color: var(--muted); font-weight: 500; margin: var(--s4) 0 var(--s2); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.kpi { background: var(--sunken); border-radius: var(--r-sm); padding: var(--s3); }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .l { font-size: 11px; color: var(--muted); }
.row { display: grid; grid-template-columns: 6.5rem 1fr 5rem; gap: var(--s3); align-items: center; margin: 5px 0; font-size: 12px; }
.row.click { cursor: pointer; border-radius: 6px; } .row.click:hover span:first-child { color: var(--accent); }
.track { height: 8px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.track i { display: block; height: 100%; border-radius: 4px; }
.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
ul.weak { margin: 0; padding-left: 1.1em; font-size: 12px; line-height: 1.9; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: var(--s2); border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 500; }
th.n, td.n { text-align: right; font-variant-numeric: tabular-nums; }
.gtbl { overflow-x: auto; margin: var(--s1) 0; }
.mx th { text-align: center; }
.mx td.cell { cursor: pointer; text-align: center; line-height: 1.5; border-radius: 6px; }
.mx td.cell:hover { background: var(--accent-weak); }
.nextrow { display: flex; gap: var(--s3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.nextrow .primary { margin: 0; }
.exam { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.examdays { font-size: 16px; font-weight: 600; }
.examdays span { font-size: 44px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; margin: 0 6px; line-height: 1.05; letter-spacing: -.01em; }
.examsub { font-size: 14px; margin-top: 2px; }
/* 成績の並び: スマホは重要な順に1列、PC は2カラム */
#tab-stats:not([hidden]) { display: flex; flex-direction: column; gap: var(--s4); }
.scol { display: contents; }
.sp-exam { order: 0; } .sp-est { order: 1; } .sp-next { order: 2; } .sp-log { order: 3; } .sp-matrix { order: 4; }
.sp-weakcats { order: 5; } .sp-cats { order: 6; } .sp-review { order: 7; } .sp-scores { order: 8; }

/* ---------- 文法 ---------- */
.glist { display: flex; flex-direction: column; gap: var(--s2); }
.gflowbox { margin-top: var(--s3); } .gflowbox summary { cursor: pointer; }
.gflow { margin: var(--s2) 0 0; padding-left: 1.2em; font-size: 12px; line-height: 1.85; color: var(--muted); }
.gchap { border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); box-shadow: var(--shadow); }
.gchap > summary { list-style: none; cursor: pointer; padding: var(--s3) var(--s4); display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; min-height: 52px; }
.gchap > summary::-webkit-details-marker { display: none; }
.gchap > summary .gid { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; min-width: 2.4em; }
.gchap > summary .gt { font-weight: 600; font-size: 14px; }
.gchap > summary .gacc { margin-left: auto; font-size: 11px; font-variant-numeric: tabular-nums; }
.gchap[open] > summary { border-bottom: 1px solid var(--line); }
.gbody { padding: var(--s4); font-size: 13px; line-height: 1.75; }
.gbody h3 { font-size: 13px; margin: var(--s4) 0 6px; color: var(--accent); font-weight: 600; }
.gbody h3 .sid { color: var(--muted); font-weight: 400; font-size: 11px; margin-right: 6px; }
.gbody ul { margin: 0; padding-left: 1.2em; }
.gbody .sum { margin: 0; }
.gtbl table td, .gtbl table th { white-space: normal; min-width: 5em; }
.gex { margin: 6px 0 0; padding: 6px var(--s3); border-left: 2px solid var(--ok); background: var(--sunken); border-radius: 0 6px 6px 0; }
.gex .ng { color: var(--bad); font-size: 12px; }
.gbox { margin-top: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--sunken); font-size: 12px; }
.gbox b { display: block; font-size: 11px; margin-bottom: 2px; }
.gbox.tip b { color: var(--ok); } .gbox.trap b { color: var(--bad); }

/* ---------- アカウント・管理 ---------- */
main.auth { max-width: 400px; padding-top: 10vh; }
.brand { display: flex; align-items: center; justify-content: center; gap: var(--s3); font-size: 22px; font-weight: 800; margin: 0 0 var(--s2); }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.temp { font-family: ui-monospace, Menlo, monospace; background: var(--sunken); border: 1px solid var(--warn); padding: 2px 8px; border-radius: 4px; color: var(--warn); user-select: all; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--accent-weak); color: var(--accent); margin-left: 4px; }
.tag.off { background: var(--bad-weak); color: var(--bad); }
#tab-account .panel { max-width: 640px; width: 100%; margin: 0 auto; }

/* ---------- PC ---------- */
@media (min-width: 1000px) {
  #tab-stats:not([hidden]) { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--s4); align-items: start; }
  .scol { display: flex; flex-direction: column; gap: var(--s4); }

  /* Part6/7: 本文｜設問の2カラムを画面の高さぴったりに収め、各カラムだけスクロール */
  main.rcfit { height: calc(100dvh - var(--top)); padding-bottom: var(--s5); }
  main.rcfit > #tab-quiz { flex: 1; min-height: 0; }
  main.rcfit > #tab-quiz > .panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  main.rcfit #qbox { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  main.rcfit .rcwrap { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--s5); }
  main.rcfit .rcdocs, main.rcfit .rcqs { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding-right: var(--s2); }
  main.rcfit .rcdocs .doc:last-child { margin-bottom: 0; }
  main.rcfit .rcqs .rcq:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
  main.rcfit .rcqs #res { position: sticky; bottom: 0; background: var(--panel); padding-top: var(--s3); }
  main.rcfit .rcqs #res .primary { margin-top: 0; }
}

/* ---------- スマホ ---------- */
@media (max-width: 759px) {
  :root { --top: 52px; --tabbar: calc(60px + env(safe-area-inset-bottom)); }
  /* backdrop-filter があると position:fixed の基準が上部バーになり下部タブが固定されないため外す */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .tb-inner { padding: 0 var(--s4); }
  .who { max-width: 50%; }
  /* グローバルメニューは画面下のタブバーに */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar); margin: 0; gap: 0;
    padding: 0 var(--s2) env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-top: 1px solid var(--border);
  }
  .tabs button { flex: 1; flex-direction: column; justify-content: center; gap: 3px; height: 60px; padding: 0; font-size: 10px; }
  .tabs button svg { width: 22px; height: 22px; }
  .tabs button.on::after { display: none; }
  main { padding: var(--s3) var(--s3) calc(var(--s6) + var(--tabbar)); gap: var(--s3); }
  main > section:not([hidden]), #tab-stats:not([hidden]) { gap: var(--s3); }
  .panel { padding: var(--s4); }
  select, input { font-size: 16px; }   /* iOS の入力時拡大を防ぐ */
  .qbar { grid-template-columns: 1fr 1fr; margin-bottom: var(--s4); }
  .qbar .seg { grid-column: 1 / -1; }
  .q { font-size: 16px; }
  .q.word { font-size: 28px; }
  .primary { width: 100%; }
  .nextrow .primary, .primary.sm { width: auto; }
  .big, .examdays span { font-size: 38px; }
  .kpi { padding: var(--s2) var(--s3); }
  .kpi .v { font-size: 19px; }
  .row { grid-template-columns: 5.5rem 1fr 4.5rem; gap: var(--s2); }
  .mx th, .mx td { padding: 6px 3px; }
  .mx td.cell { font-size: 11px; }
  #userList td { font-size: 11px; }
  .doc { padding: var(--s3); }
  .doc .dt { font-size: 14px; }
  main.auth { padding-top: 8vh; }
}

/* ---------- 問題へのフィードバック ---------- */
.fb { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); }
.fbb {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 var(--s3);
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 12px; font-weight: 500;
  transition: color .12s, border-color .12s, background-color .12s;
}
.fbb svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.fbb:hover { color: var(--text); }
.fbb.up.on { color: var(--ok); border-color: var(--ok); background: var(--ok-weak); }
.fbb.up.on svg { fill: var(--ok-weak); }
.fbb.down.on { color: var(--bad); border-color: var(--bad); background: var(--bad-weak); }
.fbmsg { font-size: 11px; }
.fbtabs { max-width: 260px; margin-bottom: var(--s2); }
.fblist { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s3); }
.fbi { background: var(--sunken); border-radius: var(--r-sm); padding: var(--s3); }
.fbi-head { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-bottom: 4px; }
.fbi-head .tag { margin-left: 0; }
.fbcount { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fbcount.down { color: var(--bad); } .fbcount.up { color: var(--ok); }
.fbi-text { font-size: 13px; line-height: 1.6; }
