/* My Digital Closet: editorial, quiet, phone-first.
   Ivory paper, ink type, a camel accent; Cormorant Garamond for display,
   Inter for everything you read at small sizes. */

@font-face { font-family: "Cormorant Garamond"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/cormorant-garamond-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Cormorant Garamond"; font-style: italic; font-weight: 500; font-display: swap; src: url("/fonts/cormorant-garamond-latin-500-italic.woff2") format("woff2"); }
@font-face { font-family: "Cormorant Garamond"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 500; font-display: swap; src: url("/fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/inter-latin-600-normal.woff2") format("woff2"); }

:root {
  --bg: #f7f4ef;
  --bg-elev: #fdfbf8;
  --bar: rgba(247, 244, 239, 0.86);
  --surface: #ffffff;
  --surface-2: #efe9e1;
  --surface-3: #e3dbd0;
  --studio-bg: #ebe5dc;
  --ink: #171615;
  --ink-2: #4b4642;
  --muted: #8a837a;
  --line: rgba(23, 22, 21, 0.08);
  --line-strong: rgba(23, 22, 21, 0.16);
  --accent: #8b6a45;
  --accent-soft: #f0e6d9;
  --accent-text: #6e5133;
  --heart: #b5473c;
  --danger: #ad3a2f;
  --on-ink: #f7f4ef;
  --scrim: rgba(18, 16, 14, 0.42);
  --checker: #ebe5dd;
  /* Backdrop behind product images: stays light in dark mode so a navy
     tee or black boots remain visible, like a retailer's product shots. */
  --media: #efe9e1;
  --media-hi: #ffffff;
  --checker-base: #ffffff;
  --shadow-sm: 0 1px 2px rgba(40, 30, 18, 0.05), 0 4px 14px rgba(40, 30, 18, 0.05);
  --shadow-md: 0 10px 34px rgba(40, 30, 18, 0.12);
  --shadow-lg: 0 24px 60px rgba(30, 22, 12, 0.22);

  --serif: "Cormorant Garamond", "Iowan Old Style", "Palatino", "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --gutter: 20px;
  --tabbar-h: 62px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211;
    --bg-elev: #1b1a18;
    --bar: rgba(19, 18, 17, 0.84);
    --surface: #1f1d1b;
    --surface-2: #292623;
    --surface-3: #37332e;
    --studio-bg: #0e0d0c;
    --ink: #f3efe9;
    --ink-2: #cbc4ba;
    --muted: #8f877d;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.16);
    --accent: #c9a477;
    --accent-soft: #352d24;
    --accent-text: #dcbf98;
    --heart: #e0695e;
    --danger: #e0685c;
    --on-ink: #131211;
    --scrim: rgba(0, 0, 0, 0.6);
    --checker: #c9c2b8;
    --media: #c8c1b7;
    --media-hi: #ddd7ce;
    --checker-base: #ddd7ce;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 34px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  }
}

/* ------------------------------------------------------------ base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}
html.is-locked, html.is-locked body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.is-loading .app { visibility: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

svg { width: 22px; height: 22px; flex: none; }
[data-icon], .icon { display: inline-grid; place-items: center; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  opacity: 0;
}
.small { font-size: 13px; line-height: 1.45; }
.muted { color: var(--muted); }
.noscript { padding: 40px 24px; text-align: center; }

/* ------------------------------------------------------------ layout */

.view {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 18px) var(--gutter) calc(var(--tabbar-h) + var(--safe-b) + 104px);
  animation: view-in 0.35s var(--ease);
}
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

.page-head { padding: 10px 0 6px; }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-title {
  margin-top: 6px;
  font: 500 46px/0.98 var(--serif);
  letter-spacing: -0.01em;
}
.page-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-sub { margin-top: 8px; color: var(--muted); font-size: 14px; }

