/* base.css — reset, shell layout, typography */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: calc(16px * var(--font-scale, 1));
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

img, svg, video { max-width: 100%; }
img { height: auto; }

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 .5rem; font-weight: 700; }
p { margin: 0 0 .75rem; }
ul, ol { margin: 0 0 .75rem; padding-inline-start: 1.4rem; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Bare text-like controls must never fall back to the browser's light
 * default background (white) while text inherits light ink. This covers
 * every input that is NOT wrapped in .field — e.g. the exam duration
 * input, the library search box, and the practice jump input. Checkbox
 * and radio inputs are excluded on purpose (they use accent-color). */
input[type="text"], input[type="number"], input[type="search"],
input[type="email"], input[type="password"], input[type="tel"],
input[type="url"], input[type="date"], input[type="time"],
select, textarea {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
button:disabled { cursor: not-allowed; opacity: .55; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

::selection { background: var(--gold); color: var(--gold-ink); }

/* ---- App shell ---- */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#view {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 14px calc(var(--nav-h) + 24px);
  min-width: 0;
}

/* Sidebar (desktop) + bottom nav (mobile) are rendered by js/ui.js
   into these containers; hidden by default until filled. */
#sidebar { display: none; }
#bottomnav { display: block; }

.sidebar-inner {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 14px;
  background: var(--bg2);
  border-inline-end: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.brand-mark {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1b2342, #0b0f1e);
  border: 1.5px solid var(--gold);
  color: var(--gold);
  display: grid; place-items: center;
  font-size: 22px; font-weight: 800; line-height: 1;
}
.brand-name { font-size: 1.02rem; font-weight: 800; line-height: 1.3; }
.brand-sub { font-size: .8rem; color: var(--muted); line-height: 1.3; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--ink);
  font-weight: 600;
  font-size: .98rem;
}
.nav-link:hover { background: var(--surface2); text-decoration: none; }
.nav-link.active {
  background: var(--surface2);
  color: var(--gold);
  box-shadow: inset 3px 0 0 var(--gold);
}
.nav-link svg { flex: 0 0 auto; width: 22px; height: 22px; }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border);
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.5;
}
.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}
.offline-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); flex: 0 0 auto; }
.offline-badge.ready { color: var(--green); }
.offline-badge.ready .dot { background: var(--green); }

/* Bottom navigation (mobile) */
.bottomnav-inner {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  height: var(--nav-h);
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav-inner .nav-link {
  flex: 1;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
  min-height: var(--nav-h);
  padding: 6px 2px;
  border-radius: 0;
  font-size: .72rem;
  font-weight: 600;
  text-align: center;
}
.bottomnav-inner .nav-link.active { box-shadow: inset 0 3px 0 var(--gold); }
.bottomnav-inner .nav-link svg { width: 22px; height: 22px; }

/* ---- Boot / first-run loading screen ---- */
#boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
#boot[hidden] { display: none; }
.boot-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding: 28px 22px;
}
.boot-mark {
  width: 84px; height: 84px;
  margin: 0 auto 16px;
  border-radius: 22px;
  background: linear-gradient(135deg, #1b2342, #0b0f1e);
  border: 2px solid var(--gold);
  color: var(--gold);
  display: grid; place-items: center;
  font-size: 40px; font-weight: 800;
}
.boot-card h1 { font-size: 1.25rem; margin-bottom: 4px; }
.boot-card p { color: var(--muted); font-size: .92rem; }
.boot-status { min-height: 1.6em; font-size: .9rem; }
.boot-error { color: var(--red); font-size: .9rem; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--gold);
  color: var(--gold-ink);
  padding: 10px 16px;
  border-radius: 0 0 10px 0;
  font-weight: 700;
  z-index: 200;
}
.skip-link:focus { left: 0; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media print {
  #sidebar, #bottomnav, #toast-root, .no-print { display: none !important; }
  #view { padding: 0; max-width: none; }
  body { background: #fff; color: #111; }
}
