/* ===== にほんごステップ — モバイルファースト・フラットデザイン ===== */
:root {
  --green: #58cc02;
  --green-dark: #46a302;
  --green-bg: #d7ffb8;
  --green-text: #58a700;
  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-bg: #ffdfe0;
  --red-text: #ea2b2b;
  --blue: #1cb0f6;
  --blue-dark: #1899d6;
  --orange: #ff9600;
  --ink: #3c3c3c;
  --muted: #777;
  --line: #e5e5e5;
  --line-dark: #cecece;
  --bg: #fff;
  --soft: #f7f7f7;
  --radius: 16px;
  --tap: 48px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #f0f0f0;
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ビューポート制限コンテナ */
.app {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line);
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
}
.screen.is-active { display: flex; animation: fade-in .25s ease-out; }

@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 20px;
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: .04em;
  cursor: pointer;
  user-select: none;
  transition: transform .08s, filter .15s;
}
.btn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; margin-top: 2px; }
.btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible, .speak-btn:focus-visible, .mic-btn:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--green); border-color: var(--green-dark); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn-primary:disabled { background: var(--line); border-color: var(--line); color: #afafaf; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--blue); }
.btn-success { background: var(--green); border-color: var(--green-dark); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red-dark); color: #fff; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border: none;
  background: none;
  color: #afafaf;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 12px;
}
.icon-btn:hover { background: var(--soft); }

/* ===== ホーム ===== */
.home-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.header-right { display: flex; align-items: center; gap: 4px; }
.bgm-toggle { font-size: 1.25rem; color: var(--ink); }
.bgm-toggle.is-muted { opacity: .45; }
.bgm-toggle.small { width: 44px; height: 44px; font-size: 1.1rem; }
.brand { margin: 0; font-size: 1.5rem; font-weight: 900; color: var(--green); letter-spacing: .02em; }
.brand span { color: var(--ink); }

.streak-pill {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 4px 12px;
  border-radius: 999px; background: #fff4e5;
  color: var(--orange); font-weight: 900; font-size: 1.1rem;
}
.streak-pill.small { min-height: 32px; padding: 2px 10px; font-size: 1rem; flex: none; }

.hero-card {
  text-align: center;
  padding: 24px 16px 18px;
  border: 2px solid var(--line);
  border-radius: 20px;
  margin-bottom: 16px;
}
.hero-count { margin: 4px 0 0; font-size: 2.6rem; font-weight: 900; color: var(--orange); }
.hero-count small { font-size: 1rem; margin-left: 4px; color: var(--ink); }
.hero-sub { margin: 4px 0 12px; color: var(--muted); font-weight: 600; }
.freeze-row {
  display: inline-flex; gap: 10px; align-items: center;
  padding: 6px 14px; border-radius: 999px;
  background: #ddf4ff; color: var(--blue-dark); font-weight: 700; font-size: .9rem;
}

.stats-grid, .complete-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.complete-stats { grid-template-columns: repeat(2, 1fr); }
.stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px 6px; border: 2px solid var(--line); border-radius: var(--radius);
}
.stat-num { font-size: 1.5rem; font-weight: 900; }
.stat-label { font-size: .78rem; color: var(--muted); font-weight: 700; }

.level-picker { margin-bottom: 14px; }
.level-picker-label { margin: 0 0 8px; font-weight: 800; font-size: .95rem; }
.level-picker-note { margin: 6px 0 0; font-size: .78rem; color: var(--muted); }
.segmented { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 6px; }
.segmented button {
  min-height: var(--tap);
  border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 12px;
  background: #fff; color: var(--muted);
  font: inherit; font-weight: 900; font-size: .95rem; cursor: pointer;
}
.segmented button:active { transform: translateY(2px); border-bottom-width: 2px; }
.segmented button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.segmented button[aria-checked="true"] { background: #ddf4ff; border-color: #84d8ff; color: var(--blue-dark); }
.level-row.is-dim { opacity: .4; }
.level-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.level-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; }
.level-row .badge { justify-self: start; }
.level-bar { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.level-bar > div { height: 100%; background: var(--green); border-radius: 999px; transition: width .4s ease-out; }
.level-count { font-size: .8rem; color: var(--muted); font-weight: 700; min-width: 3.5em; text-align: right; }

.data-panel { margin-top: 20px; border: 2px solid var(--line); border-radius: var(--radius); padding: 0 16px; }
.data-panel summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; font-weight: 800; color: var(--muted); }
.data-note { margin: 0 0 12px; font-size: .85rem; color: var(--muted); }
.data-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-bottom: 16px; }

/* ===== レッスン ===== */
.screen-lesson { padding-bottom: 0; }
.lesson-header { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }

.progress { flex: 1; height: 16px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  position: relative;
  transition: width 0.3s ease-out;
}
.progress-fill::after { /* ハイライト */
  content: ""; position: absolute; left: 8px; right: 8px; top: 4px; height: 4px;
  background: rgba(255,255,255,.35); border-radius: 999px;
}

