/* Mapa de Estudos — offline app.
   Layout: a full-bleed study canvas (or a reading list); header, library, inspector and dock float above it.
   Phone (≤640px): sheets and a compact dock. Tablet (641–1100px): panels slide over the canvas. Desktop (>1100px): panels dock beside it. */

@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/newsreader-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/newsreader-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/newsreader-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: italic; font-weight: 500; font-display: swap; src: url("fonts/newsreader-latin-500-italic.woff2") format("woff2"); }
@font-face { font-family: "Figtree"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/figtree-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Figtree"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/figtree-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Figtree"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/figtree-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Figtree"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/figtree-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }

:root {
  --canvas: #f3f4f8;
  --canvas-glow: #ffffff;
  --dot: rgba(28, 36, 72, .10);
  --panel: rgba(255, 255, 255, .82);
  --panel-solid: #ffffff;
  --fg: #151a2d;
  --muted: #5f6782;
  --faint: #8d93a8;
  --hair: rgba(21, 26, 45, .09);
  --hair-strong: rgba(21, 26, 45, .16);
  --field: rgba(21, 26, 45, .045);
  --gold: #9a6d12;
  --gold-soft: rgba(184, 137, 43, .14);
  --gold-ring: #c4952f;
  --root-bg: #151a2d;
  --root-fg: #f7f3ea;
  --root-eb: #e2bd6a;
  --btn-bg: #151a2d;
  --btn-fg: #f6e3b4;
  --review: #d4552c;
  --learning: #3c6fe0;
  --done: #178a5e;
  --mono-a: #3a4058; --mono-b: #1b1f30; --mono-line: #7d849c; --mono-ink: #f7f3ea;
  --shadow-panel: 0 1px 0 rgba(255,255,255,.6) inset, 0 10px 30px -12px rgba(21,26,45,.22), 0 2px 6px -2px rgba(21,26,45,.08);
  --scrim: rgba(14, 18, 34, .42);
  --f-display: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --f-ui: "Figtree", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --tap: 36px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0b0f1d; --canvas-glow: #15203d; --dot: rgba(190, 205, 255, .075);
    --panel: rgba(20, 25, 44, .82); --panel-solid: #161b2f; --fg: #eef0f7; --muted: #a2a9c2; --faint: #6f7692;
    --hair: rgba(220, 228, 255, .09); --hair-strong: rgba(220, 228, 255, .17); --field: rgba(220, 228, 255, .05);
    --gold: #e6c06e; --gold-soft: rgba(230, 192, 110, .14); --gold-ring: #e6c06e;
    --root-bg: #1b2240; --root-fg: #f7f1e3; --root-eb: #e6c06e;
    --btn-bg: #e6c06e; --btn-fg: #141a2e;
    --review: #ff8a5e; --learning: #79a3ff; --done: #4fd497;
    --mono-a: #3b4366; --mono-b: #262c47; --mono-line: #8d95b5; --mono-ink: #f1ece0;
    --shadow-panel: 0 1px 0 rgba(255,255,255,.05) inset, 0 16px 40px -14px rgba(0,0,0,.7), 0 2px 8px -2px rgba(0,0,0,.4);
    --scrim: rgba(3, 5, 12, .62);
    color-scheme: dark;
  }
}
@media (pointer: coarse) { :root { --tap: 44px; } }

html, body { height: 100%; margin: 0; }
body {
  background: var(--canvas); color: var(--fg); font-family: var(--f-ui); font-size: 15px;
  overflow: hidden; overscroll-behavior: none; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--gold-ring); outline-offset: 2px; }
.eyebrow { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); font-weight: 500; }

.app {
  position: fixed; inset: 0; overflow: hidden;
  --free-l: max(16px, var(--sal)); --free-r: max(16px, var(--sar));
}
@media (min-width: 1101px) {
  .app.lib-open { --free-l: calc(max(16px, var(--sal)) + 288px); }
  .app.insp-open { --free-r: calc(max(16px, var(--sar)) + 340px); }
}

