/* ==========================================================================
   たっぷらーん - デザインシステム
   暖色系・軽いゲーム感・モバイルファースト（320px〜）
   ========================================================================== */

:root {
  /* カラー: ライトモード（既定） */
  --color-primary: #FF8A3D;       /* オレンジ */
  --color-primary-dark: #E86F1F;
  --color-accent-coral: #FF6B6B;  /* コーラル */
  --color-accent-yellow: #FFC94A; /* 黄色 */
  --color-bg: #FFFBF2;            /* アイボリー */
  --color-surface: #FFFFFF;
  --color-text: #3A2A1E;
  --color-text-muted: #8A7361;
  --color-border: #F0DFC9;
  --color-remembered: #3EA55C;    /* グリーン */
  --color-review: #FF7A45;        /* オレンジ系のまだ */
  --color-danger: #E14848;
  --shadow-card: 0 4px 14px rgba(120, 72, 20, 0.12);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --font-size-base: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --color-bg: #2B2118;            /* ダークブラウン */
  --color-surface: #3A2C20;
  --color-text: #F5E9D8;
  --color-text-muted: #C7AD93;
  --color-border: #4C3A2A;
  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.4);
}

[data-font-size="small"] { --font-size-base: 14px; }
[data-font-size="medium"] { --font-size-base: 16px; }
[data-font-size="large"] { --font-size-base: 19px; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--font-size-base);
  line-height: 1.6;
  min-width: 320px;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--color-primary-dark); }

button {
  font-family: inherit;
  font-size: 1em;
  cursor: pointer;
}

/* フォーカス表示 */
:focus-visible {
  outline: 3px solid var(--color-accent-yellow);
  outline-offset: 2px;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---- ヘッダー ---- */
.app-header {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent-coral));
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-card);
}
.app-header__back {
  background: rgba(255,255,255,0.25);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
}
.app-header__title {
  font-weight: 700;
  font-size: 1.15em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header__logo {
  font-weight: 800;
  letter-spacing: 0.02em;
}

/* ---- オフラインバナー ---- */
.offline-banner {
  background: var(--color-accent-yellow);
  color: #4a3200;
  font-size: 0.85em;
  padding: 8px 14px;
  text-align: center;
  display: none;
}
.offline-banner.show { display: block; }

/* ---- メイン ---- */
.app-main {
  flex: 1;
  padding: 16px 16px calc(24px + var(--safe-bottom));
}

/* ---- ホームカード ---- */
.home-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
.home-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  width: 100%;
  min-height: 64px;
  color: var(--color-text);
}
.home-card__icon {
  font-size: 1.8em;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--color-accent-yellow);
  flex-shrink: 0;
}
.home-card__body { flex: 1; }
.home-card__title { font-weight: 700; margin-bottom: 2px; }
.home-card__desc { font-size: 0.85em; color: var(--color-text-muted); }

.section-title {
  font-size: 1em;
  font-weight: 700;
  margin: 20px 0 8px;
  color: var(--color-text);
}

/* ---- 最近学習カード（横スクロール） ---- */
.recent-scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.recent-chip {
  flex: 0 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  min-width: 160px;
  box-shadow: var(--shadow-card);
  text-align: left;
}
.recent-chip__title { font-weight: 700; font-size: 0.9em; margin-bottom: 4px; }
.recent-chip__meta { font-size: 0.75em; color: var(--color-text-muted); }

.empty-state {
  color: var(--color-text-muted);
  text-align: center;
  padding: 24px 12px;
  font-size: 0.9em;
}

/* ---- リスト（レベル/教科/単元/問題集） ---- */
.list-group { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  width: 100%;
  text-align: left;
  color: var(--color-text);
}
.list-item__title { font-weight: 600; }
.list-item__meta { font-size: 0.8em; color: var(--color-text-muted); }
.list-item__chevron { color: var(--color-primary); font-size: 1.2em; }

