/* ===== デザイントークン ===== */
:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --text: #1f1d1a;
  --text-sub: #6b665e;
  --border: #e2ddd2;
  --accent: #b5452f;        /* 朱色 */
  --accent-text: #ffffff;
  --accent-soft: #f6e4df;
  --correct: #2f7d4f;
  --correct-soft: #e2f1e7;
  --wrong: #b3261e;
  --wrong-soft: #fbe5e3;
  --radius: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181b;
    --surface: #232327;
    --text: #f2f0ec;
    --text-sub: #a8a39a;
    --border: #3a3a40;
    --accent: #e0745c;
    --accent-text: #1a1a1a;
    --accent-soft: #3d2924;
    --correct: #6cc792;
    --correct-soft: #1f3328;
    --wrong: #f08a80;
    --wrong-soft: #3d2422;
  }
}

/* ===== ベース ===== */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

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

/* ===== レイアウト ===== */
.app-header {
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-title {
  display: block;
  max-width: 640px;
  margin: 0 auto;
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
  text-decoration: none;
}

.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 32px);
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  outline: none;
}

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

h1, h2 { line-height: 1.3; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 15px; color: var(--text-sub); font-weight: 600; margin-top: 28px; }

.lead { color: var(--text-sub); margin: 0 0 8px; }

.note {
  margin-top: 40px;
  font-size: 12px;
  color: var(--text-sub);
  text-align: center;
}

/* ===== ボタン ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-text {
  width: auto;
  min-height: 44px;
  border: none;
  background: none;
  color: var(--text-sub);
  font-size: 15px;
  font-weight: 500;
  padding: 8px 4px;
}
.btn-stack { display: grid; gap: 12px; margin-top: 24px; }

/* ===== ホーム：分野一覧 ===== */
.category-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.category {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.category:active { transform: scale(0.98); }
.category:disabled { cursor: default; opacity: 0.55; transform: none; }
.category-body { flex: 1; min-width: 0; }
.category-name { display: block; font-size: 18px; font-weight: 700; }
.category-desc { display: block; font-size: 13px; color: var(--text-sub); }
.category-badge {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-sub);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}
.category-arrow { flex-shrink: 0; color: var(--accent); font-size: 20px; }
.category-weak { margin: 16px 0 0; border-color: var(--accent); background: var(--accent-soft); }
.category-weak:disabled { border-color: var(--border); background: var(--surface); }
.category-count {
  flex-shrink: 0;
  min-width: 48px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  text-align: center;
}

/* ===== 出題画面 ===== */
.quiz-top { display: flex; align-items: center; justify-content: space-between; margin: -8px 0 6px; }
.quit-confirm {
  margin: 0 0 14px;
  padding: 14px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.quit-confirm[hidden] { display: none; }
.quit-confirm p { margin: 0 0 10px; font-weight: 600; }
.quit-confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quit-confirm-actions .btn { min-height: 46px; font-size: 16px; }

.quiz-count { font-weight: 700; font-variant-numeric: tabular-nums; }

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}
.progress-bar { height: 100%; background: var(--accent); transition: width 0.2s ease; }

.card {
  padding: 20px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.prompt { margin: 0 0 14px; font-size: 14px; color: var(--text-sub); }

.sentence {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  line-height: 1.9;
  word-break: normal;
  line-break: strict;
}
.subject {
  margin: 4px 0 0;
  font-family: var(--font-serif);
  font-size: 44px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  letter-spacing: 0.08em;
}

.subject.is-long { font-size: 30px; letter-spacing: 0.04em; }

.target {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-decoration-color: var(--accent);
}

.answer-form { margin-top: 18px; display: grid; gap: 10px; }

.answer-input {
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 20px;   /* 16px以上：iOSの自動ズーム防止 */
}
.answer-input:focus { outline: none; border-color: var(--accent); }
.answer-input:disabled { opacity: 0.7; }

.answer-sub { display: flex; justify-content: center; }

/* 4択 */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  position: relative;
  min-height: 60px;
  padding: 10px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  word-break: break-all;
}
.choice.is-long { padding: 10px 22px; font-size: 15px; line-height: 1.4; }
.choice:active { transform: scale(0.97); }
.choice:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.choice:disabled { cursor: default; transform: none; opacity: 0.45; }
.choice.is-correct, .choice.is-wrong { opacity: 1; }
.choice.is-correct { background: var(--correct-soft); border-color: var(--correct); color: var(--correct); }
.choice.is-wrong { background: var(--wrong-soft); border-color: var(--wrong); color: var(--wrong); }
.choice.is-correct::before, .choice.is-wrong::before {
  position: absolute;
  top: 4px;
  left: 8px;
  font-size: 14px;
}
.choice.is-correct::before { content: "○"; }
.choice.is-wrong::before { content: "×"; }