/* Canvas */
.stage {
  position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.3px), radial-gradient(ellipse at 50% 42%, var(--canvas-glow) 0%, transparent 62%);
  background-size: 24px 24px, 100% 100%;
}
.stage.panning { cursor: grabbing; }
.stage:focus-visible { outline: none; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#world.anim { transition: transform .45s cubic-bezier(.2,.75,.2,1); }
#edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }

.node { position: absolute; left: 0; top: 0; width: max-content; max-width: 260px; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; display: flex; align-items: center; gap: 7px; line-height: 1.28; will-change: transform; }
.node .body { display: flex; flex-direction: column; min-width: 0; }
.node .eb { font-family: var(--f-mono); font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase; font-weight: 500; margin-bottom: 2px; color: var(--line, var(--faint)); }
.node .tx { white-space: pre-wrap; overflow-wrap: anywhere; outline: none; }
.node .tx[contenteditable] { cursor: text; user-select: text; -webkit-user-select: text; }
.node.d0 {
  background: var(--root-bg); color: var(--root-fg); padding: 16px 28px 18px; border-radius: 20px; max-width: 360px; text-align: center; justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(230,192,110,.35), inset 0 0 0 5px var(--root-bg), inset 0 0 0 6px rgba(230,192,110,.18), 0 24px 50px -22px rgba(10,14,30,.7);
}
.node.d0 .body { align-items: center; }
.node.d0 .tx { font-family: var(--f-display); font-style: italic; font-weight: 500; font-size: 27px; letter-spacing: -.01em; line-height: 1.12; }
.node.d0 .eb { color: var(--root-eb); margin-bottom: 6px; }
.node.d1 {
  background: linear-gradient(135deg, var(--ca), var(--cb)); color: var(--ink); padding: 9px 16px 10px; border-radius: 13px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28), inset 0 -1px 0 rgba(0,0,0,.08), 0 10px 22px -12px var(--cb);
  font-weight: 600; font-size: 15.5px; letter-spacing: -.005em;
}
.node.d1 .eb { color: var(--ink); opacity: .72; }
.node.d2 { font-size: 15px; font-weight: 500; padding: 3px 4px 6px; color: var(--fg); background-image: linear-gradient(var(--line), var(--line)); background-size: 100% 2px; background-position: 0 100%; background-repeat: no-repeat; }
.node.dn { font-size: 14px; padding: 2px 3px 5px; color: var(--fg); background-image: linear-gradient(var(--line), var(--line)); background-size: 100% 1.5px; background-position: 0 100%; background-repeat: no-repeat; }
.node.st-done.d2 .tx, .node.st-done.dn .tx { color: var(--muted); }
.node.sel::after, .node.editing::after, .node.hit::after, .node.drop-in::after, .node.lifted::after {
  content: ""; position: absolute; inset: -5px; border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 2px var(--gold-ring), 0 0 0 6px var(--gold-soft);
}
.node.d0.sel::after, .node.d0.editing::after { border-radius: 25px; }
.node.d1.sel::after, .node.d1.editing::after { border-radius: 17px; }
.node.hit::after { box-shadow: 0 0 0 2px var(--review), 0 0 0 6px color-mix(in srgb, var(--review) 18%, transparent); }
.node.drop-in::after { box-shadow: 0 0 0 2px var(--done), 0 0 0 6px color-mix(in srgb, var(--done) 18%, transparent); }
.node.lifted { transform-origin: center; }
.node.dim { opacity: .22 !important; }
.node.dragging { opacity: .35 !important; }
.node.drop-before::before, .node.drop-after::before { content: ""; position: absolute; left: -4px; right: -4px; height: 3px; background: var(--done); border-radius: 2px; }
.node.drop-before::before { top: -8px; }
.node.drop-after::before { bottom: -9px; }
.mk { flex: none; display: block; }
.mk.review { color: var(--review); } .mk.learning { color: var(--learning); } .mk.done { color: var(--done); }
.node.d1 .mk { color: var(--ink); }
.nt { flex: none; opacity: .55; display: block; }
.node.d1 .nt { opacity: .8; }
.tog {
  position: absolute; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 5px; border: 1.5px solid var(--line, var(--faint)); background: var(--panel-solid);
  color: var(--fg); font: 600 10.5px/17px var(--f-ui); text-align: center; display: none; font-variant-numeric: tabular-nums; box-shadow: 0 2px 6px -2px rgba(0,0,0,.25);
}
.tog::before { content: ""; position: absolute; inset: -10px; }
.node.has-kids:hover .tog, .node.has-kids.sel .tog, .node.collapsed .tog { display: block; }
.node.d0 .tog { display: none !important; }
.node.sr .tog { left: calc(100% + 7px); }
.node.sl .tog { right: calc(100% + 7px); }
.node.d1 .tog { top: calc(50% - 10px); }
.node.d2 .tog, .node.dn .tog { top: calc(100% - 11px); }
@media (pointer: coarse) { .node.has-kids .tog { display: block; } }

