:root {
  --bg: #fff6fa;
  --surface: #ffffff;
  --surface-2: #fbeef5;
  --surface-3: #f4dfea;
  --border: #f0dde8;
  --text: #2a1b29;
  --muted: #8a7287;
  --accent: #d92a76;
  --accent-2: #ff7fb5;
  --accent-ink: #ffffff;
  --accent-soft: #ffe3ef;
  --danger: #e5484d;
  --stage: #f1e7ed;
  --checker-a: #ffffff;
  --checker-b: #ece4ea;
  --shadow: 0 10px 34px rgba(90, 20, 60, 0.14);
  --toast: #2a1b29;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161016;
    --surface: #201820;
    --surface-2: #2b212b;
    --surface-3: #372b36;
    --border: #3a2d39;
    --text: #f8eef5;
    --muted: #ae98a9;
    --accent: #ff69aa;
    --accent-2: #ff9fca;
    --accent-ink: #2a0a1a;
    --accent-soft: #43222f;
    --stage: #0e0a0e;
    --checker-a: #2b252b;
    --checker-b: #221c22;
    --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
    --toast: #3a2d39;
  }
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ic { display: inline-flex; flex: none; }
.ic svg { width: 20px; height: 20px; display: block; }
.ic.filled svg { fill: currentColor; }

.checker {
  background-color: var(--checker-a);
  background-image: conic-gradient(var(--checker-b) 25%, transparent 0 50%, var(--checker-b) 0 75%, transparent 0);
  background-size: 18px 18px;
}