.breadcrumb {
  font-size: 0.8em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  font-weight: 700;
  transition: transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-secondary { background: var(--color-surface); color: var(--color-primary-dark); border: 2px solid var(--color-primary); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-block { width: 100%; }
.btn-remembered { background: var(--color-remembered); color: #fff; }
.btn-review { background: var(--color-review); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  .btn, .card-flip, * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---- 出題設定画面 ---- */
.option-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.option-chip {
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  text-align: center;
  font-weight: 600;
  min-height: 44px;
}
.option-chip.selected {
  border-color: var(--color-primary);
  background: rgba(255, 138, 61, 0.12);
  color: var(--color-primary-dark);
}

/* ---- 学習進捗ゲージ ---- */
.progress-gauge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
}
.progress-gauge__bar {
  flex: 1;
  height: 10px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-gauge__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent-yellow));
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-gauge__label {
  font-size: 0.8em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ---- フラッシュカード ---- */
.card-stage {
  perspective: 1200px;
  margin: 16px 0;
}
.card-flip {
  position: relative;
  min-height: 320px;
  border-radius: var(--radius-lg);
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
  cursor: pointer;
}
.card-flip.flipped { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  max-height: 60vh;
}
.card-face--back { transform: rotateY(180deg); }
.card-face__label {
  font-size: 0.75em;
  font-weight: 700;
  color: var(--color-primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.card-face__content { flex: 1; font-size: 1.05em; word-break: break-word; }
.card-face__content img { max-width: 100%; border-radius: var(--radius-sm); margin-top: 8px; }
.card-face__hint {
  margin-top: 14px;
  text-align: center;
  font-size: 0.85em;
  color: var(--color-text-muted);
}
.card-face__explanation {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--color-border);
  font-size: 0.9em;
  color: var(--color-text-muted);
}

/* スワイプ演出 */
.card-stage.swiping-right .card-flip { transform: translateX(40px) rotate(4deg); }
.card-stage.swiping-left .card-flip { transform: translateX(-40px) rotate(-4deg); }
.swipe-indicator {
  position: absolute;
  top: 16px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9em;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.swipe-indicator--right { right: 16px; background: var(--color-remembered); color: #fff; }
.swipe-indicator--left { left: 16px; background: var(--color-review); color: #fff; }
.card-stage.swiping-right .swipe-indicator--right { opacity: 1; }
.card-stage.swiping-left .swipe-indicator--left { opacity: 1; }

.judge-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.judge-buttons .btn { flex-direction: column; padding: 16px 8px; font-size: 1.05em; }
.judge-buttons .btn .icon { font-size: 1.4em; }

.undo-toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-bg);
  padding: 10px 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-card);
  z-index: 50;
  font-size: 0.9em;
}
[data-theme="dark"] .undo-toast { background: var(--color-accent-yellow); color: #3a2200; }

.success-burst {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 60;
}
.success-burst__emoji {
  font-size: 3em;
  animation: pop-in 0.5s ease;
}
@keyframes pop-in {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

/* ---- モーダル / ダイアログ ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 18, 8, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
}
.modal-sheet {
  background: var(--color-surface);
  border-radius: 20px 20px 0 0;
  padding: 22px 18px calc(22px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}
.modal-sheet--center {
  border-radius: var(--radius-lg);
  margin: auto;
}
.modal-title { font-weight: 700; font-size: 1.1em; margin-bottom: 10px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* 全画面広告モック */
.ad-overlay {
  position: fixed;
  inset: 0;
  background: #201812;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  text-align: center;
}
.ad-overlay__badge {
  background: var(--color-accent-yellow);
  color: #3a2200;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8em;
  margin-bottom: 16px;
}
.ad-overlay__box {
  width: 100%;
  max-width: 320px;
  aspect-ratio: 4/3;
  border: 2px dashed rgba(255,255,255,0.4);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1em;
  margin-bottom: 20px;
}

/* ---- リザルト ---- */
.result-hero {
  text-align: center;
  padding: 24px 12px;
}
.result-hero__emoji { font-size: 3em; }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.result-stat {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 12px 6px;
  text-align: center;
  border: 1px solid var(--color-border);
}
.result-stat__value { font-size: 1.4em; font-weight: 800; }
.result-stat--remembered .result-stat__value { color: var(--color-remembered); }
.result-stat--review .result-stat__value { color: var(--color-review); }
.result-stat__label { font-size: 0.75em; color: var(--color-text-muted); }

/* ---- 履歴 ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 4px;
  text-align: center;
}
.stat-box__value { font-weight: 800; font-size: 1.2em; }
.stat-box__label { font-size: 0.7em; color: var(--color-text-muted); }

.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 0.85em; }
.bar-row__label { width: 92px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row__track { flex: 1; height: 10px; background: var(--color-border); border-radius: 999px; overflow: hidden; }
.bar-row__fill { height: 100%; background: linear-gradient(90deg, var(--color-remembered), var(--color-accent-yellow)); }
.bar-row__value { width: 44px; text-align: right; flex-shrink: 0; }

/* ---- 設定 ---- */
.settings-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
}
.settings-section h2 { font-size: 1em; margin: 0 0 10px; }
.toggle-row { display: flex; gap: 10px; }
.toggle-row button { flex: 1; }

/* ---- フォーム ---- */
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 0.85em; font-weight: 600; margin-bottom: 4px; }
.form-field input[type="file"],
.form-field input[type="text"],
.form-field input[type="password"] {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 44px;
}

.error-box {
  background: rgba(225, 72, 72, 0.1);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85em;
  margin-top: 8px;
}
.error-box ul { margin: 6px 0 0; padding-left: 18px; }

.tag-badge {
  display: inline-block;
  font-size: 0.7em;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-accent-yellow);
  color: #4a3200;
}
.tag-badge.draft { background: var(--color-border); color: var(--color-text-muted); }

/* ---- タブ ---- */
.tab-bar { display: flex; gap: 8px; margin-bottom: 14px; border-bottom: 1px solid var(--color-border); }
.tab-bar button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0;
  font-weight: 700;
  color: var(--color-text-muted);
  border-bottom: 3px solid transparent;
  min-height: 44px;
}
.tab-bar button.active { color: var(--color-primary-dark); border-bottom-color: var(--color-primary); }

/* ユーティリティ */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.text-muted { color: var(--color-text-muted); }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

@media (min-width: 480px) {
  .app-shell { border-left: 1px solid var(--color-border); border-right: 1px solid var(--color-border); }
}