/* ------------------------------------------------------------ controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.005em;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s var(--ease), background-color 0.2s, opacity 0.2s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.38; }
.btn svg { width: 19px; height: 19px; }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-outline { border-color: var(--line-strong); color: var(--ink); }
.btn-outline:active { background: var(--surface-2); }
.btn-quiet { color: var(--ink-2); }
.btn-quiet:active { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-text { color: var(--danger); }
.btn-sm { min-height: 38px; padding: 0 15px; font-size: 13.5px; gap: 6px; }
.btn-sm svg { width: 17px; height: 17px; }
.btn.is-busy { opacity: 0.6; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn-col { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 12px; }
.btn-col .btn-quiet { padding-left: 4px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: var(--ink);
  transition: background-color 0.15s;
}
.icon-btn:active { background: var(--surface-2); }

.search {
  position: relative;
  display: block;
  margin-top: 18px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-icon svg { width: 19px; height: 19px; }
.search input {
  width: 100%;
  height: 46px;
  padding: 0 16px 0 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px; /* 16px stops iOS zooming into the field */
  box-shadow: var(--shadow-sm);
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--line-strong); }

.chips-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 8px calc(var(--gutter) * -1) 6px;
  padding: 0 var(--gutter);
  background: var(--bar);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 15px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
  transition: background-color 0.18s, color 0.18s, border-color 0.18s, transform 0.15s;
}
.chip:active { transform: scale(0.96); }
.chip[aria-pressed="true"], .chip[aria-checked="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
}
.chip.is-empty:not([aria-pressed="true"]) { opacity: 0.5; }
.chip-count { font-size: 11.5px; font-variant-numeric: tabular-nums; opacity: 0.6; }
.chip-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------ wardrobe grid */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 12px;
  margin-top: 6px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px 16px; } }

.card { position: relative; min-width: 0; animation: card-in 0.4s var(--ease) both; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }

.card-media {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  width: 100%;
  aspect-ratio: 4 / 5;
  padding: 13%;
  border-radius: 18px;
  background:
    radial-gradient(120% 90% at 50% 18%, var(--media-hi) 0%, transparent 70%),
    var(--media);
  overflow: hidden;
  transition: transform 0.2s var(--ease);
}
.card-media:active { transform: scale(0.975); }
/* Product images fill a padded frame and letterbox inside it; max-height on
   a grid item can't stop an auto-sized row from growing with a tall photo. */
.card-media img, .tray-item img, .detail-img, .piece-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}
.card-media img {
  filter: drop-shadow(0 10px 14px rgba(40, 28, 12, 0.14));
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}
.card-fav {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: transform 0.15s var(--ease), color 0.15s;
}
.card-fav svg { width: 18px; height: 18px; }
.card-fav:active { transform: scale(0.88); }
.card-fav[aria-pressed="true"] { color: var(--heart); }
.card-fav[aria-pressed="true"] svg path, .fav-toggle[aria-pressed="true"] svg path { fill: currentColor; }
.card-meta { display: grid; gap: 1px; padding: 9px 2px 0; }
.card-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.fab {
  position: fixed;
  right: max(var(--gutter), calc((100vw - 1100px) / 2 + var(--gutter)));
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 56px;
  padding: 0 22px 0 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transition: transform 0.18s var(--ease);
}
.fab:active { transform: scale(0.95); }

/* ------------------------------------------------------------ empty states */