/* ルビ */
rt { font-family: var(--font-sans); font-size: 0.5em; font-weight: 400; }
.target rt { color: var(--accent); font-weight: 700; }

/* ===== 正誤フィードバック ===== */
.feedback {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
}
.feedback.is-correct { background: var(--correct-soft); border-color: var(--correct); }
.feedback.is-wrong { background: var(--wrong-soft); border-color: var(--wrong); }
.feedback-title { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 20px; font-weight: 700; }
.is-correct .feedback-title { color: var(--correct); }
.is-wrong .feedback-title { color: var(--wrong); }
.feedback-mark { font-size: 26px; line-height: 1; }
.feedback dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.feedback dt { color: var(--text-sub); font-size: 14px; }
.feedback dd { margin: 0; font-weight: 600; word-break: break-all; }
.explanation { margin: 10px 0 0; font-size: 14px; }

.full-reading {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
}
.full-reading-label { margin: 0; font-size: 12px; color: var(--text-sub); }
.full-reading-text { margin: 0; font-family: var(--font-serif); font-size: 19px; line-height: 2.3; }

/* ===== 結果画面 ===== */
.score { text-align: center; padding: 8px 0 4px; }
.score-category { color: var(--text-sub); margin: 0; }
.score-number { margin: 4px 0; font-size: 48px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.score-number small { font-size: 22px; font-weight: 600; color: var(--text-sub); }
.score-message { margin: 0; font-weight: 600; }

.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.result-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.result-mark { flex-shrink: 0; width: 24px; font-size: 20px; font-weight: 700; line-height: 1.5; text-align: center; }
.result-mark.is-correct { color: var(--correct); }
.result-mark.is-wrong { color: var(--wrong); }
.result-body { min-width: 0; flex: 1; }
.result-sentence { margin: 0; font-family: var(--font-serif); font-size: 16px; line-height: 2.2; }
.result-answer { margin: 2px 0 0; font-size: 14px; color: var(--text-sub); }
.result-answer strong { color: var(--text); }
.result-yours.is-wrong { color: var(--wrong); text-decoration: line-through; }

/* ===== ダッシュボード（ホーム） ===== */
/* --theme / --theme-soft は日替わりテーマ（js/dashboard.js）で決まる */
.dash { margin: -20px -16px 20px; }

.dash-hero {
  position: relative;
  min-height: 210px;
  padding: 20px 20px 44px;
  color: #fff;
  background-color: var(--theme);
  background-image: linear-gradient(135deg, var(--theme), color-mix(in srgb, var(--theme) 55%, #000));
  background-size: cover;
  background-position: center;
}
/* 写真の上でも文字が読めるように暗いグラデーションを重ねる */
.dash-hero.has-photo::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.55) 100%);
}
.dash-hero > * { position: relative; }
.dash-date { margin: 0 0 6px; font-size: 15px; font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.dash-title { margin: 0; font-size: 28px; line-height: 1.25; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
.dash-title span { display: block; }
.dash-title-sub { font-size: 16px; font-weight: 600; opacity: 0.95; }
.dash-greeting {
  display: inline-block;
  margin: 12px 0 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--theme);
  font-size: 17px;
  font-weight: 800;
}
.photo-credit {
  margin: 6px 16px 0;
  font-size: 11px;
  color: var(--text-sub);
  text-align: right;
}
.photo-credit a { color: inherit; }

.dash-card {
  margin: -28px 12px 0;
  padding: 18px 16px;
  border: 2px solid var(--theme);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  position: relative;
}
.dash-progress { display: flex; align-items: center; gap: 16px; }

/* まるいメーター（conic-gradient） */
.ring {
  --size: 120px;
  flex-shrink: 0;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: conic-gradient(var(--theme) calc(var(--p) * 1%), var(--border) 0);
  display: grid;
  place-items: center;
}
.ring-inner {
  width: calc(var(--size) - 26px);
  height: calc(var(--size) - 26px);
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-percent { font-size: 34px; font-weight: 900; line-height: 1; color: var(--theme); font-variant-numeric: tabular-nums; }
.ring-percent small { font-size: 16px; }
.ring-label { margin-top: 4px; font-size: 13px; font-weight: 700; color: var(--text-sub); }

.dash-summary { flex: 1; min-width: 0; }
.dash-count { margin: 0; font-size: 18px; font-weight: 700; }
.dash-count strong { font-size: 30px; color: var(--theme); }
.dash-count-label { margin: 0 0 8px; font-size: 13px; color: var(--text-sub); }

.stack-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--border); }
.stack-mastered { background: #f5b301; }
.stack-learning { background: #ff8a3d; }

.legend { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.legend strong { font-variant-numeric: tabular-nums; }

.dash-cheer {
  margin: 14px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--theme-soft);
  color: var(--theme);
  font-size: 17px;
  font-weight: 800;
  text-align: center;
}

.dash-stats { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dash-stats li {
  padding: 8px 4px;
  border-radius: 12px;
  background: var(--bg);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}
.dash-stats span { display: block; font-size: 12px; color: var(--text-sub); }
.dash-stats strong { font-size: 24px; color: var(--theme); margin-right: 2px; font-variant-numeric: tabular-nums; }

.dash-updated { margin: 12px 0 0; font-size: 14px; color: var(--text-sub); text-align: center; }

/* 分野ごとの小さな進み具合 */
.category-name rt { font-size: 0.55em; font-weight: 600; color: var(--text-sub); }
.category-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--text-sub); }
.mini-bar { flex: 0 0 72px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.mini-bar span { display: block; height: 100%; background: var(--accent); }

/* 313字マップ */
.kanji-map-section { margin-top: 28px; }
.map-help { margin: -4px 0 8px; font-size: 14px; color: var(--text-sub); }
.legend-map { margin: 0 0 10px; font-size: 14px; }
.legend-map li { display: flex; align-items: center; gap: 4px; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; }
.kanji-map {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 4px;
}
.kanji-map li {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1;
}
.kanji-mastered { background: #ffd54f; color: #3e2c00; font-weight: 700; }
.kanji-learning { background: #ffccbc; color: #5d2a12; }
.kanji-new { background: var(--surface); color: var(--text-sub); border: 1px solid var(--border); }

@media (prefers-color-scheme: dark) {
  .kanji-mastered { background: #b28704; color: #fff8e1; }
  .kanji-learning { background: #8d3f1f; color: #fff3ee; }
}

@media (min-width: 768px) {
  .dash { margin: -32px 0 24px; }
  .dash-hero { border-radius: 0 0 20px 20px; min-height: 240px; }
  .dash-title { font-size: 34px; }
}

/* ===== 共有・更新の案内 ===== */
.share { margin-top: 32px; text-align: center; }
.share-status { min-height: 1.6em; margin: 8px 0 0; font-size: 14px; color: var(--text-sub); }

.update-banner {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 608px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  font-weight: 600;
  z-index: 10;
}
.update-banner .btn { width: auto; min-height: 44px; font-size: 15px; }

/* ===== タブレット・PC ===== */
@media (min-width: 768px) {
  .app-main { padding-top: 32px; }
  .sentence { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active, .category:active { transform: none; }
}
