/* =========================================================
   G-Test Practice App  |  styles.css
   Light theme (white + gold accent)
   ========================================================= */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f6f1;
  --bg-card: #ffffff;
  --bg-card-hi: #faf8f1;
  --ink: #1a1a1a;
  --ink-muted: #555555;
  --ink-dim: #8a8780;
  --gold: #0fa37c;
  --gold-soft: #2dd4a8;
  --emerald: #0fa37c;
  --emerald-soft: #2dd4a8;
  --amber: #d97706;
  --amber-soft: #f59e0b;
  --red: #c0392b;
  --red-bright: #e74c3c;
  --blue: #2b6cb0;
  --blue-bright: #3182ce;
  --green: #2f855a;
  --green-bright: #38a169;
  --line: #e3e0d4;
  --shadow: 0 4px 14px rgba(40,30,10,.08);
  --shadow-lg: 0 10px 28px rgba(40,30,10,.12);
  --radius: 10px;
  --radius-lg: 16px;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  --font-en: "Trajan Pro", "Times New Roman", "Cinzel", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-jp);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(45,212,168,0.10) 0%, transparent 45%),
    radial-gradient(circle at 80% 100%, rgba(43,108,176,0.05) 0%, transparent 45%);
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(15,163,124,0.18);
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}
.quiz-submit:active,
.btn-result:active,
.btn-action:active,
.quiz-nav-btn:active,
.q-choice:active,
.chapter-card:active,
.view-toggle-btn:active,
.jump-btn:active {
  transform: scale(0.97);
}

.view { display: none; min-height: 100vh; min-height: 100dvh; }
.view.active { display: block; }

/* ========================
   View Toggle (PC / Mobile)
   ======================== */
#view-lp { position: relative; }
.view-toggle {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  z-index: 50;
  box-shadow: var(--shadow);
}
.view-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  padding: 7px 14px;
  font-size: 12px;
  letter-spacing: 0.08em;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-jp);
  transition: background 0.2s, color 0.2s;
}
.view-toggle-btn:hover { color: var(--ink); }
.view-toggle-btn.active {
  background: var(--gold);
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(15,163,124,0.35);
}
.view-toggle-icon { font-size: 14px; line-height: 1; }
.view-toggle-label { line-height: 1; }

/* ========================
   Landing Page
   ======================== */
.lp-header {
  text-align: center;
  padding: 56px 20px 36px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(45,212,168,0.08), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
}

.lp-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lp-logo {
  display: flex;
  align-items: center;
  gap: 14px;
}
.hex {
  width: 60px; height: 60px;
  background:
    linear-gradient(135deg, var(--blue) 0%, var(--blue-bright) 100%);
  clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.hex-inner {
  width: 36px; height: 36px;
  background: var(--bg);
  clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%);
  position: relative;
}
.hex-inner::before {
  content: "G";
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-en);
  font-weight: bold;
  color: var(--blue-bright);
  font-size: 22px;
}
.brand-text {
  display: flex; flex-direction: column;
  text-align: left;
  letter-spacing: 0.05em;
  color: var(--blue-bright);
}
.brand-line1 { font-size: 11px; }
.brand-line2 { font-size: 14px; }
.brand-line3 { font-size: 26px; font-weight: 700; }

.lp-banner {
  display: inline-block;
  background: var(--blue);
  color: #ffffff;
  padding: 6px 24px;
  font-size: 13px;
  letter-spacing: 0.18em;
  clip-path: polygon(8% 0, 100% 0, 92% 100%, 0% 100%);
}

