/* CadetDX — dark, mobile-first */
:root {
  --bg: #0b1220;
  --bg-elev: #111a2f;
  --bg-card: #15203a;
  --bg-card-2: #1b2745;
  --border: #233055;
  --text: #e6ecf5;
  --text-dim: #9aa8c2;
  --text-mute: #66759a;
  --primary: #3b82f6;
  --primary-2: #1e40af;
  --accent: #8b5cf6;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --gold: #fbbf24;
  --bronze: #b45309;
  --silver: #94a3b8;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0,0,0,.45);
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
body { font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; min-height: 100vh; min-height: 100dvh; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input[type=text], input[type=password], textarea {
  font: inherit; color: var(--text); background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.hidden { display: none !important; }

/* --- Layout shells --- */
#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
#app.boot .topbar, #app.boot .bottomnav { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg, #0e1729, #0b1220);
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 0 0 auto; font-weight: 700; }
.topbar-stats { flex: 1 1 auto; text-align: center; color: var(--text-dim); font-size: 14px; }
.topbar-stats .stat { display: inline-flex; align-items: center; gap: 4px; margin: 0 6px; }
.topbar-stats .stat strong { color: var(--text); }

.bottomnav {
  position: sticky; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #0e1729; border-top: 1px solid var(--border);
  padding: 6px 4px max(6px, env(safe-area-inset-bottom));
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--text-dim); padding: 6px 4px; min-height: var(--tap);
}
.nav-btn span { font-size: 11px; }
.nav-btn.active { color: var(--text); }
.nav-elmer { color: var(--accent); font-weight: 600; }

.icon-btn { font-size: 20px; padding: 6px 10px; border-radius: var(--radius-sm); min-width: var(--tap); min-height: var(--tap); }
.icon-btn:hover { background: var(--bg-card); }

.view { flex: 1; padding: 14px 14px 24px; overflow-y: auto; max-width: 720px; margin: 0 auto; width: 100%; }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: var(--radius-sm); font-weight: 600; min-height: var(--tap);
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text); }
.btn:hover { background: var(--bg-card-2); }
.btn.primary, .primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #2563eb; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #052e22; }
.btn.full { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Cards --- */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-title { margin: 0 0 6px; font-size: 18px; }
.card-sub { color: var(--text-dim); font-size: 14px; margin: 0 0 10px; }

/* --- Login --- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-logo { font-size: 40px; text-align: center; margin-bottom: 6px; }
.auth-title { text-align: center; margin: 0 0 4px; font-size: 22px; }
.auth-sub { text-align: center; color: var(--text-dim); margin: 0 0 18px; font-size: 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.auth-error { color: var(--bad); font-size: 14px; margin-top: 8px; min-height: 1.2em; }

/* --- Home / Unit cards --- */
.welcome { padding: 6px 4px 14px; }
.welcome h1 { margin: 0 0 2px; font-size: 22px; }
.welcome p { margin: 0; color: var(--text-dim); }
.unit-card {
  border-left: 6px solid var(--primary);
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-2));
}
.unit-head { display: flex; align-items: center; gap: 12px; }
.unit-icon { font-size: 28px; }
.unit-meta { color: var(--text-dim); font-size: 13px; }
.unit-progress { margin-top: 10px; }
.progress-bar { height: 6px; background: #0b1220; border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width: 0%; transition: width .4s; }
.progress-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.lesson-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; margin-top: 10px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
}
.lesson-row:hover { border-color: var(--primary); }
.lesson-row .ico { font-size: 22px; }
.lesson-row .title { font-weight: 600; }
.lesson-row .meta { color: var(--text-dim); font-size: 13px; }
.lesson-row .badge { margin-left: auto; font-size: 12px; padding: 4px 8px; border-radius: 99px; }
.lesson-row .badge.pass { background: rgba(16,185,129,.15); color: var(--good); border: 1px solid var(--good); }
.lesson-row .badge.partial { background: rgba(245,158,11,.15); color: var(--warn); border: 1px solid var(--warn); }
.lesson-row .badge.retry { background: rgba(139,92,246,.15); color: var(--accent); border: 1px solid var(--accent); }

