:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #1f3a5f;
  --accent-soft: #e6edf6;
  --weak: #c2410c;
  --weak-soft: #fff1e8;
  --done: #15803d;
  --done-soft: #e8f6ed;
  --star: #d39e00;
  --code-bg: #f0f2f5;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --surface: #1b1f25;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --border: #2c323a;
    --accent: #8fb4e3;
    --accent-soft: #23314a;
    --weak: #fb923c;
    --weak-soft: #3a2416;
    --done: #4ade80;
    --done-soft: #16301f;
    --star: #f2c94c;
    --code-bg: #252b33;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418;
  --surface: #1b1f25;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --border: #2c323a;
  --accent: #8fb4e3;
  --accent-soft: #23314a;
  --weak: #fb923c;
  --weak-soft: #3a2416;
  --done: #4ade80;
  --done-soft: #16301f;
  --star: #f2c94c;
  --code-bg: #252b33;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
strong { color: var(--accent); }

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--weak); padding: 16px; }

.sync-status { margin-left: 10px; font-size: 13px; color: var(--muted); }
.sync-status.ok { color: var(--done); }
.sync-status.err { color: var(--weak); }
.stats { margin: 0; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

main { max-width: 760px; margin: 0 auto; }
.view { padding: 0 16px 24px; }
.view-title { font-size: 17px; margin: 20px 0 8px; }

/* ---------- controls（iPhone向けにコンパクト。下スクロールで隠れる） ---------- */
.controls {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  display: grid;
  gap: 6px;
  margin: 0 -16px;
  padding: 8px 16px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: transform 0.2s ease;
}
.controls.tucked { transform: translateY(calc(-100% - env(safe-area-inset-top, 0px))); }
@media (prefers-reduced-motion: reduce) { .controls { transition: none; } }

.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; min-width: 0; }
input[type="search"], input[type="url"], input[type="text"] {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px; /* 16px未満だとiOSが入力時にズームする */
  -webkit-appearance: none;
  appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.icon-btn {
  position: relative;
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.icon-btn.has-filter::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--weak);
}

.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 3px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
}
.seg button.active { background: var(--accent); color: var(--surface); }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chips a {
  flex: none;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  line-height: 22px;
  white-space: nowrap;
}

/* ---------- sections ---------- */
.gsec { padding-top: 8px; scroll-margin-top: 92px; }
.gsec h2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 18px;
  margin: 20px 0 10px;
}
.sec-progress { font-size: 12px; font-weight: normal; color: var(--muted); white-space: nowrap; }
.gbody > p, .gbody > ul { margin: 10px 0; }
.gbody ul { padding-left: 20px; }
.gbody li { margin: 4px 0; }

.table-scroll { overflow-x: auto; margin: 10px 0; -webkit-overflow-scrolling: touch; }
.table-scroll table {
  border-collapse: collapse;
  min-width: 100%;
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
  font-size: 14px;
}
.table-scroll th, .table-scroll td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.table-scroll th { background: var(--accent-soft); font-weight: 600; white-space: nowrap; }