.lp-title {
  margin: 28px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lp-title-main {
  font-size: 56px;
  letter-spacing: 0.08em;
  font-weight: 900;
  background: linear-gradient(180deg, #d4af37 0%, #b8901c 60%, #8a6d14 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(180,140,30,0.15);
}
.lp-title-sub {
  font-family: var(--font-en);
  letter-spacing: 0.45em;
  color: #b8901c;
  font-size: 14px;
  margin-top: 6px;
}
.lp-tagline {
  color: var(--ink-muted);
  font-size: 14px;
  margin: 12px 0 0;
}

/* Stats */
.lp-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  max-width: 1100px;
  margin: 32px auto 0;
  padding: 0 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.stat-label { display: block; font-size: 12px; color: var(--ink-dim); letter-spacing: 0.1em; }
.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 4px;
  font-family: var(--font-en);
}

/* Action buttons */
.lp-actions {
  max-width: 1100px;
  margin: 24px auto 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.btn-action {
  text-align: left;
  padding: 18px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--ink);
  transition: all 0.2s;
  display: flex; flex-direction: column; gap: 4px;
}
.btn-action:hover {
  border-color: var(--gold);
  background: var(--bg-card-hi);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.btn-action-title { font-weight: 700; font-size: 15px; color: var(--gold-soft); }
.btn-action-sub { font-size: 12px; color: var(--ink-muted); }
.btn-action-wrong .btn-action-title { color: var(--red-bright); }
.btn-action-random .btn-action-title { color: var(--ink); }
.btn-action-reset { opacity: 0.75; }
.btn-action-reset .btn-action-title { color: var(--ink-muted); }

/* Backup section */
.lp-backup {
  max-width: 1100px;
  margin: 28px auto 0;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.lp-backup-text { font-size: 12.5px; color: var(--ink-muted); line-height: 1.55; flex: 1; min-width: 0; }
.lp-backup-text strong { display: block; color: var(--ink); font-size: 13px; margin-bottom: 2px; }
.lp-backup-text small { display: block; font-size: 11px; color: var(--ink-dim); margin-top: 1px; }
.lp-backup-text small.warn { color: var(--red-bright); font-weight: 600; }
.lp-backup-buttons { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }
.btn-backup {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-backup:hover { border-color: var(--gold); color: var(--gold); background: #f3fbf6; }
.btn-backup:active { transform: scale(0.96); }
.btn-backup-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  border-color: var(--gold);
  color: #ffffff;
  font-weight: 700;
}
.btn-backup-primary:hover {
  background: linear-gradient(135deg, var(--gold), var(--gold));
  color: #ffffff;
  border-color: var(--gold);
}

/* Section title */
.lp-section-title {
  max-width: 1100px;
  margin: 48px auto 16px;
  padding: 0 20px;
  font-size: 22px;
  letter-spacing: 0.1em;
  color: var(--gold-soft);
  border-left: 4px solid var(--gold);
  padding-left: 16px;
}

/* Chapters */
.lp-chapters {
  max-width: 1100px;
  margin: 0 auto 48px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.chapter-card {
  display: grid;
  grid-template-columns: 90px 1fr;
  background: linear-gradient(135deg, #ffffff 0%, #faf8f0 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}
.chapter-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--emerald), var(--emerald-soft));
  opacity: 0.9;
}
.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--emerald);
  background: linear-gradient(135deg, #ffffff 0%, #e6faf2 100%);
}
.chapter-num {
  display: flex; flex-direction: column;
  justify-content: center;
  align-items: center;
  border-right: 1px solid var(--line);
  padding-right: 16px;
}
.chapter-num-en { font-family: var(--font-en); font-size: 11px; color: var(--ink-dim); letter-spacing: 0.2em; }
.chapter-num-val { font-family: var(--font-en); font-size: 42px; color: var(--emerald); font-weight: 700; line-height: 1; margin-top: 4px; }
.chapter-num-jp { font-size: 11px; color: var(--ink-dim); margin-top: 4px; }

.chapter-info { padding-left: 18px; display: flex; flex-direction: column; justify-content: center; }
.chapter-title { font-size: 18px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.chapter-subtitle { font-size: 12px; color: var(--ink-muted); margin-bottom: 10px; }
.chapter-meta { display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--ink-dim); flex-wrap: wrap; }
.chapter-meta strong { color: var(--emerald); font-family: var(--font-en); font-weight: 600; }

.chapter-progress {
  height: 4px;
  background: var(--bg-soft);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}
.chapter-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald), var(--emerald-soft));
  width: 0;
  transition: width 0.4s ease;
}

.lp-section-title--study {
  color: var(--amber);
  border-left-color: var(--amber-soft);
}

.lp-section-note {
  max-width: 1100px;
  margin: -8px auto 14px;
  padding: 0 20px 0 20px;
  font-size: 13px;
  color: var(--ink-muted);
}

/* Study chapter list (LP) */
.lp-study {
  max-width: 1100px;
  margin: 0 auto 48px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.study-card-btn {
  display: grid;
  grid-template-columns: 90px 1fr;
  background: linear-gradient(135deg, #ffffff 0%, #fff4e0 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
  text-align: left;
  font: inherit;
  color: inherit;
}
.study-card-btn::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--amber), var(--amber-soft));
  opacity: 0.95;
}
.study-card-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--amber-soft);
  background: linear-gradient(135deg, #ffffff 0%, #ffe7c2 100%);
}
.study-card-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.study-card-btn .chapter-num-val { color: var(--amber); }
.study-card-btn .chapter-title { color: var(--amber); }
.study-card-btn .chapter-subtitle { color: var(--amber-soft); }
.study-cta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--amber);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* LP — Note (tabbed viewer) */
.lp-section-title--note {
  color: var(--blue);
  border-left-color: var(--blue-bright);
}
.lp-note-viewer {
  max-width: 1100px;
  margin: 0 auto 48px;
  padding: 0 20px;
}
.note-tabs {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  align-items: flex-end;
  border-bottom: 2px solid var(--blue);
  padding: 0 4px;
}
.note-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font: inherit;
  color: var(--ink-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.15s;
  margin-bottom: -1px;
  max-width: 220px;
  min-width: 0;
}
.note-tab:hover {
  background: #eef4fb;
  color: var(--blue);
}
.note-tab.active {
  background: #ffffff;
  border-color: var(--blue);
  border-bottom: 2px solid #ffffff;
  color: var(--blue);
  font-weight: 700;
  z-index: 1;
  box-shadow: 0 -2px 6px rgba(43,108,176,0.08);
  margin-bottom: -2px;
}
.note-tab-num {
  font-family: var(--font-en);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: inherit;
  opacity: 0.85;
  white-space: nowrap;
}
.note-tab-title {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}
.note-tab.has-content .note-tab-dot {
  background: var(--blue-bright);
  box-shadow: 0 0 0 2px rgba(49,130,206,0.18);
}

.note-tab-panel {
  background: #ffffff;
  border: 1px solid var(--blue);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 22px 24px 26px;
  box-shadow: var(--shadow);
}
.note-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--line);
  flex-wrap: wrap;
}
.note-panel-titles { min-width: 0; }
.note-panel-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--blue);
}
.note-panel-subtitle {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 4px;
}
.note-panel-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-dim);
  flex-wrap: wrap;
}
.note-panel-meta strong {
  color: var(--blue);
  font-family: var(--font-en);
  font-weight: 600;
}
.note-panel-empty-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink-dim);
  border: 1px solid var(--line);
  font-size: 11px;
}
.note-panel-edit {
  background: var(--blue);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.18s, transform 0.15s;
}
.note-panel-edit:hover { background: var(--blue-bright); }
.note-panel-edit:active { transform: scale(0.97); }
.note-panel-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  min-height: 160px;
  max-height: 60vh;
  overflow: auto;
}
.note-panel-body.is-empty {
  color: var(--ink-dim);
  font-style: italic;
}
.note-card-btn.is-empty {
  background: linear-gradient(135deg, #ffffff 0%, #f5f7fa 100%);
}
.note-card-btn.is-empty .note-card-body {
  color: var(--ink-dim);
  font-style: italic;
}

/* Study (slides reading) page */
.study-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.study-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-soft);
  letter-spacing: 0.05em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.study-main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}
