:root {
  --bg: #050505;
  --bg-2: #141416;
  --panel: #1c1c20;
  --panel-2: #26262b;
  --line: rgba(255, 255, 255, 0.08);
  --gold: #ffffff;
  --gold-2: #ffffff;
  --text: #f4f4f6;
  --muted: #8e8e96;
  --danger: #e07a6a;
  --page: #161318;
  --binder: #2a2a30;
  --gutter: 10px;
  --page-pad: 10px;
  --pocket-radius: 8px;
  --cols: 3;
  --rows: 3;
  --font: "Outfit", system-ui, sans-serif;
  --serif: "Nunito", system-ui, sans-serif;
  --top: 58px;
  --cards: 320px;
  --tile-green: #2f6b3a;
  --tile-lilac: #c9b6f2;
  --tile-orange: #e48a4a;
  --tile-rust: #c85a3c;
  --tile-pink: #f0a8c8;
  --tile-blue: #6eb4e8;
  --radius: 24px;
  --radius-sm: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,0.13) 1.1px, transparent 1.2px);
  background-size: 18px 18px;
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0.01em;
  overflow: hidden;
}

button, input, select { font-family: inherit; }

#boot {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-content: center; gap: 12px;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,0.13) 1.1px, transparent 1.2px);
  background-size: 18px 18px;
  text-align: center;
}
#boot.gone { opacity: 0; pointer-events: none; transition: opacity .4s; }
#boot p { color: var(--muted); font-weight: 600; }
.boot-mark {
  font-family: var(--serif); font-weight: 800; font-size: 48px;
  color: var(--gold-2); letter-spacing: -0.04em;
}
.boot-bar {
  width: 180px; height: 3px; margin: 8px auto 0;
  background: var(--line); overflow: hidden; border-radius: 99px;
}
.boot-bar span {
  display: block; height: 100%; width: 40%;
  background: var(--gold);
  animation: load 1.1s ease-in-out infinite;
}
@keyframes load {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(350%); }
}

.top {
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 18px;
  border-bottom: 0;
  background: transparent;
  position: relative;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-word {
  font-family: var(--serif); font-weight: 800; font-size: 26px;
  color: #fff; line-height: 1; letter-spacing: -0.04em;
}
.brand-sub {
  font-size: 10px;
  line-height: 1.15;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.binder-switch {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  max-width: 280px;
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 6px 0 14px;
}
.binder-name {
  flex: 1; min-width: 0;
  background: transparent; border: 0; color: var(--text);
  font-size: 14px; font-weight: 500; outline: none;
  padding: 7px 0;
}
.chev-btn {
  border: 0; background: none; color: var(--muted);
  cursor: pointer; padding: 6px 8px; font-size: 12px; line-height: 1;
}
.chev-btn:hover, .binder-switch:focus-within { border-color: rgba(255,255,255,0.22); }
.layout-tag {
  font-size: 11px; color: var(--muted); letter-spacing: 0.04em;
  white-space: nowrap; flex-shrink: 0;
}

.top-tools {
  display: flex; align-items: center; gap: 8px; margin-left: auto; position: relative;
}
.view-toggle {
  display: flex; padding: 3px; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
}
.view-toggle button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
  font-size: 12px; letter-spacing: 0.02em; font-weight: 600;
}
.view-toggle button.on {
  background: #fff; color: #111;
}

.icon-btn, .ghost, .gold-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.02em;
  font-weight: 600;
}
.icon-btn:hover, .ghost:hover { border-color: rgba(255,255,255,0.22); background: var(--panel-2); }
.icon-btn.on { background: #fff; color: #111; border-color: #fff; }
.gold-btn {
  background: #fff;
  color: #111;
  border-color: transparent;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.gold-btn:hover { filter: brightness(0.94); }
.gold-btn.tiny, .ghost.tiny { padding: 6px 12px; font-size: 11px; }
#btn-account {
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#btn-account.hidden { display: none !important; }
.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.auth-form .search { width: 100%; }
.auth-err {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}
.auth-switch { margin-top: 14px; }
.row-btns .gold-btn { flex: 1; }
#account-signed.hidden, #account-form.hidden, #account-toggle.hidden, #account-copy.hidden { display: none !important; }
.file-btn { display: inline-flex; align-items: center; }
.danger { color: var(--danger); }
.danger-btn {
  background: var(--tile-rust);
  color: #fff;
}
.confirm-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
button:disabled { opacity: 0.38; cursor: default; pointer-events: none; }

.top-actions {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  margin: 0;
  padding: 10px;
  min-width: 168px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
  z-index: 41;
}
.top-actions.open { display: flex; }
.top-actions .icon-btn,
.top-actions .gold-btn,
.top-actions .file-btn { width: 100%; justify-content: center; }
.more-btn { display: inline-flex; }

.popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  max-width: min(360px, 90vw);
  max-height: min(70vh, 480px);
  overflow: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
  z-index: 40;
}
.binder-switch .popover { left: 0; right: auto; }
.look-pop { left: auto; right: 0; min-width: 220px; }
.hidden { display: none !important; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--cards);
  height: calc(100% - var(--top));
}