.empty { max-width: 360px; margin: 0 auto; padding: 44px 8px 24px; text-align: center; }
.empty-mark {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin: 0 auto 18px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.empty-mark svg { width: 30px; height: 30px; }
.empty-title { font: 500 31px/1.05 var(--serif); }
.empty-text { margin: 10px 0 22px; color: var(--ink-2); font-size: 14.5px; }

/* ------------------------------------------------------------ lookbook */

.looks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 14px;
  margin-top: 18px;
}
@media (min-width: 600px) { .looks { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .looks { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 28px 18px; } }
.look { min-width: 0; animation: card-in 0.4s var(--ease) both; }
.look-media {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 18px;
  overflow: hidden;
  background: var(--media);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease);
}
.look-media:active { transform: scale(0.975); }
.look-media img { width: 100%; height: 100%; object-fit: cover; }
.look-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: 4px; padding-top: 10px; }
.look-meta > div { min-width: 0; }
.look-name { font: 500 21px/1.1 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.look-sub { margin-top: 3px; font-size: 12px; color: var(--muted); }
.look-more { margin: -8px -8px 0 0; color: var(--muted); }

/* ------------------------------------------------------------ me */

.panel {
  margin-top: 14px;
  padding: 18px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.panel-title { font: 500 24px/1.1 var(--serif); margin-bottom: 4px; }
.panel-danger .panel-title { color: var(--danger); }
.panel-danger .btn { margin-top: 14px; }
.me-photo-panel { display: grid; grid-template-columns: minmax(0, 128px) minmax(0, 1fr); gap: 16px; margin-top: 18px; }
@media (min-width: 600px) { .me-photo-panel { grid-template-columns: 200px 1fr; gap: 24px; } }
.me-photo-frame, .me-photo-empty {
  width: 100%;
  aspect-ratio: 3 / 4.4;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface-2);
}
.me-photo-frame img { width: 100%; height: 100%; object-fit: cover; }
.me-photo-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px;
  border: 1.5px dashed var(--line-strong);
  background: transparent;
  text-align: center;
}
.me-photo-empty .empty-mark { width: 52px; height: 52px; margin-bottom: 8px; }
.me-photo-empty-title { font-size: 13.5px; font-weight: 600; }
.tips { margin: 12px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); display: grid; gap: 4px; }
.tips li { position: relative; padding-left: 14px; }
.tips li::before { content: ""; position: absolute; left: 2px; top: 0.6em; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 16px 8px 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.stat-num { font: 500 34px/1 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.stat-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }

.kv { margin: 14px 0 0; display: grid; gap: 8px; font-size: 13.5px; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 500; }
.inline-icon svg { width: 16px; height: 16px; vertical-align: -3px; }
.colophon { margin-top: 28px; text-align: center; font-size: 10.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }

/* ------------------------------------------------------------ tab bar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding: 0 max(8px, calc((100vw - 640px) / 2)) var(--safe-b);
  background: var(--bar);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  backdrop-filter: blur(22px) saturate(1.5);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: color 0.2s;
}
.tab svg { width: 24px; height: 24px; transition: transform 0.2s var(--ease); }
.tab:active svg { transform: scale(0.9); }
.tab.is-active { color: var(--ink); font-weight: 600; }
.tab.is-active svg { stroke-width: 1.9; }
body.in-studio .tabbar, body.in-studio .fab { display: none; }

/* ------------------------------------------------------------ studio */

.view-studio {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  max-width: none;
  padding: var(--safe-t) 0 0;
  background: var(--studio-bg);
  animation: none;
}
.studio-bar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px auto;
  align-items: center;
  gap: 4px;
  padding: 6px 12px 2px 6px;
}
.studio-name { display: grid; justify-items: center; min-width: 0; padding: 4px 6px; border-radius: 12px; }
.studio-name:active { background: var(--surface-2); }
.studio-name-text {
  max-width: 100%;
  font: 500 23px/1.1 var(--serif);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.studio-status { font-size: 10px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.studio-status.is-saved { color: var(--accent); }
#studio-save { min-width: 76px; }

.studio-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 2px 8px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.studio-tools::-webkit-scrollbar { display: none; }
.tool {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 48px;
  padding: 4px 2px;
  border-radius: 12px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 500;
  transition: opacity 0.2s, background-color 0.15s;
}
.tool svg { width: 21px; height: 21px; }
.tool:active:not(:disabled) { background: var(--surface-2); }
.tool:disabled { opacity: 0.28; }
.tool-sep { flex: none; width: 1px; height: 26px; margin: 0 6px; background: var(--line-strong); }

.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.stage {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: var(--surface-2);
  box-shadow: var(--shadow-md);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  --unit: 3px;
}
.stage.is-blank { background: linear-gradient(#f3eee7, #e6ded3); }
.stage-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}
.stage-layers { position: absolute; inset: 0; }
.layer, .selection {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 50% 50%;
  pointer-events: none;
}
.layer { will-change: transform; }
.layer img {
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  filter: drop-shadow(0 calc(var(--unit) * 0.8) calc(var(--unit) * 1.2) rgba(0, 0, 0, 0.18));
}
.layer.is-pulse { animation: pulse 0.5s var(--ease); }
@keyframes pulse { 50% { opacity: 0.45; } }
.selection {
  border-radius: 3px;
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.95), 0 0 0 3px rgba(0, 0, 0, 0.22);
}
.stage.is-gesturing .selection { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7); }
.sel-handle {
  position: absolute;
  right: -17px;
  bottom: -17px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #fffdfa;
  color: #171615;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  touch-action: none;
  cursor: nwse-resize;
}
.sel-handle::before { content: ""; position: absolute; inset: -10px; border-radius: 999px; }
.sel-handle * { pointer-events: none; }
.sel-handle svg { width: 17px; height: 17px; }
.stage.is-gesturing .sel-handle { opacity: 0.5; }
.stage-hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(20, 18, 16, 0.58);
  color: #fbf8f3;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.stage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px 32px;
  text-align: center;
  background: color-mix(in srgb, var(--studio-bg) 88%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.stage-empty .empty-text { max-width: 300px; margin-bottom: 14px; }
.stage-empty .btn-primary { min-width: 220px; }

.tray {
  flex: none;
  padding: 6px 0 calc(var(--safe-b) + 10px);
  border-radius: 24px 24px 0 0;
  background: var(--bg-elev);
  box-shadow: 0 -8px 30px rgba(30, 22, 12, 0.08);
}
.chips-tray { padding: 8px 14px 6px; gap: 6px; }
.tray-list {
  display: flex;
  gap: 10px;
  min-height: 96px;
  padding: 4px 14px 2px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tray-list::-webkit-scrollbar { display: none; }
.tray-item {
  position: relative;
  flex: none;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  width: 78px;
  height: 90px;
  padding: 9px;
  border-radius: 16px;
  background: var(--media);
  scroll-snap-align: start;
  transition: transform 0.15s var(--ease), box-shadow 0.2s;
}
.tray-item:active { transform: scale(0.94); }
.tray-item img { -webkit-user-drag: none; pointer-events: none; }
.tray-item[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--ink); }
.tray-check {
  position: absolute;
  top: 5px;
  right: 5px;
  display: none;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--on-ink);
}
.tray-check svg { width: 13px; height: 13px; stroke-width: 2.4; }
.tray-item[aria-pressed="true"] .tray-check { display: grid; }
.tray-empty { display: flex; align-items: center; gap: 14px; padding: 18px 4px; color: var(--muted); font-size: 14px; }

@media (min-width: 900px) {
  .tray { max-width: 900px; width: 100%; margin: 0 auto; }
}

/* ------------------------------------------------------------ sheets & dialogs */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay-dialog { align-items: center; padding: 24px; }
.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 0.28s;
}
.overlay.is-open .overlay-backdrop { opacity: 1; }

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - var(--safe-t) - 28px);
  max-height: calc(100dvh - var(--safe-t) - 28px);
  padding-bottom: var(--safe-b);
  border-radius: 28px 28px 0 0;
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg);
  transform: translateY(105%);
  transition: transform 0.36s var(--ease);
  outline: none;
}
.overlay.is-open .sheet { transform: none; }
.sheet.is-dragging { transition: none; }
@media (min-width: 600px) {
  .overlay-sheet { align-items: center; padding: 24px; }
  .sheet { border-radius: 28px; padding-bottom: 0; transform: translateY(24px); opacity: 0; transition: transform 0.3s var(--ease), opacity 0.25s; }
  .overlay.is-open .sheet { opacity: 1; }
}
.sheet-grab { flex: none; width: 40px; height: 5px; margin: 9px auto 0; border-radius: 3px; background: var(--line-strong); touch-action: none; }
.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 2px 22px;
  touch-action: none;
}
.sheet-title { font: 500 27px/1.1 var(--serif); }
.sheet-close { color: var(--muted); }
.sheet-close svg { width: 20px; height: 20px; }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 22px 18px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sheet-foot {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 12px 22px 14px;
  border-top: 1px solid var(--line);
}
.sheet-foot .btn { flex: 1; }

