:root {
  --bg: #070b14;
  --surface: #101726;
  --surface-alt: #182238;
  --border: #1f2d4a;
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --accent: #10b981;
  --danger: #ef4444;
  --gold: #f59e0b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --der: #38bdf8;
  --die: #f43f5e;
  --das: #22c55e;
  --verb: #c084fc;
  --konn: #fb923c;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
body { background: var(--bg); color: var(--text); display: flex; justify-content: center; min-height: 100vh; padding: 12px; }

#app { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 12px; padding-bottom: 30px; }

header { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.brand { font-size: 1.25rem; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand-badge { background: var(--primary); font-size: 0.75rem; padding: 2px 8px; border-radius: 6px; font-weight: 700; color: #fff; }
.header-meta { font-size: 0.8rem; color: var(--text-muted); }

/* Navigation */
nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; background: var(--surface); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
nav button { padding: 9px 2px; border: none; background: transparent; color: var(--text-muted); font-size: 0.74rem; font-weight: 700; cursor: pointer; border-radius: 8px; transition: 0.15s; }
nav button.active { background: var(--primary); color: #fff; }

.view { display: none; flex-direction: column; gap: 12px; }
.view.active { display: flex; }

/* Filter Pills */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filter-btn { white-space: nowrap; padding: 6px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; color: var(--text-muted); font-size: 0.75rem; cursor: pointer; font-weight: 600; }
.filter-btn.active { background: var(--primary-light); color: white; border-color: var(--primary-light); }

/* Flashcards */
.card-wrapper { perspective: 1000px; height: 260px; cursor: pointer; }
.card-inner { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 18px; }
.card-inner.flipped { transform: rotateY(180deg); }

.card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; background: var(--surface); border-radius: 18px; border: 1px solid var(--border); padding: 22px; display: flex; flex-direction: column; justify-content: space-between; box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.card-back { transform: rotateY(180deg); background: #0c1427; border-color: var(--primary); }

.article-badge { display: inline-block; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; }
.art-der { background: rgba(56, 189, 248, 0.15); color: var(--der); border: 1px solid var(--der); }
.art-die { background: rgba(244, 63, 94, 0.15); color: var(--die); border: 1px solid var(--die); }
.art-das { background: rgba(34, 197, 94, 0.15); color: var(--das); border: 1px solid var(--das); }
.art-verb { background: rgba(192, 132, 252, 0.15); color: var(--verb); border: 1px solid var(--verb); }
.art-konn { background: rgba(251, 146, 60, 0.15); color: var(--konn); border: 1px solid var(--konn); }

.card-center { text-align: center; margin: auto 0; }
.main-word { font-size: 1.65rem; font-weight: 800; letter-spacing: -0.5px; }
.plural-info { font-size: 0.9rem; color: var(--text-muted); margin-top: 4px; }
.icon-btn { background: var(--surface-alt); border: 1px solid var(--border); color: #fff; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; }
.icon-btn.fav-active { color: var(--gold); border-color: var(--gold); }

.trans-sq { font-size: 1.35rem; font-weight: 700; color: #38bdf8; }
.example-box { font-size: 0.88rem; color: #cbd5e1; margin-top: 10px; background: rgba(0,0,0,0.3); padding: 10px 14px; border-radius: 8px; border-left: 3px solid var(--primary-light); text-align: left; }

.action-btns { display: flex; gap: 8px; }
.btn { flex: 1; padding: 12px; border-radius: 12px; border: none; font-weight: 700; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.btn-repeat { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-pass { background: var(--accent); color: white; }

/* Dictionary */
.dict-search-box { position: relative; }
.dict-input { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; color: #fff; font-size: 0.95rem; outline: none; }
.dict-input:focus { border-color: var(--primary-light); }
.dict-list { display: flex; flex-direction: column; gap: 6px; max-height: 540px; overflow-y: auto; padding-right: 2px; }
.dict-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; }
.dict-de { font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; }
.dict-sq { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

/* Stories View */
.story-selector { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.story-btn { white-space: nowrap; padding: 7px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text-muted); font-size: 0.78rem; font-weight: 700; cursor: pointer; }
.story-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.story-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.story-title { font-size: 1.05rem; font-weight: 800; color: var(--gold); }
.story-body { line-height: 2.1; font-size: 1.05rem; }
.story-token { cursor: pointer; padding: 2px 4px; border-radius: 5px; transition: background 0.15s; }
.story-token:hover { background: var(--primary); color: white; }
.inspector-box { background: #070e1d; border: 1px solid var(--primary); border-radius: 12px; padding: 12px 14px; min-height: 55px; display: flex; align-items: center; font-size: 0.92rem; }

/* Grammar Compendium */
.grammar-list { display: flex; flex-direction: column; gap: 10px; }
.grammar-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.grammar-card h3 { font-size: 1rem; color: var(--gold); display: flex; align-items: center; gap: 6px; }
.grammar-card p { font-size: 0.88rem; color: #cbd5e1; line-height: 1.5; }
.rule-formula { background: #070d18; border-left: 3px solid var(--primary-light); padding: 8px 12px; border-radius: 6px; font-family: monospace; font-size: 0.85rem; color: #38bdf8; }
.rule-ex-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.rule-ex-item { font-size: 0.84rem; background: rgba(0,0,0,0.25); padding: 6px 10px; border-radius: 6px; }

/* Scramble */
.box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.prompt-sq { font-size: 0.95rem; color: #cbd5e1; font-weight: 600; line-height: 1.4; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.drop-zone { min-height: 60px; background: rgba(0,0,0,0.3); border: 2px dashed var(--border); border-radius: 12px; padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.chips-pool { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-alt); border: 1px solid var(--border); color: #fff; padding: 6px 12px; border-radius: 10px; font-size: 0.88rem; font-weight: 600; cursor: pointer; user-select: none; }
.chip.active-chip { background: var(--primary); border-color: var(--primary-light); }
.chip.used { opacity: 0.25; pointer-events: none; }