/* --- Lesson reader --- */
.reader-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.reader-bar .crumb { color: var(--text-dim); font-size: 13px; }
.screen-progress { display: flex; gap: 4px; margin: 8px 0 14px; }
.screen-progress .dot { flex: 1; height: 4px; border-radius: 99px; background: var(--border); }
.screen-progress .dot.done { background: var(--primary); }
.screen-progress .dot.current { background: var(--accent); }
.screen-hero { font-size: 48px; text-align: center; margin: 6px 0 4px; }
.screen-title { font-size: 22px; margin: 0 0 10px; }
.screen-body p { margin: 0 0 10px; }
.screen-body ul { padding-left: 22px; margin: 0 0 10px; }
.screen-body li { margin-bottom: 4px; }
.screen-body strong { color: #fff; }
.screen-body em { color: var(--text-dim); font-style: normal; border-bottom: 1px dashed var(--text-mute); }
.screen-body a { color: var(--primary); }

.tip {
  margin: 14px 0; padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(59,130,246,.10); border-left: 4px solid var(--primary);
}

.ric-svg { margin: 14px 0; text-align: center; }
.ric-svg svg { max-width: 100%; height: auto; }
.ric-caption { font-size: 12px; color: var(--text-dim); margin-top: 6px; font-style: italic; }

.screen-photo { margin: 0 0 14px; padding: 0; }
.screen-photo img { width: 100%; height: auto; border-radius: var(--radius-sm); display: block; border: 1px solid var(--border); }
.screen-photo figcaption { font-size: 12px; color: var(--text-dim); margin-top: 6px; font-style: italic; }

.note-btn { margin-top: 14px; }
.reader-footer { display: flex; gap: 8px; margin-top: 18px; }
.reader-footer .btn { flex: 1; }

/* --- Checkpoint banner --- */
.checkpoint-banner {
  background: linear-gradient(90deg, #4c1d95, #6d28d9);
  color: #fff; padding: 14px; border-radius: var(--radius); margin: 12px 0;
  display: flex; gap: 12px; align-items: center;
}
.checkpoint-banner .ico { font-size: 28px; }

/* --- Quiz --- */
.quiz-question { margin: 0 0 10px; font-size: 17px; font-weight: 600; }
.quiz-options { display: grid; gap: 8px; }
.quiz-opt {
  text-align: left; padding: 12px; border-radius: var(--radius-sm);
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  display: flex; gap: 10px; align-items: flex-start;
}
.quiz-opt:hover { border-color: var(--primary); }
.quiz-opt[data-state=correct] { border-color: var(--good); background: rgba(16,185,129,.10); }
.quiz-opt[data-state=wrong]   { border-color: var(--bad);  background: rgba(239,68,68,.10); }
.quiz-opt[data-state=missed]  { border-color: var(--good); background: rgba(16,185,129,.06); }
.quiz-opt .letter { font-weight: 700; min-width: 22px; }
.quiz-explain {
  margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(139,92,246,.10); border-left: 4px solid var(--accent);
  font-size: 14px;
}
.quiz-progress { color: var(--text-dim); font-size: 13px; margin-bottom: 6px; }
.quiz-summary { text-align: center; padding: 18px; }
.quiz-summary .score { font-size: 48px; font-weight: 800; margin: 6px 0; }
.quiz-summary .verdict { font-size: 16px; color: var(--text-dim); }

/* --- Notebook --- */
.note-list { display: grid; gap: 10px; margin-top: 10px; }
.note-item { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.note-meta { color: var(--text-dim); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.note-text { margin: 6px 0 8px; white-space: pre-wrap; }
.note-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.star-btn { font-size: 18px; }
.star-btn.on { color: var(--gold); }

/* --- Profile --- */
.rank-card { text-align: center; }
.rank-icon { font-size: 48px; }
.rank-name { font-size: 22px; font-weight: 700; margin: 4px 0; }
.rank-xp { color: var(--text-dim); }
.rank-bar { margin-top: 12px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 10px; }
.ach-tile { padding: 10px; border-radius: var(--radius-sm); background: var(--bg-elev); border: 1px solid var(--border); text-align: center; }
.ach-tile.locked { opacity: .45; }
.ach-tile .ach-ic { font-size: 28px; }
.ach-tile .ach-t { font-size: 13px; font-weight: 600; margin-top: 4px; }
.ach-tile .ach-d { font-size: 11px; color: var(--text-dim); }
.ach-tile.bronze { border-color: var(--bronze); }
.ach-tile.silver { border-color: var(--silver); }
.ach-tile.gold   { border-color: var(--gold); }

/* --- Elmer drawer --- */
.elmer-drawer {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: 50vh; height: 50dvh;
  background: #0e1729; border-top: 1px solid var(--border);
  z-index: 50; display: flex; flex-direction: column;
  transform: translateY(0); transition: transform .25s ease;
  box-shadow: 0 -10px 30px rgba(0,0,0,.4);
}
.elmer-drawer.hidden { transform: translateY(105%); display: flex !important; pointer-events: none; }
.elmer-header { display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border); }
.elmer-id { display: flex; gap: 10px; align-items: center; }
.elmer-avatar { font-size: 24px; }
.elmer-name { font-weight: 700; }
.elmer-sub { font-size: 12px; color: var(--text-dim); }
.elmer-chat { flex: 1; overflow-y: auto; padding: 10px 12px; }
.elmer-msg { padding: 8px 10px; border-radius: 10px; margin-bottom: 6px; max-width: 90%; }
.elmer-msg.user { background: var(--primary); color: #fff; margin-left: auto; }
.elmer-msg.assistant { background: var(--bg-card); border: 1px solid var(--border); }
.elmer-msg.error { background: rgba(239,68,68,.10); border: 1px solid var(--bad); color: var(--bad); }
.elmer-msg p { margin: 0 0 6px; }
.elmer-msg p:last-child { margin-bottom: 0; }
.elmer-msg strong { color: #fff; }
.elmer-msg.user strong { color: #fff; }
.elmer-msg.assistant strong { color: var(--text); }
.elmer-chips { display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto; flex-wrap: nowrap; }
.chip {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 10px; border-radius: 99px; font-size: 12px; white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--primary); }
.elmer-input { display: flex; gap: 8px; padding: 8px 12px env(safe-area-inset-bottom);
  border-top: 1px solid var(--border); background: #0e1729; }
.elmer-input input { flex: 1; }
.elmer-input .primary { padding: 0 16px; }

/* --- Toasts --- */
.toast-tray { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: var(--bg-card-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); max-width: 320px; font-size: 14px; animation: tin .25s ease; }
.toast.good { border-color: var(--good); }
.toast.xp   { border-color: var(--gold); }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* --- Misc --- */
.spacer-50 { height: 50vh; }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-mute); margin: 18px 0 6px; }
.empty { text-align: center; color: var(--text-mute); padding: 22px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-dim); }
.pill.good { color: var(--good); border-color: var(--good); }
.pill.warn { color: var(--warn); border-color: var(--warn); }

/* Unit cover image */
.unit-cover { width: calc(100% + 28px); margin: -14px -14px 12px; max-height: 140px; object-fit: cover; display: block; border-radius: var(--radius) var(--radius) 0 0; }

/* Match-game grid */
.match-grid button { transition: background .2s, color .2s; }