.muted { color: var(--muted); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow { flex: 1; }
.hidden-input { position: fixed; left: -1000px; top: 0; width: 1px; height: 1px; opacity: 0; }

/* App frame */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.screens { position: relative; min-height: 0; min-width: 0; grid-row: 1; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }

.nav {
  grid-row: 2;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.nav-btn .ic svg { width: 24px; height: 24px; }
.nav-btn.active { color: var(--accent); }

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 10px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
}
.btn .ic svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.small { height: 34px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: transparent;
}
.icon-btn:disabled { opacity: 0.3; }

@media (hover: hover) {
  .btn:not(:disabled):hover, .icon-btn:not(:disabled):hover { background: var(--surface-2); }
  .btn.primary:not(:disabled):hover { background: var(--accent); filter: brightness(1.06); }
  .btn.danger:not(:disabled):hover { background: var(--danger); filter: brightness(1.06); }
  .vg-tile:hover { background: var(--surface-3); }
  .chip:hover:not(.on), .side-row:hover:not(.active), .choice:hover, .tool-btn:hover:not(:disabled), .big-choice:hover { background: var(--surface-3); }
}

/* Editor */

.ed-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ed-main { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; overflow: hidden; }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--stage);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.photo {
  position: absolute;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.2);
}
.photo.checker {
  background-color: var(--checker-a);
  background-image: conic-gradient(var(--checker-b) 25%, transparent 0 50%, var(--checker-b) 0 75%, transparent 0);
  background-size: 18px 18px;
}
.base { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.layers { position: absolute; inset: 0; }
.stk {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  transform-origin: 50% 50%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.overlay { position: absolute; pointer-events: none; }
.sel {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 50% 50%;
  border: 1.5px dashed rgba(255, 255, 255, 0.95);
  outline: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 6px;
}
.h {
  position: absolute;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  touch-action: none;
}
.h::before { content: ""; position: absolute; inset: -10px; border-radius: 50%; }
.h .ic svg { width: 16px; height: 16px; stroke-width: 2.6; }
.h-del { top: -15px; left: -15px; background: #3b2a38; }
.h-rot { right: -15px; bottom: -15px; cursor: grab; }

.ed-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.ed-empty-card {
  max-width: 380px;
  text-align: center;
  background: var(--surface);
  border-radius: 22px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
}
.ed-empty-card h2 { font-size: 21px; margin-bottom: 6px; }
.ed-empty-card p { color: var(--muted); font-size: 15px; line-height: 1.45; }
.ed-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; }

.layer-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 58px;
  padding: 4px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.layer-bar button {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 56px;
  padding: 6px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 11.5px;
  font-weight: 650;
}
.layer-bar button:disabled { opacity: 0.35; }
.bar-hint { display: none; margin: 0; padding: 0 12px; color: var(--muted); font-size: 13.5px; text-align: center; }
.layer-bar.idle button { display: none; }
.layer-bar.idle .bar-hint { display: block; }
.layer-bar .danger, .tool-btn.danger, .sel-actions .danger, .choice.danger { color: var(--danger); }

.tray {
  flex: none;
  height: clamp(190px, 38dvh, 360px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tray.collapsed { height: auto; }
.tray.collapsed .tray-grid, .tray.collapsed .tray-search, .tray.collapsed .tray-empty { display: none; }
.tray-head { display: flex; align-items: center; gap: 4px; padding: 7px 8px 7px 4px; }
.tray-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
.tray-toggle .ic { transition: transform 0.2s; }
.tray.collapsed .tray-toggle .ic { transform: rotate(180deg); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.chips::-webkit-scrollbar, .layer-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  max-width: 190px;
  padding: 0 12px;
  border-radius: 17px;
  border: 0;
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip .ic svg { width: 16px; height: 16px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip.icon-only { width: 34px; padding: 0; justify-content: center; }
.tray-search { padding: 0 10px 4px; }
.tray-search input, .field {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 16px;
  outline: none;
}
.field:focus, .tray-search input:focus { border-color: var(--accent); }
.tray-grid { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; position: relative; }
.tray-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px;
  color: var(--muted);
  text-align: center;
}

/* Virtual grid tiles */

.vg-inner { position: relative; width: 100%; }
.vg-tile {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline-offset: 2px;
}
.vg-tile:active { background: var(--surface-3); }
.vg-tile img {
  width: 84%;
  height: 84%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}
.tile-fav { position: absolute; top: 5px; right: 5px; color: #ffb21a; display: none; }
.tile-fav .ic svg { width: 14px; height: 14px; }
.vg-tile.is-fav .tile-fav { display: block; }
.tile-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  display: none;
  place-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.tile-check .ic svg { width: 13px; height: 13px; stroke-width: 3; visibility: hidden; }
.selecting .tile-check { display: grid; }
.vg-tile.is-selected { box-shadow: inset 0 0 0 3px var(--accent); }
.vg-tile.is-selected .tile-check { background: var(--accent); }
.vg-tile.is-selected .tile-check svg { visibility: visible; }

/* Library */

.title-btn {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 4px 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
}
.title-text { display: flex; flex-direction: column; min-width: 0; }
.title { font-size: 18px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.title-chevron { display: none; color: var(--muted); }
.title-btn.has-menu .title-chevron { display: inline-flex; }

.lib-body { flex: 1; min-height: 0; display: flex; position: relative; }
.lib-side {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  width: min(320px, 86vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  visibility: hidden;
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.lib-side.open { transform: none; visibility: visible; transition: transform 0.25s ease, visibility 0s; }
.lib-side:focus { outline: none; }
.side-scrim {
  position: absolute;
  inset: 0;
  z-index: 19;
  background: rgba(20, 8, 18, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.side-scrim.open { opacity: 1; pointer-events: auto; }
.side-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  margin: 10px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
}
.side-search input, .search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
}
.side-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 6px 6px; }
.side-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 15px;
}
.side-row .ic { color: var(--muted); }
.side-row.active { background: var(--accent-soft); font-weight: 700; }
.side-row.active .ic { color: var(--accent); }
.side-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.side-label {
  padding: 14px 10px 6px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.side-none { padding: 6px 12px; color: var(--muted); font-size: 14px; line-height: 1.4; }
.side-new { margin: 4px 10px 12px; }

.lib-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.lib-tools { display: flex; gap: 8px; padding: 10px 12px 0; }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
}
.sort {
  height: 42px;
  max-width: 40%;
  padding: 0 8px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 15px;
}
.grid-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.grid { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; position: relative; }
.lib-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}
.lib-empty > * { pointer-events: auto; max-width: 420px; }
.lib-empty h2 { font-size: 20px; }
.lib-empty p { color: var(--muted); line-height: 1.45; }
.empty-art {
  width: 72px;
  height: 72px;
  margin: 0 auto 6px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--accent-soft);
  color: var(--accent);
}
.empty-art .ic svg { width: 34px; height: 34px; }
.tips { text-align: left; color: var(--muted); font-size: 14px; line-height: 1.5; padding-left: 18px; margin: 6px 0 0; }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 12px 0;
  padding: 12px;
  border-radius: 14px;
  background: var(--accent-soft);
  font-size: 14px;
  line-height: 1.4;
}
.banner .ic { color: var(--accent); }

.selbar { background: var(--accent-soft); }
.sel-count { font-weight: 700; padding-left: 4px; }
.sel-actions {
  flex: none;
  display: flex;
  justify-content: space-around;
  padding: 4px 6px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.sel-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}
.sel-actions button:disabled { opacity: 0.35; }

/* Sheets and dialogs */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(25, 8, 22, 0.42);
  opacity: 0;
  transition: opacity 0.22s;
}
.modal.open .backdrop { opacity: 1; }
.sheet:focus { outline: none; }
.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: calc(100% - 32px - env(safe-area-inset-top));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 10px 6px 20px; }
.sheet-head h2 { font-size: 18px; font-weight: 750; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 16px; }
.sheet-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
}
.sheet-actions .btn { flex: 1; max-width: 260px; height: 46px; }
.dialog-msg { color: var(--muted); line-height: 1.45; margin-bottom: 4px; }
.dialog .field { margin-top: 10px; }

.modal.full .sheet { max-width: none; height: 100%; max-height: none; border-radius: 0; }
.modal.full .sheet-head { padding-top: calc(10px + env(safe-area-inset-top)); }

.choices { display: flex; flex-direction: column; gap: 6px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2);
  text-align: left;
  font-size: 16px;
  font-weight: 600;
}
.choice > .ic { color: var(--accent); }
.choice.danger > .ic { color: var(--danger); }
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-text small { color: var(--muted); font-size: 13px; font-weight: 500; }

