/* ===== テーマ ===== */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e2e6ec;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --good: #16a34a;
  --again: #e0812f;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #171c24;
    --text: #e8ecf2;
    --muted: #97a1b0;
    --border: #262d38;
    --accent: #4c8dff;
    --accent-ink: #0b1220;
    --good: #35c46a;
    --again: #e9a13b;
    --danger: #f0645f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
               "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}

/* ===== トップバー ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.05rem; letter-spacing: .02em; }

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

.view { animation: fade .18s ease; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ===== 汎用 ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.panel h3 { margin: 0 0 6px; font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; line-height: 1.6; }

button, select, input { font: inherit; color: inherit; }

.primary-btn, .ghost-btn, .danger-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.primary-btn { background: var(--accent); color: var(--accent-ink); }
.primary-btn.small { padding: 10px; margin: 8px 0 0; }
.ghost-btn { background: transparent; border-color: var(--border); color: var(--text); }
.danger-btn { background: transparent; border-color: var(--danger); color: var(--danger); }
.primary-btn:active, .ghost-btn:active, .danger-btn:active { filter: brightness(.92); }
.ghost-btn:hover, .danger-btn:hover { background: rgba(127, 127, 127, .08); }

.file-btn { text-align: center; }

.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: transparent;
  border: none;
  border-radius: 10px;
  font-size: 1.15rem;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(127, 127, 127, .12); }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: .92rem;
}
.field:last-child { border-bottom: none; }
.field select {
  flex: 1;
  max-width: 60%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
}

/* ===== ホーム統計 ===== */
.stats-row { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-label { display: block; font-size: .74rem; color: var(--muted); }
#stat-due { color: var(--accent); }
#stat-done { color: var(--good); }

.progress-wrap { margin: 0 2px 16px; }
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
#progress-fill, #session-fill {
  height: 100%;
  width: 0;
  background: var(--good);
  border-radius: 99px;
  transition: width .35s ease;
}
.progress-text { margin: 6px 2px 0; font-size: .78rem; color: var(--muted); text-align: right; }

/* ===== 学習画面 ===== */
.study-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.session-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
#session-fill { background: var(--accent); }
.session-count { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.flashcard { min-height: 240px; padding: 24px 20px; position: relative; }

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tag {
  font-size: .68rem;
  padding: 2px 9px;
  border-radius: 99px;
  background: rgba(31, 111, 235, .12);
  color: var(--accent);
  white-space: nowrap;
}

.card-front { text-align: center; padding: 8px 0; }
.q-word {
  margin: 0;
  font-size: clamp(1.5rem, 6vw, 2rem);
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
}
.q-sub { margin: 6px 0 0; font-size: .88rem; color: var(--muted); }

.speak-btn {
  margin-top: 12px;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 1.1rem;
  cursor: pointer;
}
.speak-btn:active { filter: brightness(.9); }

.answer-area hr { border: none; border-top: 1px solid var(--border); margin: 18px 0 14px; }
.a-main { margin: 0 0 12px; font-size: 1.15rem; font-weight: 600; }
.a-ex { margin: 0; font-size: .95rem; }
.a-exja { margin: 4px 0 0; font-size: .86rem; color: var(--muted); }

/* 4択 */
.choice-area { display: grid; gap: 9px; margin-top: 18px; }
.choice {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  cursor: pointer;
  font-size: .92rem;
  line-height: 1.5;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:disabled { cursor: default; }
.choice.correct { border-color: var(--good); background: rgba(22, 163, 74, .12); font-weight: 600; }
.choice.wrong { border-color: var(--danger); background: rgba(220, 38, 38, .1); }

/* スペル入力 */
.spell-area { margin-top: 18px; }
#spell-input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  font-size: 1.05rem;
}
#spell-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.spell-result { margin: 10px 0 0; font-size: .95rem; font-weight: 600; min-height: 1.2em; }
.spell-result.ok { color: var(--good); }
.spell-result.ng { color: var(--danger); }

/* 判定ボタン */
.btn-row { display: flex; gap: 10px; }
.btn-row .primary-btn { margin-bottom: 0; }
.judge-btn {
  flex: 1;
  padding: 15px;
  border-radius: 12px;
  border: 1px solid;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
}
.judge-btn.again { color: var(--again); border-color: var(--again); }
.judge-btn.good { color: var(--accent-ink); background: var(--good); border-color: var(--good); }
.judge-btn:active { filter: brightness(.92); }

/* ===== 結果 ===== */
.result-card { text-align: center; padding: 30px 20px; }
.result-emoji { font-size: 2.4rem; margin: 0; }
.result-card h2 { margin: 6px 0 14px; font-size: 1.2rem; }
.result-line { margin: 4px 0; font-size: .95rem; }

/* ===== 一覧 ===== */
.list-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.head-title { margin: 0; font-size: 1.05rem; }
#search {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.word-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.word-item summary {
  display: flex;
  align-items: baseline;
  gap: 9px;
  cursor: pointer;
  list-style: none;
}
.word-item summary::-webkit-details-marker { display: none; }
.wi-en { font-weight: 650; }
.wi-ja { flex: 1; font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wi-box {
  flex: none;
  font-size: .68rem;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.wi-box.learned { color: var(--good); border-color: var(--good); }
.wi-body { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: .88rem; }
.wi-body p { margin: 0 0 4px; }
.wi-body .ipa { color: var(--muted); font-size: .82rem; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: .9rem; }
.error-box {
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--danger);
  font-size: .88rem;
  line-height: 1.7;
}
