/* ============ Tokens ============ */
:root {
  --bg: #0b0c18;
  --bg2: #141733;
  --ink: #eef0ff;
  --muted: #9ca3c9;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-2: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --a: #8b7cff;
  --b: #ff6fb1;
  --c: #41e3c4;
  --keep: #4ade80;
  --trash: #f87171;
  --edit: #fbbf24;
  --sort: #60a5fa;
  --grad: linear-gradient(120deg, var(--a), var(--b) 55%, var(--c));
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f4ff;
    --bg2: #ffffff;
    --ink: #15172b;
    --muted: #5a6088;
    --panel: rgba(255, 255, 255, 0.7);
    --panel-2: rgba(255, 255, 255, 0.95);
    --line: rgba(20, 22, 60, 0.12);
    --shadow: 0 20px 50px -22px rgba(40, 30, 120, 0.35);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f5f4ff;
  --bg2: #ffffff;
  --ink: #15172b;
  --muted: #5a6088;
  --panel: rgba(255, 255, 255, 0.7);
  --panel-2: rgba(255, 255, 255, 0.95);
  --line: rgba(20, 22, 60, 0.12);
  --shadow: 0 20px 50px -22px rgba(40, 30, 120, 0.35);
  color-scheme: light;
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--c); outline-offset: 3px; border-radius: 10px; }

.orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.orbs span {
  position: absolute;
  width: 45vmax;
  height: 45vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.28;
  animation: drift 28s ease-in-out infinite alternate;
}
.orbs span:nth-child(1) { background: var(--a); top: -15vmax; left: -10vmax; }
.orbs span:nth-child(2) { background: var(--b); bottom: -18vmax; right: -12vmax; animation-duration: 34s; }
.orbs span:nth-child(3) { background: var(--c); top: 30%; left: 40%; width: 30vmax; height: 30vmax; opacity: 0.16; animation-duration: 40s; }
@keyframes drift { to { transform: translate(6vmax, 4vmax) scale(1.08); } }

/* ============ Navbar ============ */
.nav {
  position: sticky;
  top: 12px;
  z-index: 20;
  margin: 12px auto 0;
  width: min(1000px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; font-weight: 700; letter-spacing: -0.01em; }
.mark {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--grad);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mark::after {
  content: "";
  position: absolute;
  left: 9px;
  top: 9px;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--bg2);
  box-shadow: 0 0 0 2px var(--a) inset;
}
.brand:hover .mark { transform: rotate(-12deg) scale(1.08); }

.tabs {
  margin-left: auto;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
}
.tabs a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  transition: color 0.2s, background 0.3s, box-shadow 0.3s;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 6px 20px -6px var(--a);
}
.tabs i { font-style: normal; font-size: 16px; }

.avatar {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  border: 0;
  padding: 0;
  background: var(--grad);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.2s;
}
.avatar:hover { transform: scale(1.07); }

/* ============ Layout ============ */
main { width: min(1000px, calc(100% - 32px)); margin: 0 auto; padding: 40px 0 80px; }
.view { display: none; }
.view.active { display: block; animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.view-head h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin: 0 0 4px; letter-spacing: -0.02em; }
.view-head p { margin: 0; color: var(--muted); }

.eyebrow {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.hero h1 { font-size: clamp(2.2rem, 6vw, 4rem); line-height: 1.02; letter-spacing: -0.04em; margin: 16px 0; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { max-width: 56ch; color: var(--muted); font-size: 1.05rem; }
.cta { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0 8px; }
.hint { color: var(--muted); font-size: 13px; min-height: 1.2em; margin: 0; }
.drop {
  margin-top: 16px;
  border: 2px dashed var(--line);
  border-radius: 20px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.2s, background 0.2s;
}
.drop.over { border-color: var(--c); background: var(--panel); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 10px 30px -10px var(--a); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--trash); color: var(--trash); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ============ Home stats & steps ============ */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 40px 0 24px; }
.stat {
  padding: 16px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s;
}
.stat:hover { transform: translateY(-3px); }
.stat b { display: block; font-size: 1.8rem; letter-spacing: -0.03em; }
.stat span { color: var(--muted); font-size: 13px; }

.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.step { padding: 18px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); }
.step em {
  font-style: normal;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--grad);
  color: #fff;
  font-weight: 700;
  margin-bottom: 10px;
}
.step h3 { margin: 0 0 4px; font-size: 1rem; }
.step p { margin: 0; color: var(--muted); font-size: 14px; }

/* ============ Sort deck ============ */
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0; }
.lg { padding: 6px 12px; border-radius: 999px; font-size: 13px; border: 1px solid var(--line); background: var(--panel); }
.lg.up { color: var(--keep); }
.lg.down { color: var(--trash); }
.lg.left { color: var(--edit); }
.lg.right { color: var(--sort); }

.deck {
  position: relative;
  width: min(340px, 88vw);
  height: min(440px, 58vh);
  margin: 12px auto 0;
}
.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px;
  border-radius: 26px;
  background: linear-gradient(160deg, var(--bg2), var(--panel-2));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  cursor: grab;
  transform: translateY(calc(var(--depth, 0) * 12px)) scale(calc(1 - var(--depth, 0) * 0.05));
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card.dragging { cursor: grabbing; transition: none; }
.card-top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--grad);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.fname { font-size: 1.35rem; line-height: 1.25; margin: 0 0 6px; word-break: break-word; letter-spacing: -0.02em; }
.fpath { margin: 0; color: var(--muted); font-size: 13px; word-break: break-all; }
.card-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.deck .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  border: 2px dashed var(--line);
  border-radius: 26px;
}

