:root {
  --bg: #14171c;
  --panel: #1c2027;
  --line: #2c323c;
  --fg: #e6e9ef;
  --muted: #8d97a8;
  --accent: #4da3ff;
  --danger: #ff6b6b;
  --ok: #2fbf71;
}

* { box-sizing: border-box; }
/* Author display rules (flex, grid) beat the UA's [hidden]; this keeps hidden hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-weight: 400; }

/* --- top bar + views --- */
html { display: block; }
.topbar { display: flex; align-items: center; gap: .6rem; padding: .45rem .9rem;
  background: #10141a; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.brand { color: var(--fg); font-weight: 650; text-decoration: none; letter-spacing: .01em; }
.brand:hover { color: var(--accent); }
.account { display: flex; align-items: center; gap: .4rem; position: relative; }
.account button { width: auto; margin: 0; }
.badge { font-size: 10.5px; padding: 0 5px; border-radius: 8px; background: #2a3d57; color: #9ccaff; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 160px; z-index: 40;
  background: #1a1e25; border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.menu[hidden] { display: none; }
.menu button { display: block; width: 100%; margin: 0; text-align: left; background: none;
  border: none; padding: .45rem .6rem; border-radius: 5px; }
.menu button:hover { background: #262c36; }
.home { flex: 1; overflow-y: auto; min-height: 0; }
.home[hidden], .admin[hidden] { display: none; }
.admin { flex: 1; overflow-y: auto; min-height: 0; }
.modal .switch { font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.modal .switch a { color: var(--accent); }

/* --- drop zone --- */
.drop {
  display: grid; place-items: center;
  text-align: center; padding: 3rem 2rem 2rem;
}
.drop-inner {
  border: 2px dashed var(--line); border-radius: 14px;
  padding: 3rem 3.5rem; max-width: 560px;
  transition: border-color .15s, background .15s;
}
.drop.over .drop-inner { border-color: var(--accent); background: #1a2331; }
.drop h1 { margin: 0 0 .5rem; font-size: 1.6rem; font-weight: 600; }
.drop p { margin: .5rem 0; color: var(--muted); }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }
.hint { font-size: 12.5px; color: var(--muted); }
.hint.warn { color: #e0a33e; }

/* --- layout --- */
/* A bare `main { display:flex }` outranks the UA's [hidden] rule, so the
   editor would stay laid out underneath the drop zone. */
main[hidden] { display: none; }
main { display: flex; flex: 1; min-height: 0; }
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.toolbar, .statusbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .8rem; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.statusbar {
  border-bottom: none; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
}
.file-name { font-weight: 600; }
.chk { display: flex; align-items: center; gap: .35rem; color: var(--muted); font-size: 13px; }

#svg { flex: 1; width: 100%; background: #0f1216; touch-action: none; cursor: grab; }
#svg.panning { cursor: grabbing; }

/* --- panel --- */
.panel {
  width: 330px; flex-shrink: 0; overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line);
}
.panel section { padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.panel h2 {
  margin: 0 0 .6rem; font-size: 11px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.panel label {
  display: block; margin: .55rem 0; font-size: 12.5px; color: var(--muted);
}
.panel input[type=range] { width: 100%; margin-top: .25rem; accent-color: var(--accent); }
.panel select, .panel input[type=number], .panel input[type=text] {
  width: 100%; margin-top: .25rem; padding: .4rem .5rem;
  background: #12151a; color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
}
.val { float: right; color: var(--fg); font-variant-numeric: tabular-nums; }
details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin: .6rem 0; }

button {
  width: 100%; padding: .5rem .7rem; margin-top: .5rem;
  background: #262c36; color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
button:hover:not(:disabled) { background: #2f3743; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
button.primary:hover { background: #6bb4ff; }
button.danger { border-color: #5a2b2b; color: var(--danger); }
button.danger:hover:not(:disabled) { background: #3a2020; }
button.ghost { width: auto; margin: 0; padding: .3rem .6rem; font-size: 12.5px; }

/* --- stats --- */
.stats { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: 12.5px; }
.stats dt, .stats .k { color: var(--muted); }
.stats .v { text-align: right; font-variant-numeric: tabular-nums; }
.stats .v.big { color: var(--ok); font-weight: 600; }

/* --- path list --- */
.path-list { max-height: 230px; overflow-y: auto; margin: .4rem 0; }
.path-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .3rem .45rem; border-radius: 5px; cursor: pointer; font-size: 12.5px;
}
.path-row:hover { background: #262c36; }
.path-row.sel { background: #1d3450; color: #cfe6ff; }
.path-row .len { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.path-row.sel .len { color: #9ec8f5; }
.path-row .tag {
  font-size: 10px; padding: .05rem .3rem; border-radius: 3px;
  background: #2b3240; color: var(--muted);
}
.path-row .del { color: var(--muted); padding: 0 .2rem; }
.path-row .del:hover { color: var(--danger); }

/* --- keys --- */
.keys { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; margin: 0; font-size: 12px; }
.keys dt { color: var(--fg); }
.keys dd { margin: 0; color: var(--muted); }
kbd {
  background: #262c36; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 .25rem; font-size: 11px; font-family: inherit;
}

/* --- toast --- */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: #262c36; border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem 1rem; font-size: 13px; z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.toast.err { border-color: var(--danger); color: #ffc9c9; }

/* --- svg pieces --- */
/* The visible line lets clicks through to the wider .geom-hit path under it;
   otherwise a click right on the line lands here and is ignored. */
.geom { fill: none; stroke: #2fbf71; stroke-linejoin: round; stroke-linecap: round;
  pointer-events: none; }
.geom.sel { stroke: #4da3ff; }
.geom-hit { fill: none; stroke: transparent; cursor: pointer; }
.vert { fill: #0f1216; stroke: #4da3ff; }
.vert:hover { fill: #4da3ff; }
.vert.sel { fill: #ffd166; stroke: #ffd166; }
.reject { fill: none; stroke: var(--danger); stroke-dasharray: 4 3; }
.band { fill: rgba(77,163,255,.12); stroke: var(--accent); stroke-dasharray: 4 3; }

/* photo mode */
.layer-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.panel .layer-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 0; }
.panel .layer-row input { width: auto; margin: 0; }
.panel .layer-row .count { margin-left: auto; opacity: 0.6; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block;
          border: 1px solid rgba(127,127,127,0.5); flex: none; }
.inks { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 4px; }
.inks .k { font-size: 13px; }
.chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px;
        border-radius: 10px; border: 1px solid rgba(127,127,127,0.4); font-size: 12px;
        cursor: pointer; font-family: ui-monospace, monospace; }
.chip:hover { border-color: #d33; }
.chip.auto { opacity: 0.6; cursor: default; }
button.small { width: auto; margin-top: 0; padding: 2px 10px; font-size: 12px; }
button.active { outline: 2px solid #2fbf71; }
svg.picking { cursor: crosshair; }
.panel .chips .muted { font-size: 12px; }

/* inline errors */
.error-strip { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px;
  padding: 8px 10px; border-radius: 6px; font-size: 12.5px; line-height: 1.4;
  background: rgba(220, 70, 70, 0.12); border: 1px solid rgba(220, 70, 70, 0.45); color: #ffb4b4; }
.error-strip span { flex: 1; }
.error-strip .x, .modal .x { width: auto; margin: 0; padding: 0 4px; background: none; border: none;
  color: inherit; cursor: pointer; font-size: 13px; }

/* dialog */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #1a1e25; border: 1px solid var(--line); border-radius: 10px; width: 100%;
  max-width: 420px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.modal.wide { max-width: 720px; }
.modal header { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px; }
.modal h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 4px 16px 8px; font-size: 13.5px; color: var(--fg); }
.modal-body p { margin: 6px 0; line-height: 1.45; }
.modal-body label { display: block; margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }
.modal-body input, .modal-body textarea { width: 100%; margin-top: 4px; padding: .45rem .55rem;
  background: #12151a; color: var(--fg); border: 1px solid var(--line); border-radius: 6px;
  font-size: 13.5px; font-family: inherit; box-sizing: border-box; }
.modal .error-strip { margin: 0 16px 8px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 16px 14px; }
.modal footer button { width: auto; margin: 0; }
button.danger.solid { background: #a33; border-color: #a33; color: #fff; }

/* loading + empty */
.stage { position: relative; }
/* Blocks the canvas while busy (pointer-events on): edits made now would be
   overwritten by the result. */
.busy { position: absolute; inset: 44px 0 30px 0; display: flex; align-items: center;
  justify-content: center; gap: 10px; background: rgba(14, 17, 22, 0.55); color: var(--fg);
  font-size: 14px; pointer-events: auto; cursor: progress; z-index: 5; text-align: left; }
.busy .muted { font-size: 12px; }
#editor.busy-lock .path-list, #editor.busy-lock .version-list .vactions { pointer-events: none; opacity: .5; }
.busy[hidden] { display: none; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 14px 10px; font-size: 12.5px; color: var(--muted); text-align: center;
  line-height: 1.45; }
.drop .error-strip { max-width: 520px; margin: 12px auto 0; text-align: left; }

/* saved scans */
.toolbar button.small { width: auto; margin: 0; }
button.attention { box-shadow: 0 0 0 2px #e0a33e; }
.version-list { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.version-row { padding: 6px 8px; border-radius: 6px; border: 1px solid transparent; font-size: 13px; }
.version-row.current { background: #1f2c40; border-color: #2c4566; }
.vline { display: flex; gap: 8px; align-items: baseline; }
.vnum { font-weight: 650; min-width: 2.2em; }
.vlabel { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmeta, .vnote { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.vnote { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: italic; }
.vactions { display: flex; gap: 5px; margin-top: 5px; }
.vactions button { width: auto; margin: 0; padding: 2px 8px; font-size: 11.5px; }
.tag { font-size: 10.5px; padding: 0 5px; border-radius: 6px; background: #2b3340; color: var(--muted); }

/* library */
.library { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem 3rem; }
.library-head { display: flex; align-items: center; gap: .6rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.library-head h2 { margin: 0; font-size: 15px; }
.library-head input, .library-head select { padding: .4rem .55rem; background: #12151a; color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.library-head input { width: 220px; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column; }
.card.skeleton { height: 270px; background: linear-gradient(90deg, #1b1f26 0%, #222833 50%, #1b1f26 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.card .thumb { width: 100%; margin: 0; padding: 0; height: 160px; background: #0f1216; border: none;
  border-bottom: 1px solid var(--line); border-radius: 0; display: grid; place-items: center; cursor: pointer; }
.card .thumb { overflow: hidden; flex-shrink: 0; position: relative; }
.card .thumb img { position: absolute; inset: 6px; width: calc(100% - 12px);
  height: calc(100% - 12px); object-fit: contain; }
.card .thumb .ph { width: 40%; height: 40%; border-radius: 8px; background: #1b2028; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.card-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; }
.card-actions button { width: auto; margin: 0; flex: 1; }
.card input.rename { width: 100%; padding: .3rem .45rem; background: #12151a; color: var(--fg);
  border: 1px solid var(--accent); border-radius: 5px; font: inherit; font-weight: 600; }
.library .empty { text-align: center; padding: 2rem 1rem; }
button.danger.small { width: auto; }

/* compare */
/* Not ".ghost": that's the secondary-button class, and pointer-events:none here
   would make every such button unclickable. */
.ghost-path { fill: none; stroke: #f0b54a; stroke-linejoin: round; pointer-events: none; }
.ghost-path.current-ghost { stroke: #7fb0ff; }
.compare-front { pointer-events: none; }
.compare-box { margin-top: 10px; padding: 10px; border: 1px solid #4a3d22; border-radius: 8px;
  background: rgba(240, 181, 74, 0.06); font-size: 12.5px; }
.compare-head { margin-bottom: 6px; }
.ghost-key { display: inline-block; width: 18px; height: 0; border-top: 2px dashed #f0b54a;
  vertical-align: middle; margin: 0 4px; }
.warn-chip { margin: 6px 0; padding: 6px 8px; border-radius: 6px; background: rgba(224, 163, 62, 0.15);
  border: 1px solid rgba(224, 163, 62, 0.5); color: #f3c77a; line-height: 1.4; }
.compare-table { width: 100%; border-collapse: collapse; margin: 8px 0 4px; font-variant-numeric: tabular-nums; }
.compare-table th, .compare-table td { padding: 2px 4px; text-align: right; font-weight: 400; }
.compare-table th:first-child { text-align: left; color: var(--muted); }
.compare-table thead th { color: var(--muted); font-size: 11.5px; border-bottom: 1px solid var(--line); }
.vactions button.active { outline: 1px solid #f0b54a; color: #f3c77a; }

/* admin */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  border-bottom: 1px solid var(--line); padding: 6px 8px; }
.admin-table td { padding: 8px; border-bottom: 1px solid #22272f; vertical-align: top; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .actions { display: flex; flex-wrap: wrap; gap: 5px; }
.admin-table .actions button { width: auto; margin: 0; }
.admin-table .actions .error-strip { flex-basis: 100%; margin-top: 4px; }
.loading-row { color: var(--muted); padding: 1rem 8px; display: flex; align-items: center; gap: 8px; }