/* ---------- cards ---------- */
.cards { display: grid; gap: 10px; margin: 10px 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.card[data-status="weak"] { border-left-color: var(--weak); }
.card[data-status="done"] { border-left-color: var(--done); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card h3 { margin: 0; font-size: 16px; }
.freq { color: var(--star); font-size: 13px; letter-spacing: -1px; white-space: nowrap; }
.card dl { margin: 8px 0 0; display: grid; gap: 4px; }
.card dl div { display: grid; grid-template-columns: 4.5em 1fr; gap: 8px; }
.card dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
.card dd { margin: 0; overflow-wrap: anywhere; }

.card-actions { display: flex; gap: 8px; margin-top: 10px; }

/* 例文：英文 + 🔊 / 訳 */
.ex { display: block; margin: 2px 0 6px; }
.ex:last-child { margin-bottom: 0; }
.ex-body { display: block; min-width: 0; }
.ex-body .ja { display: block; font-size: 13px; color: var(--muted); line-height: 1.5; }
.say {
  flex: none;
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
  margin-left: 2px;
  padding: 0;
}
.say svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.say svg path:first-child { fill: currentColor; }
.say:active { transform: scale(0.92); }
.st, .practice {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  padding: 6px 0;
  font-size: 13px;
  color: var(--muted);
}
.st[data-status="weak"][aria-pressed="true"] { background: var(--weak-soft); border-color: var(--weak); color: var(--weak); font-weight: 600; }
.st[data-status="done"][aria-pressed="true"] { background: var(--done-soft); border-color: var(--done); color: var(--done); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- review ---------- */
.review-head { padding-top: 16px; }
.review-card {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 16px;
  min-height: 240px;
}
.review-sentence { font-size: 20px; line-height: 1.5; margin: 8px 0 16px; }
.review-sentence strong { color: var(--text); }
.review-hint { font-size: 12px; color: var(--muted); }
.review-answer { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 12px; }
.review-answer h3 { margin: 0 0 4px; font-size: 17px; }
.review-answer dl { margin: 8px 0 0; display: grid; gap: 4px; }
.review-answer dl div { display: grid; grid-template-columns: 4.5em 1fr; gap: 8px; }
.review-answer dt { color: var(--muted); font-size: 12px; padding-top: 2px; }
.review-answer dd { margin: 0; overflow-wrap: anywhere; }
.review-actions { display: flex; gap: 8px; margin-top: 16px; }
.review-actions button { flex: 1; }

/* ---------- drill ---------- */
.drill-head { display: grid; gap: 8px; }
.scope-row { display: flex; gap: 6px; }
.scope-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
}
.scope-key { flex: none; font-size: 12px; color: var(--muted); }
.scope-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--accent); }
.scope-btn svg, .scope-expand svg { width: 16px; height: 16px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.scope-clear {
  flex: none;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.relaxed { display: block; color: var(--weak); }

/* 範囲選択シート */
body.sheet-open { overflow: hidden; }
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.45);
}
.sheet-panel {
  width: 100%;
  max-height: calc(100% - 40px - env(safe-area-inset-top, 0px));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 16px; text-align: center; }
.sheet-head button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  padding: 6px 4px;
}
.sheet-head button.primary {
  background: var(--accent);
  color: var(--surface);
  border-radius: 8px;
  padding: 6px 14px;
  font-weight: 600;
}
.sheet-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--muted);
}
.sheet-tools button { border: 0; background: transparent; color: var(--accent); font-size: 13px; padding: 4px 0; }
.sheet-list { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 16px; display: grid; gap: 8px; align-content: start; }
.scope-sec { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.scope-sec.has-pick { border-color: var(--accent); }
.scope-sec-head { display: flex; align-items: center; gap: 4px; }
.scope-sec-label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 12px 0 12px 12px; font-weight: 600; }
.scope-expand {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.scope-expand[aria-expanded="true"] svg { transform: rotate(180deg); }
.scope-items { border-top: 1px solid var(--border); padding: 4px 0; }
.scope-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px 9px 34px; font-size: 14px; }
.scope-item span:nth-of-type(1) { flex: 1; min-width: 0; }
.scope-item .freq { flex: none; }
.sheet input[type="checkbox"] { width: 20px; height: 20px; flex: none; margin: 0; accent-color: var(--accent); }
.drill-title { margin: 0; font-size: 15px; color: var(--accent); }
.drill-opts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: space-between; }
.drill-ja { margin: 12px 0 4px; font-size: 18px; line-height: 1.6; }
.drill-prompt { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.drill-en { margin: 0; font-size: 20px; line-height: 2; overflow-wrap: anywhere; }
.blank { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: baseline; }
.slot {
  display: inline-block;
  min-width: 2.6em;
  border-bottom: 2px solid var(--accent);
  text-align: center;
  line-height: 1.4;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.drill-en mark {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  border-radius: 4px;
  padding: 0 3px;
}
.review-card .review-actions + .review-actions { margin-top: 8px; }
button[disabled] { opacity: 0.4; }

/* ---------- buttons / forms ---------- */
.row { display: flex; gap: 8px; margin-top: 12px; }
.row button, .review-actions button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 14px;
}
button.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.field { display: block; margin-top: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  height: var(--tabbar-h);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.tabbar button.active { color: var(--accent); }

/* 間違い例（~~取り消し線~~） */
del { color: var(--weak); text-decoration-thickness: 1px; }