.form { display: flex; flex-direction: column; gap: 14px; }
fieldset { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; border: 0; min-width: 0; }
legend {
  margin-bottom: 8px;
  padding: 0;
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.radio, .check { display: flex; align-items: flex-start; gap: 10px; font-size: 15px; line-height: 1.35; cursor: pointer; }
.radio input, .check input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.radio small, .check small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.indent { display: flex; flex-direction: column; gap: 8px; padding-left: 30px; }
.note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.4;
}
.note .ic svg { width: 18px; height: 18px; }
.new-note { margin-bottom: 12px; }
.lead { font-size: 17px; font-weight: 650; }
.progress { height: 10px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.progress-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s; }
details summary { cursor: pointer; font-weight: 650; }
.fail-list { max-height: 200px; overflow-y: auto; margin: 8px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.field-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 650; color: var(--muted); }
.field-label .field { color: var(--text); font-weight: 500; }

.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.segmented.wrap { flex-wrap: wrap; }
.seg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  min-width: 64px;
  padding: 4px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 650;
  font-size: 14.5px;
}
.seg small { font-weight: 500; color: var(--muted); font-size: 12px; }
.seg.on { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.shape-icon { display: inline-block; height: 16px; border: 2px solid currentColor; border-radius: 3px; }
input[type="color"] { width: 100%; height: 44px; border: 0; border-radius: 12px; background: none; padding: 0; }

.big-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.big-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 10px;
  border: 0;
  border-radius: 16px;
  background: var(--surface-2);
  text-align: center;
}
.big-choice .ic { color: var(--accent); margin-bottom: 4px; }
.big-choice .ic svg { width: 28px; height: 28px; }
.big-choice small { color: var(--muted); font-size: 13px; }

.tool-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; margin: 14px 0 4px; }
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 650;
}
.tool-btn.on { color: var(--accent); }
.tool-btn:disabled { opacity: 0.4; }

.detail-preview, .save-stage {
  position: relative;
  height: clamp(160px, 32dvh, 300px);
  margin-bottom: 14px;
  border-radius: 16px;
  overflow: hidden;
}
/* Centered and scaled down to fit, keeping the image's own aspect ratio. */
.detail-preview img, .save-preview {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
}
.detail-preview img:not([src]), .save-preview:not([src]) { visibility: hidden; }
.meta-line { margin-top: 10px; color: var(--muted); font-size: 12.5px; }

.save-stage { height: clamp(180px, 44dvh, 420px); margin-bottom: 12px; }
.save-preview { box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2); }
.save .segmented { margin-bottom: 4px; }

