/* ===== ADHD Field Guide — styles ===== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #1a1c2b;
  --text-soft: #5b6072;
  --border: #e3e6ef;
  --brand: #5b5bd6;
  --brand-soft: #ecebfb;
  --accent: #e0567e;
  --good: #1d9a6c;
  --shadow: 0 1px 2px rgba(20,22,40,.06), 0 8px 24px rgba(20,22,40,.06);
  --radius: 16px;
  --tab-h: 62px;
  --top-h: 56px;
  --maxw: 720px;

  /* category accents — tuned to pass WCAG AA as small text on light surfaces */
  --c-trait: #5350cf;
  --c-strength: #8a6a00;
  --c-mechanism: #0f7d57;
  --c-concept: #2159c9;
  --c-analogy: #c22f5c;
  --c-side-effect: #ab4629;
  --c-resource: #6f49c0;
}
:root[data-theme="dark"] {
  --bg: #0f1017;
  --surface: #191b24;
  --surface-2: #23262f;
  --text: #eef0f7;
  --text-soft: #a2a8bd;
  --border: #2b2e3a;
  --brand: #9a97ff;
  --brand-soft: #24243a;
  --accent: #f47aa0;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --c-trait: #9a97ff; --c-strength: #e7c24d; --c-mechanism: #3fca97;
  --c-concept: #6fa2ff; --c-analogy: #f47aa0; --c-side-effect: #ef8a63; --c-resource: #b394ff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1017; --surface: #191b24; --surface-2: #23262f;
    --text: #eef0f7; --text-soft: #a2a8bd; --border: #2b2e3a;
    --brand: #9a97ff; --brand-soft: #24243a; --accent: #f47aa0;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
    --c-trait: #9a97ff; --c-strength: #e7c24d; --c-mechanism: #3fca97;
    --c-concept: #6fa2ff; --c-analogy: #f47aa0; --c-side-effect: #ef8a63; --c-resource: #b394ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 6px;
  padding-left: 12px; padding-right: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(150%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 17px; font-weight: 800; margin: 0; letter-spacing: -.02em; flex: 1; cursor: pointer; }
.brand span { color: var(--brand); }
.icon-btn {
  border: none; background: transparent; color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 20px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---- Layout ---- */
.view { max-width: var(--maxw); margin: 0 auto; padding: 16px 16px 28px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-soft); margin: 22px 4px 10px; font-weight: 700; }
.muted { color: var(--text-soft); }

/* ---- Tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(150%) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  border: none; background: transparent; color: var(--text-soft);
  font-size: 11px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--brand); }

/* ---- Hero ---- */
.hero { background: linear-gradient(135deg, var(--brand) 0%, #7b6cf0 55%, var(--accent) 130%);
  color: #fff; border-radius: 20px; padding: 20px; box-shadow: var(--shadow); }
.hero h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.02em; }
.hero p { margin: 0; opacity: .92; font-size: 14px; }
.hero .stat-row { display: flex; gap: 10px; margin-top: 16px; }
.hero .stat { background: rgba(255,255,255,.16); border-radius: 12px; padding: 10px 12px; flex: 1; }
.hero .stat b { display: block; font-size: 22px; line-height: 1; }
.hero .stat span { font-size: 11px; opacity: .9; }

/* ---- Search ---- */
.search { position: relative; margin: 16px 0 6px; }
.search input {
  width: 100%; padding: 13px 14px 13px 42px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 15px; box-shadow: var(--shadow);
}
.search input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.search::before { content: "\1F50D"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 15px; opacity: .6; }

/* ---- Chips ---- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- Category grid (home) ---- */
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat-card {
  text-align: left; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 14px; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden;
  font: inherit;
}
.cat-card .ico { font-size: 24px; }
.cat-card b { font-size: 15px; }
.cat-card small { color: var(--text-soft); font-size: 12px; }
.cat-card::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--acc, var(--brand)); }

/* ---- Entry cards ---- */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); display: flex; gap: 12px; align-items: flex-start;
  cursor: pointer; position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--acc, var(--brand)); }
.card .body { flex: 1; min-width: 0; }
.card .title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h3 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.card .summary { margin: 4px 0 0; color: var(--text-soft); font-size: 13.5px; }
.pill { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-soft); }
.pill.acc { background: color-mix(in srgb, var(--acc) 9%, var(--surface)); color: var(--acc); }

/* mark button */
.mark {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--border); background: transparent; cursor: pointer;
  display: grid; place-items: center; font-size: 15px; color: transparent; transition: .15s;
}
.mark:hover { border-color: var(--brand); }
.mark.on { background: var(--good); border-color: var(--good); color: #fff; }

/* ---- Detail ---- */
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.detail h2 { font-size: 24px; margin: 6px 0 2px; letter-spacing: -.02em; }
.detail .summary-lead { font-size: 16px; color: var(--text); font-weight: 600; margin: 8px 0 14px; }
.detail .prose { font-size: 15.5px; }
.detail .prose p { margin: 0 0 12px; }
.detail .prose ul { margin: 0 0 12px; padding-left: 20px; }
.detail .prose li { margin: 4px 0; }
.detail .prose strong { color: var(--text); }
.detail .tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; }
.tag { font-size: 12px; background: var(--surface-2); color: var(--text-soft); padding: 4px 10px; border-radius: 999px; }
.source-note { font-size: 12.5px; color: var(--text-soft); margin-top: 8px; }
.disclaimer { background: color-mix(in srgb, var(--c-side-effect) 12%, transparent); border: 1px solid color-mix(in srgb, var(--c-side-effect) 30%, transparent);
  color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin: 14px 0; }

.big-mark { width: 100%; margin-top: 8px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 12px 16px; border-radius: 14px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.good { background: var(--good); color: #fff; border-color: var(--good); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- Forms ---- */
.field { margin: 14px 0; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--text-soft); }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 15px; font-family: inherit;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--brand); border-color: transparent; }
.help { font-size: 12.5px; color: var(--text-soft); margin-top: 6px; }
.help a { color: var(--brand); }

/* card container for settings/add panels */
.panel { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel h3 { margin: 0 0 4px; font-size: 16px; }

/* ---- Empty & loading ---- */
.empty { text-align: center; padding: 42px 16px; color: var(--text-soft); }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.spinner { width: 22px; height: 22px; border: 3px solid color-mix(in srgb, var(--brand) 30%, transparent); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--text-soft); font-size: 14px; }

/* ---- Iceberg visual ---- */
.viz { width: 100%; border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); margin: 6px 0 4px; }
.viz svg { display: block; width: 100%; height: auto; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 50; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.fade-in { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- iceberg SVG text ---- */
.ib-h { font: 800 22px -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: .5px; }
.ib-cap { font: 800 12px -apple-system, "Segoe UI", Roboto, sans-serif; text-transform: uppercase; letter-spacing: .5px; }
.ib-above { font: 700 13px -apple-system, "Segoe UI", Roboto, sans-serif; fill: #1a3550; }
.ib-below { font: 600 11px -apple-system, "Segoe UI", Roboto, sans-serif; fill: #ffffff; text-anchor: middle;
  stroke: #0d3b5c; stroke-width: 2.4px; paint-order: stroke fill; stroke-linejoin: round; }
.ib-dark { fill: #14324a; }
.ib-light { fill: #eaf6ff; }

@media (min-width: 560px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
