/* Inkpad – „Tmavý ateliér“. Every value here comes from DESIGN.md; add nothing outside it. */

@import url('../vendor/fonts/fonts.css');

:root {
  --chrome: #1C1C1E;
  --surface: #2A2A2D;
  --surface-2: #333337;
  --text: #ECE8E1;
  --primary: #F6B652;
  --on-primary: #1C1C1E;
  --muted: #C2BCB3;
  --line: #5E5E64;
  --line-strong: #7E7E84;
  --desk: #3A3A3E;
  --danger: #F7A592;
  --paper: #fbfbf8;
  --paper-shadow: 0 1px 2px rgb(0 0 0 / .45), 0 10px 28px rgb(0 0 0 / .28);
  --radius: 6px;
  --toolbar-h: 56px;
  --nav-w: 240px;
  --sans: 'Instrument Sans', sans-serif;
  --serif: 'Instrument Serif', serif;
  --mono: 'JetBrains Mono', monospace;
  color-scheme: dark;
  scrollbar-color: var(--line-strong) transparent;
  font: 400 14px/1.45 var(--sans);
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--chrome);
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--primary); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
:disabled { opacity: .4; cursor: default; }

/* Shared text roles */

.label-caps, .nav-label, .side-head > span, .dialog-body .card h3, fieldset.field legend, .binding .badge {
  font: 600 12px/1.45 var(--sans);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.num-text, .size-value, .range-value, .save-status, .btn.zoom, .page-label, #hud, .readout, .field > span > b,
.nav-item .count, #home-grid .card .sub, .page-thumb .num, kbd, .popover kbd {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* Views: the notes overview and the editor */

.view { height: 100dvh; }
body.view-home #app, body.view-editor #home { display: none; }
#app { display: flex; }

/* Workspace + toolbar */

#workspace {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#toolbar {
  height: var(--toolbar-h);
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}

.tb-side, .tb-center { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tb-right { justify-content: flex-end; }

.group { display: flex; align-items: center; gap: 0; flex: none; }
.group[hidden] { display: none; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; flex: none; }
.spacer { flex: 1; min-width: 8px; }

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.icon-btn::-webkit-details-marker { display: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.active, .icon-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--primary); }
.icon-btn:disabled { background: none; }

.btn {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  flex: none;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { background: none; }
.btn.primary, .btn.primary:hover { background: var(--primary); color: var(--on-primary); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.zoom { min-width: 64px; }
.btn.with-icon { display: inline-flex; align-items: center; gap: 8px; }
.btn.with-icon svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.title-input {
  width: 220px;
  min-width: 100px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  font: 400 17px/1.2 var(--serif);
  text-overflow: ellipsis;
  -webkit-user-select: text;
  user-select: text;
}

.title-input:hover { border-color: var(--line-strong); }
.title-input:focus { outline: none; border-color: var(--primary); background: var(--surface); }

.swatches { display: flex; }

/* Ink swatch: 20 px circle, 32 px target, inner ring so black ink shows on the dark bar. */
.swatch, .color-pick {
  position: relative;
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.swatch::before, .color-pick::before {
  content: '';
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.swatch.active::before { box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 2px var(--chrome), 0 0 0 4px var(--primary); }

/* Custom colour: an empty ring with a plus. */
.color-pick::before { background: none; box-shadow: inset 0 0 0 1px var(--line-strong); }
.color-pick::after { content: '+'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; line-height: 1; }
.color-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer; }
.color-pick:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }

#colors[hidden] { display: none; }

/* Tip size: a dot as big as the tip (within reason) and its number; the slider is in a popover. */
.size-btn { width: auto; min-width: 40px; padding: 0 8px; display: inline-flex; gap: 8px; }
.size-btn[hidden] { display: none; }
.size-dot { width: var(--dot, 6px); height: var(--dot, 6px); border-radius: 50%; background: currentColor; }
.size-value { min-width: 16px; text-align: left; color: var(--muted); }
.size-menu { min-width: 0; padding: 12px 16px; }
.size-menu input { width: 176px; display: block; }

.select {
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  flex: none;
  cursor: pointer;
}

.select:focus-visible { outline: none; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }

.save-status { color: var(--muted); white-space: nowrap; flex: none; padding: 0 8px; }
.save-status.error { color: var(--danger); }
.save-status.offline { color: var(--text); }
#save-status.saved { display: none; }

/* Menu */

.menu { position: static; flex: none; }
.menu[open] > summary { background: var(--surface-2); }

.menu-panel {
  position: fixed;
  top: calc(var(--toolbar-h) - 4px);
  right: 8px;
  min-width: 280px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  z-index: 20;
}

.menu-panel button, .menu-panel .check {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
  cursor: pointer;
}

.menu-panel button:hover, .menu-panel .check:hover { background: var(--surface-2); }
.menu-panel button:focus-visible { outline-offset: -2px; }

.menu-panel .range {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
}

.menu-panel .range input { flex: 1; min-width: 0; }
.range-value { width: 28px; text-align: right; color: var(--muted); }
.menu-panel .danger { color: var(--danger); }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* Canvas stage */

#stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  touch-action: none;
  cursor: none; /* the overlay draws the tool cursor */
  background: var(--desk);
}

#stage.panning { cursor: grab; }
#stage.panning.dragging { cursor: grabbing; }

.layer { position: absolute; left: 0; top: 0; display: block; }
.layer-live { touch-action: none; }
.layer-overlay { pointer-events: none; }

#hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 4px 8px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  pointer-events: none;
  z-index: 10;
}