.slider { display: flex; align-items: center; gap: 10px; }
.slider span { font-size: 14px; font-weight: 650; }
.slider input { flex: 1; accent-color: var(--accent); }
.slider output { min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { padding: 12px 6px; border-radius: 14px; background: var(--surface-2); text-align: center; }
.stats b { display: block; font-size: 19px; }
.stats small { color: var(--muted); }
.settings h3 {
  margin: 18px 0 8px;
  font-size: 12.5px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.setting {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-2);
}
.setting > .ic { color: var(--accent); }
.setting-text { flex: 1; min-width: 0; }
.setting-text small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.version { margin-top: 16px; text-align: center; color: var(--muted); font-size: 12px; }

/* Clean-up tool */

.cleanup .sheet-body { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; }
.cleanup-stage { position: relative; flex: 1; min-height: 180px; border-radius: 14px; overflow: hidden; }
.cleanup-stage.light { background: #fff; }
.cleanup-stage.dark { background: #111; }
.cleanup-canvas {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: calc(100% - 20px);
  max-height: calc(100% - 20px);
  cursor: crosshair;
  touch-action: manipulation;
}
.cleanup-controls { display: flex; flex-direction: column; gap: 10px; flex: none; }
.cleanup .tool-row { margin: 0; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.4; }

/* Toasts and drop target */

.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(100%, 460px);
  padding: 12px 14px 12px 16px;
  border-radius: 14px;
  background: var(--toast);
  color: #fff;
  font-size: 14.5px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; }
/* Notices without a button never get in the way of taps on what is underneath. */
.toast:not(:has(.toast-btn)) { pointer-events: none; }
.toast-btn { padding: 4px 6px; border: 0; background: transparent; color: var(--accent-2); font-weight: 750; }

.drop-hint {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  background: rgba(255, 79, 154, 0.12);
  pointer-events: none;
}
.drop-hint > div {
  max-width: 340px;
  padding: 24px 28px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 650;
}
.drop-hint .ic { color: var(--accent); margin-bottom: 8px; }
.drop-hint .ic svg { width: 36px; height: 36px; }

.fatal { max-width: 520px; margin: 12vh auto; padding: 24px; line-height: 1.5; }
.fatal h1 { font-size: 22px; margin-bottom: 10px; }
.fatal p { margin-bottom: 10px; }

/* Narrow phones: icon-only header buttons where space is tight */

@media (max-width: 899px) {
  .title-chevron { display: inline-flex; }
}

@media (max-width: 420px) {
  #lib-bar .btn-label { display: none; }
  #lib-bar .btn:has(.btn-label) { padding: 0 11px; }
}

/* Tablets and computers */

@media (min-width: 700px) {
  .modal { align-items: center; padding: 24px; }
  .sheet {
    max-height: min(86vh, 860px);
    border-radius: 22px;
    opacity: 0;
    transform: translateY(18px) scale(0.98);
    transition: transform 0.22s ease, opacity 0.22s ease;
  }
  .modal.open .sheet { opacity: 1; transform: none; }
  .dialog.sheet { max-width: 440px; }
  .modal.full .sheet { width: min(1100px, 100%); height: min(92vh, 900px); border-radius: 22px; }
  .cleanup .sheet-body { flex-direction: row; padding: 0 16px 16px; }
  .cleanup-controls { width: 300px; }
}

@media (min-width: 900px), (orientation: landscape) and (max-height: 500px) {
  .toasts { bottom: 24px; }
  #app { grid-template-rows: none; grid-template-columns: 84px minmax(0, 1fr); }
  .screens { grid-row: 1; grid-column: 2; }
  .nav {
    grid-row: 1;
    grid-column: 1;
    flex-direction: column;
    gap: 6px;
    padding: 14px 8px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .nav-btn { flex: none; padding: 12px 0 10px; border-radius: 14px; }
  .nav-btn.active { background: var(--accent-soft); }
  .only-narrow { display: none; }
  .bar { padding: 0 16px; }

  .ed-body { flex-direction: row; }
  .layer-bar.idle { display: none; }
  .layer-bar {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    border: 0;
    border-radius: 16px;
    box-shadow: var(--shadow);
  }
  .tray { width: 340px; height: auto; border-top: 0; border-left: 1px solid var(--border); }
  .tray-toggle { display: none; }
  /* The side tray has no collapse button, so a collapsed state remembered from portrait is ignored. */
  .tray.collapsed .tray-grid, .tray.collapsed .tray-search { display: block; }
  .tray.collapsed .tray-empty { display: flex; }
  .tray-head { padding-left: 10px; }

  .lib-side {
    position: static;
    width: 270px;
    flex: none;
    transform: none;
    visibility: visible;
    box-shadow: none;
    border-right: 1px solid var(--border);
    transition: none;
  }
  .side-scrim { display: none; }
}

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

@media (orientation: landscape) and (max-height: 500px) {
  .nav { padding: 8px 6px; gap: 2px; }
  .nav-btn { padding: 8px 0 6px; }
  .tray { width: min(300px, 40%); }
  .lib-side { width: min(240px, 34%); }
}
