:root {
  --bg: #f7f4ed;
  --surface: #ffffff;
  --ink: #0f2744;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-dark: #0b4f4a;
  --accent: #f4c95d;
  --danger: #c2413a;
  --success: #178a55;
  --warning: #d97706;
  --line: #dbe5e3;
  --shadow: 0 14px 35px rgba(15, 39, 68, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background:
  radial-gradient(circle at top right, rgba(15,118,110,.12), transparent 34rem), var(--bg); }
button, input, textarea, select { font: inherit; }
button, .file-label { min-height: 48px; border-radius: 14px; border: 0; padding: 0 18px; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button:active, .file-label:active { transform: translateY(1px); }
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); }
.secondary { background: #e8f2f1; color: var(--brand-dark); border: 1px solid #bdd4d1; }
.ghost { background: transparent; color: white; border: 1px solid rgba(255,255,255,.5); }
.danger { background: #fee8e6; color: #9f2923; }
.warning { background: #fff1d6; color: #9a5806; }
.success { background: #dff6e9; color: #0f6a40; }
.small { min-height: 40px; padding-inline: 14px; }
.hidden { display: none !important; }
.topbar { position: sticky; top: 0; z-index: 10; padding: calc(14px + env(safe-area-inset-top)) 18px 14px; background: linear-gradient(135deg, #0d5f59, #0f766e); color: white; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 8px 24px rgba(15,39,68,.18); }
.topbar h1 { margin: 0; font-size: 1.45rem; }
.eyebrow { margin: 0 0 4px; font-size: .72rem; letter-spacing: .12em; font-weight: 900; color: inherit; opacity: .8; }
main { width: min(100%, 760px); margin: 0 auto; padding: 18px 14px calc(32px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.panel { background: rgba(255,255,255,.94); border: 1px solid rgba(15,118,110,.12); border-radius: 22px; box-shadow: var(--shadow); }
.hero { padding: 24px; display: grid; gap: 18px; overflow: hidden; position: relative; }
.hero::after { content: "🚦"; position: absolute; right: 18px; top: 16px; font-size: 4.5rem; opacity: .13; transform: rotate(8deg); }
h2, h3, p { margin-top: 0; }
.hero h2, .section-heading h2, .section-heading h3 { margin-bottom: 8px; }
.muted { color: var(--muted); line-height: 1.5; }
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.stat { padding: 17px 10px; text-align: center; }
.stat strong { display: block; font-size: 1.7rem; }
.stat span { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.section-block { padding: 18px; margin-top: 14px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.deck-list { display: grid; gap: 12px; }
.deck-card { overflow: hidden; box-shadow: none; border-left: 6px solid var(--deck-color, var(--brand)); }
.deck-main { width: 100%; min-height: 82px; padding: 14px; background: transparent; color: var(--ink); border-radius: 0; justify-content: flex-start; text-align: left; }
.deck-icon { font-size: 1.75rem; }
.deck-copy { flex: 1; display: grid; gap: 4px; }
.deck-copy strong { font-size: 1rem; }
.deck-copy small, .deck-meta { color: var(--muted); font-weight: 600; }
.deck-meta { font-size: .8rem; white-space: nowrap; }
.deck-actions { display: flex; gap: 8px; padding: 0 12px 12px 62px; flex-wrap: wrap; }
.deck-actions button { min-height: 36px; padding-inline: 12px; font-size: .82rem; }
.study-toolbar { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 10px; margin-bottom: 12px; }
.study-toolbar h2 { margin: 0; font-size: 1.25rem; }
.icon-button { width: 48px; min-width: 48px; min-height: 48px; padding: 0; border-radius: 50%; background: #e8f2f1; color: var(--brand-dark); font-size: 1.35rem; }
.progress-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-size: .8rem; color: var(--muted); margin-bottom: 12px; }
.progress-track { height: 8px; background: #dbe7e5; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.study-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; margin-bottom: 14px; }
.study-controls label { color: var(--muted); font-size: .75rem; font-weight: 800; }
select, input, textarea { width: 100%; border: 1px solid #cddbd9; background: #fff; color: var(--ink); border-radius: 12px; padding: 12px; margin-top: 6px; }
.flashcard { position: relative; min-height: 410px; perspective: 1200px; cursor: pointer; outline: none; }
.card-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 28px; padding: 28px 22px; background: linear-gradient(160deg, #fff, #f7fbfa); box-shadow: 0 22px 55px rgba(15,39,68,.16); border: 1px solid rgba(15,118,110,.17); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; transition: transform .5s; }
.card-back { transform: rotateY(180deg); background: linear-gradient(160deg, #0e5d58, #0a3f3b); color: white; }
.flashcard.flipped .card-front { transform: rotateY(180deg); }
.flashcard.flipped .card-back { transform: rotateY(360deg); }
.card-badge { position: absolute; top: 18px; left: 18px; padding: 8px 11px; border-radius: 999px; background: #e5f3f1; color: var(--brand-dark); font-size: .72rem; font-weight: 900; letter-spacing: .08em; }
.card-badge.answer { background: rgba(255,255,255,.14); color: white; }
.card-visual { font-size: clamp(4.5rem, 18vw, 8rem); line-height: 1; margin-bottom: 20px; filter: drop-shadow(0 8px 10px rgba(15,39,68,.1)); }
.card-face h3 { font-size: clamp(1.5rem, 5vw, 2.15rem); margin-bottom: 12px; }
.card-back p { font-size: 1.05rem; line-height: 1.55; }
.action-box { background: rgba(255,255,255,.13); border: 1px solid rgba(255,255,255,.2); border-radius: 16px; padding: 13px; line-height: 1.45; width: 100%; margin-top: 4px; }
.note { opacity: .8; font-size: .9rem !important; margin-top: 12px; }
.tap-hint { position: absolute; bottom: 15px; font-size: .78rem !important; opacity: .6; }
.rating-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-label { text-align: center; }
.small-text { font-size: .82rem; margin: 12px 0 0; }
dialog { width: min(92vw, 560px); border: 0; border-radius: 24px; padding: 0; box-shadow: 0 32px 80px rgba(15,39,68,.28); }
dialog::backdrop { background: rgba(15,39,68,.55); backdrop-filter: blur(4px); }
.dialog-form { padding: 20px; display: grid; gap: 14px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.dialog-heading h2 { margin: 0; }
.dialog-form label { font-weight: 800; font-size: .86rem; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 24px); opacity: 0; pointer-events: none; background: #0f2744; color: white; padding: 12px 16px; border-radius: 12px; z-index: 100; transition: .2s; box-shadow: var(--shadow); max-width: 88vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed #b9cfcb; border-radius: 16px; }
.card-list { display: grid; gap: 8px; margin-top: 10px; }
.card-row { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.card-row strong { display: block; }
.card-row small { color: var(--muted); }
.card-row-actions { display: flex; gap: 6px; }
.card-row-actions button { min-height: 34px; width: 34px; padding: 0; border-radius: 10px; }
@media (min-width: 700px) {
  .hero { grid-template-columns: 1.4fr 1fr; align-items: end; }
  .flashcard { min-height: 500px; }
}
@media (max-width: 420px) {
  .hero-actions, .study-controls, .button-grid { grid-template-columns: 1fr; }
  .stats-grid { gap: 6px; }
  .section-block { padding: 14px; }
  .flashcard { min-height: 390px; }
  .deck-actions { padding-left: 12px; }
}