.study-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.slide-figure {
  margin: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.06));
  overflow: hidden;
}
.slide-img-wrap {
  position: relative;
  font-size: 0;
  line-height: 0;
}
.slide-img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}
.slide-mask {
  position: absolute;
  background: #EAD1DC;
  pointer-events: none;
}
.slide-caption {
  padding: 6px 14px 8px;
  font-size: 11px;
  color: var(--ink-dim);
  text-align: right;
  font-family: var(--font-en);
  letter-spacing: 0.1em;
  border-top: 1px solid var(--line);
}
.slide-empty {
  text-align: center;
  color: var(--ink-muted);
  padding: 48px 20px;
}
.slide-error {
  display: none;
  padding: 8px 14px;
  font-size: 11px;
  color: var(--red-bright, #c0392b);
  background: #fff5f5;
  border-top: 1px solid #fecaca;
  word-break: break-all;
}
.slide-figure.slide-broken .slide-img { display: none; }
.slide-figure.slide-broken { background: #fff5f5; min-height: 80px; }
.slide-figure.slide-broken .slide-error { display: block; }
.study-actions {
  margin-top: 28px;
  display: flex;
  justify-content: center;
}
.study-actions .btn-action { max-width: 480px; width: 100%; }

/* ========================
   Study — Note Panel
   ======================== */
.note-toggle {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: var(--gold);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-lg);
  transition: right 0.25s ease, bottom 0.25s ease, transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.note-toggle:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(40,30,10,.16); }
.note-toggle:active { transform: scale(0.97); }
.note-toggle-icon { font-size: 16px; line-height: 1; }
.note-toggle-label { line-height: 1; }
body.note-open .note-toggle {
  background: var(--bg-card);
  color: var(--ink);
  border-color: var(--line);
}

.study-note {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  width: 32vw;
  min-width: 360px;
  max-width: 540px;
  background: var(--bg-card);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 28px rgba(40,30,10,0.10);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 60;
  overscroll-behavior: contain;
}
body.note-open .study-note { transform: translateX(0); }
/* When the Note panel is open, hide the Note toggle and surface the AI
   toggle in its place (left of the Note panel) so the user can switch. */
body.note-open .note-toggle { display: none; }
body.note-open .ai-toggle {
  right: calc(min(32vw, 540px) + 24px);
  /* Compact appearance while Note is the active panel: emoji + "AIチューター" only */
  padding: 8px 12px;
  font-size: 12px;
  gap: 6px;
}
body.note-open .ai-toggle .ai-toggle-icon { font-size: 14px; }
body.note-open .ai-toggle .ai-toggle-label { font-size: 0; max-width: none; }
body.note-open .ai-toggle .ai-toggle-label::after {
  content: "AIチューター";
  font-size: 12px;
}
body.note-open .ai-toggle .ai-toggle-badge { display: none; }
/* When the note panel is open, shift slides left WITHOUT shrinking them.
   Keep max-width unchanged; just stop centering so they sit flush-left. */
#view-study .study-main {
  transition: margin 0.25s ease;
}
body.note-open #view-study .study-main {
  margin-left: 0;
  margin-right: auto;
}

.study-note-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  flex-shrink: 0;
}
.study-note-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.study-note-status {
  flex: 1;
  font-size: 11px;
  color: var(--ink-dim);
  text-align: right;
}
.study-note-close {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: var(--ink-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.study-note-close:hover { background: rgba(0,0,0,0.06); color: var(--ink); }

.study-note-area {
  flex: 1;
  border: 0;
  padding: 16px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background: transparent;
  resize: none;
  outline: none;
  width: 100%;
  overscroll-behavior: contain;
  -webkit-appearance: none;
  appearance: none;
}
.study-note-area::placeholder { color: var(--ink-dim); }

/* ========================
   Study — AIチューター
   ======================== */
.ai-toggle {
  position: fixed;
  right: calc(24px + 110px);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-lg);
  transition: right 0.25s ease, bottom 0.25s ease, transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.ai-toggle:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(43,108,176,.28); }
.ai-toggle:active { transform: scale(0.97); }
.ai-toggle-icon { font-size: 16px; line-height: 1; }
.ai-toggle-label { line-height: 1; }
.ai-toggle-badge {
  display: inline-block;
  padding: 1px 7px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  border-radius: 999px;
  background: rgba(255,255,255,0.28);
  color: #ffffff;
}
/* 未課金時：AIチューターはプレミアム限定（タップでアップグレード導線） */
.ai-toggle.ai-locked .ai-toggle-badge {
  background: #ffffff;
  color: var(--blue);
  letter-spacing: 0.02em;
  font-size: 9px;
}
body.ai-open .ai-toggle {
  background: var(--bg-card);
  color: var(--ink);
  border-color: var(--line);
}
body.ai-open .ai-toggle .ai-toggle-badge {
  background: var(--blue);
  color: #ffffff;
}

.study-ai {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  width: 32vw;
  min-width: 360px;
  max-width: 540px;
  background: var(--bg-card);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 28px rgba(40,30,10,0.10);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 60;
  overscroll-behavior: contain;
}
body.ai-open .study-ai { transform: translateX(0); }
/* When the AI panel is open, hide the AI toggle and surface the Note
   toggle in its place (left of the AI panel) so the user can switch. */
body.ai-open .ai-toggle { display: none; }
body.ai-open .note-toggle {
  right: calc(min(32vw, 540px) + 24px);
}
body.ai-open #view-study .study-main {
  margin-left: 0;
  margin-right: auto;
}