.dialog {
  position: relative;
  width: min(100%, 340px);
  padding: 22px 20px 14px;
  border-radius: 24px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.25s var(--ease), opacity 0.2s;
  outline: none;
}
.overlay.is-open .dialog { transform: none; opacity: 1; }
.dialog .sheet-head { padding: 0; }
.dialog .sheet-title { font-size: 25px; }
.dialog .sheet-body { padding: 8px 0 18px; overflow: visible; }
.dialog .sheet-foot { padding: 0; border: 0; gap: 8px; }
.dialog .sheet-foot .btn { min-height: 46px; padding: 0 12px; }
.dialog-text { color: var(--ink-2); font-size: 14.5px; }
.dialog-form .field-input { width: 100%; }

.action-sheet .sheet-body { padding-top: 2px; }
.action-list { display: grid; }
.action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 0 4px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
  text-align: left;
}
.action-row:last-child { border-bottom: 0; }
.action-row:active { background: var(--surface-2); }
.action-row .icon { color: var(--ink-2); }
.action-row.is-danger, .action-row.is-danger .icon { color: var(--danger); }

/* ------------------------------------------------------------ forms */

.field { display: grid; gap: 7px; margin-top: 16px; min-width: 0; }
.field-label { font-size: 11px; font-weight: 600; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.field-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.field-input:focus { outline: none; border-color: var(--ink); }
.field-input::placeholder { color: var(--muted); }
select.field-input {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%238a837a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.checker {
  background-color: var(--checker-base);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%, transparent 75%, var(--checker) 75%),
    linear-gradient(45deg, var(--checker) 25%, transparent 25%, transparent 75%, var(--checker) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}

.piece-preview-wrap {
  position: relative;
  height: min(40vh, 340px);
  border-radius: 20px;
  overflow: hidden;
  background: var(--media);
}
.piece-preview { position: absolute; inset: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); padding: 14px; }
.piece-canvas { display: block; }
.spinner {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--ink);
  opacity: 0;
  animation: spin 0.8s linear infinite;
  transition: opacity 0.2s;
}
.piece-preview-wrap.is-busy .spinner { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
.piece-note {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13px;
}
.cut-controls {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.switch-row { position: relative; display: flex; align-items: center; gap: 10px; min-height: 32px; font-size: 15px; font-weight: 500; cursor: pointer; }
.switch-row .icon { color: var(--ink-2); }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  position: relative;
  flex: none;
  width: 48px;
  height: 29px;
  margin-left: auto;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background-color 0.2s;
}
.switch::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.22s var(--ease);
}
.switch-row input:checked ~ .switch { background: var(--ink); }
.switch-row input:checked ~ .switch::after { transform: translateX(19px); }
.switch-row input:focus-visible ~ .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-row input:disabled ~ .switch { opacity: 0.4; }
.slider-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.slider { flex: 1; min-width: 0; accent-color: var(--ink); height: 28px; }