.ghost { position: fixed; z-index: 100; pointer-events: none; background: var(--panel-solid); border: 1px solid var(--hair-strong); box-shadow: var(--shadow-panel); padding: 6px 12px; border-radius: 10px; font-size: 14px; max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Reading list view */
.outline { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--canvas); overscroll-behavior: contain; }
.ol-inner { max-width: 760px; margin: 0 auto; padding: calc(var(--sat) + 92px) max(20px, var(--sar)) calc(var(--sab) + 120px) max(20px, var(--sal)); }
@media (min-width: 1101px) {
  .app.lib-open .ol-inner { margin-left: max(calc(304px + 24px), calc(50% - 380px)); }
  .app.insp-open .ol-inner { margin-right: max(calc(356px + 24px), calc(50% - 380px)); }
}
.ol-head { padding: 0 0 22px; border-bottom: 1px solid var(--hair); margin-bottom: 14px; cursor: pointer; }
.ol-head h1 { margin: 6px 0 0; font-family: var(--f-display); font-style: italic; font-weight: 500; font-size: clamp(30px, 6vw, 42px); line-height: 1.08; letter-spacing: -.015em; text-wrap: balance; overflow-wrap: anywhere; }
.ol-head .ol-sum { margin: 12px 0 0; display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.ol-head.sel h1 { text-decoration: underline; text-decoration-color: var(--gold-ring); text-decoration-thickness: 2px; text-underline-offset: 6px; }
.ol-list { list-style: none; margin: 0; padding: 0; }
.ol-list .ol-list { margin-left: 15px; padding-left: 14px; border-left: 2px solid color-mix(in srgb, var(--line) 45%, transparent); }
.ol-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: start; gap: 4px; padding: 7px 8px 7px 0; border-radius: 12px; cursor: pointer; }
.ol-row:hover { background: var(--field); }
.ol-row.sel { background: var(--gold-soft); }
.ol-row.dim { opacity: .3; }
.ol-row.hit { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--review) 50%, transparent); }
.ol-tog { width: 28px; height: 28px; border: 0; background: transparent; color: var(--line); display: grid; place-items: center; border-radius: 8px; margin-top: -3px; }
.ol-tog svg { transition: transform .2s; }
.ol-tog.closed svg { transform: rotate(-90deg); }
.ol-tog .dot { width: 7px; height: 7px; border-radius: 4px; background: var(--line); opacity: .7; }
.ol-main { min-width: 0; display: grid; gap: 2px; }
.ol-main .eb { font-family: var(--f-mono); font-size: 9.5px; letter-spacing: .13em; text-transform: uppercase; color: var(--line); }
.ol-text { font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-wrap; }
.ol-note { font-size: 13.5px; line-height: 1.5; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }
.ol-st { padding-top: 3px; }
.ol-item.d1 > .ol-row { padding-top: 12px; padding-bottom: 10px; }
.ol-item.d1 > .ol-row .ol-text { font-family: var(--f-display); font-weight: 500; font-size: 22px; line-height: 1.2; letter-spacing: -.01em; }
.ol-item.d1 > .ol-row .ol-tog .dot { width: 12px; height: 12px; border-radius: 6px; background: linear-gradient(135deg, var(--ca), var(--cb)); opacity: 1; }
.ol-item.d1 + .ol-item.d1 { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--hair); }
.ol-item.st-done > .ol-row .ol-text { color: var(--muted); }

/* Glass surfaces */
.glass { background: var(--panel); -webkit-backdrop-filter: blur(20px) saturate(1.5); backdrop-filter: blur(20px) saturate(1.5); border: 1px solid var(--hair); box-shadow: var(--shadow-panel); }

