:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef4fb;
  --text: #102033;
  --muted: #5d6f82;
  --brand: #0b5cab;
  --brand-2: #073b78;
  --accent: #eaf3ff;
  --danger: #b3261e;
  --danger-bg: #fff1f0;
  --priority: #0f766e;
  --priority-bg: #ecfdf5;
  --border: #d8e3f0;
  --shadow: 0 12px 30px rgba(7, 34, 68, 0.10);
  --radius: 18px;
  --tap: 56px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071224;
  --surface: #0f1e33;
  --surface-2: #14283f;
  --text: #eef6ff;
  --muted: #b8c9dc;
  --brand: #58a6ff;
  --brand-2: #8fc5ff;
  --accent: #102a46;
  --danger: #ffb4ab;
  --danger-bg: #3b1415;
  --priority: #7de0c9;
  --priority-bg: #0e332f;
  --border: #27405d;
  --shadow: 0 16px 36px rgba(0,0,0,0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: 0;
}
button, input, a { font: inherit; }
button { min-height: var(--tap); }
a { color: var(--brand); }
.skip-link { position: absolute; left: -999px; top: 8px; }
.skip-link:focus { left: 8px; z-index: 99; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  color: white;
  box-shadow: var(--shadow);
}
.app-header h1 { font-size: clamp(1.3rem, 5vw, 1.8rem); margin: 0; letter-spacing: -0.02em; }
.eyebrow { margin: 0 0 4px; text-transform: uppercase; letter-spacing: .08em; font-size: .76rem; font-weight: 800; color: var(--brand); }
.app-header .eyebrow { color: rgba(255,255,255,.85); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.ghost-btn {
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(255,255,255,.14);
  color: white;
  font-weight: 800;
  cursor: pointer;
}
.ghost-btn.install { padding-inline: 16px; }

.app-shell, .viewer-shell { width: min(900px, 100%); margin: 0 auto; padding: 16px; }
.hero, .panel, .topic-detail, .topic-row, .section-card, .topic-block, .pdf-toolbar, .pdf-page-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero { padding: 22px; margin-bottom: 16px; }
.hero h2, .panel h2, .topic-heading h2 { margin: 0 0 8px; line-height: 1.1; letter-spacing: -0.03em; }
.hero p, .panel p { color: var(--muted); }
.badge { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: var(--accent); color: var(--brand); font-weight: 800; font-size: .82rem; margin-bottom: 10px; }
.notice { margin-top: 14px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }

.grid.four { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.section-card {
  display: grid;
  gap: 8px;
  text-align: left;
  padding: 18px;
  min-height: 150px;
  cursor: pointer;
  color: var(--text);
}
.section-card:hover, .topic-row:hover, .home-return:hover, .back-btn:hover, .pdf-btn:hover { transform: translateY(-1px); }
.section-card:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.section-num { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; color: white; background: var(--brand); font-weight: 900; }
.section-title { display: block; font-weight: 900; font-size: 1.02rem; line-height: 1.18; }
.section-short { color: var(--muted); font-size: .92rem; }

.panel { padding: 18px; margin-bottom: 16px; }
.panel.compact { padding: 16px; }
.feature-list { display: flex; flex-wrap: wrap; gap: 8px; }
.feature-list span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 7px 10px; font-weight: 700; font-size: .9rem; }
.warning-panel { border-color: color-mix(in srgb, var(--danger), var(--border) 50%); }

.topic-list { display: grid; gap: 10px; margin-bottom: 16px; }
.topic-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  text-align: left;
  padding: 16px;
  cursor: pointer;
  color: var(--text);
}
.topic-row span { font-weight: 850; }
.topic-row small { color: var(--muted); white-space: nowrap; font-weight: 700; }

.home-return, .back-btn, .link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--brand);
  font-weight: 900;
  padding: 0 16px;
  cursor: pointer;
  text-decoration: none;
  margin: 6px 8px 14px 0;
}
.home-return { background: var(--brand); border-color: var(--brand); color: white; }

.topic-detail { padding: 14px; margin-bottom: 16px; }
.topic-heading { padding: 8px 8px 14px; }
.topic-heading h2 { font-size: clamp(1.45rem, 6vw, 2.3rem); }
.topic-block { padding: 16px; margin: 10px 0; box-shadow: none; }
.topic-block h3 { margin: 0 0 10px; font-size: 1.05rem; }
.topic-block ul { margin: 0; padding-left: 1.1rem; }
.topic-block li { margin: 0 0 8px; }
.topic-block.priority { background: var(--priority-bg); border-color: color-mix(in srgb, var(--priority), var(--border) 50%); }
.topic-block.priority h3 { color: var(--priority); }
.topic-block.red { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger), var(--border) 50%); }
.topic-block.red h3 { color: var(--danger); }
.topic-block.official { background: var(--surface-2); }
.pdf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  text-decoration: none;
  border-radius: 14px;
  padding: 10px 14px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: white;
  font-weight: 900;
  margin: 8px 8px 8px 0;
}
.pdf-btn.secondary { background: transparent; color: var(--brand); }
.muted { color: var(--muted); }

.viewer-body { padding-bottom: 0; }
.viewer-header h1 { font-size: clamp(1rem, 5vw, 1.35rem); max-width: 70vw; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.pdf-toolbar {
  position: sticky;
  top: 78px;
  z-index: 15;
  padding: 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.pdf-toolbar button, .pdf-toolbar input {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 800;
  min-height: 46px;
  padding: 0 12px;
}
.pdf-toolbar button:not(:disabled) { cursor: pointer; }
.pdf-toolbar button:disabled { opacity: .45; }
#pageForm { display: flex; align-items: center; justify-content: center; gap: 6px; }
#pageInput { width: 74px; text-align: center; }
.viewer-note { color: var(--muted); font-size: .9rem; margin: 6px 0 10px; }
.pdf-page-frame { margin: 0; padding: 8px; overflow: auto; }
.pdf-page-frame img { display: block; width: 100%; height: auto; border-radius: 10px; background: white; }
.pdf-page-frame figcaption { text-align: center; color: var(--muted); padding: 10px 4px 2px; }

@media (max-width: 650px) {
  .grid.four { grid-template-columns: 1fr; }
  .section-card { min-height: 112px; }
  .topic-row { align-items: flex-start; flex-direction: column; }
  .pdf-toolbar { top: 74px; grid-template-columns: 1fr; }
  #pageForm { justify-content: space-between; }
  .viewer-shell, .app-shell { padding: 12px; }
}

@media print {
  .app-header, .home-return, .back-btn, .pdf-toolbar, .viewer-actions { display: none !important; }
  body { background: white; color: black; padding: 0; }
  .topic-block, .panel, .topic-detail { box-shadow: none; border-color: #aaa; }
}

.single-action {
  margin: 4px 0 16px;
}
.about-button {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--brand);
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.about-button:hover { transform: translateY(-1px); }
.important-card {
  border-color: color-mix(in srgb, var(--danger), var(--border) 55%);
  background: color-mix(in srgb, var(--danger-bg), var(--surface) 35%);
}