.detail-media {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  height: min(44vh, 380px);
  padding: 22px;
  border-radius: 22px;
  background:
    radial-gradient(110% 80% at 50% 20%, var(--media-hi) 0%, transparent 70%),
    var(--media);
}
.detail-img { filter: drop-shadow(0 12px 18px rgba(40, 28, 12, 0.16)); }
.detail-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.fav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}
.fav-toggle svg { width: 19px; height: 19px; }
.fav-toggle[aria-pressed="true"] { color: var(--heart); border-color: currentColor; }

.export { display: grid; gap: 10px; }
.export-img {
  width: 100%;
  max-height: 58vh;
  object-fit: contain;
  border-radius: 16px;
  background: var(--media);
}

/* ------------------------------------------------------------ toast */

.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 88px);
  z-index: 70;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}
body.in-studio .toast-root { bottom: calc(var(--safe-b) + 150px); }
.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(100%, 440px);
  padding: 12px 14px 12px 18px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 0.22s, transform 0.3s var(--ease);
  pointer-events: none;
}
/* Touches pass through a toast (it often sits over the Studio stage);
   only its action button takes them. */
.toast.is-open { opacity: 1; transform: none; }
.toast.is-open .toast-action { pointer-events: auto; }
.toast.is-error { background: var(--danger); color: #fff; }
.toast-action {
  flex: none;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
}

@media (prefers-color-scheme: light) {
  .toast-action { color: #e2c49c; }
}

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