.study-ai-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  flex-shrink: 0;
}
.study-ai-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.study-ai-status {
  flex: 1;
  font-size: 11px;
  color: var(--ink-dim);
  text-align: right;
  margin-right: 4px;
}
.study-ai-icon-btn {
  border: 0;
  background: transparent;
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: var(--ink-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.study-ai-icon-btn:hover { background: rgba(0,0,0,0.06); color: var(--ink); }
.study-ai-close { font-size: 20px; }

.study-ai-messages-wrap {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.study-ai-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-soft);
}
.study-ai-scroll-bottom {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(43,108,176,0.25);
  color: var(--blue);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s, color 0.18s, transform 0.18s, opacity 0.18s, box-shadow 0.18s, border-color 0.18s;
  opacity: 0.85;
  padding: 0;
}
.study-ai-scroll-bottom:hover {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
  transform: translateY(-2px);
  opacity: 1;
  box-shadow: 0 6px 18px rgba(43,108,176,0.30);
}
.study-ai-scroll-bottom:active { transform: scale(0.94); }
.study-ai-scroll-bottom[hidden] { display: none; }
.ai-msg-empty {
  margin: auto;
  text-align: center;
  color: var(--ink-dim);
  padding: 24px 12px;
  max-width: 360px;
}
.ai-msg-empty-icon { font-size: 38px; margin-bottom: 8px; }
.ai-msg-empty-title { font-size: 14px; font-weight: 700; color: var(--ink-muted); margin-bottom: 6px; }
.ai-msg-empty-sub { font-size: 12px; line-height: 1.7; }

.ai-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
}
.ai-msg-label {
  font-size: 10.5px;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
  font-weight: 600;
}
.ai-msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.7;
}
.ai-msg-user { align-self: flex-end; }
.ai-msg-user .ai-msg-label { text-align: right; }
.ai-msg-user .ai-msg-body {
  background: var(--blue);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}
.ai-msg-assistant { align-self: flex-start; }
.ai-msg-assistant .ai-msg-body {
  background: var(--bg-card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.ai-msg-pending .ai-msg-body { padding: 12px 16px; }
.ai-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-dim);
  animation: ai-typing-bounce 1.1s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.study-ai-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-card);
  flex-shrink: 0;
  align-items: stretch;
}
.study-ai-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  outline: none;
  background: var(--bg);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
.study-ai-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(43,108,176,0.15); }
.study-ai-send {
  background: var(--blue);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s, transform 0.15s;
}
.study-ai-send:hover { background: var(--blue-bright); }
.study-ai-send:active { transform: scale(0.97); }
.study-ai-send:disabled { opacity: 0.5; cursor: not-allowed; }
.study-ai-send.is-cancel {
  background: var(--red);
  color: #ffffff;
}
.study-ai-send.is-cancel:hover { background: var(--red-bright); }

/* Per-message actions (edit / regenerate) */
.ai-msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  opacity: 0.55;
  transition: opacity 0.18s;
}
.ai-msg:hover .ai-msg-actions,
.ai-msg-actions:focus-within { opacity: 1; }
.ai-msg-user .ai-msg-actions { justify-content: flex-end; }
.ai-msg-action {
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  font: inherit;
  font-size: 11px;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.ai-msg-action:hover {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}
.ai-msg-action:active { transform: scale(0.95); }
.ai-msg-action:disabled { opacity: 0.4; cursor: not-allowed; }

/* Inline edit mode for a user message */
.ai-msg-editing {
  max-width: 100%;
  align-self: stretch;
}
.ai-msg-editing .ai-msg-label { color: var(--blue); font-weight: 700; }
.ai-msg-edit-input {
  width: 100%;
  min-height: 70px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--blue);
  background: #ffffff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  box-shadow: 0 0 0 2px rgba(43,108,176,0.10);
  -webkit-appearance: none;
  appearance: none;
}
.ai-msg-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}
.ai-msg-edit-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--ink-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}
.ai-msg-edit-btn:hover { background: var(--bg-soft); color: var(--ink); }
.ai-msg-edit-btn:active { transform: scale(0.96); }
.ai-msg-edit-btn.ai-msg-edit-save {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
  font-weight: 700;
}
.ai-msg-edit-btn.ai-msg-edit-save:hover {
  background: var(--blue-bright);
  border-color: var(--blue-bright);
  color: #ffffff;
}

.study-ai-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 12px 10px;
  font-size: 10.5px;
  color: var(--ink-dim);
  background: var(--bg-card);
  border-top: 1px dashed var(--line);
}
.study-ai-foot code { font-family: var(--font-en); font-size: 11px; }
.study-ai-foot-warn { color: var(--ink-dim); }

.lp-footer {
  text-align: center;
  padding: 24px 20px 36px;
  font-size: 11px;
  color: var(--ink-dim);
  border-top: 1px solid var(--line);
}
.lp-footer-links {
  font-size: 12.5px;
  margin: 0 0 10px;
}
.lp-footer-links a {
  color: var(--ink-muted);
  text-decoration: none;
}
.lp-footer-links a:hover { color: var(--gold); text-decoration: underline; }
.lp-footer-links span { color: var(--ink-dim); margin: 0 6px; }

/* ========================
   Quiz Page
   ======================== */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.quiz-back {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-muted);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.quiz-back-arrow { font-size: 14px; line-height: 1; }