.stamp {
  position: absolute;
  padding: 6px 12px;
  border: 3px solid;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 1.1rem;
  background: var(--bg2);
  opacity: 0;
  pointer-events: none;
}
.s-up    { top: 30%; left: 50%; transform: translateX(-50%); color: var(--keep); border-color: var(--keep); }
.s-down  { top: 62%; left: 50%; transform: translateX(-50%); color: var(--trash); border-color: var(--trash); }
.s-left  { top: 50%; left: 14px; color: var(--edit); border-color: var(--edit); transform: translateY(-50%) rotate(-8deg); }
.s-right { top: 50%; right: 14px; color: var(--sort); border-color: var(--sort); transform: translateY(-50%) rotate(8deg); }

.actions { display: flex; justify-content: center; gap: 16px; margin-top: 24px; }
.act {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}
.act:hover { transform: scale(1.08); background: var(--panel-2); }
.act.trash { color: var(--trash); }
.act.edit { color: var(--edit); }
.act.keep { color: var(--keep); }
.act.sort { color: var(--sort); }
.count { text-align: center; color: var(--muted); margin-top: 14px; }

/* ============ File lists ============ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 14px;
}
.chip[aria-selected="true"] { background: var(--grad); color: #fff; border-color: transparent; }

.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.row .name { font-weight: 600; word-break: break-word; }
.row .sub { color: var(--muted); font-size: 13px; word-break: break-all; }
.row select, .field input, .field select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
}
.row-actions { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 14px; margin: 0; }
.editor-pane {
  margin-top: 20px;
  padding: 20px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
  justify-items: start;
}
.editor-pane h3 { margin: 0; font-size: 1.2rem; }

/* ============ Settings sheet ============ */
.sheet {
  width: min(460px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--bg2);
  color: var(--ink);
  padding: 24px;
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(5, 5, 15, 0.55); backdrop-filter: blur(4px); }
.sheet[open] { animation: pop 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 0 8px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.field input, .field select { color: var(--ink); }
.or { text-align: center; color: var(--muted); font-size: 13px; margin: 12px 0; }
.msg { min-height: 1.4em; font-size: 14px; color: var(--muted); margin: 10px 0 0; }
.msg.err { color: var(--trash); }
.icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 20px;
}
.user-card { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 16px; background: var(--panel); }
.switch { display: flex; gap: 10px; align-items: center; margin: 8px 0; font-size: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 160%);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--bg2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 50;
  max-width: 90vw;
  font-size: 14px;
}
.toast.show { transform: translate(-50%, 0); }

/* ============ Mobile: bottom dock ============ */
@media (max-width: 720px) {
  .brand-name { display: none; }
  .nav { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .tabs {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    margin: 0;
    padding: 6px;
    background: var(--bg2);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    z-index: 30;
  }
  .tabs a { flex: 1; flex-direction: column; gap: 0; padding: 8px 6px; justify-content: center; font-size: 12px; }
  main { padding-bottom: 120px; }
  .toast { bottom: 100px; }
  .card-foot span:last-child { display: none; }
  .row { grid-template-columns: auto 1fr; }
  .row-actions { grid-column: 1 / -1; }
  .row-actions select { flex: 1; }
}

/* ============ Motion preferences ============ */
@media (prefers-reduced-motion: reduce) {
  .orbs span { animation: none; }
}
[data-motion="reduced"] *,
[data-motion="reduced"] *::before,
[data-motion="reduced"] *::after {
  animation: none !important;
  transition-duration: 0.01ms !important;
}
[data-motion="reduced"] .orbs { display: none; }

/* ============ PDF editor ============ */
.pdf-host { width: 100%; display: grid; gap: 12px; }
.pdf-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pdf-bar input, .pdf-bar select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  min-width: 0;
}
.pdf-bar input { flex: 1 1 160px; }
.pdf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  justify-items: center;
}
.pdf-grid.placing .stage { cursor: crosshair; outline: 2px dashed var(--c); outline-offset: 4px; }
.pg { margin: 0; display: grid; gap: 6px; justify-items: center; min-height: 260px; align-content: start; }
.pg.failed .stage::after { content: "Could not draw this page"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.stage { position: relative; background: #fff; border-radius: 6px; box-shadow: var(--shadow); line-height: 0; min-width: 120px; min-height: 160px; }
.stage canvas { border-radius: 6px; }
.overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 6px; }
.tx { position: absolute; width: 0; height: 0; }
.tx span {
  position: absolute;
  left: 0;
  bottom: 0;
  white-space: nowrap;
  color: #000;
  font-family: Helvetica, Arial, sans-serif;
  line-height: 1;
  pointer-events: auto;
  cursor: pointer;
}
.pg figcaption { color: var(--muted); font-size: 13px; }
.pg-tools { display: flex; gap: 4px; }
.mini {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 15px;
}
.mini:hover { background: var(--panel-2); }
.mini.danger { color: var(--trash); }

/* ============ Word editor ============ */
.doc-list { display: grid; gap: 6px; }
.doc-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.doc-row .tag { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.doc-row.in-table { margin-left: 14px; border-left: 3px solid var(--line); padding-left: 10px; }
.doc-row textarea {
  width: 100%;
  resize: none;
  overflow: hidden;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}
.doc-row .locked {
  grid-column: 1 / -1;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  white-space: pre-wrap;
}
.doc-tools { display: flex; gap: 4px; }
.doc-more { margin-top: 8px; }
@media (max-width: 720px) { .doc-row { grid-template-columns: 1fr; } .doc-tools { justify-content: flex-end; } }
