/* Knowledge Wallet — mobile-first, no framework, system fonts only. */

:root {
  --navy: #16355c;
  --navy-deep: #0e2340;
  --accent: #2f7ee0;
  --accent-strong: #1e63b8;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #e9eef5;
  --text: #1c2733;
  --text-dim: #5b6b7d;
  --border: #d8e0ea;
  --star: #e8a013;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(16, 35, 60, 0.10);
  --appbar-bg: var(--navy);
  --appbar-text: #ffffff;
  --radius: 12px;
  --tabbar-h: 58px;
}

[data-theme="dark"] {
  --bg: #101820;
  --surface: #1a2530;
  --surface-2: #223040;
  --text: #e8edf3;
  --text-dim: #93a4b8;
  --border: #2d3d50;
  --appbar-bg: #0e2340;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  background: var(--appbar-bg); color: var(--appbar-text);
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 30px; height: 30px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }

/* ---------- Layout ---------- */
#view {
  max-width: 760px; margin: 0 auto;
  padding: 12px 14px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  outline: none;
}
.section-title { font-size: 15px; font-weight: 700; margin: 16px 0 8px; }
.section-title:first-child { margin-top: 4px; }
.muted { color: var(--text-dim); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; font-size: 11px; color: var(--text-dim);
  height: var(--tabbar-h);
}
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--accent-strong); font-weight: 600; }
[data-theme="dark"] .tab.on { color: #6db1f7; }

/* ---------- Search + filters ---------- */
.searchbar {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; margin-bottom: 10px;
}
.searchbar svg { width: 17px; height: 17px; flex: none; color: var(--text-dim); }
.searchbar input {
  flex: 1; border: 0; background: none; color: var(--text);
  font: inherit; font-size: 14px; outline: none; min-width: 0;
}
.searchbar .clear-btn { color: var(--text-dim); font-size: 17px; line-height: 1; padding: 2px 4px; }

.chiprow {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chiprow::-webkit-scrollbar { display: none; }
.chip {
  flex: none; font-size: 12px; padding: 5px 11px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  white-space: nowrap;
}
.chip.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
.chip.tagchip { background: var(--surface-2); }
.chip.tagchip.on { background: var(--accent-strong); }

/* ---------- Covers ---------- */
.cover {
  position: relative; overflow: hidden; border-radius: 10px;
  display: flex; align-items: flex-end;
  color: #fff; padding: 8px;
}
.cover .cover-label {
  position: relative; z-index: 1;
  font-size: 10px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  background: rgba(10, 25, 45, 0.55); padding: 2px 6px; border-radius: 4px;
}
.cover-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: top center;
}
.cover .play-badge {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 1;
}
.cover .play-badge span {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.92); color: var(--navy);
  display: grid; place-items: center; font-size: 13px; padding-left: 3px;
}
.g0 { background: linear-gradient(150deg, #16355c, #2f7ee0); }
.g1 { background: linear-gradient(150deg, #0e4d64, #23a6b8); }
.g2 { background: linear-gradient(150deg, #1b2d5e, #6c63d8); }
.g3 { background: linear-gradient(150deg, #143c2b, #2fa26a); }
.g4 { background: linear-gradient(150deg, #5c2e16, #e08a2f); }
.g5 { background: linear-gradient(150deg, #4a1633, #c0397a); }

/* ---------- Featured cards ---------- */
.rowwrap { position: relative; }
.rownav { display: none; }
.cardrow {
  display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.cardrow::-webkit-scrollbar { display: none; }
.fcard {
  flex: none; width: 140px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; text-align: left;
}
.fcard .cover { height: 88px; border-radius: 0; }
.fcard .fcard-body { padding: 8px 9px 10px; display: flex; flex-direction: column; gap: 3px; }
.fcard .fcard-title {
  font-size: 12px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.fcard .fcard-sub { font-size: 10.5px; color: var(--text-dim); }

/* ---------- List rows ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px;
}
.row .cover { width: 46px; height: 60px; flex: none; padding: 4px; }
.row .cover .cover-label { font-size: 7px; }
.row .cover:has(.cover-img) .cover-label { display: none; }
.row.video-row .cover { height: 46px; }
.row-body { flex: 1; min-width: 0; }
.row-title {
  font-size: 13.5px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.row-star { flex: none; padding: 8px; color: var(--text-dim); }
.row-star.on { color: var(--star); }
.row-star svg { width: 20px; height: 20px; }

.result-count { font-size: 12px; color: var(--text-dim); margin: 2px 0 8px; }

.empty {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 26px 18px; text-align: center; color: var(--text-dim);
  font-size: 13px; margin-top: 14px; line-height: 1.5;
}
.empty .big { font-size: 26px; margin-bottom: 6px; }

/* ---------- Install banner ---------- */
.install-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px;
}
.install-banner .btn-small { flex: none; }
.install-banner .dismiss { flex: none; color: var(--text-dim); font-size: 17px; padding: 4px 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent-strong); color: #fff; font-weight: 600; font-size: 14px;
  border-radius: 10px; padding: 12px 16px; width: 100%;
}
.btn:active { background: var(--navy); }
.btn.secondary {
  background: var(--surface); color: var(--accent-strong);
  border: 1px solid var(--accent-strong);
}
[data-theme="dark"] .btn.secondary { color: #6db1f7; border-color: #6db1f7; }
.btn-small {
  background: var(--accent-strong); color: #fff; font-size: 12px; font-weight: 600;
  border-radius: 999px; padding: 6px 14px;
}
.btnrow { display: flex; gap: 8px; margin: 12px 0; }
.btnrow .btn { flex: 1; padding: 11px 8px; font-size: 13px; }

/* ---------- Detail page ---------- */
.detail-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.back-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--text-dim); padding: 6px 8px 6px 0; }
.detail-actions { display: flex; gap: 4px; }
.detail-actions .icon-btn { color: var(--text-dim); }
.detail-actions .icon-btn:active { background: var(--surface-2); }
.detail-actions .icon-btn.on { color: var(--star); }

.detail-hero { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.detail-hero .cover { height: 150px; border-radius: 0; padding: 12px; }
.detail-hero .cover-label { font-size: 11px; }

.video-frame { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.video-frame .cover { height: auto; aspect-ratio: 16 / 9; border-radius: 0; }
.video-frame iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; display: block; background: #000; }

.detail-title { font-size: 19px; font-weight: 700; line-height: 1.25; margin: 14px 0 2px; }
.detail-subtitle { font-size: 14px; color: var(--text-dim); margin-bottom: 4px; }
.detail-kicker { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.type-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--accent-strong); background: var(--surface-2);
  padding: 2px 8px; border-radius: 4px;
}
[data-theme="dark"] .type-badge { color: #6db1f7; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-top: 12px;
}
.card h3 { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.card p { font-size: 13.5px; line-height: 1.55; }
.card .chiprow { padding-bottom: 0; margin-top: 10px; flex-wrap: wrap; }
.read-more {
  display: inline-block; margin-top: 8px; padding: 2px 0;
  font-size: 13px; font-weight: 600; color: var(--accent-strong);
}
[data-theme="dark"] .read-more { color: #6db1f7; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 5px 0; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv .k { color: var(--text-dim); flex: none; }
.kv .v { text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Bottom sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 20, 35, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadein 0.15s ease;
}
.sheet {
  background: var(--surface); color: var(--text);
  border-radius: 16px 16px 0 0;
  width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  animation: slideup 0.2s ease;
}
.sheet-grip { width: 34px; height: 4px; border-radius: 2px; background: var(--border); margin: 2px auto 12px; }
.sheet h2 { font-size: 17px; margin-bottom: 4px; }
.sheet .sheet-sub { font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.sheet-box {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; color: var(--text-dim); margin: 12px 0; overflow-wrap: anywhere;
}
@keyframes fadein { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(30px); opacity: 0.6; } }

/* ---------- Settings ---------- */
.set-group { margin-top: 14px; }
.set-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); margin-bottom: 6px; }
.set-box { background: var(--surface-2); border-radius: 10px; padding: 4px 12px; }
.set-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; font-size: 14px; width: 100%; text-align: left; }
.set-item + .set-item { border-top: 1px solid var(--border); }
.set-item .sub { display: block; font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.set-item .val { color: var(--text-dim); font-size: 13px; flex: none; }

.toggle {
  flex: none; width: 42px; height: 24px; border-radius: 12px;
  background: var(--border); position: relative; transition: background 0.15s;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: left 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.toggle.on { background: var(--accent-strong); }
.toggle.on::after { left: 20px; }

.about-blurb { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; padding: 10px 0; }

/* ---------- Intro (onboarding) ---------- */
.intro-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  animation: fadein 0.2s ease;
}
.intro-card {
  position: relative; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center;
  padding: 32px 28px calc(30px + env(safe-area-inset-bottom));
}
.intro-skip {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 20px;
  color: var(--text-dim); font-size: 14px; padding: 6px 8px;
}
.intro-art { color: var(--accent-strong); margin-bottom: 6px; }
.intro-art svg { width: 170px; height: 170px; }
[data-theme="dark"] .intro-art { color: #6db1f7; }
.intro-title { font-size: 24px; font-weight: 800; color: var(--text); }
.intro-sub { font-size: 14.5px; color: var(--text-dim); line-height: 1.55; max-width: 320px; }
.intro-dots { display: flex; gap: 8px; margin: 8px 0 4px; }
.intro-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.intro-dots .dot.on { background: var(--accent-strong); }
.intro-next { max-width: 300px; }

/* splash (screen 0, mobile) */
.intro-card.splash {
  background: linear-gradient(168deg, #0b1d38 0%, #16355c 55%, #1e63b8 130%);
  color: #fff;
}
.intro-card.splash .intro-skip { color: rgba(255, 255, 255, 0.65); }
.splash-art { color: #fff; opacity: 0.95; margin-bottom: 18px; animation: splashin 0.7s ease; }
.splash-art svg { width: 130px; height: 130px; }
.splash-eyebrow {
  font-size: 12px; font-weight: 600; letter-spacing: 3.5px; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
}
.splash-title {
  font-size: 32px; line-height: 1.22; font-weight: 800; letter-spacing: 0.2px;
  margin-top: 4px;
}
.splash-rule {
  width: 44px; height: 2px; margin: 16px 0 10px;
  background: rgba(255, 255, 255, 0.45); border-radius: 1px;
}
.splash-by { font-size: 13.5px; color: rgba(255, 255, 255, 0.75); letter-spacing: 0.5px; }
.splash-btn {
  max-width: 300px; margin-top: 34px;
  background: #fff; color: var(--navy);
}
.splash-btn:active { background: #d8e0ea; }
@keyframes splashin { from { opacity: 0; transform: scale(0.92); } }

@media (min-width: 1024px) {
  .intro-backdrop {
    background: rgba(10, 20, 35, 0.45);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  }
  .intro-card {
    width: 60%; max-width: 620px; height: auto; min-height: 60vh;
    background: var(--surface); border-radius: 18px;
    box-shadow: 0 12px 44px rgba(0, 0, 0, 0.35);
    padding: 48px 48px 40px;
    animation: slideup 0.22s ease;
  }
  .intro-skip { top: 16px; }
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + 14px); z-index: 60; display: flex; justify-content: center; pointer-events: none; }
.toast {
  background: var(--navy-deep); color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  animation: fadein 0.2s ease;
}

/* ---------- Tablet ---------- */
@media (min-width: 700px) {
  .list.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .fcard { width: 160px; }
  .brand-title { font-size: 16px; }
}

/* ---------- Desktop: top nav bar, wide grids, two-column detail ---------- */
/* On phones the wrappers are transparent (display: contents). */
.detail-main, .detail-side { display: contents; }

@media (min-width: 1024px) {
  #view {
    max-width: 1100px;
    padding-left: 24px; padding-right: 24px;
    padding-bottom: 48px;
  }

  /* bottom tabs become a centered top bar overlaid on the app bar */
  .appbar { padding-top: 12px; padding-bottom: 12px; }
  .tabbar {
    top: 0; bottom: auto; left: 50%; right: auto;
    transform: translateX(-50%);
    width: auto; height: 54px;
    background: none; border: 0; padding: 0;
    align-items: stretch; gap: 4px; z-index: 21;
  }
  .tab {
    flex: none; flex-direction: row; align-items: center; gap: 7px;
    height: auto; padding: 0 16px;
    font-size: 13.5px; color: rgba(255, 255, 255, 0.72);
    border-bottom: 2.5px solid transparent;
  }
  .tab svg { width: 18px; height: 18px; }
  .tab.on, [data-theme="dark"] .tab.on {
    color: #fff; font-weight: 600;
    border-bottom-color: #fff;
  }
  #toast-root { bottom: 30px; }

  /* topic/type chips wrap instead of scrolling */
  .chiprow { flex-wrap: wrap; overflow-x: visible; }

  /* card rows get hover arrows + wheel scrolling (see app.js) */
  .rownav {
    display: grid; place-items: center;
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; border-radius: 50%; z-index: 2;
    background: var(--surface); border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: var(--text-dim); font-size: 26px; line-height: 1; padding-bottom: 4px;
    opacity: 0.85; transition: opacity 0.15s;
  }
  .rowwrap:hover .rownav { opacity: 1; }
  .rownav:hover { color: var(--accent-strong); }
  .rowwrap.no-scroll .rownav { display: none; }
  .rownav.prev { left: -14px; }
  .rownav.next { right: -14px; }

  /* wider grids */
  .list.grid2 { grid-template-columns: repeat(3, 1fr); }
  .fcard { width: 190px; }
  .fcard .cover { height: 118px; }
  .searchbar { max-width: 560px; }

  /* detail page: content left, sticky details rail right */
  #view[data-route="item"] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    column-gap: 28px;
    align-content: start;
  }
  #view[data-route="item"] .detail-top { grid-column: 1 / -1; }
  #view[data-route="item"] .detail-main { display: block; grid-column: 1; min-width: 0; }
  #view[data-route="item"] .detail-side {
    display: block; grid-column: 2;
    position: sticky; top: 70px; align-self: start;
  }
  #view[data-route="item"] .detail-side .card { margin-top: 0; }
  .detail-hero .cover { height: 260px; }
  .detail-title { font-size: 24px; }
  .btnrow { max-width: 560px; }
}