.lesson-body { flex: 1; display: flex; flex-direction: column; }

.q-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 8px;
  font-weight: 900; font-size: .85rem; color: #fff; background: var(--green);
}
.badge.N4 { background: var(--blue); }
.badge.N3 { background: #ce82ff; }
.badge.N2 { background: var(--orange); }
.q-category { font-size: .85rem; font-weight: 700; color: var(--muted); }
.retry-tag { font-size: .8rem; font-weight: 800; color: var(--orange); background: #fff4e5; padding: 2px 8px; border-radius: 8px; }

.q-instruction { margin: 0 0 16px; font-size: 1.35rem; font-weight: 900; }

.q-prompt-row { display: flex; align-items: flex-end; gap: 8px; }
.q-bubble {
  position: relative; flex: 1; display: flex; align-items: flex-start; gap: 10px;
  padding: 10px; border: 2px solid var(--line); border-radius: 16px; margin-bottom: 18px;
}
.q-bubble::before, .q-bubble::after { /* しっぽ（左向き） */
  content: ""; position: absolute; left: -12px; bottom: 18px;
  border: 6px solid transparent; border-right: 6px solid var(--line); border-top-width: 6px;
}
.q-bubble::after { left: -9px; border-right-color: #fff; }
.speak-btn {
  flex: none;
  width: 52px; height: 52px;
  border: none; border-radius: 14px;
  background: var(--blue); color: #fff; font-size: 1.5rem;
  box-shadow: 0 4px 0 var(--blue-dark);
  cursor: pointer;
}
.speak-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--blue-dark); }
.speak-btn.is-speaking { animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.q-prompt {
  margin: 0;
  padding: 4px 2px;
  font-size: 1.2rem;
  line-height: 2.1;
  font-weight: 600;
  flex: 1;
}
.blank { white-space: nowrap; color: var(--blue-dark); }
ruby rt { font-size: .55em; color: var(--muted); font-weight: 500; }
.q-meaning { margin: 8px 0 16px; color: var(--muted); font-size: .9rem; min-height: 1.2em; }

/* トークン */
.answer-area {
  min-height: 64px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  padding: 8px 0 12px;
  border-bottom: 2px solid var(--line);
  margin-bottom: 20px;
}
.answer-area.is-choice { display: none; }

.token-bank { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.token-bank.is-choice { display: grid; grid-template-columns: 1fr; gap: 10px; }

.chip {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  animation: chip-pop .18s ease-out;
  transition: background .15s, border-color .15s, opacity .15s;
}
.chip:hover { background: var(--soft); }
.chip:active { transform: translateY(2px); border-bottom-width: 2px; }
@keyframes chip-pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.chip.is-placeholder { /* バンクに残る空き枠 */
  background: var(--line); border-color: var(--line); color: transparent; pointer-events: none; animation: none;
}
.chip.choice { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; }
.chip.choice .key {
  flex: none; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 8px; font-size: .8rem; color: var(--muted);
}
.chip.choice.is-selected { background: #ddf4ff; border-color: #84d8ff; color: var(--blue-dark); }
.chip.choice.is-selected .key { border-color: #84d8ff; color: var(--blue-dark); }
.chip:disabled { cursor: default; }

.mic-row { display: flex; align-items: center; gap: 10px; margin: 20px 0 12px; flex-wrap: wrap; }
.mic-btn {
  min-height: 44px; padding: 8px 14px; border-radius: 12px;
  border: 2px solid var(--line); border-bottom-width: 4px; background: #fff;
  font: inherit; font-weight: 800; color: var(--blue); cursor: pointer;
}
.mic-btn.is-listening { border-color: var(--red); color: var(--red); animation: pulse .9s ease-in-out infinite; }
.mic-btn[hidden] { display: none; }
.mic-status { font-size: .85rem; color: var(--muted); }
.save-exit-btn {
  margin-left: auto;
  min-height: 44px; padding: 8px 14px; border-radius: 12px;
  border: 2px solid var(--line); border-bottom-width: 4px; background: #fff;
  font: inherit; font-weight: 800; font-size: .9rem; color: var(--muted); cursor: pointer;
}
.save-exit-btn:hover { background: var(--soft); }
.save-exit-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.save-exit-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.lesson-footer {
  position: sticky; bottom: 0;
  margin: 0 -20px;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--line);
  background: #fff;
}

/* ===== ボトムシート ===== */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  transform: translateY(calc(100% + 80px));
  visibility: hidden;
  transition: transform .28s cubic-bezier(.2,.9,.3,1.1), visibility 0s linear .28s;
  z-index: 10;
}
.sheet.is-open { transform: translateY(0); visibility: visible; transition-delay: 0s; }
.sheet-inner { position: relative; padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet.is-correct .sheet-inner { background: var(--green-bg); color: var(--green-text); }
.sheet.is-wrong .sheet-inner { background: var(--red-bg); color: var(--red-text); }
.sheet-title { margin: 0 112px 6px 0; font-size: 1.4rem; font-weight: 900; display: flex; align-items: center; gap: 8px; }
.sheet-answer { margin: 0 112px 4px 0; font-weight: 800; font-size: 1.1rem; line-height: 1.9; }
.sheet-answer:empty, .sheet-explain:empty { display: none; }
.sheet-explain { margin: 0 0 14px; font-size: .95rem; color: var(--ink); line-height: 1.6; }
.sheet.is-correct .btn { background: var(--green); border-color: var(--green-dark); color: #fff; }
.sheet.is-wrong .btn { background: var(--red); border-color: var(--red-dark); color: #fff; }
.sheet .btn { margin-top: 8px; }

/* ===== 完了画面 ===== */
.screen-complete { justify-content: center; }
.complete-inner { text-align: center; }
@keyframes bounce { 0% { transform: scale(.3); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.complete-inner h2 { margin: 8px 0; font-size: 1.8rem; font-weight: 900; color: var(--orange); }
.complete-streak { font-size: 1.4rem; font-weight: 900; color: var(--orange); margin: 0 0 6px; }
.complete-note { color: var(--muted); font-weight: 600; min-height: 1.2em; margin: 0 0 20px; }

/* ===== トースト ===== */
.toast {
  position: absolute; left: 50%; top: 16px;
  transform: translate(-50%, -150%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: #fff; font-weight: 700; font-size: .9rem;
  transition: transform .25s ease-out;
  z-index: 20;
  pointer-events: none;
}
.toast.is-visible { transform: translate(-50%, 0); }
.toast.is-error { background: var(--red-dark); }

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

/* ===== しばお（マスコット） ===== */
.mascot { display: block; height: auto; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.mascot-lg { width: 120px; }
.mascot-sm { width: 84px; flex: none; animation: sway 3s ease-in-out infinite; transform-origin: bottom center; }
.mascot-xl { width: 200px; margin: 0 auto; animation: bounce .7s ease-out; }
@keyframes sway { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }

.mascot-hero { display: flex; align-items: center; justify-content: center; gap: 4px; }
.mascot-hero .mascot { animation: bounce .6s ease-out; }
.bubble {
  position: relative; margin: 0; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: 16px; background: #fff;
  font-weight: 800; font-size: 1rem; max-width: 190px; text-align: left; line-height: 1.5;
}
.bubble-left::before, .bubble-left::after {
  content: ""; position: absolute; left: -13px; top: 50%; transform: translateY(-50%);
  border: 7px solid transparent; border-right-color: var(--line);
}
.bubble-left::after { left: -10px; border-right-color: #fff; }

.sheet-mascot {
  position: absolute; right: 12px; top: -64px; width: 104px;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,.06));
}
.sheet.is-open .sheet-mascot { animation: hop .45s ease-out; }
@keyframes hop { 0% { transform: translateY(30px) scale(.8); opacity: 0; } 70% { transform: translateY(-6px) scale(1.04); opacity: 1; } 100% { transform: none; } }

.screen-streak { justify-content: center; }
.streak-big { margin: 4px 0 0; font-size: 4rem; font-weight: 900; color: var(--orange); line-height: 1; }
.screen-streak h2 { margin: 4px 0 8px; font-size: 1.5rem; font-weight: 900; color: var(--orange); }
.week-dots { display: flex; justify-content: center; gap: 8px; margin: 0 0 24px; }
.week-dots span {
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--line); color: #afafaf; font-size: .8rem; font-weight: 800;
}
.week-dots span.on { background: var(--orange); color: #fff; }

.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; flex: 1; color: var(--muted); font-weight: 700; }

/* ===== 表示言語（JLS と同じ7言語） ===== */
.lang-picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 0 0 14px; }
.lang-btn {
  min-width: 40px; height: 42px; padding: 0 4px;
  font-size: 1.35rem; line-height: 1;
  background: var(--bg); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 12px;
  cursor: pointer;
}
.lang-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.lang-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.lang-btn[aria-pressed="true"] { background: #ddf4ff; border-color: #84d8ff; }

/* 解説の訳（原文の日本語解説の下） */
.sheet-explain-l10n { margin-top: -6px; color: var(--muted); }
.q-prompt[lang]:not([lang="ja"]) { font-size: 1.05rem; }

/* ===== JLS からの起動のみ ===== */
body.is-locked .app { display: none; }
.auth-gate-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: #f0f0f0;
}
.auth-gate-backdrop[hidden] { display: none; }
.auth-gate-card {
  width: 100%; max-width: 420px; padding: 28px 22px 20px;
  text-align: center; background: var(--bg);
  border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 20px;
}
.auth-gate-mascot { width: 110px; height: auto; margin-bottom: 8px; }
.auth-gate-card h2 { margin: 0 0 8px; font-size: 1.3rem; }
.auth-gate-card p { margin: 0 0 20px; line-height: 1.55; color: var(--muted); }
.auth-gate-link { display: flex; text-decoration: none; margin-bottom: 18px; }
.auth-gate-card .lang-picker { margin: 0; }