.rail {
  background: transparent;
  overflow: auto;
  padding: 16px 14px 28px;
}
.rail-right {
  border-left: 0;
  display: flex; flex-direction: column; padding: 0;
  min-width: 0;
  overflow: hidden;
  margin: 8px 12px 12px 0;
  border-radius: 32px;
  background: #1a1a1e;
  box-shadow:
    0 28px 70px rgba(0,0,0,.55),
    inset 0 1px 0 rgba(255,255,255,.06);
}
.rail section { margin-bottom: 0; }
.sec-h {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.04em;
  text-transform: none;
  color: #fff;
  margin-bottom: 0;
}
.sec-h-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.sec-h-actions { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; min-width: 0; }
.lang-toggle {
  display: flex; padding: 3px; gap: 2px; flex: 0 0 auto;
  background: #111114; border: 1px solid var(--line); border-radius: 999px;
}
.lang-toggle button {
  border: 0; background: transparent; color: var(--muted);
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
  font-size: 11px; min-width: 32px; font-weight: 700;
}
.lang-toggle button.on { background: #fff; color: #111; }
.ghost.tiny.icon-only {
  padding: 5px 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.ghost.tiny.icon-only svg { width: 14px; height: 14px; display: block; }
.ghost.tiny.icon-only.on { background: #fff; color: #111; border-color: #fff; }
.sec-h-actions .gold-btn.tiny { white-space: nowrap; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 0 0 10px; }
.row-btns { display: flex; gap: 8px; }
.row-btns .ghost { flex: 1; }

.page-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.page-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 13px;
}
.page-item.active { border-color: #fff; background: #111; }
.page-item button {
  margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer;
}
.page-meta { margin-left: 8px; color: var(--muted); font-size: 11px; flex: 1; font-weight: 400; }

.chip-row, .swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 12px;
  font-weight: 700;
}
.chip.on { background: #fff; color: #111; border-color: #fff; }
.look-label { font-size: 11px; color: var(--muted); margin: 8px 0 6px; }
.look-label:first-child { margin-top: 0; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.swatch.on { border-color: var(--gold-2); }

.stage {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 12px 6px; min-width: 0; min-height: 0; overflow: hidden;
}
.stage-bar {
  display: flex; align-items: center; gap: 6px;
  width: 100%; max-width: 100%;
  flex-shrink: 0;
  padding: 6px 0 2px;
}
.page-chips {
  display: flex; gap: 4px; overflow-x: auto;
  flex: 1; min-width: 0;
  scrollbar-width: none;
}
.page-chips::-webkit-scrollbar { display: none; }
.page-chip {
  flex: 0 0 auto;
  min-width: 32px; height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.page-chip.on { border-color: transparent; color: #111; background: #fff; }
.page-chip button {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  padding: 0; font-size: 14px; line-height: 1; display: none;
}
.page-chip.on button { display: inline; }
.stage-help { color: var(--muted); font-size: 12px; margin: 4px 0 0; text-align: center; flex-shrink: 0; min-height: 0; }
.stage-help:empty { display: none; }
.binder-wrap {
  display: flex; justify-content: center; align-items: center;
  flex: 1; width: 100%; min-height: 0;
  perspective: 900px;
}

.binder-shell {
  --binder: #2a2a30;
  background:
    radial-gradient(ellipse at 30% 18%, rgba(255,255,255,.14), transparent 46%),
    var(--binder);
  border-radius: 28px;
  padding: 14px 16px 14px 32px;
  position: relative;
  height: auto;
  max-height: 100%;
  max-width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: stretch;
  box-shadow:
    0 32px 80px rgba(0,0,0,.55),
    inset 0 1px 0 rgba(255,255,255,.08);
}
.binder-shell.spread {
  gap: 0; padding: 14px 16px;
  border-radius: 28px;
}
.spine {
  position: absolute; left: 10px; top: 20px; bottom: 20px; width: 16px;
  display: flex; flex-direction: column; justify-content: space-evenly; align-items: center;
}
.binder-shell.spread .spine {
  position: relative; left: auto; top: auto; bottom: auto;
  width: 16px;
  height: auto;
  margin: 0 -1px;
  flex-shrink: 0;
  justify-content: stretch;
  align-items: stretch;
  background:
    linear-gradient(90deg,
      rgba(255,255,255,.05) 0%,
      rgba(0,0,0,.18) 28%,
      rgba(0,0,0,.55) 48%,
      rgba(0,0,0,.72) 50%,
      rgba(0,0,0,.55) 52%,
      rgba(0,0,0,.18) 72%,
      rgba(255,255,255,.05) 100%);
  pointer-events: none;
}
.binder-shell.spread .ring { display: none; }
.binder-shell.spread > .page-sheet:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  box-shadow:
    inset -14px 0 22px rgba(0,0,0,.32),
    inset 0 0 0 1px rgba(255,255,255,.04),
    0 8px 20px rgba(0,0,0,.3);
}
.binder-shell.spread > .page-sheet:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  box-shadow:
    inset 14px 0 22px rgba(0,0,0,.32),
    inset 0 0 0 1px rgba(255,255,255,.04),
    0 8px 20px rgba(0,0,0,.3);
}
.ring {
  width: 14px; height: 22px; border: 2px solid #c5c0b6;
  border-radius: 8px; background: linear-gradient(#ece8df, #9d9890);
  box-shadow: 0 2px 4px rgba(0,0,0,.4);
}

.pages-row {
  display: flex;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.page-sheet {
  --page: #161318;
  background: var(--page);
  padding: var(--page-pad);
  border-radius: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.04),
    0 8px 20px rgba(0,0,0,.3);
}
.page-sheet.snow { --page: #efe8dc; }
.page-sheet.cream { --page: #e4d2ae; }
.page-sheet.snow .pocket::after,
.page-sheet.cream .pocket::after {
  box-shadow:
    inset 0 0 0 1.5px rgba(0,0,0,.12),
    inset 0 10px 16px rgba(0,0,0,.12),
    0 0 0 calc(var(--gutter) / 2) var(--page);
}

.page-stage {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
}

.span-layer, .pocket-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: var(--gutter);
  width: 100%;
  height: 100%;
  align-items: stretch;
  justify-items: stretch;
}
.span-layer {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
}
.span-layer.join-layer { z-index: 4; }
.pocket-grid { position: relative; z-index: 2; pointer-events: none; }

.insert {
  position: relative;
  overflow: hidden;
  border-radius: var(--pocket-radius);
  pointer-events: auto;
  cursor: pointer;
  background: #0a0908;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  -webkit-touch-callout: none;
  user-select: none;
}
.insert.selected { outline: 2px solid var(--gold); outline-offset: 1px; z-index: 3; cursor: grab; touch-action: none; }
.insert.selected:active { cursor: grabbing; }
body.is-panning-art,
body.is-panning-art * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-user-drag: none !important;
  cursor: grabbing !important;
}
body.is-panning-art {
  touch-action: none;
}
.insert img, .insert .fill {
  width: 100%; height: 100%; object-fit: cover;
  transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(var(--zoom, 1));
  transform-origin: center;
  pointer-events: none;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}
.insert:not(.joined) {
  --iw: 1;
  --ih: 1;
  --slot-w: calc((100% - (var(--iw) - 1) * var(--gutter)) / var(--iw));
  --slot-h: calc((100% - (var(--ih) - 1) * var(--gutter)) / var(--ih));
  -webkit-mask-image:
    repeating-linear-gradient(90deg, #000 0 var(--slot-w), transparent var(--slot-w) calc(var(--slot-w) + var(--gutter))),
    repeating-linear-gradient(180deg, #000 0 var(--slot-h), transparent var(--slot-h) calc(var(--slot-h) + var(--gutter)));
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-composite: source-in;
  mask-image:
    repeating-linear-gradient(90deg, #000 0 var(--slot-w), transparent var(--slot-w) calc(var(--slot-w) + var(--gutter))),
    repeating-linear-gradient(180deg, #000 0 var(--slot-h), transparent var(--slot-h) calc(var(--slot-h) + var(--gutter)));
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
  mask-composite: intersect;
}
.insert.placeholder {
  background:
    repeating-linear-gradient(-45deg, rgba(255,255,255,.06) 0 8px, transparent 8px 16px);
  display: grid; place-items: center;
  color: #fff; font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase;
}
.insert.ghost { opacity: 0.38; }
.insert.joined {
  -webkit-mask-image: none;
  mask-image: none;
  box-shadow:
    inset 0 0 0 1.5px rgba(255,255,255,.16),
    inset 0 12px 18px rgba(0,0,0,.28);
  z-index: 4;
}

.insert-edit {
  position: absolute; top: 4px; right: 4px; z-index: 6;
  width: 22px; height: 22px; border: 0; border-radius: 50%;
  background: rgba(12,11,9,.72); color: #fff; cursor: pointer;
  opacity: 0;
  pointer-events: auto;
  display: grid; place-items: center;
  padding: 0;
}
.insert-edit svg { width: 12px; height: 12px; display: block; }
.insert-edit.show,
.insert:hover .insert-edit,
.insert.selected .insert-edit { opacity: 1; }
@media (hover: none) {
  .insert-edit { opacity: 1; }
}

.pocket {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: var(--pocket-radius);
  pointer-events: auto;
  overflow: hidden;
}
.pocket::after {
  content: "";
  position: absolute; inset: 0; border-radius: var(--pocket-radius);
  box-shadow:
    inset 0 0 0 1.5px rgba(255,255,255,.16),
    inset 0 12px 18px rgba(0,0,0,.28),
    0 0 0 calc(var(--gutter) / 2) var(--page);
  pointer-events: none; z-index: 3;
}
.pocket .card-img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: calc(var(--pocket-radius) - 1px);
  display: block;
}
.pocket.empty .drop-hint {
  position: absolute; inset: 10% 8%;
  border: 1px dashed rgba(244,226,190,.18);
  border-radius: var(--pocket-radius);
  display: grid; place-items: center;
  color: rgba(244,226,190,.28); font-size: 16px; font-weight: 300;
}
.pocket-actions {
  display: none;
  position: absolute;
  inset: 8%;
  z-index: 6;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
}
.pocket-actions button {
  border: 0;
  border-radius: 999px;
  background: rgba(12, 11, 9, 0.82);
  color: #fff;
  font-size: 10px;
  letter-spacing: 0.04em;
  padding: 7px 6px;
  cursor: pointer;
}
.pocket-actions button:hover { background: rgba(12, 11, 9, 0.94); color: #fff; }
@media (hover: hover) and (pointer: fine) {
  .pocket.empty:hover .pocket-actions { display: flex; }
  .pocket.empty:hover .drop-hint { opacity: 0; }
}
body.is-holding .pocket-actions,
body.dragging .pocket-actions { display: none !important; }
body.is-holding .pocket.empty:hover,
body.dragging .pocket.empty:hover,
body.is-holding .pocket.empty.over,
body.dragging .pocket.empty.over {
  z-index: 5;
}
body.is-holding .pocket.empty:hover::before,
body.dragging .pocket.empty:hover::before,
body.is-holding .pocket.empty.over::before,
body.dragging .pocket.empty.over::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 18px rgba(201, 182, 242, 0.35);
  pointer-events: none;
  z-index: 4;
}

.pocket.over, .insert.over {
  outline: 2px solid var(--gold); outline-offset: 0;
}
.pocket .card-img { transition: opacity 0.15s ease; }
.pocket.ghost::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--gold);
  border-radius: inherit;
  z-index: 4;
  pointer-events: none;
  box-sizing: border-box;
}
.pocket-x {
  position: absolute; top: 4px; right: 4px; z-index: 5;
  width: 20px; height: 20px; border: 0; border-radius: 50%;
  background: rgba(12,11,9,.72); color: #fff; cursor: pointer;
  opacity: 0; pointer-events: none; font-size: 14px; line-height: 1;
}
@media (hover: hover) and (pointer: fine) {
  .pocket:hover .pocket-x { opacity: 1; pointer-events: auto; }
}
.pocket.ghost .pocket-x { opacity: 1; pointer-events: auto; }
.pocket.will-swap { outline: 2px solid var(--gold-2); }
.pocket.pending .drop-hint {
  border-color: var(--gold);
  color: var(--gold-2);
  box-shadow: 0 0 0 1px var(--gold);
}
.page-chip { cursor: grab; }
.page-chip.chip-over { border-color: #fff; background: var(--panel-2); }
.page-chip.chip-drag { opacity: 0.45; }

.binder-shell.page-turn {
  animation: page-turn 0.34s ease;
}
@keyframes page-turn {
  from {
    opacity: 0.4;
    transform: translateX(var(--turn, 48px));
  }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .binder-shell.page-turn { animation: none; }
}

.grab-ghost, .drag-card {
  position: fixed;
  width: 96px;
  height: calc(96px * 88 / 63);
  border-radius: 12px;
  overflow: hidden;
  pointer-events: none;
  z-index: 90;
  box-shadow:
    0 22px 40px rgba(0,0,0,.55),
    0 0 0 1px rgba(255,255,255,.12);
  transform: rotate(-12deg);
}
.drag-card {
  position: absolute;
  left: -240px;
  top: 0;
}
.grab-ghost img, .drag-card img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
body.is-holding, body.dragging { cursor: grabbing; }
body.is-holding .pocket.empty, body.dragging .pocket.empty { cursor: copy; }
body.holding-card .insert { cursor: not-allowed; }
.pocket.fit::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 16px rgba(110, 180, 232, 0.35);
  pointer-events: none;
  z-index: 4;
}
.pocket.no-fit::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--danger);
  pointer-events: none;
  z-index: 4;
}

.search-sec { padding: 18px 16px 12px; border-bottom: 1px solid var(--line); min-width: 0; overflow-x: hidden; }
.custom-sec {
  flex: 0 0 auto;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}
.search {
  width: 100%; padding: 11px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #111114;
  color: var(--text); outline: none;
}
.search:focus { border-color: rgba(255,255,255,.28); background: #0c0c0e; }
.filters {
  display: none;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  margin-top: 8px;
  width: 100%;
  max-width: 100%;
}
body.show-filters .filters { display: grid; }
.filters select {
  background: #111114; color: var(--text); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 10px; font-size: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.result-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px; font-size: 11px; color: var(--muted);
}
.custom-lib {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  min-height: 0;
  max-height: 168px;
  overflow-y: auto;
}
.custom-lib .hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 11px;
}
.custom-lib .thumb {
  aspect-ratio: 63/88; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); cursor: grab; background: #111;
  position: relative;
}
.custom-lib img { width: 100%; height: 100%; object-fit: cover; display: block; }
.custom-lib .thumb.held {
  outline: 3px solid #fff; outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(201, 182, 242, 0.35);
}
.custom-lib .thumb-x {
  position: absolute; top: 3px; right: 3px; z-index: 2;
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(12,11,9,.75); color: #fff;
  font-size: 12px; line-height: 16px; text-align: center;
  opacity: 0; cursor: pointer;
}
.custom-lib .thumb:hover .thumb-x { opacity: 1; }

.grid-sec { flex: 1; overflow: auto; min-height: 0; padding: 10px 14px 12px; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}
.card-tile {
  cursor: grab; border: 0; padding: 0; background: none; text-align: left; color: inherit;
  border-radius: 16px; position: relative;
  display: flex; flex-direction: column;
  width: 100%; min-width: 0;
  box-sizing: border-box;
  transition: transform 0.15s, opacity 0.15s;
}
.card-tile .art {
  display: block;
  width: 100%;
  aspect-ratio: 63 / 88;
  overflow: hidden;
  border-radius: 14px;
  background: #121214;
  flex: 0 0 auto;
  line-height: 0;
  box-shadow: 0 10px 22px rgba(0,0,0,.4);
  transition: transform 0.15s ease;
}
.card-tile .art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
  border-radius: 0;
  aspect-ratio: auto;
}
.card-tile .art.missing-art,
.insert.missing-art,
.pocket:has(img.missing) {
  background: linear-gradient(180deg, #3a3228, #1c1814);
}
img.missing { opacity: 0 !important; }
.card-grid .card-tile:has(.art.missing-art),
.card-grid .card-tile:has(img.missing) {
  display: none !important;
}
.card-tile .meta {
  margin-top: 4px; font-size: 11px; line-height: 1.3;
  height: 2.7em; overflow: hidden; flex: 0 0 auto;
}
.card-tile .meta b { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tile .meta span { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tile.held .art {
  box-shadow: 0 0 0 3px #fff, 0 12px 24px rgba(0,0,0,.45);
}
.card-tile.held .meta b { color: #fff; }
.card-tile:hover .art { transform: translateY(-2px); }
.grid-end { text-align: center; color: var(--muted); font-size: 12px; padding: 12px; }
.other-lang-hint {
  display: block;
  width: 100%;
  margin: 8px 0 4px;
  padding: 12px 14px;
  border-radius: 999px;
  border: 0;
  background: #fff;
  color: #111;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}
.other-lang-hint:hover {
  filter: brightness(0.94);
}
.other-lang-hint.hidden { display: none !important; }

.insert-toolbar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: #1a1a1e; border: 1px solid var(--line);
  padding: 10px 14px; border-radius: 999px; z-index: 20;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.insert-toolbar.hidden { display: none !important; }
.insert-toolbar label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.insert-toolbar .tb-zoom { white-space: nowrap; }

.span-picker {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; z-index: 30;
}
.span-picker-inner {
  background: #1a1a1e; border: 1px solid var(--line);
  padding: 24px; border-radius: 28px; width: min(440px, 92vw);
  box-shadow: 0 28px 70px rgba(0,0,0,.55);
}
.span-title {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.span-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.span-choice {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: #111114; color: var(--text); border: 0;
  padding: 12px 8px; border-radius: 18px; cursor: pointer;
}
.span-choice:nth-child(6n+1) { background: var(--tile-green); color: #fff; }
.span-choice:nth-child(6n+2) { background: var(--tile-lilac); color: #1a1224; }
.span-choice:nth-child(6n+3) { background: var(--tile-orange); color: #1a1008; }
.span-choice:nth-child(6n+4) { background: var(--tile-rust); color: #fff; }
.span-choice:nth-child(6n+5) { background: var(--tile-pink); color: #2a1220; }
.span-choice:nth-child(6n+6) { background: var(--tile-blue); color: #0e2230; }
.span-choice:hover, .span-choice.suggested { transform: translateY(-2px); }
.span-choice.suggested { box-shadow: 0 0 0 2px #fff; }
.span-choice span { font-size: 11px; font-weight: 700; color: inherit; opacity: 0.8; }
.span-mini {
  display: grid;
  grid-template-columns: repeat(var(--mc, 3), 7px);
  grid-template-rows: repeat(var(--mr, 3), 10px);
  gap: 2px;
}
.span-mini i { background: rgba(255,255,255,.28); border-radius: 2px; display: block; }
.span-mini i.on { background: #fff; }

.multi-picker-inner {
  width: min(920px, 96vw);
  height: min(86vh, 820px);
  display: flex;
  flex-direction: column;
  padding: 18px;
}
.multi-picked {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  min-height: 56px;
  margin-top: 10px;
  padding-bottom: 4px;
}
.multi-picked:empty { display: none; }
.multi-pick {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  background: #111;
  border: 1px solid var(--line);
}
.multi-pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.multi-pick button {
  position: absolute; top: 1px; right: 1px;
  width: 16px; height: 16px; border: 0; border-radius: 50%;
  background: rgba(12,11,9,.8); color: #fff; cursor: pointer;
  font-size: 11px; line-height: 16px; padding: 0;
}
.multi-grid-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
  margin-top: 8px;
}
.multi-grid-wrap .card-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.card-tile.queued .art {
  box-shadow: 0 0 0 3px #fff, 0 12px 24px rgba(0,0,0,.45);
}
.card-tile .queue-n {
  position: absolute;
  top: 8px; left: 8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
  z-index: 2;
}

.toast {
  position: fixed; bottom: 18px; right: 18px;
  background: #1a1a1e; border: 1px solid var(--line);
  padding: 12px 16px; border-radius: 999px; z-index: 40;
  font-size: 13px; font-weight: 600;
  animation: toast-in .2s ease;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

body.dragging .pocket, body.dragging .insert,
body.is-holding .pocket, body.is-holding .insert { cursor: copy; }
body.is-holding .pocket.will-swap { cursor: grab; }

.search-wrap { position: relative; }
.search-wrap .search { padding-right: 32px; }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 2px 6px;
}
.search-clear:hover { color: var(--text); }
.text-btn {
  border: 0; background: none; color: var(--tile-lilac); cursor: pointer;
  font-size: 11px; padding: 0; letter-spacing: 0.04em; font-weight: 700;
}
.text-btn:hover { color: #fff; }

.desk-only { display: inline-flex; }
.mob-only, .mobile-nav { display: none; }

button, a, .chip, .page-item, .page-chip, .card-tile, .swatch, .thumb, .pocket, .span-choice {
  touch-action: manipulation;
}

@media (max-width: 1100px) {
  :root { --cards: 260px; }
}

@media (min-width: 841px) {
  body.cards-collapsed .app { grid-template-columns: minmax(0, 1fr); }
  body.cards-collapsed .rail-right { display: none; }
}

@media (max-width: 840px) {
  :root { --tabbar: calc(56px + env(safe-area-inset-bottom, 0px)); --top: auto; }
  html, body { height: 100dvh; overflow: hidden; }
  body {
    display: flex;
    flex-direction: column;
    padding-bottom: var(--tabbar);
  }

  .desk-only { display: none !important; }
  .more-btn { display: inline-flex; }

  .top {
    height: auto;
    min-height: 52px;
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .brand-word { font-size: 22px; }
  .brand-sub { font-size: 9px; }
  .binder-switch { max-width: none; flex: 1; }
  .layout-tag { display: none; }
  .view-toggle button { padding: 6px 8px; font-size: 11px; }

  .top-actions {
    display: none;
    position: absolute;
    top: calc(100% - 4px);
    right: 8px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin: 0;
    padding: 10px;
    min-width: 168px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0,0,0,.45);
  }
  .top-actions.open { display: flex; }
  .top-actions .icon-btn,
  .top-actions .gold-btn,
  .top-actions .file-btn { width: 100%; justify-content: center; }

  .look-pop { right: 8px; left: auto; }

  .app {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    flex: 1;
    min-height: 0;
    height: auto;
  }
  body.cards-collapsed .app { grid-template-columns: 1fr; }
  body.cards-collapsed .rail-right { display: flex; }

  .stage {
    grid-area: 1 / 1;
    min-height: 0;
    padding: 6px 8px 4px;
  }
  .stage-bar { gap: 4px; }
  .stage-bar .ghost { padding: 8px 10px; }
  .page-chip { min-width: 36px; height: 36px; }

  .rail {
    grid-area: 1 / 1;
    z-index: 14;
    width: 100%;
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(110%);
    transition: transform 0.28s ease;
    padding-bottom: 20px;
    pointer-events: none;
  }
  body.tab-cards .rail-right {
    transform: none;
    pointer-events: auto;
    display: flex;
  }

  .rail-right {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .search { font-size: 16px; padding: 12px 40px 12px 12px; }
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }

  .pocket-x {
    width: 28px; height: 28px; font-size: 16px; line-height: 28px;
  }
  .insert-edit { width: 28px; height: 28px; opacity: 1; }
  .custom-lib .thumb-x {
    opacity: 1; width: 28px; height: 28px; font-size: 16px; line-height: 28px;
  }

  .insert-toolbar {
    left: 8px; right: 8px; transform: none;
    bottom: calc(var(--tabbar) + 8px);
    border-radius: 16px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px 12px;
  }
  .span-picker { align-items: end; }
  .span-picker-inner {
    width: 100%;
    max-height: 85dvh;
    overflow: auto;
    border-radius: 20px 20px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .multi-picker-inner {
    height: 85dvh;
    max-height: 85dvh;
    width: 100%;
    overflow: hidden;
  }
  .toast { bottom: calc(var(--tabbar) + 10px); right: 10px; left: 10px; }

  .mobile-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 26;
    height: var(--tabbar);
    padding: 8px 12px env(safe-area-inset-bottom, 8px);
    background: #0a0a0c;
    border-top: 1px solid var(--line);
    justify-content: space-around;
    align-items: flex-start;
    gap: 8px;
  }
  .mobile-nav button {
    flex: 1;
    border: 0;
    background: #1a1a1e;
    color: var(--muted);
    padding: 10px 8px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.02em;
    border-radius: 999px;
  }
  .mobile-nav button.on { color: #111; background: #fff; }

  .swatch { width: 28px; height: 28px; }
  .chip, .page-item { padding: 12px 12px; min-height: 44px; }
}

@media (orientation: landscape) and (max-height: 540px) {
  :root { --tabbar: 0px; --gutter: 5px; --page-pad: 4px; }
  html, body {
    height: 100dvh;
    overflow: hidden;
    padding: 0 !important;
  }
  .top,
  .more-btn,
  .mobile-nav,
  .stage-bar,
  .stage-help,
  .rail,
  .insert-toolbar {
    display: none !important;
  }
  .app {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
    height: 100dvh !important;
    width: 100% !important;
    flex: none;
    padding: 0;
  }
  .stage {
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    padding: 2px 4px;
  }
  .binder-wrap {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: 100%;
  }
  .binder-shell,
  .binder-shell.spread {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    padding: 4px 6px;
    border-radius: 6px;
    box-sizing: border-box;
  }
  .binder-shell.spread .spine { margin: 0 4px; }
  .pages-row { gap: 8px; }
  .page-sheet { padding: var(--page-pad); }
  .toast { display: none; }
}

body.phone-landscape .top,
body.phone-landscape .more-btn,
body.phone-landscape .mobile-nav,
body.phone-landscape .stage-bar,
body.phone-landscape .stage-help,
body.phone-landscape .rail,
body.phone-landscape .insert-toolbar {
  display: none !important;
}
body.phone-landscape {
  padding-bottom: 0 !important;
}
body.phone-landscape .app {
  display: grid !important;
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr !important;
  height: 100dvh !important;
  width: 100% !important;
}
body.phone-landscape .stage {
  width: 100%;
  height: 100%;
  padding: 2px 4px;
}
body.phone-landscape .binder-wrap {
  width: 100%;
  height: 100%;
}
body.phone-landscape .binder-shell,
body.phone-landscape .binder-shell.spread {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.print-root { display: none; }
@media print {
  body > *:not(.print-root) { display: none !important; }
  .print-root, .print-root[hidden] { display: block !important; }
  .print-page {
    page-break-after: always;
    padding: 8mm;
  }
  .print-page h2 {
    font-family: Outfit, sans-serif;
    font-size: 11pt;
    margin: 0 0 6mm;
    font-weight: 500;
  }
  .print-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 3), 63mm);
    grid-template-rows: repeat(var(--rows, 3), 88mm);
    gap: 2mm;
    justify-content: start;
  }
  .print-grid.tiles {
    grid-template-columns: repeat(3, 63mm);
    grid-auto-rows: 88mm;
  }
  .print-pocket {
    width: 63mm;
    height: 88mm;
    overflow: hidden;
    border: 0.2mm dashed #bbb;
    border-radius: 2mm;
    box-sizing: border-box;
  }
  .print-pocket img,
  .print-pocket canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  .print-empty {
    display: grid;
    place-items: center;
    color: #ccc;
    font-size: 8mm;
  }
  .print-span { overflow: hidden; }
}