#hud:empty, #hud[hidden] { display: none; }

@media (max-width: 1100px) {
  #toolbar { display: flex; overflow-x: auto; scrollbar-width: none; }
  .tb-side, .tb-center { flex: none; }
  .tb-right { margin-left: auto; }
}

@media (max-width: 800px) {
  .title-input { width: 130px; }
}

/* Dialogs */

.dialog {
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}

.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: rgb(0 0 0 / .55); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 8px 24px;
  border-bottom: 1px solid var(--line);
  margin: 0;
}

.dialog-head h2 { font: 600 18px/1.3 var(--sans); margin: 0; }

.dialog-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  padding: 24px;
  overflow-y: auto;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

/* Tablet dialog: sections divided by a line, no boxes */

.col { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

.dialog-body .card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-body .card + .card { border-top: 1px solid var(--line); padding-top: 24px; }
.dialog-body .card h3 { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.device-name { font: 400 17px/1.2 var(--serif); }
.device-sub { color: var(--muted); margin-top: 4px; }

.note { color: var(--muted); margin: 0; }
.note code, .note pre { font: 400 12px/1.45 var(--mono); color: var(--text); }
.note pre { background: var(--chrome); padding: 8px; border-radius: var(--radius); overflow-x: auto; -webkit-user-select: text; user-select: text; }
.help summary { cursor: pointer; }

.warn {
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { display: flex; justify-content: space-between; }
.field > span > b { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.caps {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
}

.caps dt { color: var(--muted); }
.caps dd { margin: 0; font-variant-numeric: tabular-nums; }
.caps .yes { font-weight: 600; }

.bindings { display: flex; flex-direction: column; gap: 8px; }
.binding { display: flex; align-items: center; gap: 8px; }
.binding .label { flex: 1; }
.binding .badge { margin-left: 8px; }
.binding .select { width: 176px; }

.binding .remove {
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.binding .remove:hover { color: var(--danger); background: var(--surface-2); }

kbd {
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--chrome);
}

.curve-wrap { display: flex; gap: 16px; align-items: flex-start; }
.curve {
  width: 200px;
  height: 200px;
  flex: none;
  border-radius: var(--radius);
  background: var(--chrome);
  touch-action: none;
  cursor: grab;
}

.curve-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.presets { display: flex; gap: 4px; }
.presets .btn { flex: 1; padding: 0 8px; box-shadow: inset 0 0 0 1px var(--line-strong); }
.presets .btn.active { background: var(--surface-2); color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.readout { color: var(--muted); }

/* Test pad is paper. */
.pad {
  width: 100%;
  height: 216px;
  border-radius: 2px;
  background: var(--paper);
  box-shadow: var(--paper-shadow);
  touch-action: none;
  cursor: crosshair;
}

@media (max-width: 760px) {
  .dialog-body { grid-template-columns: 1fr; }
  .curve-wrap { flex-direction: column; }
}

/* Notes overview: a desk with sheets of paper */

#home { display: flex; flex-direction: column; }

.home-side {
  width: var(--nav-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; height: var(--toolbar-h); flex: none; padding: 0 16px; font: 400 17px/1.2 var(--serif); }
.brand svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.side-foot { flex: none; padding: 12px 16px; border-top: 1px solid var(--line); }
.side-foot .save-status { padding: 0; }
.nav-toggle { display: none; }

.home-filters { display: flex; align-items: center; gap: 16px; margin: -8px 0 32px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  flex: 0 1 400px;
  min-width: 0;
  padding: 0 8px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.search:focus-within { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.search svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within kbd { display: none; }
.search kbd { color: var(--muted); }

/* Sorting reads as a sentence: "Řadit naposledy upravené ⌄". */
.sort { position: relative; display: flex; align-items: center; gap: 4px; height: 40px; padding: 0 4px 0 8px; margin-left: auto; border-radius: var(--radius); color: var(--muted); cursor: pointer; }
.sort:hover { background: var(--surface-2); }
.sort:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.sort select { appearance: none; border: 0; background: none; padding: 0 24px 0 0; margin-right: -20px; color: var(--text); cursor: pointer; outline: none; }
.sort svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; -webkit-user-select: text; user-select: text; }
.search input::placeholder, .input::placeholder { color: var(--muted); opacity: 1; }

.home-body { flex: 1; min-height: 0; display: flex; position: relative; }

#home-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--surface-2); color: var(--primary); }
.nav-item.drop { outline: 2px dashed var(--primary); outline-offset: -2px; }
.nav-item svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nav-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { color: var(--muted); }
.nav-item .twisty { width: 24px; height: 24px; flex: none; display: grid; place-items: center; margin: 0 -4px; color: var(--muted); border-radius: var(--radius); }
.nav-item .twisty:hover { background: var(--line); }
.nav-item .twisty svg { width: 12px; height: 12px; transition: transform .12s; }
.nav-item .twisty.open svg { transform: rotate(90deg); }
.nav-sep { height: 1px; background: var(--line); margin: 8px; }
.nav-label { padding: 8px 8px 4px; }

#home-main { flex: 1; min-width: 0; overflow-y: auto; padding: 8px 32px 32px; }
#home-main .home-title { min-height: var(--toolbar-h); margin-bottom: 16px; }

.home-title { display: flex; align-items: center; gap: 12px; min-height: 40px; margin-bottom: 24px; }
.home-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
#home-crumbs { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px; font: 400 30px/1.1 var(--serif); }
#home-crumbs button { border: 0; background: none; font: inherit; color: var(--muted); padding: 0 4px; border-radius: var(--radius); cursor: pointer; }
#home-crumbs button:hover { color: var(--text); background: var(--surface-2); }
#home-crumbs .sep-c { color: var(--muted); }
#home-crumbs .current { padding: 0 4px; }
.home-note { margin: -16px 0 24px; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 32px 24px;
}

#home-grid .card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 2px;
  cursor: pointer;
}
#home-grid .card.dragging { opacity: .4; }
#home-grid .card.drop .thumb { outline: 2px dashed var(--primary); outline-offset: 4px; }

/* The sheet: the thumbnail image is the page itself (transparent around it), so the shadow
   follows its outline. Without a thumbnail, an empty sheet of the note's paper. */
#home-grid .card .thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#home-grid .card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom;
  display: block;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / .45)) drop-shadow(0 10px 28px rgb(0 0 0 / .28));
}
#home-grid .card.note .thumb:not(:has(img)) { background: var(--paper); border-radius: 2px; box-shadow: var(--paper-shadow); }
#home-grid .card .thumb svg { display: none; }

/* A folder is a bundle of two sheets. */
#home-grid .card.folder .thumb::before, #home-grid .card.folder .thumb::after {
  content: '';
  position: absolute;
  border-radius: 2px;
  box-shadow: var(--paper-shadow);
}
#home-grid .card.folder .thumb::before { inset: 0 12% 8% 0; background: #fdf6e3; }
#home-grid .card.folder .thumb::after { inset: 8% 0 0 12%; background: var(--paper); }

#home-grid .card .meta { display: flex; align-items: flex-start; gap: 4px; padding-top: 12px; }
#home-grid .card .text { flex: 1; min-width: 0; }
#home-grid .card .title { font: 400 17px/1.2 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#home-grid .card .sub { color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#home-grid .card .more { margin: -8px -8px 0 0; }

.empty { padding: 64px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font: 400 17px/1.2 var(--serif); margin-bottom: 8px; }
.empty .btn { margin-top: 16px; }

/* Popovers: card menu, page menu, zoom menu, layers */

.popover {
  position: fixed;
  z-index: 20;
  min-width: 220px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.popover button {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
  cursor: pointer;
}
.popover button:hover { background: var(--surface-2); }
.popover button:focus-visible { background: var(--surface-2); outline-offset: -2px; }
.popover .danger { color: var(--danger); }
.popover button:disabled { background: none; }
.popover button.with-key { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.popover kbd { padding: 0; border: 0; background: none; color: var(--muted); }
.popover hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.layers-list { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px; overflow-y: auto; }
.layer-row { display: flex; align-items: center; gap: 0; padding: 0 4px; border-radius: var(--radius); }
.layer-row.active { background: var(--surface-2); }
.layer-row .icon-btn { width: 32px; height: 32px; flex: none; }
.layer-row .icon-btn svg { width: 18px; height: 18px; }
.layer-row .icon-btn.off { color: var(--line-strong); }
.layer-row .name { flex: 1; min-width: 0; min-height: 36px; padding: 0 4px; border: 0; background: none; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .name:hover { background: none; }
.layer-row.active .name { color: var(--primary); font-weight: 600; }
.layer-row .name small { color: var(--muted); font-size: inherit; font-weight: 400; margin-left: 8px; }
.layer-row.hidden-layer .name { color: var(--muted); }
.layers-foot { flex: none; border-top: 1px solid var(--line); padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.layers-foot .select { width: 100%; }

/* Toast, selection bar, drop hint */

.toast {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  z-index: 30;
  pointer-events: none;
  max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }

.sel-bar {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  z-index: 10;
}
.sel-bar[hidden] { display: none; }
.sel-layer { display: flex; align-items: center; gap: 8px; color: var(--muted); padding-left: 8px; }
.sel-layer .select { height: 32px; max-width: 144px; color: var(--text); }
.sel-bar .danger { border-left: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) 0; }

.drop-hint {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  background: rgb(28 28 30 / .6);
  color: var(--primary);
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
}
.drop-hint[hidden] { display: none; }
#stage[data-tool="select"] { cursor: default; }

/* Forms */

.radio-list { display: flex; flex-direction: column; gap: 8px; }
.radio-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.range-row .input { flex: 1; }
.field-error { margin: 8px 0 0; color: var(--danger); }

.dialog.small { width: min(480px, calc(100vw - 24px)); }
.dialog.small form { display: flex; flex-direction: column; min-height: 0; margin: 0; }
.dialog.small .dialog-head { border-bottom: 0; padding-bottom: 0; }
.dialog.small .dialog-foot { border-top: 0; padding: 16px 24px 24px; }
.form { display: flex; flex-direction: column; gap: 16px; padding: 16px 24px 4px; overflow-y: auto; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field legend { padding: 0; margin-bottom: 8px; }

.input {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  -webkit-user-select: text;
  user-select: text;
}
.input:focus-visible { outline: none; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }

.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice {
  display: flex;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--primary); background: var(--surface-2); }
.choice:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.choice.disabled { opacity: .4; cursor: not-allowed; }
.choice input { margin: 4px 0 0; }
.choice b { display: block; font-weight: 600; }
.choice small { display: block; color: var(--muted); font-size: inherit; }

/* Paper colours are paper: square-ish sheets, ringed when chosen. */
.paper-swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.paper-swatches button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 2px;
  background: var(--c);
  cursor: pointer;
  padding: 0;
}
.paper-swatches button.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }
.paper-swatches .color-pick { margin: 0; }

.pattern-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pattern-choices button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
}
.pattern-choices button.active { border-color: var(--primary); background: var(--surface-2); color: var(--primary); }
.pattern-choices canvas { width: 56px; height: 40px; border-radius: 2px; }

.folder-pick { max-height: 50vh; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 0; }
.folder-pick .nav-item[aria-selected="true"] { background: var(--surface-2); color: var(--primary); }
.folder-pick .nav-item[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

@media (max-width: 800px) {
  .nav-toggle { display: inline-grid; }
  .home-side { position: absolute; top: 0; bottom: 0; left: 0; z-index: 20; }
  body:not(.nav-open) .home-side { display: none; }
  .search { flex: 1; }
  .sort > span { display: none; }
  #home-crumbs { font-size: 24px; min-width: 0; }
  .btn.with-icon { padding: 0 8px; }
  .btn.with-icon .label { display: none; }
  #home-import { display: none; }
  #home-main { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 24px 16px; }
}

/* Page bar (bottom of the editor) */

.page-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  z-index: 10;
}
.page-label { min-width: 64px; padding: 0 8px; text-align: center; }
.page-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
button.page-label { border: 0; background: none; height: 40px; border-radius: var(--radius); cursor: pointer; }
button.page-label:hover { background: var(--surface-2); }

/* Format picker */

.format-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.format-row .select { flex: 1; min-width: 144px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: none; padding: 0 12px; height: 34px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.active { background: var(--surface-2); color: var(--primary); }
.seg button:focus-visible { outline-offset: -2px; }
.custom-size { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.custom-size .input { width: 96px; }

/* Editor body: pages panel + stage */

.editor-body { flex: 1; min-height: 0; display: flex; }
.stage-wrap { position: relative; flex: 1; min-width: 0; display: flex; }
.stage-wrap #stage { flex: 1; }

.side-panel {
  width: 232px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  border-right: 1px solid var(--line);
}
.side-panel[hidden] { display: none; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  padding: 4px 4px 4px 16px;
  border-bottom: 1px solid var(--line);
}
.side-head > span { flex: 1; }
.side-head .icon-btn[hidden] { display: none; }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Pages / Layers switch at the foot of the panel. */
.side-switch { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px; border-top: 1px solid var(--line); }
.side-switch button { height: 36px; border: 0; border-radius: var(--radius); background: none; color: var(--muted); cursor: pointer; }
.side-switch button:hover { background: var(--surface-2); color: var(--text); }
.side-switch button[aria-selected="true"] { background: var(--surface-2); color: var(--primary); font-weight: 600; }
.narrow-only { display: none; }
.pages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  touch-action: pan-y;
}
.page-thumb {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border-radius: 2px;
  touch-action: none;
}
.page-thumb canvas {
  width: 160px;
  display: block;
  border-radius: 2px;
  background: var(--paper);
  box-shadow: var(--paper-shadow);
}
.page-thumb .num { color: var(--muted); }
.page-thumb.active canvas { outline: 2px solid var(--primary); outline-offset: 2px; }
.page-thumb.active .num { color: var(--primary); }
.page-thumb.dragging { opacity: .4; }
.page-thumb.drop-before::before, .page-thumb.drop-after::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}
.page-thumb.drop-before::before { top: -9px; }
.page-thumb.drop-after::after { bottom: -9px; }
.page-ghost {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  opacity: .85;
  box-shadow: var(--paper-shadow);
  border-radius: 2px;
}

/* Minimap */

.minimap {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 200px;
  height: 140px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: none;
  z-index: 10;
}
.minimap[hidden] { display: none; }

@media (max-width: 800px) {
  .side-panel { position: absolute; top: 0; bottom: 0; left: 0; z-index: 20; }
  .narrow-only { display: inline-grid; }
  .minimap { width: 140px; height: 100px; bottom: 72px; }
}

/* Touch devices: 16 px in fields so iOS doesn't zoom while typing. */
@media (pointer: coarse) {
  .input, .select, .search input, .title-input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}
