/* ============================================ */
/* デザイントークン                                    */
/* ============================================ */
:root {
  /* カラー：カピバラ先生の世界観 */
  --green-main: #7BA98C;       /* 草色（カピバラのジャケット） */
  --green-deep: #4F7A5E;       /* 深い森 */
  --green-light: #C4DCC9;      /* 若葉 */
  --green-soft: #EAF3EC;       /* やさしい緑のbg */
  --paper: #FAF6EE;            /* 温かい紙 */
  --paper-deep: #F2EAD8;       /* 紙のかげ */
  --warm: #D89968;             /* 木の実色（アクセント） */
  --warm-light: #F4DCC0;       /* 木の実のうすい */
  --text: #2C3A2E;             /* 深い森の文字 */
  --text-mute: #6B7A6C;        /* 控えめな文字 */
  --line: #D8DDD3;             /* 罫線 */
  --danger: #C25A4D;           /* やさしい赤 */
  --success: #5FA86B;          /* 正解の緑 */
  
  /* 影 */
  --shadow-sm: 0 1px 2px rgba(76, 95, 76, 0.06);
  --shadow-md: 0 2px 8px rgba(76, 95, 76, 0.08);
  --shadow-lg: 0 8px 24px rgba(76, 95, 76, 0.12);
  
  /* radius */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  
  /* font */
  --f-display: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  --f-body: "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  --f-num: "Inter", "Noto Sans JP", sans-serif;
}

/* ============================================ */
/* ベース */
/* ============================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
  background: transparent;
}

select {
  font-family: inherit;
  font-size: 1em;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: white;
  color: var(--text);
}

/* ============================================ */
/* ヘッダー */
/* ============================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-back {
  font-size: 1.4em;
  color: var(--green-deep);
  padding: 4px 10px;
  border-radius: var(--r-sm);
}
.app-back:hover { background: var(--green-soft); }

.app-title {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.app-title .capy-mini {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green-soft);
  overflow: hidden;
  flex-shrink: 0;
}
.app-title .capy-mini img {
  width: 110%;
  height: 110%;
  object-fit: cover;
  object-position: center 20%;
}

.app-settings {
  font-size: 1.3em;
  color: var(--text-mute);
  padding: 4px 8px;
  border-radius: var(--r-sm);
}
.app-settings:hover { background: var(--green-soft); }

/* ============================================ */
/* 画面切り替え */
/* ============================================ */
#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px;
}

.screen { display: none; }
.screen.active { display: block; animation: fadeIn .25s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.screen-title {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.4em;
  margin: .8em 0 1em;
  color: var(--green-deep);
}

/* ============================================ */
/* ホーム：ヒーロー */
/* ============================================ */
.home-hero {
  background: linear-gradient(135deg, var(--green-soft) 0%, var(--paper-deep) 100%);
  border-radius: var(--r-lg);
  padding: 22px 18px 18px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}

.home-hero::before {
  content: "";
  position: absolute;
  inset: -20% -20% auto auto;
  width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(123, 169, 140, .15), transparent 70%);
  pointer-events: none;
}

