:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #efebe1;
  --ink: #1d231f;
  --ink-2: #5b625d;
  --ink-3: #8a8f8a;
  --line: #e2ddd0;
  --brand: #1f3a2e;
  --brand-ink: #f6f3ec;
  --accent: #e6b450;
  --danger: #b4412f;
  --ok: #2f7a4f;

  --l100: #2f7a4f;  --l100-bg: #e2f0e6;
  --l200: #2c5f9e;  --l200-bg: #e1ebf7;
  --l300: #a06514;  --l300-bg: #f7ecd9;
  --l400: #a3384f;  --l400-bg: #f6e3e7;
  --l500: #6a4a9c;  --l500-bg: #ece5f6;

  --radius: 16px;
  --shadow: 0 1px 2px rgb(30 35 31 / .06), 0 4px 16px rgb(30 35 31 / .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Dark mode: follows the phone unless the user picked Light or Dark in Settings. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #121614;
    --surface: #1a201d;
    --surface-2: #232a26;
    --ink: #eef0ec;
    --ink-2: #a9b0ab;
    --ink-3: #7b827d;
    --line: #2c3430;
    --brand: #8fc9a4;
    --brand-ink: #10241a;
    --danger: #ec8a78;
    --ok: #8fc9a4;
    --l100: #8fd3a7;  --l100-bg: #1c3226;
    --l200: #93b9ec;  --l200-bg: #1c2a3d;
    --l300: #e7b765;  --l300-bg: #3a2c15;
    --l400: #ec9aab;  --l400-bg: #3c1f27;
    --l500: #c2a8ec;  --l500-bg: #2c2240;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-mode="dark"] {
    --bg: #121614;
    --surface: #1a201d;
    --surface-2: #232a26;
    --ink: #eef0ec;
    --ink-2: #a9b0ab;
    --ink-3: #7b827d;
    --line: #2c3430;
    --brand: #8fc9a4;
    --brand-ink: #10241a;
    --danger: #ec8a78;
    --ok: #8fc9a4;
    --l100: #8fd3a7;  --l100-bg: #1c3226;
    --l200: #93b9ec;  --l200-bg: #1c2a3d;
    --l300: #e7b765;  --l300-bg: #3a2c15;
    --l400: #ec9aab;  --l400-bg: #3c1f27;
    --l500: #c2a8ec;  --l500-bg: #2c2240;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.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(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand img { border-radius: 7px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  display: grid; place-items: center; width: 42px; height: 42px;
  border: 0; border-radius: 12px; background: transparent; color: var(--ink-2); text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.pill-offline { background: var(--surface-2); color: var(--ink-2); }

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

/* ---------- headings & text ---------- */
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; margin: 12px 0 4px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 28px 0 10px; font-weight: 700; }
.sub { color: var(--ink-2); margin: 0 0 16px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; color: var(--ink-3); margin-top: 8px; }
.crumbs a { text-decoration: none; color: var(--ink-2); }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }

/* ---------- search ---------- */
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 0 14px; margin: 8px 0 4px; box-shadow: var(--shadow);
}
.search svg { color: var(--ink-3); flex: none; }
.search input { flex: 1; border: 0; background: transparent; padding: 14px 0; outline: none; min-width: 0; }