/* Header */
.top { position: absolute; top: calc(var(--sat) + 12px); left: max(16px, var(--sal)); right: max(16px, var(--sar)); display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; z-index: 30; pointer-events: none; }
.top > * { pointer-events: auto; }
.pill { border-radius: 16px; display: flex; align-items: center; gap: 4px; padding: 6px; min-width: 0; }
.pill.left { padding-right: 16px; flex: 0 1 auto; }
.pill.right { flex: none; }
.mark { width: 34px; height: 34px; display: grid; place-items: center; flex: none; }
.title-block { display: grid; gap: 1px; min-width: 0; padding-left: 4px; }
.title-block .eyebrow { display: flex; gap: 8px; align-items: center; white-space: nowrap; overflow: hidden; }
.save-dot { width: 6px; height: 6px; border-radius: 3px; background: var(--done); flex: none; }
.save-dot.busy { background: var(--gold-ring); animation: pulse 1s ease-in-out infinite; }
.save-dot.err { background: var(--review); }
@keyframes pulse { 50% { opacity: .3; } }
.map-title { font-family: var(--f-display); font-style: italic; font-weight: 500; font-size: 19px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.divider { width: 1px; height: 26px; background: var(--hair-strong); margin: 0 6px; flex: none; }
.icon-btn { border: 0; background: transparent; width: var(--tap); height: var(--tap); border-radius: 11px; display: inline-grid; place-items: center; color: var(--muted); flex: none; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--field); color: var(--fg); }
.icon-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.icon-btn.on { color: var(--gold); background: var(--gold-soft); }
.btn { border: 1px solid var(--hair-strong); background: transparent; border-radius: 11px; min-height: var(--tap); padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s, transform .15s; }
.btn:hover { background: var(--field); }
.btn.primary { background: var(--btn-bg); color: var(--btn-fg); border-color: transparent; font-weight: 600; box-shadow: 0 6px 16px -8px rgba(10,14,30,.6); }
.btn.primary:hover { transform: translateY(-1px); }
.btn.wide { width: 100%; }
.seg { display: flex; background: var(--field); border-radius: 11px; padding: 2px; }
.seg .icon-btn { width: calc(var(--tap) - 4px); height: calc(var(--tap) - 4px); border-radius: 9px; }
.seg .icon-btn.on { background: var(--panel-solid); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.search { position: relative; }
.search input { width: 190px; height: var(--tap); border: 1px solid transparent; background: var(--field); border-radius: 11px; padding: 0 12px 0 34px; font-size: 14px; transition: width .2s, border-color .2s; }
.search input:focus { width: 240px; border-color: var(--hair-strong); outline: none; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.ring-wrap { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 4px; font-variant-numeric: tabular-nums; }
.ring-wrap b { font-family: var(--f-display); font-size: 18px; font-weight: 500; }
.ring-wrap small { display: block; font-size: 11px; color: var(--muted); line-height: 1.1; }
.searchbar { position: absolute; top: calc(var(--sat) + 72px); left: max(16px, var(--sal)); right: max(16px, var(--sar)); z-index: 31; border-radius: 14px; padding: 6px; display: flex; gap: 6px; align-items: center; }
.searchbar input { flex: 1; min-width: 0; height: 40px; border: 0; background: var(--field); border-radius: 10px; padding: 0 12px; font-size: 16px; }
.searchbar input:focus { outline: 2px solid var(--gold-ring); }

/* Popover menu */
.menu { position: absolute; z-index: 70; border-radius: 14px; padding: 6px; min-width: 240px; max-width: calc(100vw - 32px); display: grid; background: var(--panel-solid); border: 1px solid var(--hair); box-shadow: var(--shadow-panel); animation: fade .12s ease-out; }
.menu button { border: 0; background: transparent; text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 14.5px; font-weight: 500; display: grid; gap: 2px; min-height: var(--tap); }
.menu button small { color: var(--muted); font-size: 12px; font-weight: 400; }
.menu button:hover { background: var(--field); }
.menu button.danger { color: var(--review); }
.menu hr { border: 0; border-top: 1px solid var(--hair); margin: 4px 6px; }

/* Floating panels */
.panel { position: absolute; top: calc(var(--sat) + 76px); bottom: calc(var(--sab) + 16px); border-radius: 20px; z-index: 40; display: flex; flex-direction: column; min-height: 0; transition: transform .35s cubic-bezier(.2,.75,.2,1), opacity .25s; }
.lib { left: max(16px, var(--sal)); width: 272px; }
.insp { right: max(16px, var(--sar)); width: 324px; }
.app:not(.lib-open) .lib { transform: translateX(calc(-100% - 40px)); opacity: 0; pointer-events: none; }
.app:not(.insp-open) .insp { transform: translateX(calc(100% + 40px)); opacity: 0; pointer-events: none; }
.panel-head { padding: 18px 18px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2 { margin: 0; font-family: var(--f-display); font-weight: 500; font-size: 22px; letter-spacing: -.01em; }
.lib-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 0 16px 10px; }
.lib-scroll { overflow: auto; flex: 1; padding: 0 10px 12px; -webkit-overflow-scrolling: touch; }
.folder { margin-top: 10px; }
.folder-head { display: flex; align-items: center; gap: 6px; padding: 6px 4px 4px 12px; }
.folder-head .eyebrow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-head .icon-btn { width: 30px; height: 30px; }
.map-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.map-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 2px 6px; border-radius: 13px; padding: 9px 4px 9px 12px; cursor: pointer; transition: background .15s; }
.map-item:hover { background: var(--field); }
.map-item.cur { background: var(--gold-soft); }
.map-item .nm { font-family: var(--f-display); font-size: 16.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.map-item .meta { grid-column: 1; font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.map-item .ring { grid-row: 1 / span 2; grid-column: 2; }
.map-item .more { grid-row: 1 / span 2; grid-column: 3; width: 32px; height: 32px; }
.lib-foot { padding: 12px 16px calc(14px + var(--sab) * 0); border-top: 1px solid var(--hair); display: grid; gap: 8px; }
.offline-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.offline-line .save-dot { flex: none; }
.lib-foot .links { display: flex; gap: 6px; flex-wrap: wrap; }
.lib-foot .links .btn { min-height: 32px; font-size: 13px; padding: 0 10px; }
.tag-ex { font-family: var(--f-mono); font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; border: 1px solid var(--hair-strong); border-radius: 5px; padding: 1px 5px; color: var(--muted); }

.sheet-handle { display: none; }
.insp-scroll { overflow: auto; padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 22px; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sec { display: grid; gap: 10px; }
.title-input { width: 100%; border: 0; border-bottom: 1px solid var(--hair-strong); background: transparent; font-family: var(--f-display); font-weight: 500; font-size: 24px; letter-spacing: -.01em; padding: 2px 0 8px; border-radius: 0; resize: none; line-height: 1.2; overflow: hidden; }
.title-input:focus { outline: none; border-bottom-color: var(--gold-ring); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--hair-strong); background: transparent; border-radius: 999px; padding: 5px 11px; min-height: calc(var(--tap) - 4px); font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); transition: all .15s; }
.chip:hover { color: var(--fg); border-color: var(--faint); }
.chip.on { background: var(--fg); color: var(--panel-solid); border-color: var(--fg); }
.chip.st.on { background: color-mix(in srgb, currentColor 12%, transparent); border-color: currentColor; }
.chip.st[data-st="review"] { color: var(--review); } .chip.st[data-st="learning"] { color: var(--learning); } .chip.st[data-st="done"] { color: var(--done); }
.chip.st[data-st=""].on { color: var(--fg); background: var(--field); border-color: var(--hair-strong); }
.note-field { width: 100%; min-height: 168px; border: 1px solid var(--hair); background: var(--field); border-radius: 14px; padding: 12px 14px; font-size: 15px; line-height: 1.6; resize: vertical; }
.note-field:focus { outline: none; border-color: var(--gold-ring); background: transparent; }
.branch-line { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.bar { flex: 1; height: 4px; border-radius: 2px; background: var(--hair-strong); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--done); border-radius: 2px; transition: width .4s; }
.overview { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.overview .big b { font-family: var(--f-display); font-size: 30px; font-weight: 500; line-height: 1; display: block; }
.overview .big span { font-size: 13px; color: var(--muted); }
.counts { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--hair); border-radius: 14px; overflow: hidden; }
.counts div { padding: 10px 12px; display: grid; gap: 2px; }
.counts div + div { border-left: 1px solid var(--hair); }
.counts b { font-family: var(--f-display); font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.counts span { font-size: 12px; color: var(--muted); }
.counts .r b { color: var(--review); } .counts .l b { color: var(--learning); } .counts .d b { color: var(--done); }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch { border: 1px solid var(--hair-strong); background: transparent; border-radius: 12px; padding: 10px 8px 8px; display: grid; gap: 7px; justify-items: center; font-size: 12px; color: var(--muted); }
.swatch.on { border-color: var(--gold-ring); box-shadow: 0 0 0 3px var(--gold-soft); color: var(--fg); }
.swatch .dots { display: flex; }
.swatch .dots i { width: 14px; height: 14px; border-radius: 7px; margin-left: -4px; border: 2px solid var(--panel-solid); }
.swatch .dots i:first-child { margin-left: 0; }
.rev-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rev-list button { width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 10px; font-size: 14px; display: grid; grid-template-columns: auto 1fr; column-gap: 9px; align-items: baseline; }
.rev-list button:hover { background: var(--field); }
.rev-list button .mk { grid-row: 1 / span 2; align-self: start; margin-top: 2px; }
.rev-list .path { grid-column: 2; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0; }
details.keys-box summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.keys-box summary::-webkit-details-marker { display: none; }
details.keys-box summary::after { content: "+"; font-family: var(--f-mono); color: var(--faint); }
details.keys-box[open] summary::after { content: "−"; }
@media (pointer: coarse) { details.keys-box { display: none; } }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; font-size: 13px; color: var(--muted); align-items: center; margin-top: 12px; }
kbd { font-family: var(--f-mono); font-size: 10.5px; border: 1px solid var(--hair-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; background: var(--panel-solid); color: var(--fg); white-space: nowrap; justify-self: start; }
.sheet-close { position: absolute; right: 10px; top: 10px; z-index: 2; display: none; }

/* Dock */
.dock-wrap { position: absolute; left: var(--free-l); right: var(--free-r); bottom: calc(var(--sab) + 16px); display: flex; justify-content: center; pointer-events: none; z-index: 25; transition: left .35s cubic-bezier(.2,.75,.2,1), right .35s cubic-bezier(.2,.75,.2,1); }
.dock { pointer-events: auto; display: flex; align-items: center; gap: 2px; border-radius: 18px; padding: 5px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.dock::-webkit-scrollbar { display: none; }
.dock .divider { height: 22px; margin: 0 4px; }
.zoom-pct { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); width: 50px; text-align: center; border: 0; background: transparent; flex: none; height: var(--tap); border-radius: 10px; font-variant-numeric: tabular-nums; }
.zoom-pct:hover { background: var(--field); }
.app.view-list .map-only { display: none !important; }
.toast { position: absolute; bottom: calc(var(--sab) + 84px); left: 50%; transform: translateX(-50%); background: var(--btn-bg); color: var(--btn-fg); font-size: 13.5px; font-weight: 500; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow-panel); z-index: 95; max-width: calc(100% - 32px); animation: rise .25s ease-out; display: flex; align-items: center; gap: 12px; }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; padding: 4px; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
@keyframes fade { from { opacity: 0; } }

/* Note preview */
.notecard { position: absolute; z-index: 35; width: 280px; border-radius: 16px; padding: 14px 16px; pointer-events: none; animation: fade .15s ease-out; background: var(--panel-solid); border: 1px solid var(--hair); box-shadow: var(--shadow-panel); }
.notecard .eyebrow { margin-bottom: 6px; display: block; }
.notecard p { margin: 0; font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: hidden; }

/* Dialogs */
.dialog-wrap { position: absolute; inset: 0; z-index: 90; background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: calc(var(--sat) + 20px) max(16px, var(--sar)) calc(var(--sab) + 20px) max(16px, var(--sal)); animation: fade .15s; }
.dialog { width: min(480px, 100%); max-height: 100%; overflow: auto; background: var(--panel-solid); border: 1px solid var(--hair); border-radius: 22px; box-shadow: var(--shadow-panel); padding: 22px; display: grid; gap: 16px; }
.dialog h3 { margin: 0; font-family: var(--f-display); font-weight: 500; font-size: 25px; letter-spacing: -.01em; overflow-wrap: anywhere; text-wrap: balance; }
.dialog p { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--muted); }
.dialog .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.dialog .field { width: 100%; height: 44px; border: 1px solid var(--hair-strong); background: var(--field); border-radius: 12px; padding: 0 12px; font-size: 16px; }
.dialog .field:focus { outline: 2px solid var(--gold-ring); border-color: transparent; }
.pkg-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--hair); border-radius: 14px; overflow: hidden; }
.pkg-list li { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; padding: 10px 14px; font-size: 14.5px; }
.pkg-list li + li { border-top: 1px solid var(--hair); }
.pkg-list li span:first-child { font-family: var(--f-display); font-size: 17px; min-width: 0; overflow-wrap: anywhere; }
.pkg-list .tag { font-family: var(--f-mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.pkg-list .tag.up { color: var(--learning); } .pkg-list .tag.new { color: var(--done); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14.5px; line-height: 1.5; }
.steps b { font-weight: 600; }
.help-tabs { display: flex; gap: 6px; }

/* Trainer */
.trainer { position: absolute; inset: 0; z-index: 80; background: rgba(10, 13, 28, .74); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); display: flex; flex-direction: column; align-items: center; padding: calc(var(--sat) + 16px) max(16px, var(--sar)) calc(var(--sab) + 16px) max(16px, var(--sal)); animation: fade .2s; overflow: auto; }
.tr-shell { width: min(620px, 100%); display: flex; flex-direction: column; gap: 18px; margin: auto 0; }
.tr-top { display: flex; align-items: center; gap: 12px; color: #f3efe4; }
.tr-top .eyebrow { color: rgba(243,239,228,.7); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-count { font-family: var(--f-mono); font-size: 12px; color: rgba(243,239,228,.85); font-variant-numeric: tabular-nums; }
.tr-top .icon-btn { color: rgba(243,239,228,.8); }
.tr-top .icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.tr-bar { height: 3px; border-radius: 2px; background: rgba(255,255,255,.15); overflow: hidden; }
.tr-bar i { display: block; height: 100%; background: #e6c06e; transition: width .4s; }
.card3d { perspective: 1600px; height: min(400px, 58vh); cursor: pointer; touch-action: none; }
.card-move { height: 100%; transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.card-move.dragging { transition: none; }
.card-inner { position: relative; height: 100%; transition: transform .7s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.card3d.flipped .card-inner { transform: rotateY(180deg); }
.card3d.enter .card-inner { animation: cardin .45s cubic-bezier(.2,.8,.2,1); }
@keyframes cardin { from { transform: translateY(24px) scale(.97); opacity: 0; } }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 24px; background: var(--panel-solid); border: 1px solid var(--hair); box-shadow: 0 40px 80px -30px rgba(0,0,0,.6); padding: 28px 32px; display: flex; flex-direction: column; overflow: hidden; }
.face.back { transform: rotateY(180deg); }
.face .crumb { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.face .crumb span { overflow: hidden; text-overflow: ellipsis; }
.face .crumb i { width: 8px; height: 8px; border-radius: 4px; flex: none; }
.face .q { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; text-align: center; }
.face .q h3 { margin: 0; font-family: var(--f-display); font-style: italic; font-weight: 500; font-size: clamp(26px, 6vw, 38px); line-height: 1.12; letter-spacing: -.015em; text-wrap: balance; overflow-wrap: anywhere; }
.face .hint { text-align: center; font-size: 12.5px; color: var(--faint); }
.face.back h4 { margin: 6px 0 12px; font-family: var(--f-display); font-weight: 500; font-size: 21px; overflow-wrap: anywhere; }
.face.back .ans { flex: 1; overflow: auto; font-size: 16px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.face.back ul { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.face.back li { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.face.back li::before { content: ""; width: 5px; height: 5px; border-radius: 3px; background: var(--faint); flex: none; }
.swipe-tag { position: absolute; top: 22px; z-index: 3; font-family: var(--f-mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; padding: 6px 10px; border-radius: 8px; border: 2px solid currentColor; opacity: 0; pointer-events: none; background: var(--panel-solid); }
.swipe-tag.l { left: 22px; color: #c9532d; } .swipe-tag.r { right: 22px; color: #17885c; } .swipe-tag.u { left: 50%; transform: translateX(-50%); color: #3d68d6; }
.tr-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tr-actions.one { grid-template-columns: 1fr; }
.rate { border: 0; border-radius: 16px; padding: 12px 10px; min-height: 54px; display: grid; gap: 2px; justify-items: center; font-weight: 600; font-size: 15px; color: #fff; transition: transform .15s, filter .15s; }
.rate:hover { transform: translateY(-2px); filter: brightness(1.08); }
.rate small { font-family: var(--f-mono); font-size: 10.5px; font-weight: 500; opacity: .75; letter-spacing: .08em; }
.rate.r { background: #c9532d; } .rate.l { background: #3d68d6; } .rate.d { background: #17885c; }
.rate.show { background: #f3efe4; color: #151a2d; }
.tr-swipe-hint { text-align: center; font-size: 12.5px; color: rgba(243,239,228,.7); }
.tr-done { text-align: center; color: #f3efe4; display: grid; gap: 14px; justify-items: center; }
.tr-done h3 { margin: 0; font-family: var(--f-display); font-style: italic; font-weight: 500; font-size: 36px; }
.tr-done .counts { width: min(420px, 100%); border-color: rgba(255,255,255,.15); background: rgba(255,255,255,.06); }
.tr-done .counts div + div { border-color: rgba(255,255,255,.15); }
.tr-done .counts span { color: rgba(243,239,228,.75); }
.tr-done .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.tr-done .btn { color: #f3efe4; border-color: rgba(255,255,255,.25); }
.tr-done .btn.primary { background: #e6c06e; color: #151a2d; }
.scrim { position: absolute; inset: 0; background: var(--scrim); z-index: 38; display: none; }

.update-bar { position: absolute; top: calc(var(--sat) + 72px); left: 50%; transform: translateX(-50%); z-index: 60; border-radius: 14px; padding: 8px 8px 8px 16px; display: flex; gap: 12px; align-items: center; font-size: 14px; max-width: calc(100% - 32px); }
.update-bar .btn { min-height: 34px; }

/* Tablet: panels slide over the canvas */
@media (max-width: 1100px) {
  .lib { width: 320px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); }
  .insp { width: 340px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); }
  .app.lib-open .scrim { display: block; }
  .search input { width: 150px; }
  .search input:focus { width: 190px; }
  .ring-wrap small { display: none; }
  .sheet-close { display: inline-grid; }
}
@media (max-width: 860px) {
  .search { display: none; }
  .only-wide { display: none !important; }
}
@media (min-width: 861px) { .only-narrow { display: none !important; } }

/* Phone: full-height library, bottom sheet inspector, compact header */
@media (max-width: 640px) {
  .top { top: calc(var(--sat) + 8px); left: max(10px, var(--sal)); right: max(10px, var(--sar)); gap: 6px; }
  .pill { padding: 4px; border-radius: 15px; }
  .pill.left { padding-right: 12px; }
  .mark, .title-block .eyebrow { display: none; }
  .seg { background: transparent; padding: 0; }
  .seg .icon-btn { width: var(--tap); height: var(--tap); }
  .seg .icon-btn.on { display: none; }
  .map-title { font-size: 17px; }
  .ring-wrap, .tr-label { display: none; }
  .btn.primary.train { padding: 0; width: var(--tap); }
  .lib { top: 0; bottom: 0; left: 0; width: min(360px, 92%); border-radius: 0 24px 24px 0; padding-top: var(--sat); padding-left: var(--sal); padding-bottom: var(--sab); }
  .insp { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: min(68%, 620px); border-radius: 26px 26px 0 0; padding-left: var(--sal); padding-right: var(--sar); transition: transform .35s cubic-bezier(.2,.75,.2,1), opacity .25s, height .3s; }
  .insp.full { height: calc(100% - var(--sat) - 24px); }
  .app:not(.insp-open) .insp { transform: translateY(calc(100% + 30px)); }
  .sheet-handle { display: block; width: 100%; height: 26px; border: 0; background: transparent; position: relative; flex: none; touch-action: none; }
  .sheet-handle::before { content: ""; position: absolute; left: 50%; top: 10px; width: 40px; height: 5px; border-radius: 3px; background: var(--hair-strong); transform: translateX(-50%); }
  .insp-scroll { padding: 4px 20px calc(24px + var(--sab)); }
  .sheet-close { top: 18px; }
  .dock-wrap { left: max(10px, var(--sal)); right: max(10px, var(--sar)); bottom: calc(var(--sab) + 10px); }
  .app.insp-open .dock-wrap { opacity: 0; pointer-events: none; }
  .dock .divider { margin: 0 2px; }
  .hide-phone { display: none !important; }
  .card3d { height: min(440px, 60vh); }
  .face { padding: 22px; }
  .dialog-wrap { align-items: flex-end; padding: 0; }
  .dialog { border-radius: 24px 24px 0 0; padding: 22px max(20px, var(--sar)) calc(22px + var(--sab)) max(20px, var(--sal)); }
  .ol-inner { padding-top: calc(var(--sat) + 74px); }
}
@media (min-width: 641px) { .only-phone { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  #world.anim, .panel, .card-inner, .card-move, .dock-wrap, .bar i, .tr-bar i, .ol-tog svg { transition: none; }
  .card3d.enter .card-inner, .toast, .save-dot.busy, .dialog-wrap, .menu { animation: none; }
}