.capy-greet {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.capy-face {
  font-size: 3em;
  line-height: 1;
  background: white;
  width: 96px; height: 96px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  overflow: hidden;
}
.capy-face img {
  width: 110%;
  height: 110%;
  object-fit: cover;
  object-position: center 20%;
}

.capy-bubble {
  background: white;
  padding: 10px 14px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  font-family: var(--f-display);
  font-weight: 500;
  font-size: .95em;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.capy-bubble::before {
  content: "";
  position: absolute;
  left: -7px; top: 14px;
  border: 7px solid transparent;
  border-right-color: white;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-card {
  background: white;
  border-radius: var(--r-md);
  padding: 10px 6px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-num {
  font-family: var(--f-num);
  font-weight: 800;
  font-size: 1.5em;
  color: var(--green-deep);
  line-height: 1.1;
}
.stat-num .unit { font-size: .55em; font-weight: 600; margin-left: 2px; }
.stat-label {
  font-size: .75em;
  color: var(--text-mute);
  margin-top: 2px;
}

/* ============================================ */
/* CTA・メニュー */
/* ============================================ */
.cta-big {
  width: 100%;
  background: linear-gradient(135deg, var(--warm) 0%, #C5854F 100%);
  color: white;
  border-radius: var(--r-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  box-shadow: var(--shadow-md);
  transition: transform .15s, box-shadow .15s;
  margin-bottom: 14px;
}
.cta-big:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.cta-big:active { transform: translateY(0); }

.cta-icon { font-size: 1.8em; }
.cta-text { display: flex; flex-direction: column; }
.cta-text strong { font-family: var(--f-display); font-weight: 700; font-size: 1.2em; }
.cta-text small { font-size: .8em; opacity: .9; }

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.menu-card {
  background: white;
  border-radius: var(--r-md);
  padding: 16px 14px;
  text-align: left;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform .15s, box-shadow .15s;
  border: 1.5px solid transparent;
}
.menu-card:hover { transform: translateY(-1px); border-color: var(--green-light); box-shadow: var(--shadow-md); }
.menu-ico { font-size: 1.6em; }
.menu-card strong { font-family: var(--f-display); font-weight: 700; font-size: 1em; color: var(--green-deep); }
.menu-card small { color: var(--text-mute); font-size: .8em; }

/* Streak Viz */
.home-streak-viz {
  margin-top: 22px;
  background: white;
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.home-streak-viz h3 {
  font-family: var(--f-display);
  font-size: .95em;
  margin: 0 0 10px;
  color: var(--green-deep);
}
.streak-dots {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}
.streak-dot {
  flex: 1;
  height: 36px;
  background: var(--paper-deep);
  border-radius: 8px;
  position: relative;
  font-size: .65em;
  color: var(--text-mute);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
}
.streak-dot.done {
  background: linear-gradient(180deg, var(--green-light), var(--green-main));
  color: white;
  font-weight: 700;
}
.streak-dot.today { outline: 2px solid var(--warm); outline-offset: 1px; }

/* ============================================ */
/* デッキ・単元リスト */
/* ============================================ */
.deck-list, .unit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.deck-card {
  background: white;
  border-radius: var(--r-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid var(--green-main);
  text-align: left;
  transition: transform .15s;
  width: 100%;
}
.deck-card:hover { transform: translateX(2px); }
.deck-card strong { font-family: var(--f-display); font-size: 1.15em; color: var(--green-deep); }
.deck-card small { color: var(--text-mute); display: block; font-size: .85em; }
.deck-card .arrow { color: var(--green-main); font-size: 1.4em; }

.unit-card {
  background: white;
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  width: 100%;
  border-left: 3px solid var(--paper-deep);
  transition: transform .15s, border-color .15s;
}
.unit-card:hover { border-left-color: var(--green-main); transform: translateX(2px); }
.unit-card.done { border-left-color: var(--success); background: linear-gradient(90deg, #f1f8f2 0%, white 30%); }
.unit-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.unit-card strong { font-family: var(--f-display); font-size: 1.05em; }
.unit-card .unit-count { color: var(--text-mute); font-size: .85em; }
.unit-progress {
  height: 6px;
  background: var(--paper-deep);
  border-radius: 99px;
  overflow: hidden;
}
.unit-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green-light), var(--green-main));
  border-radius: 99px;
  transition: width .4s;
}
.unit-meta {
  display: flex;
  justify-content: space-between;
  font-size: .8em;
  color: var(--text-mute);
}
.unit-meta .acc { color: var(--green-deep); font-weight: 700; }

/* ============================================ */
/* クイズ画面 */
/* ============================================ */
.quiz-screen { padding-top: 6px; }

.quiz-progress {
  margin-bottom: 16px;
}
.quiz-bar {
  height: 6px;
  background: var(--paper-deep);
  border-radius: 99px;
  overflow: hidden;
}
.quiz-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warm-light), var(--warm));
  border-radius: 99px;
  transition: width .35s ease;
}
.quiz-meta {
  display: flex;
  justify-content: space-between;
  font-size: .8em;
  color: var(--text-mute);
  margin-top: 6px;
  font-family: var(--f-num);
  font-weight: 600;
}

.quiz-card {
  background: white;
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.quiz-tag {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: .85em;
}
.quiz-tag #quiz-category { color: var(--green-deep); font-weight: 600; }
.quiz-type-pill {
  background: var(--green-soft);
  color: var(--green-deep);
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .8em;
  font-weight: 600;
}

.quiz-question {
  font-size: 1.1em;
  line-height: 1.7;
  margin-bottom: 18px;
  white-space: pre-wrap;
  font-weight: 500;
}

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

.choice {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  text-align: left;
  font-size: 1em;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all .15s;
  width: 100%;
}
.choice:hover:not(:disabled) {
  border-color: var(--green-main);
  background: var(--green-soft);
}
.choice .choice-letter {
  background: white;
  border: 1.5px solid var(--line);
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--f-num);
  font-weight: 700;
  font-size: .85em;
  flex-shrink: 0;
}
.choice.correct {
  border-color: var(--success);
  background: #ecf6ed;
}
.choice.correct .choice-letter { background: var(--success); color: white; border-color: var(--success); }
.choice.wrong {
  border-color: var(--danger);
  background: #faecea;
}
.choice.wrong .choice-letter { background: var(--danger); color: white; border-color: var(--danger); }
.choice:disabled { cursor: default; opacity: .8; }
.choice.dim { opacity: .5; }

/* 並び替え */
.quiz-ordering { margin-top: 10px; }
.ordering-answer {
  min-height: 56px;
  background: var(--paper);
  border: 2px dashed var(--line);
  border-radius: var(--r-md);
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.ordering-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.tile {
  background: white;
  border: 1.5px solid var(--green-main);
  color: var(--green-deep);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-family: var(--f-num);
  font-weight: 600;
  font-size: .95em;
  cursor: pointer;
  transition: transform .15s;
}
.tile:hover { transform: translateY(-1px); background: var(--green-soft); }
.tile.placed { background: var(--green-main); color: white; border-color: var(--green-main); }
.ordering-clear {
  font-size: .85em;
  color: var(--text-mute);
  padding: 4px 10px;
}

.quiz-submit, .quiz-next {
  width: 100%;
  background: var(--green-main);
  color: white;
  font-family: var(--f-display);
  font-weight: 700;
  padding: 14px;
  border-radius: var(--r-md);
  font-size: 1.05em;
  margin-top: 16px;
  transition: background .15s, transform .15s;
}
.quiz-submit:hover, .quiz-next:hover { background: var(--green-deep); }
.quiz-submit:disabled { background: var(--line); cursor: default; }

.quiz-result {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
}
.result-badge {
  display: inline-block;
  font-family: var(--f-display);
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 99px;
  font-size: .9em;
  margin-bottom: 10px;
}
.result-badge.correct { background: #ecf6ed; color: var(--success); }
.result-badge.wrong { background: #faecea; color: var(--danger); }
.result-answer { margin: 8px 0; }
.result-answer strong { color: var(--green-deep); }
.result-explanation {
  background: var(--paper);
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border-left: 3px solid var(--warm);
  font-size: .95em;
  color: var(--text);
  margin-top: 8px;
}

/* インターバル */
.quiz-interval {
  background: white;
  border-radius: var(--r-lg);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.interval-capy {
  margin-bottom: 12px;
}
.interval-capy img { width: 240px; max-width: 70%; }
.interval-message {
  font-family: var(--f-display);
  font-weight: 500;
  font-size: 1.05em;
  line-height: 1.8;
  white-space: pre-wrap;
  margin-bottom: 20px;
}
.interval-next {
  background: var(--green-main);
  color: white;
  padding: 12px 28px;
  border-radius: var(--r-md);
  font-weight: 700;
  font-family: var(--f-display);
}

/* ============================================ */
/* セッション結果 */
/* ============================================ */
.result-summary {
  background: white;
  border-radius: var(--r-lg);
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.result-capy { margin-bottom: 10px; line-height: 1; }
.result-capy img, .result-capy video { width: 240px; max-width: 80%; border-radius: 14px; }
.result-summary h2 { font-family: var(--f-display); margin: 0 0 8px; color: var(--green-deep); }
.result-praise { color: var(--text-mute); margin: 0 0 22px; font-size: .95em; }
.result-stats {
  background: var(--paper);
  border-radius: var(--r-md);
  padding: 14px 18px;
  margin-bottom: 22px;
  text-align: left;
}
.rs-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.rs-row:last-child { border-bottom: none; }
.rs-row strong { font-family: var(--f-num); color: var(--green-deep); }
.result-actions { display: flex; gap: 10px; }
.btn-primary, .btn-secondary {
  flex: 1;
  padding: 12px;
  border-radius: var(--r-md);
  font-weight: 700;
  font-family: var(--f-display);
}
.btn-primary { background: var(--green-main); color: white; }
.btn-primary:hover { background: var(--green-deep); }
.btn-secondary { background: var(--paper); color: var(--text); border: 1.5px solid var(--line); }
.btn-secondary:hover { background: var(--paper-deep); }

/* ============================================ */
/* 復習画面 */
/* ============================================ */
.review-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--line);
}
.tab {
  padding: 10px 14px;
  font-family: var(--f-display);
  font-weight: 600;
  color: var(--text-mute);
  position: relative;
  font-size: .95em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab.active { color: var(--green-deep); }
.tab.active::after {
  content: "";
  position: absolute;
  bottom: -2px; left: 0; right: 0;
  height: 2px;
  background: var(--green-main);
}
.tab span {
  background: var(--warm);
  color: white;
  font-size: .7em;
  padding: 1px 7px;
  border-radius: 99px;
  font-family: var(--f-num);
}
.tab span:empty { display: none; }

.review-item {
  background: white;
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.review-item-info { flex: 1; min-width: 0; }
.review-item-cat { font-size: .8em; color: var(--green-deep); font-weight: 600; }
.review-item-text {
  font-size: .9em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.review-start {
  background: var(--green-main);
  color: white;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: .85em;
  flex-shrink: 0;
}
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-mute);
}
.empty-state .empty-capy { margin-bottom: 10px; }
.empty-state .empty-capy img { width: 200px; max-width: 60%; }

/* ============================================ */
/* 統計画面 */
/* ============================================ */
.stat-grid-big {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.big-stat {
  background: white;
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.big-stat-num {
  font-family: var(--f-num);
  font-weight: 800;
  font-size: 1.8em;
  color: var(--green-deep);
  line-height: 1.1;
}
.big-stat-num span { font-size: .55em; font-weight: 600; }
.big-stat-label { font-size: .8em; color: var(--text-mute); margin-top: 2px; }

.stats-h3 {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1em;
  color: var(--green-deep);
  margin: 22px 0 10px;
}
.chart-wrap {
  background: white;
  border-radius: var(--r-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.weak-unit-row {
  background: white;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
}
.weak-unit-row .wu-name { font-size: .9em; }
.weak-unit-row .wu-rate {
  font-family: var(--f-num);
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .85em;
}
.wu-rate.low { background: #faecea; color: var(--danger); }
.wu-rate.mid { background: var(--warm-light); color: #a06030; }
.wu-rate.high { background: #ecf6ed; color: var(--success); }

/* ============================================ */
/* 学習ガイド */
/* ============================================ */
.guide-card {
  background: white;
  border-radius: var(--r-md);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.guide-card h3 {
  font-family: var(--f-display);
  font-weight: 700;
  color: var(--green-deep);
  margin: 0 0 10px;
}
.guide-card ol, .guide-card p { margin: 0; line-height: 1.8; }
.guide-card ol { padding-left: 22px; }
.guide-card li { margin: 6px 0; }

/* ============================================ */
/* 設定 */
/* ============================================ */
.settings-list {
  background: white;
  border-radius: var(--r-md);
  padding: 4px 0;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.setting-row:last-child { border-bottom: none; }
.setting-row label { font-weight: 600; font-size: .95em; }
.setting-row.danger { background: #fdf6f4; }

.btn-danger {
  background: white;
  color: var(--danger);
  border: 1.5px solid var(--danger);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: .85em;
}
.btn-danger:hover { background: var(--danger); color: white; }

.settings-meta {
  text-align: center;
  color: var(--text-mute);
  font-size: .8em;
}
.settings-meta p { margin: 4px 0; }

/* ============================================ */
/* 小型レスポンシブ */
/* ============================================ */
@media (max-width: 380px) {
  .home-stats { gap: 6px; }
  .stat-num { font-size: 1.3em; }
  .stat-label { font-size: .7em; }
  .menu-card { padding: 12px 10px; }
  .quiz-card { padding: 16px 14px; }
  .quiz-question { font-size: 1.05em; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
