/* Farbwelt: elegantes Schiefergrau (fest, unabhängig vom Hell/Dunkel-Modus des Geräts) */
:root {
  --bg: #2F333B;
  --bg-2: #393E47;
  --card: #3B404A;
  --ink: #EEF0F4;
  --ink-2: #A9B0BC;
  --line: #4B515C;
  --accent: #FF6B6B;
  --accent-2: #FFB84C;
  --good: #2EC4B6;
  --good-bg: #1E4845;
  --bad: #EF476F;
  --bad-bg: #55303B;
  --warn-bg: #4A4331;
  --romaji: #B7A8FF;
  --shadow: 0 6px 0 rgba(0, 0, 0, .22), 0 10px 24px rgba(0, 0, 0, .22);
  --radius: 22px;
  --tabbar-h: 68px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: 'M PLUS Rounded 1c', system-ui, 'Hiragino Maru Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
[hidden] { display: none !important; }

/* ── Kopfleiste ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand { font-weight: 800; font-size: 1.15rem; }
.chips { display: flex; gap: 6px; align-items: center; }
.chip {
  background: var(--card); border-radius: 999px; padding: 5px 10px;
  font-weight: 700; font-size: .9rem; box-shadow: 0 2px 0 var(--line);
}
.icon-btn { background: none; border: 0; font-size: 1.3rem; padding: 4px; }

main { padding: 6px 16px 24px; max-width: 640px; margin: 0 auto; outline: none; }

/* ── Tabbar ─────────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 2px solid var(--line);
}
.tabbar button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: .72rem; font-weight: 700; color: var(--ink-2);
}
.tabbar button span { font-size: 1.45rem; transition: transform .15s; }
.tabbar button.active { color: var(--accent); }
.tabbar button.active span { transform: translateY(-2px) scale(1.12); }

/* ── Allgemeine Bausteine ───────────────────────────────── */
.section-title { font-size: 1.05rem; font-weight: 800; margin: 20px 2px 10px; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 16px; padding: 14px 18px; font-weight: 800; font-size: 1rem;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 65%, #000);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 65%, #000); }
.btn.secondary { background: var(--card); color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.block { width: 100%; }
.btn.good { background: var(--good); box-shadow: 0 4px 0 color-mix(in srgb, var(--good) 65%, #000); }
.btn.bad { background: var(--bad); box-shadow: 0 4px 0 color-mix(in srgb, var(--bad) 65%, #000); }
.btn.warn { background: var(--accent-2); box-shadow: 0 4px 0 color-mix(in srgb, var(--accent-2) 65%, #000); color: #3a2a00; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.round-btn {
  width: 52px; height: 52px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center; font-size: 1.4rem;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 65%, #000);
}
.round-btn:active { transform: translateY(3px); box-shadow: none; }
.round-btn.mic { background: #7B61FF; box-shadow: 0 4px 0 #4C3AB5; }
.round-btn.mic.listening { animation: pulse 1s infinite; }
.round-btn.big { width: 84px; height: 84px; font-size: 2.2rem; }
.round-btn.playing { animation: pulse .8s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

/* ── Start ──────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #FF6B6B, #FFB84C);
  color: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px;
}
.hero h1 { font-size: 1.35rem; }
.hero p { margin: 4px 0 12px; opacity: .95; }
.hero .btn { background: #fff; color: var(--accent); box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.ring { --p: 0; width: 86px; height: 86px; flex: none; border-radius: 50%;
  background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255,255,255,.3) 0);
  display: grid; place-items: center; }
.ring > div { width: 68px; height: 68px; border-radius: 50%; background: #FF8F5A;
  display: grid; place-items: center; text-align: center; font-weight: 800; font-size: .8rem; line-height: 1.1; }
.ring b { font-size: 1.2rem; display: block; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--card); border-radius: 18px; padding: 12px; text-align: center; box-shadow: 0 3px 0 var(--line); }
.stat b { display: block; font-size: 1.4rem; }
.stat span { font-size: .75rem; color: var(--ink-2); font-weight: 700; }

.level { margin-top: 12px; background: var(--card); border-radius: 18px; padding: 12px 14px; box-shadow: 0 3px 0 var(--line); }
.bar { height: 12px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #FFB84C, #FF6B6B); }

.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cat-tile {
  border: 0; text-align: left; border-radius: 20px; padding: 14px; color: #fff;
  background: var(--c); box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 60%, #000);
  display: flex; flex-direction: column; gap: 6px; min-height: 118px; position: relative; overflow: hidden;
}
.cat-tile:active { transform: translateY(3px); box-shadow: 0 2px 0 color-mix(in srgb, var(--c) 60%, #000); }
.cat-tile .emoji { font-size: 2rem; }
.cat-tile .name { font-weight: 800; font-size: .98rem; line-height: 1.15; }
.cat-tile .meta { font-size: .75rem; opacity: .95; margin-top: auto; font-weight: 700; }
.cat-tile .bar { background: rgba(255,255,255,.35); height: 8px; margin-top: 4px; }
.cat-tile .bar > i { background: #fff; }
.cat-tile .badge { position: absolute; top: 10px; right: 10px; background: rgba(255,255,255,.95); color: var(--c);
  font-weight: 800; font-size: .7rem; padding: 2px 8px; border-radius: 99px; }

/* ── Phrasen-Darstellung ────────────────────────────────── */
.phrase { display: flex; flex-direction: column; gap: 6px; }
.phrase .jp { font-size: 2rem; font-weight: 800; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere; }
.phrase .kana { font-size: 1.05rem; color: var(--ink-2); }
.phrase .romaji { font-size: 1.2rem; font-weight: 700; color: var(--romaji); }
.phrase .de { font-size: 1.1rem; font-weight: 700; }
.phrase.compact .jp { font-size: 1.3rem; }
.phrase.compact .romaji { font-size: 1rem; }
.phrase.compact .de { font-size: .95rem; }
.tip { background: var(--warn-bg); border-radius: 14px; padding: 10px 12px; font-size: .9rem; line-height: 1.4; }
.tag { display: inline-block; font-size: .7rem; font-weight: 800; padding: 3px 8px; border-radius: 99px;
  background: var(--bg-2); color: var(--ink-2); }
.tag.video { background: #5A3036; color: #FFB3B3; }
.actions { display: flex; gap: 12px; align-items: center; margin-top: 8px; }

/* ── Karteikarten ───────────────────────────────────────── */
.progress-top { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; }
.progress-top .bar { flex: 1; margin: 0; }
.close-x { background: var(--card); border: 0; border-radius: 12px; width: 38px; height: 38px; font-size: 1.1rem; box-shadow: 0 3px 0 var(--line); }

.flash { perspective: 1200px; }
.flash-inner { position: relative; min-height: 340px; transition: transform .45s cubic-bezier(.3,1.4,.5,1); transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); padding: 22px;
  display: flex; flex-direction: column; overflow: auto; }
.face.back { transform: rotateY(180deg); }
.face .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.face.front { align-items: center; justify-content: center; text-align: center; cursor: pointer; border-top: 8px solid var(--c, var(--accent)); }
.face.front .question { font-size: 1.7rem; font-weight: 800; }
.face.front .hint { margin-top: 18px; color: var(--ink-2); font-size: .9rem; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.rate .btn { flex-direction: column; gap: 0; padding: 10px 6px; font-size: .95rem; }
.rate .btn small { font-weight: 700; opacity: .9; font-size: .7rem; }

.speak-result { border-radius: 14px; padding: 10px 12px; font-size: .92rem; font-weight: 700; }
.speak-result.good { background: var(--good-bg); }
.speak-result.ok { background: var(--warn-bg); }
.speak-result.bad { background: var(--bad-bg); }

/* ── Auswahl / Quiz ─────────────────────────────────────── */
.mode-list { display: grid; gap: 12px; }
.mode {
  border: 0; text-align: left; background: var(--card); border-radius: 20px; padding: 16px;
  display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow);
}
.mode .ico { font-size: 2rem; width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: var(--c); flex: none; }
.mode b { display: block; font-size: 1.05rem; }
.mode span { font-size: .85rem; color: var(--ink-2); }
.mode:active { transform: translateY(2px); }

.filter { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.filter::-webkit-scrollbar { display: none; }
.filter button { flex: none; border: 2px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 12px; font-weight: 700; font-size: .85rem; }
.filter button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.options { display: grid; gap: 10px; margin-top: 16px; }
.option {
  border: 2px solid var(--line); background: var(--card); border-radius: 18px; padding: 14px 16px;
  text-align: left; box-shadow: 0 4px 0 var(--line); display: flex; align-items: center; gap: 12px;
}
.option .phrase { flex: 1; gap: 2px; }
.option:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.option.correct { border-color: var(--good); background: var(--good-bg); box-shadow: 0 4px 0 var(--good); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); box-shadow: 0 4px 0 var(--bad); animation: shake .3s; }
.option.dim { opacity: .55; }
.mini-play { border: 0; background: var(--bg-2); border-radius: 12px; width: 40px; height: 40px; flex: none; font-size: 1.1rem; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.q-card { text-align: center; padding: 26px 18px; }
.q-card .phrase { align-items: center; }
.q-label { font-size: .8rem; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }

.feedback { margin-top: 14px; border-radius: 18px; padding: 14px; }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback h3 { font-size: 1.05rem; margin-bottom: 8px; }

.result { text-align: center; padding: 30px 18px; }
.result .big { font-size: 4rem; }
.result h2 { margin: 8px 0; font-size: 1.6rem; }

/* ── Dialoge ────────────────────────────────────────────── */
.chat { display: flex; flex-direction: column; gap: 12px; margin: 10px 0; }
.bubble { max-width: 88%; border-radius: 20px; padding: 12px 14px; box-shadow: 0 3px 0 var(--line); }
.bubble.npc { background: var(--card); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.me { background: #7B61FF; color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; box-shadow: 0 3px 0 #4C3AB5; }
.bubble.me .phrase .kana, .bubble.me .phrase .romaji { color: #E7E1FF; }
.bubble.situation { align-self: center; background: var(--warn-bg); box-shadow: none; text-align: center; font-weight: 700; max-width: 100%; }
.bubble .who { font-size: .72rem; font-weight: 800; color: var(--ink-2); margin-bottom: 4px; }
.bubble .row-play { display: flex; gap: 10px; align-items: center; }
.bubble .row-play .phrase { flex: 1; }
.reveal { border: 0; background: none; color: var(--ink-2); font-weight: 700; font-size: .8rem; padding: 4px 0 0; text-decoration: underline; }

/* ── Reise-Modus ────────────────────────────────────────── */
.search { position: sticky; top: 58px; z-index: 5; background: var(--bg); padding: 4px 0 10px; }
.search input {
  width: 100%; border: 2px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 16px; padding: 14px 16px; font: inherit; font-size: 1rem; outline: none;
}
.search input:focus { border-color: var(--accent); }
.list { display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 16px; padding: 10px 12px;
  box-shadow: 0 3px 0 var(--line); border: 0; text-align: left; width: 100%; border-left: 6px solid var(--c);
}
.list-item .phrase { flex: 1; gap: 1px; }
.list-item .phrase .jp { font-size: 1.15rem; }
.list-item .phrase .romaji { font-size: .9rem; }
.list-item .phrase .de { font-size: .88rem; font-weight: 700; }
.star { background: none; border: 0; font-size: 1.3rem; padding: 4px; filter: grayscale(1); opacity: .45; }
.star.on { filter: none; opacity: 1; }
.group-title { font-weight: 800; margin: 16px 2px 8px; display: flex; gap: 8px; align-items: center; }

.show {
  position: fixed; inset: 0; z-index: 50; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: 24px; text-align: center;
}
.show .jp { font-size: clamp(2.4rem, 13vw, 5rem); font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.show .kana { font-size: 1.3rem; color: var(--ink-2); }
.show .romaji { font-size: 1.4rem; font-weight: 700; color: var(--romaji); }
.show .de { font-size: 1.1rem; }
.show .close { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px; }
.show .rotate { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 16px; }

/* ── Einstellungen (Bottom-Sheet) ───────────────────────── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20, 14, 35, .45); display: flex; align-items: flex-end; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; margin: 0 auto; border-radius: 26px 26px 0 0;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow: auto; animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { font-size: 1.25rem; margin-bottom: 12px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card);
  border-radius: 16px; padding: 12px 14px; margin-bottom: 8px; }
.setting label { font-weight: 700; }
.setting small { display: block; color: var(--ink-2); font-weight: 400; font-size: .8rem; }
.switch { appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch:checked { background: var(--good); }
.switch:checked::after { transform: translateX(20px); }
.seg { display: flex; background: var(--bg-2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 10px; border-radius: 10px; font-weight: 700; font-size: .82rem; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-weight: 700;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; animation: up .2s ease-out; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -40px; font-style: normal; font-size: 1.6rem; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

.empty { text-align: center; padding: 30px 10px; color: var(--ink-2); }
.empty .big { font-size: 3rem; }

/* ── Aufnahme ───────────────────────────────────────────── */
.round-btn.mic.recording { background: var(--bad); box-shadow: 0 0 0 calc(var(--lvl, 0) * 16px + 4px) color-mix(in srgb, var(--bad) 35%, transparent); transition: box-shadow .08s; }
.rec-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.rec-actions .btn { flex: 1; padding: 10px 8px; font-size: .9rem; }
.rec-actions .btn.playing { animation: pulse .8s infinite; }
.speak-result .asr:empty { display: none; }
#asr-box .bar { margin-top: 8px; }

/* Bedienknöpfe rechts – einhändig mit dem rechten Daumen erreichbar */
.actions.right { justify-content: flex-end; align-self: stretch; }
.actions.right > span { flex: 1; }
.actions.right .round-btn { width: 60px; height: 60px; }

/* Online/Offline-Schalter auf der Startseite */
.mode-switch { margin-top: 12px; background: var(--card); border-radius: 18px; padding: 12px 14px; box-shadow: 0 3px 0 var(--line); }
.mode-switch .row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mode-switch .seg button { padding: 8px 12px; font-size: .9rem; white-space: nowrap; }
.mode-switch .seg button.on { background: var(--accent); color: #fff; }
.mode-switch .desc { font-size: .8rem; color: var(--ink-2); margin-top: 6px; line-height: 1.35; }
.mode-switch .bar { margin-top: 8px; }

/* Parken: vierter Bewertungsknopf, bewusst ruhig gefärbt */
.rate { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate .btn { padding: 10px 4px; }
.rate .btn small { line-height: 1.15; }
.btn.park { background: #6B7686; box-shadow: 0 4px 0 #474F5B; }

/* ── Playlist ───────────────────────────────────────────── */
.pl-toggle { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; font-weight: 700; font-size: .92rem; color: var(--ink-2); cursor: pointer; }
.pl-now { text-align: center; }
.pl-now .phrase { align-items: center; }
.pl-steps { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; font-size: .78rem; font-weight: 800; color: var(--ink-2); }
.pl-steps span.on { color: #fff; background: var(--accent); border-radius: 99px; padding: 2px 8px; }
.pl-controls { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 16px 0; }
.pl-btn { border: 0; background: var(--card); color: var(--ink); border-radius: 16px; min-width: 56px; height: 56px; padding: 4px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 3px 0 var(--line); font-size: 1.3rem; }
.pl-btn small { font-size: .62rem; font-weight: 800; color: var(--ink-2); }
.pl-btn.on { background: var(--good); box-shadow: 0 3px 0 color-mix(in srgb, var(--good) 60%, #000); }
.pl-btn.on small { color: #fff; }
.pl-item.current { outline: 2px solid var(--accent); }
.pl-pill { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + 10px + env(safe-area-inset-bottom)); z-index: 30; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  max-width: 608px; margin: 0 auto; display: flex; align-items: center; gap: 10px; background: #1F2228; color: var(--ink);
  border-radius: 16px; padding: 8px 8px 8px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.35); cursor: pointer; }
.pl-pill-text { flex: 1; font-weight: 700; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-pill button { border: 0; background: var(--accent); color: #fff; border-radius: 12px; width: 42px; height: 42px; font-size: 1.1rem; flex: none; }
body.has-pill main { padding-bottom: 90px; }