/* ---------- level cards ---------- */
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.level-card {
  --c: var(--l100); --cbg: var(--l100-bg);
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px; border-radius: var(--radius); text-decoration: none;
  background: var(--cbg); color: var(--c); min-height: 112px;
  transition: transform .15s ease;
}
.level-card:active { transform: scale(.98); }
.level-card .big { font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.level-card .lbl { font-weight: 700; font-size: 14px; margin-bottom: auto; }
.level-card .meta { font-size: 13px; color: var(--ink-2); margin-top: 12px; }
[data-level="100"] { --c: var(--l100); --cbg: var(--l100-bg); }
[data-level="200"] { --c: var(--l200); --cbg: var(--l200-bg); }
[data-level="300"] { --c: var(--l300); --cbg: var(--l300-bg); }
[data-level="400"] { --c: var(--l400); --cbg: var(--l400-bg); }
[data-level="500"], [data-level="600"], [data-level="700"] { --c: var(--l500); --cbg: var(--l500-bg); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  text-decoration: none; border-bottom: 1px solid var(--line); min-height: 64px;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .snippet { font-size: 13px; color: var(--ink-2); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .snippet mark { background: color-mix(in srgb, var(--accent) 40%, transparent); color: inherit; border-radius: 3px; }
.row .more { flex: none; }
.chev { color: var(--ink-3); flex: none; }

.kind {
  flex: none; width: 42px; height: 50px; border-radius: 8px;
  display: grid; place-items: end center; padding-bottom: 6px;
  font-size: 10px; font-weight: 800; letter-spacing: .04em; color: #fff;
  background: #6b7280; position: relative;
}
.kind::before { content: ""; position: absolute; top: 0; right: 0; width: 12px; height: 12px; background: linear-gradient(225deg, var(--surface) 50%, rgb(0 0 0 / .18) 50%); border-top-right-radius: 8px; }
.kind-pdf { background: #c2412d; }
.kind-pptx { background: #c8622a; }
.kind-docx { background: #2b5ca8; }
.kind-image { background: #5b7d3a; }

.course-badge {
  flex: none; width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; text-align: center;
  background: var(--cbg, var(--surface-2)); color: var(--c, var(--ink)); font-weight: 800; font-size: 12px; line-height: 1.1;
}
.dot-offline { width: 8px; height: 8px; border-radius: 99px; background: var(--ok); display: inline-block; }

.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 650; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.btn-row .btn { flex: 1 1 auto; }
.link-btn { border: 0; background: none; color: var(--ink-2); text-decoration: underline; padding: 8px; }

.fab {
  position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 0 22px 0 18px; height: 56px; border-radius: 18px;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; box-shadow: 0 6px 20px rgb(31 58 46 / .35);
  cursor: pointer; user-select: none;
}
.fab:active { transform: scale(.97); }

/* ---------- install / info card ---------- */
.callout {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; margin: 12px 0;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; font-size: 14px;
}
.callout p { margin: 0 0 8px; color: var(--ink-2); }
.callout strong { color: var(--ink); }
.callout .btn { min-height: 38px; padding: 0 14px; font-size: 14px; }

/* ---------- sheet (bottom sheet modal) ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / .4); animation: fade .15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 560px; margin: 0 auto; max-height: 92dvh; overflow: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  animation: rise .22s cubic-bezier(.2, .9, .3, 1);
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 4px 0 4px; font-size: 21px; letter-spacing: -.01em; }
.sheet .q { font-size: 22px; font-weight: 750; letter-spacing: -.015em; margin: 14px 0 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink-3); font-size: 13px; font-weight: 600; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.file-peek { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--surface-2); border-radius: 14px; margin-top: 8px; }
.file-peek .main { flex: 1; min-width: 0; }
.file-peek .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-peek .meta { font-size: 13px; color: var(--ink-3); }

.guess {
  margin: 16px 0 6px; padding: 16px; border-radius: 16px; background: var(--cbg, var(--surface-2)); color: var(--c, var(--ink));
}
.guess .code { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.guess .where { font-weight: 650; margin-top: 2px; }
.guess .why { font-size: 13px; color: var(--ink-2); margin-top: 6px; }

.taps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.taps.three { grid-template-columns: repeat(3, 1fr); }
.tap {
  min-height: 64px; border-radius: 16px; border: 2px solid transparent;
  background: var(--cbg, var(--surface-2)); color: var(--c, var(--ink));
  font-size: 19px; font-weight: 750; padding: 8px;
}
.tap small { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.tap:active { transform: scale(.97); }
.tap.ghost { background: transparent; border: 2px dashed var(--line); color: var(--ink-2); }
.tap.wide { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field label { font-size: 13px; font-weight: 650; color: var(--ink-2); }
.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg);
  padding: 13px 14px; font-size: 18px; outline: none;
}
.input:focus { border-color: var(--brand); }
.input.code { text-transform: uppercase; font-weight: 700; letter-spacing: .03em; }
.hint { font-size: 13px; color: var(--ink-3); }
.error { color: var(--danger); font-size: 14px; }

.steps { display: flex; gap: 6px; }
.steps i { width: 22px; height: 4px; border-radius: 99px; background: var(--line); }
.steps i.on { background: var(--brand); }

.action-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.action-list button {
  display: flex; align-items: center; gap: 12px; text-align: left; border: 0; background: none;
  padding: 14px 10px; border-radius: 12px; font-weight: 600;
}
.action-list button:hover { background: var(--surface-2); }
.action-list .danger { color: var(--danger); }

/* ---------- upload progress bar ---------- */
.upload-bar {
  position: fixed; left: 16px; right: 96px; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 19;
  max-width: 420px; padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px;
}
.upload-bar .track { height: 4px; border-radius: 99px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.upload-bar .fill { height: 100%; background: var(--brand); transition: width .2s; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- viewer ---------- */
.viewer-bar { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.viewer-bar .main { flex: 1; min-width: 0; }
.viewer-bar .title { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .meta { font-size: 13px; color: var(--ink-3); }
.pages { display: flex; flex-direction: column; gap: 12px; }
.page { background: #fff; border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.page canvas { display: block; width: 100%; height: auto; }
.page .num { position: absolute; right: 8px; bottom: 8px; font-size: 11px; background: rgb(0 0 0 / .55); color: #fff; padding: 2px 7px; border-radius: 99px; }
.viewer-img { width: 100%; border-radius: 8px; box-shadow: var(--shadow); }
.office-card { padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-align: center; }
.office-card p { color: var(--ink-2); }
.spinner { width: 28px; height: 28px; border-radius: 99px; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.settings-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.settings-group h3 { margin: 0 0 6px; font-size: 17px; }
.settings-group p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; }

@media (min-width: 640px) {
  .levels { grid-template-columns: repeat(4, 1fr); }
  .sheet { bottom: 24px; border-radius: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