.quiz-back-text { line-height: 1; }
.quiz-back:hover { border-color: var(--gold); color: var(--gold-soft); }
.quiz-back:active { transform: scale(0.96); }
.quiz-chapter-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-soft);
  letter-spacing: 0.05em;
}
.quiz-timers {
  display: flex;
  align-items: center;
  gap: 14px;
}
.quiz-timer {
  position: relative;
  width: 56px; height: 56px;
}
.quiz-total-timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  line-height: 1.1;
  transition: border-color 0.3s, color 0.3s, background 0.3s;
}
.total-timer-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}
.total-timer-text {
  font-family: var(--font-en);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 2px;
}
.quiz-total-timer.warn { border-color: var(--amber-soft); background: #fff7e6; }
.quiz-total-timer.warn .total-timer-text { color: var(--amber); }
.quiz-total-timer.danger {
  border-color: var(--red-bright);
  background: #fdecea;
}
.quiz-total-timer.danger .total-timer-text { color: var(--red-bright); }
.timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-bg { fill: none; stroke: var(--line); stroke-width: 2.5; }
.timer-fg {
  fill: none;
  stroke: var(--green-bright);
  stroke-width: 2.5;
  stroke-dasharray: 100, 100;
  stroke-linecap: round;
  transition: stroke-dasharray 0.95s linear, stroke 0.4s;
}
.timer-fg.warn { stroke: var(--amber-soft); }
.timer-fg.danger { stroke: var(--red-bright); }
.timer-text {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-en);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.quiz-progress {
  max-width: 900px;
  margin: 20px auto 0;
  padding: 0 24px;
  display: flex; align-items: center; gap: 14px;
}
.quiz-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.quiz-progress-bar::after {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--progress, 0%);
  background: linear-gradient(90deg, var(--gold), var(--gold-soft));
  transition: width 0.3s;
}
.quiz-progress-text {
  font-family: var(--font-en);
  color: var(--ink-muted);
  font-size: 13px;
}

.quiz-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}
.quiz-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
}
.q-number {
  display: inline-block;
  font-family: var(--font-en);
  font-size: 14px;
  color: var(--ink);
  background: var(--gold);
  padding: 4px 12px;
  border-radius: 4px;
  margin-bottom: 16px;
  font-weight: 700;
}
.q-text {
  font-size: 17px;
  line-height: 1.85;
  margin-bottom: 24px;
  white-space: pre-wrap;
}

.q-choices { display: flex; flex-direction: column; gap: 10px; }
.q-choice {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: flex-start;
  background: var(--bg-card-hi);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  color: var(--ink);
}
.q-choice:hover {
  border-color: var(--gold);
  background: #e6faf2;
}
.q-choice-letter {
  font-family: var(--font-en);
  font-weight: 700;
  color: var(--gold);
  font-size: 16px;
}
.q-choice-text {
  font-size: 14.5px;
  line-height: 1.7;
}
.q-choice.selected {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(45,212,168,0.18), rgba(45,212,168,0.05));
  box-shadow: 0 0 0 2px rgba(45,212,168,0.30);
}
.q-choice.selected .q-choice-letter { color: var(--gold); }

.quiz-footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 24px 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.quiz-nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink-muted);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
}
.quiz-nav-btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-soft); }
.quiz-nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.quiz-submit {
  margin-left: auto;
  background: linear-gradient(135deg, var(--red), var(--red-bright));
  border: none;
  color: white;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.08em;
  box-shadow: var(--shadow);
  transition: all 0.2s;
}
.quiz-submit:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }

.quiz-jump {
  display: flex; gap: 4px; flex-wrap: wrap;
  align-items: center;
}
.jump-btn {
  width: 30px; height: 30px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-en);
}
.jump-btn.answered { color: var(--gold-soft); border-color: var(--gold); }
.jump-btn.current {
  background: var(--gold);
  color: #000;
  border-color: var(--gold);
}

/* ========================
   Result Page
   ======================== */
.result-header {
  text-align: center;
  padding: 40px 20px;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--line);
}
.result-title {
  margin: 0 0 16px;
  font-size: 28px;
  letter-spacing: 0.1em;
  color: var(--gold-soft);
}
.result-score { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.result-percent {
  font-family: var(--font-en);
  font-size: 72px;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
}
.result-fraction { font-family: var(--font-en); font-size: 18px; color: var(--ink-muted); }
.result-comment { font-size: 14px; color: var(--ink); margin-top: 8px; }

.result-actions {
  max-width: 900px;
  margin: 24px auto 0;
  padding: 0 24px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-result {
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 22px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: all 0.2s;
}
.btn-result:hover { border-color: var(--gold); color: var(--gold-soft); }
.btn-result-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  border-color: var(--gold);
  color: #000;
  font-weight: 700;
}
.btn-result-primary:hover { color: #000; transform: translateY(-1px); box-shadow: var(--shadow); }

.result-list {
  max-width: 900px;
  margin: 32px auto 60px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.result-item {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green-bright);
  border-radius: var(--radius);
  padding: 18px 22px;
}
.result-item.wrong { border-left-color: var(--red-bright); }
.result-item.skipped { border-left-color: var(--ink-dim); }
.result-item-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 8px;
  font-size: 13px;
}
.result-num { font-family: var(--font-en); color: var(--ink-dim); }
.result-mark {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.result-mark.ok { background: var(--green); color: white; }
.result-mark.ng { background: var(--red); color: white; }
.result-mark.sk { background: var(--ink-dim); color: white; }

.result-q { font-size: 15px; color: var(--ink); margin: 8px 0; line-height: 1.7; white-space: pre-wrap; }
.result-choice { font-size: 13px; color: var(--ink-muted); margin: 4px 0; }
.result-choice.your { color: var(--red-bright); }
.result-choice.your.correct { color: var(--green-bright); }
.result-choice.correct { color: var(--green-bright); }
.result-explain {
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.75;
  border-left: 2px solid var(--gold);
}
.result-explain strong { color: var(--gold-soft); }

/* =========================================================
   Custom Modal
   ========================================================= */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  padding-top: calc(20px + env(safe-area-inset-top));
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.50);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 22px 20px;
  max-width: 420px;
  width: 100%;
  max-height: 86dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: modalIn 0.18s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}
