/* =========================================================
   ドリル共通スタイル
   色・書体は site.css のトークンを使うので、
   このファイルは必ず site.css の後に読み込むこと。
   ========================================================= */

/* ---------- ヘッダー ---------- */

.drill-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.drill-top .brand h1 {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.3;
  margin: 0;
  text-wrap: balance;
}

.drill-top .brand .crumb {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}

.drill-top .brand p.sub {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  max-width: 44em;
}

.stats { display: flex; gap: 22px; font-variant-numeric: tabular-nums; }
.stat { display: flex; flex-direction: column; align-items: flex-start; }

.stat b {
  font-family: var(--f-math);
  font-weight: 600;
  font-size: 22px;
  line-height: 1.1;
}

.stat span {
  font-size: 10.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 3px;
}

.stat.is-streak b { color: var(--accent); }

/* ---------- コントロール ---------- */

.controls { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: center; }
.group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.group > .label {
  font-size: 10.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
}

.chip {
  font-family: var(--f-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.chip:hover { border-color: var(--accent); color: var(--ink); }

.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 盤面 ---------- */

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .82fr);
  gap: 20px;
  align-items: start;
}

.board.is-solo { grid-template-columns: minmax(0, 1fr); max-width: 720px; }

@media (max-width: 780px) {
  .board { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.eyebrow {
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- 数式 ---------- */

.math { font-family: var(--f-math); font-feature-settings: "tnum"; }
.math i { font-style: italic; padding-right: .02em; }
.math sup { font-size: .68em; }

.prompt { font-family: var(--f-display); font-size: 15px; line-height: 1.75; margin: 0; }

.expr {
  font-family: var(--f-math);
  font-size: clamp(25px, 5.4vw, 34px);
  line-height: 1.4;
  letter-spacing: .01em;
  padding: 4px 0 2px;
  overflow-x: auto;
  white-space: nowrap;
}

/* 分数（1行内に収める簡易表記） */
.frac { display: inline-flex; flex-direction: column; vertical-align: -0.45em; text-align: center; margin: 0 .12em; }
.frac .n { border-bottom: 1px solid currentColor; padding: 0 .25em; line-height: 1.25; }
.frac .d { padding: 0 .25em; line-height: 1.25; }

/* ---------- 解答 ---------- */

.answer { display: flex; flex-direction: column; gap: 14px; }
.fields { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.field { display: flex; align-items: center; gap: 7px; }

.field > label { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* ± ボタンと入力欄をひとかたまりに。iPhoneの数字キーボードにマイナスがないため必須 */
.num-input { display: flex; align-items: stretch; gap: 5px; }

.field input {
  font-family: var(--f-math);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  width: 82px;
  padding: 7px 10px;
  text-align: center;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  transition: border-color .15s, box-shadow .15s;
}

.sign-btn {
  flex: 0 0 auto;
  min-width: 40px;
  font-family: var(--f-math);
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

.sign-btn:hover { border-color: var(--accent); color: var(--ink); }

.sign-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

@media (max-width: 480px) {
  /* 指で押せる大きさを確保しつつ、1行に2組は並ぶようにする。
     ラベルだけ上の行へ逃がす（( , ) などの装飾は入力欄と同じ行に残す必要がある）。 */
  .field input { width: 66px; font-size: 19px; }
  .sign-btn { min-width: 44px; }
  .field { flex-wrap: wrap; gap: 4px 6px; }
  .field > label { flex: 1 0 100%; font-size: 11.5px; line-height: 1.3; white-space: normal; }
  /* ラベル付きの欄は2つで1行。ラベルなし（( , ) などの記法）は分割しない */
  .field:has(> label) { flex: 1 1 calc(50% - 12px); min-width: 118px; }
  .fields { gap: 14px 12px; align-items: flex-end; }
}

.field input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field .choices { display: flex; gap: 6px; flex-wrap: wrap; }

.field .choice {
  font-family: var(--f-math);
  font-size: 17px;
  min-width: 46px;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.field .choice:hover { border-color: var(--accent); }

.field .choice[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.field .choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.paren { font-family: var(--f-math); font-size: 26px; color: var(--muted); line-height: 1; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-sm {
  font-family: var(--f-body);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--surface);
  cursor: pointer;
  transition: opacity .15s;
}

.btn-sm:hover { opacity: .87; }
.btn-sm:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-sm.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-sm.ghost:hover { color: var(--ink); border-color: var(--accent); opacity: 1; }

/* ---------- 判定 ---------- */

.verdict {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
}

.verdict.is-wrong { border-left-color: var(--warn); background: var(--warn-soft); }
.verdict b { font-family: var(--f-display); font-size: 15px; color: var(--accent-ink); }
.verdict.is-wrong b { color: var(--warn); }
.verdict span { font-size: 13px; color: var(--muted); }

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.hint b { color: var(--warn); font-family: var(--f-display); }

/* ---------- 解法 ---------- */

.solution { display: flex; flex-direction: column; gap: 10px; }

.step { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 12px; align-items: baseline; }

.step .n {
  font-family: var(--f-math);
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 4px;
  font-variant-numeric: tabular-nums;
}

.step .body { font-size: 14px; line-height: 1.85; }
.step .body .math { font-size: 16.5px; }
.step .note { color: var(--muted); font-size: 12.5px; display: block; margin-top: 1px; }

/* ---------- グラフ ---------- */

.plot {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend .key { display: flex; align-items: center; gap: 6px; }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.legend .dot.line { border-radius: 1px; width: 12px; height: 2px; background: var(--muted); }

.placeholder { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- 誤答の傾向 ---------- */

.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.panel-head h2 { font-family: var(--f-display); font-size: 17px; font-weight: 600; margin: 0; }
.panel-head .meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.bars {
  display: grid;
  grid-template-columns: minmax(120px, max-content) minmax(0, 1fr) max-content;
  align-items: center;
  gap: 9px 14px;
}

.bars .cat { font-size: 13px; }
.bars .cat small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.bars .track { height: 10px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; }
.bars .val { font-family: var(--f-math); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars .val span { color: var(--muted); font-size: 12px; }

.raw {
  width: 100%;
  min-height: 130px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  resize: vertical;
}

.panel-note { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- 単元一覧・となりの単元 ---------- */

.unit-nav { margin-top: 8px; }
.unit-nav h2 { font-family: var(--f-display); font-size: 16px; font-weight: 600; margin: 0 0 12px; }

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.unit-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, transform .15s;
}

.unit-card:hover { border-color: var(--accent); transform: translateY(-2px); color: inherit; }
.unit-card[aria-current="page"] { border-color: var(--accent); background: var(--accent-soft); }

.unit-card .chapter { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.unit-card .name { font-family: var(--f-display); font-weight: 600; font-size: 14.5px; }
.unit-card .desc { font-size: 12.5px; color: var(--muted); line-height: 1.6; }

.chapter-block { margin-bottom: 30px; }

.chapter-block > h2 {
  font-family: var(--f-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
}

.chapter-block > p.lead { margin: 0 0 14px; font-size: 13px; color: var(--muted); }

.soon { opacity: .55; cursor: default; }
.soon:hover { border-color: var(--line); transform: none; }

[hidden] { display: none !important; }

/* ---------- 学習ダッシュボード（/drill/） ---------- */
/* 記録が0件のときは JS 側で hidden のまま。初回訪問の見た目は変わらない。 */

.dash {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dash-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dash-head h2 { font-family: var(--f-display); font-size: 17px; font-weight: 600; margin: 0; }
.dash-head .meta { font-size: 12px; color: var(--muted); }

.dash-tiles { display: flex; gap: 26px; flex-wrap: wrap; }
.dash-tile b {
  display: block;
  font-family: var(--f-math);
  font-size: 30px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.dash-tile span { font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }

.dash-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; }

.dash-chip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, transform .15s;
}
.dash-chip:hover { border-color: var(--accent); transform: translateY(-2px); color: inherit; }
.dash-chip .n { font-family: var(--f-display); font-weight: 600; font-size: 14px; }
.dash-chip .m { font-size: 11.5px; color: var(--muted); }

.dash h3 { font-family: var(--f-display); font-size: 14px; font-weight: 600; margin: 0 0 10px; }
.dash-note { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.7; }

.dash-reset {
  background: none; border: none; padding: 0;
  color: var(--muted); font-family: var(--f-body); font-size: 12px;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* ---------- 1セット完了 ---------- */

.set-done {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 9px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.set-done b { font-family: var(--f-display); font-size: 15px; color: var(--accent-ink); }
.set-done p { margin: 0; font-size: 13px; color: var(--ink); line-height: 1.7; }
.set-done .actions { margin-top: 2px; }
.set-done a.btn-sm { display: inline-flex; align-items: center; text-decoration: none; }
