:root {
  --bg: #0a0f1a;
  --surface: #111827;
  --surface2: #1a2438;
  --border: #243050;
  --text: #e8f0ff;
  --muted: #7a93c0;
  --gold: #FFD34D;
  --gold-dim: #B8960A;
  --green: #3ddc84;
  --red: #ff4757;
  --red-dim: #c0392b;
  --cyan: #39d0ff;
  --amber: #f5a623;
  --purple: #b77cff;
  --emergency: #ff2d2d;
  --font-base: 17px;
  --font-sm: 14px;
  --font-lg: 20px;
  --font-xl: 26px;
  --tap: 48px;
  --radius: 6px;
}

[data-theme="light"] {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface2: #e8eef6;
  --border: #c8d8ec;
  --text: #1a2438;
  --muted: #5a7090;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: var(--font-base); scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ─── TOP BAR ─── */
#app-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 2px solid var(--gold);
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-brand {
  font-size: 15px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: .06em;
  text-transform: uppercase;
  flex: 1;
}

.topbar-btn {
  width: var(--tap);
  height: var(--tap);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.topbar-btn:active { background: var(--surface2); }

#search-bar-wrap {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

#search-bar-wrap.open { display: block; }

#search-input {
  width: 100%;
  height: var(--tap);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--font-base);
  padding: 0 14px;
  outline: none;
}

#search-input:focus { border-color: var(--gold); }
#search-input::placeholder { color: var(--muted); }

#search-results {
  margin-top: 8px;
  max-height: 60vh;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.search-result-item:hover, .search-result-item:active { background: var(--surface2); }

.search-result-icon { font-size: 22px; flex-shrink: 0; }

.search-result-title {
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--text);
}

.search-result-cat { font-size: 12px; color: var(--muted); }

.search-emergency { color: var(--emergency); }

/* ─── OFFLINE BADGE ─── */
#offline-badge {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(61,220,132,.15);
  border: 1px solid var(--green);
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 20px;
  letter-spacing: .08em;
  text-transform: uppercase;
  z-index: 200;
  pointer-events: none;
}

body.offline #offline-badge { display: block; }

/* ─── VIEWS ─── */
.view { display: none; padding: 16px; max-width: 680px; margin: 0 auto; }
.view.active { display: block; }

/* ─── HOME ─── */
.emergency-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  background: var(--emergency);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: var(--font-lg);
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  margin-bottom: 20px;
  -webkit-tap-highlight-color: transparent;
  animation: pulse-red 2s ease-in-out infinite;
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,45,45,.5); }
  50% { box-shadow: 0 0 0 10px rgba(255,45,45,0); }
}

.emergency-btn:active { filter: brightness(.9); }

.section-title {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 14px;
}

.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .12s, background .12s;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.category-card:hover, .category-card:active { border-color: var(--gold); background: var(--surface2); }

.category-card.emergency-cat { border-color: rgba(255,45,45,.4); }
.category-card.emergency-cat:hover { border-color: var(--emergency); }

.cat-icon { font-size: 28px; line-height: 1; }

.cat-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .04em;
  line-height: 1.3;
}

.cat-count { font-size: 11px; color: var(--muted); }

.cat-badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.cat-badge-emergency { background: rgba(255,45,45,.15); color: var(--emergency); border: 1px solid rgba(255,45,45,.3); }
.cat-badge-survival { background: rgba(89,240,138,.1); color: var(--green); border: 1px solid rgba(89,240,138,.25); }

.topic-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }

.topic-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: var(--tap);
  transition: border-color .12s;
}

.topic-row:hover, .topic-row:active { border-color: var(--gold); }
.topic-row.emergency-topic { border-left: 3px solid var(--emergency); }

.topic-icon { font-size: 22px; flex-shrink: 0; }
.topic-title { flex: 1; font-size: var(--font-base); font-weight: 700; }
.topic-arrow { color: var(--muted); font-size: 14px; }

.favorite-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
  color: var(--muted);
  flex-shrink: 0;
}

.favorite-btn.active { color: var(--gold); }

/* ─── CATEGORY VIEW ─── */
.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.back-btn {
  min-width: var(--tap);
  height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--font-base);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 14px;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}

.back-btn:active { background: var(--surface2); }

.view-title-block { flex: 1; }
.view-title { font-size: var(--font-xl); font-weight: 900; line-height: 1.2; }
.view-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ─── TOPIC VIEW ─── */
.topic-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  text-align: center;
}

.topic-header-icon { font-size: 48px; margin-bottom: 10px; }
.topic-header-title { font-size: var(--font-xl); font-weight: 900; margin-bottom: 6px; }
.topic-header-cat { font-size: 12px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }

.call-911-banner {
  background: rgba(255,45,45,.15);
  border: 2px solid var(--emergency);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.call-911-banner .icon { font-size: 28px; flex-shrink: 0; }
.call-911-banner .msg { font-size: var(--font-base); font-weight: 700; color: var(--emergency); }
.call-911-banner .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.call-911-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  background: var(--emergency);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: var(--font-lg);
  font-weight: 900;
  text-decoration: none;
  letter-spacing: .06em;
  margin-bottom: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.content-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
}

.content-block-title {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 12px;
}

.what-first-text {
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--green);
  line-height: 1.6;
}

.steps-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.step-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.step-num {
  min-width: 30px;
  height: 30px;
  background: var(--gold);
  color: #000;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-text { font-size: var(--font-base); line-height: 1.6; }

.warning-list { display: flex; flex-direction: column; gap: 8px; }

.warning-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: var(--font-base);
  line-height: 1.5;
}

.warning-item::before {
  content: '⚠';
  font-size: 16px;
  color: var(--amber);
  flex-shrink: 0;
  margin-top: 2px;
}

.donot-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: var(--font-base);
  line-height: 1.5;
}

.donot-item::before {
  content: '✗';
  font-size: 16px;
  color: var(--red);
  font-weight: 900;
  flex-shrink: 0;
  margin-top: 2px;
}

.supplies-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.supply-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  color: var(--muted);
}

.related-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.related-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

.related-card:hover, .related-card:active { border-color: var(--gold); }

.disclaimer-block {
  background: rgba(255,211,77,.05);
  border: 1px solid rgba(255,211,77,.2);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.disclaimer-block strong { color: var(--amber); }

/* ─── REWARD STRIP ─── */
.reward-strip {
  background: rgba(255,211,77,.06);
  border: 1px solid rgba(255,211,77,.2);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  font-size: 12px;
  color: var(--muted);
}

.reward-strip .icon { font-size: 18px; flex-shrink: 0; }
.reward-strip strong { color: var(--gold); }

/* ─── FAVORITES EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  font-size: var(--font-base);
}

.empty-state .es-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; margin-top: 6px; }

/* ─── RECENTLY VIEWED ─── */
.recent-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }

/* ─── THEME TOGGLE ─── */
.theme-icon { font-size: 18px; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── RESPONSIVE ─── */
@media (min-width: 480px) {
  .category-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 680px) {
  .category-grid { grid-template-columns: repeat(4, 1fr); }
  .view { padding: 24px 20px; }
}

/* ─── TRANSITIONS ─── */
.view { animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