.modal-body {
  font-size: 14px;
  color: var(--ink-muted);
  line-height: 1.65;
  margin-bottom: 20px;
  white-space: pre-line;
}
.modal-prompt-text {
  white-space: pre-wrap;
  margin-bottom: 12px;
  font-size: 13.5px;
  color: var(--ink-muted);
}
.modal-prompt-input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  background: var(--bg);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
.modal-prompt-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(43,108,176,0.15);
}

/* §15 APIキー信頼設計モーダル */
.modal-body--apikey { text-align: left; white-space: normal; }
.apikey-lead {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.6;
  margin: 0 0 12px;
}
.apikey-lead code {
  font-family: var(--font-en, monospace);
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.apikey-field { display: flex; gap: 8px; align-items: stretch; }
.apikey-field .apikey-input { flex: 1; }
.apikey-reveal {
  flex: 0 0 auto;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.apikey-reveal:hover { border-color: var(--blue); color: var(--blue); }
.apikey-trust {
  list-style: none;
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.apikey-trust li {
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-muted);
}
.apikey-trust strong { color: var(--ink); font-weight: 700; }
.apikey-link {
  display: inline-block;
  margin-top: 14px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--blue);
  text-decoration: none;
}
.apikey-link:hover { text-decoration: underline; }
.apikey-delete {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 9px 12px;
  border: 1px solid #e3b9b9;
  border-radius: 8px;
  background: #fbeeee;
  color: #a3372f;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.apikey-delete:hover { background: #f6e0e0; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: stretch;
}
.modal-btn {
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  background: var(--bg-card);
  color: var(--ink);
  min-height: 44px;
  cursor: pointer;
  font-family: var(--font-jp);
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
.modal-btn:active { transform: scale(0.97); }
.modal-cancel { background: var(--bg-soft); color: var(--ink-muted); }
.modal-cancel:hover { color: var(--ink); border-color: var(--ink-dim); }
.modal-confirm {
  background: linear-gradient(135deg, var(--gold), var(--gold-soft));
  color: #ffffff;
  border-color: var(--gold);
}
.modal-confirm:hover { filter: brightness(1.05); }
.modal-confirm.danger {
  background: linear-gradient(135deg, var(--red), var(--red-bright));
  border-color: var(--red);
}

/* Single-button mode (alert) */
.modal.single .modal-cancel { display: none; }
.modal.single .modal-confirm { flex: 1; }

/* =========================================================
   Mobile mode (applied when body.is-mobile via JS)
   Activated automatically on viewports <= 720px, or by the
   PC/Mobile toggle on the LP header.
   ========================================================= */
body.is-mobile { font-size: 14.5px; }

/* Phone-preview frame: when mobile mode is forced on a wider viewport,
   wrap the entire body into a centered column so quiz / result pages
   also render in mobile layout. */
html { background: #f3efe6; }
@media (min-width: 721px) {
  body.is-mobile {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: 0 0 40px rgba(40,30,10,0.10);
    background-color: var(--bg);
  }
  body.is-mobile.quiz-submit-floating .quiz-submit {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    max-width: 456px;
  }
}

/* LP — Header */
body.is-mobile .lp-header {
  padding-top: calc(64px + env(safe-area-inset-top));
  padding-right: 14px;
  padding-bottom: 24px;
  padding-left: 14px;
}
body.is-mobile .lp-logo { gap: 10px; }
body.is-mobile .hex { width: 48px; height: 48px; }
body.is-mobile .hex-inner { width: 28px; height: 28px; }
body.is-mobile .hex-inner::before { font-size: 16px; }
body.is-mobile .brand-line1 { font-size: 10px; }
body.is-mobile .brand-line2 { font-size: 12px; }
body.is-mobile .brand-line3 { font-size: 22px; }
body.is-mobile .lp-banner { font-size: 11px; padding: 5px 18px; letter-spacing: 0.14em; }
body.is-mobile .lp-title { margin: 22px 0 6px; }
body.is-mobile .lp-title-main { font-size: 38px; }
body.is-mobile .lp-title-sub { font-size: 11px; letter-spacing: 0.32em; }
body.is-mobile .lp-tagline { font-size: 12.5px; padding: 0 8px; }

/* LP — Stats (2-column grid) */
body.is-mobile .lp-stats {
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 14px;
  margin-top: 22px;
  max-width: 480px;
}
body.is-mobile .stat-card { padding: 14px 10px; }
body.is-mobile .stat-label { font-size: 11px; letter-spacing: 0.06em; }
body.is-mobile .stat-value { font-size: 22px; }

/* LP — Actions (single column) */
body.is-mobile .lp-actions {
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 0 14px;
  margin-top: 18px;
  max-width: 480px;
}
body.is-mobile .btn-action { padding: 14px 16px; }
body.is-mobile .btn-action-title { font-size: 14px; }
body.is-mobile .btn-action-sub { font-size: 11.5px; }

body.is-mobile .lp-backup {
  flex-direction: column;
  align-items: stretch;
  margin: 22px 14px 0;
  padding: 14px;
  max-width: 480px;
  gap: 12px;
}
body.is-mobile .lp-backup-buttons { width: 100%; }
body.is-mobile .btn-backup { flex: 1; padding: 11px 10px; font-size: 12.5px; min-height: 44px; }

/* LP — Section title */
body.is-mobile .lp-section-title {
  font-size: 18px;
  margin: 36px auto 12px;
  padding-left: 12px;
  padding-right: 14px;
  max-width: 480px;
}

/* LP — Chapters (single column) */
body.is-mobile .lp-chapters {
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 14px;
  margin-bottom: 36px;
  max-width: 480px;
}
body.is-mobile .chapter-card {
  padding: 16px;
  grid-template-columns: 64px 1fr;
}
body.is-mobile .chapter-num { padding-right: 12px; }
body.is-mobile .chapter-num-en { font-size: 9px; letter-spacing: 0.16em; }
body.is-mobile .chapter-num-val { font-size: 30px; }
body.is-mobile .chapter-num-jp { font-size: 10px; }
body.is-mobile .chapter-info { padding-left: 12px; }
body.is-mobile .chapter-title { font-size: 15.5px; }
body.is-mobile .chapter-subtitle { font-size: 11.5px; margin-bottom: 8px; }
body.is-mobile .chapter-meta { gap: 10px; font-size: 11px; }

body.is-mobile .lp-section-note {
  font-size: 11.5px;
  padding: 0 14px;
  max-width: 480px;
  margin: -6px auto 10px;
}
body.is-mobile .lp-study {
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 14px;
  margin-bottom: 36px;
  max-width: 480px;
}
body.is-mobile .study-card-btn {
  padding: 16px;
  grid-template-columns: 64px 1fr;
}

body.is-mobile .lp-note-viewer {
  padding: 0 14px;
  margin-bottom: 36px;
  max-width: 480px;
}
body.is-mobile .note-tabs {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 2px 2px;
  border-bottom-width: 2px;
  scrollbar-width: thin;
}
body.is-mobile .note-tab {
  padding: 7px 10px 6px;
  font-size: 12px;
  flex-shrink: 0;
  max-width: none;
}
body.is-mobile .note-tab-num { font-size: 10px; }
body.is-mobile .note-tab-title {
  display: none;
}
body.is-mobile .note-tab.active .note-tab-title {
  display: inline;
  font-size: 12px;
  max-width: 140px;
}
body.is-mobile .note-tab-panel {
  padding: 16px 14px 18px;
}
body.is-mobile .note-panel-head {
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
}
body.is-mobile .note-panel-title { font-size: 15.5px; }
body.is-mobile .note-panel-subtitle { font-size: 11.5px; }
body.is-mobile .note-panel-meta { gap: 8px; font-size: 11px; }
body.is-mobile .note-panel-edit {
  padding: 7px 12px;
  font-size: 11.5px;
}
body.is-mobile .note-panel-body {
  font-size: 13px;
  padding: 12px 14px;
  min-height: 140px;
  max-height: 55vh;
}

body.is-mobile .study-header { padding: 10px 12px; gap: 8px; }
body.is-mobile .study-header .quiz-back {
  padding: 0;
  width: 40px;
  height: 40px;
  justify-content: center;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-color: var(--line);
  color: var(--ink);
  font-size: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
body.is-mobile .study-header .quiz-back-text { display: none; }
body.is-mobile .study-header .quiz-back-arrow { font-size: 20px; font-weight: 700; }
body.is-mobile .study-title { font-size: 13px; letter-spacing: 0.02em; }
body.is-mobile .study-main { padding: 12px 8px 40px; }
body.is-mobile .study-card { gap: 12px; }
body.is-mobile .slide-caption { padding: 4px 10px 6px; font-size: 10px; }

/* Note panel — mobile (bottom sheet) */
body.is-mobile .note-toggle {
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding: 10px 14px;
  font-size: 13px;
}
body.is-mobile .study-note {
  top: auto;
  right: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 70vh;
  height: 70dvh;
  border-left: 0;
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 28px rgba(40,30,10,0.12);
  transform: translateY(100%);
}
body.is-mobile.note-open .study-note { transform: translateY(0); }
/* Note open: hide Note toggle, surface AI toggle above the sheet so user can switch. */
body.is-mobile.note-open .note-toggle { display: none; }
body.is-mobile.note-open .ai-toggle {
  right: 16px;
  bottom: calc(70dvh + 12px + env(safe-area-inset-bottom, 0px));
  /* Compact variant: emoji + "AIチューター" only, no badge */
  padding: 7px 11px;
  font-size: 11.5px;
  gap: 5px;
}
body.is-mobile.note-open .ai-toggle .ai-toggle-icon { font-size: 13px; }
body.is-mobile.note-open .ai-toggle .ai-toggle-label {
  display: inline;
  font-size: 0;
  max-width: none;
}
body.is-mobile.note-open .ai-toggle .ai-toggle-label::after {
  content: "AIチューター";
  font-size: 11.5px;
}
body.is-mobile.note-open .ai-toggle .ai-toggle-badge { display: none; }
body.is-mobile.note-open #view-study .study-main {
  padding-right: 8px;
  padding-bottom: calc(70dvh + 24px);
}

/* AI panel — mobile (bottom sheet) */
body.is-mobile .ai-toggle {
  right: calc(16px + 88px);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding: 9px 12px;
  font-size: 12px;
  gap: 6px;
}
body.is-mobile .ai-toggle-label {
  font-size: 12px;
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.is-mobile .ai-toggle-badge {
  font-size: 8.5px;
  padding: 1px 5px;
}
@media (max-width: 420px) {
  body.is-mobile .ai-toggle-label { display: none; }
}
body.is-mobile .study-ai {
  top: auto;
  right: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 70vh;
  height: 70dvh;
  border-left: 0;
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 28px rgba(40,30,10,0.12);
  transform: translateY(100%);
}
body.is-mobile.ai-open .study-ai { transform: translateY(0); }
/* AI open: hide AI toggle, surface Note toggle above the sheet so user can switch. */
body.is-mobile.ai-open .ai-toggle { display: none; }
body.is-mobile.ai-open .note-toggle {
  right: 16px;
  bottom: calc(70dvh + 12px + env(safe-area-inset-bottom, 0px));
}
body.is-mobile.ai-open #view-study .study-main {
  padding-right: 8px;
  padding-bottom: calc(70dvh + 24px);
}
body.is-mobile .study-ai-foot {
  font-size: 10px;
}

body.is-mobile .lp-footer { padding: 18px 14px 28px; font-size: 10.5px; }

/* Quiz — Header */
body.is-mobile .quiz-header { padding: 10px 12px; gap: 8px; }
body.is-mobile .quiz-back {
  padding: 0;
  width: 40px;
  height: 40px;
  justify-content: center;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-color: var(--line);
  color: var(--ink);
  font-size: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
body.is-mobile .quiz-back-text { display: none; }
body.is-mobile .quiz-back-arrow { font-size: 20px; font-weight: 700; }
body.is-mobile .quiz-back:hover { color: var(--gold); border-color: var(--gold); }
body.is-mobile .quiz-chapter-title {
  font-size: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
body.is-mobile .quiz-timers { gap: 8px; flex-shrink: 0; }
body.is-mobile .quiz-timer { width: 42px; height: 42px; }
body.is-mobile .timer-text { font-size: 13px; }
body.is-mobile .quiz-total-timer { min-width: 60px; padding: 3px 8px; }
body.is-mobile .total-timer-label { font-size: 9px; letter-spacing: 0.12em; }
body.is-mobile .total-timer-text { font-size: 16px; }

/* Quiz — Progress */
body.is-mobile .quiz-progress { padding: 0 14px; margin-top: 14px; gap: 10px; }
body.is-mobile .quiz-progress-text { font-size: 12px; }

/* Quiz — Card */
body.is-mobile .quiz-main { padding: 14px; }
body.is-mobile .quiz-card { padding: 18px 16px; border-radius: 12px; }
body.is-mobile .q-number { font-size: 12px; padding: 3px 10px; margin-bottom: 12px; }
body.is-mobile .q-text { font-size: 15px; line-height: 1.75; margin-bottom: 18px; }
body.is-mobile .q-choice { padding: 13px 14px; grid-template-columns: 28px 1fr; gap: 4px; }
body.is-mobile .q-choice-letter { font-size: 14px; }
body.is-mobile .q-choice-text { font-size: 14px; line-height: 1.6; }

/* Quiz — Footer (sticky submit only on the last-question-answered state) */
body.is-mobile .quiz-footer {
  padding: 10px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  gap: 8px;
}
body.is-mobile.quiz-submit-floating .quiz-footer {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
body.is-mobile .quiz-nav-btn { padding: 9px 12px; font-size: 12.5px; flex: 1; }
body.is-mobile .quiz-jump {
  order: -1;
  width: 100%;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
body.is-mobile .jump-btn { width: 30px; height: 30px; flex: 0 0 auto; font-size: 12px; }
body.is-mobile .quiz-submit {
  width: 100%;
  margin-left: 0;
  padding: 14px;
  font-size: 14px;
}
body.is-mobile.quiz-submit-floating .quiz-submit {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: auto;
  z-index: 30;
  box-shadow: var(--shadow-lg);
}

/* Result page */
body.is-mobile .result-header { padding: 28px 14px; }
body.is-mobile .result-title { font-size: 22px; margin-bottom: 10px; }
body.is-mobile .result-percent { font-size: 56px; }
body.is-mobile .result-fraction { font-size: 15px; }
body.is-mobile .result-comment { font-size: 13px; padding: 0 12px; }
body.is-mobile .result-actions {
  padding: 0 14px;
  gap: 8px;
  margin-top: 18px;
}
body.is-mobile .btn-result {
  padding: 12px 12px;
  font-size: 13px;
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  text-align: center;
  min-height: 44px;
}
body.is-mobile .btn-result-primary {
  flex: 1 1 100%;
  padding: 14px;
  font-size: 14px;
}
body.is-mobile .result-list {
  padding: 0 14px;
  gap: 10px;
  margin: 22px auto 36px;
}
body.is-mobile .result-item { padding: 14px 16px; }
body.is-mobile .result-q { font-size: 14px; }
body.is-mobile .result-choice { font-size: 12.5px; }
body.is-mobile .result-explain { font-size: 12.5px; padding: 10px 12px; }

/* Toggle button — smaller on mobile */
body.is-mobile .view-toggle {
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  padding: 2px;
}
body.is-mobile .view-toggle-btn { padding: 6px 10px; font-size: 11px; gap: 4px; }
body.is-mobile .view-toggle-icon { font-size: 12px; }

/* =========================================================
   Phase 3a: 有料章（第2〜10章）のロック表示（未課金）
   ========================================================= */
.chapter-card.chapter-locked,
.study-card-btn.chapter-locked { position: relative; overflow: hidden; }
.chapter-card.chapter-locked .chapter-info,
.study-card-btn.chapter-locked .chapter-info { filter: blur(2.5px); opacity: 0.5; pointer-events: none; user-select: none; }
.chapter-card.chapter-locked .chapter-num,
.study-card-btn.chapter-locked .chapter-num { opacity: 0.7; }
.chapter-lock {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0.72));
  border-radius: inherit;
  transition: background 0.15s;
}
.chapter-card.chapter-locked:hover .chapter-lock,
.study-card-btn.chapter-locked:hover .chapter-lock { background: linear-gradient(180deg, rgba(255,255,255,0.2), rgba(255,255,255,0.6)); }
.chapter-lock-icon { font-size: 24px; line-height: 1; }
.chapter-lock-text {
  font-size: 12px;
  font-weight: 700;
  color: #0b7a5c;
  background: #e6f7f1;
  border: 1px solid #b9e6d6;
  border-radius: 9999px;
  padding: 5px 14px;
}
