:root {
  --ground: #f4f1ea;
  --panel: #fbf9f4;
  --well: #e9e4d9;
  --well-line: #ddd6c8;
  --ink: #1a1814;
  --ink2: #45413a;
  --dim: #686358;
  --line: #ddd6c9;
  --chip: #f0ece3;
  --chip-hover: #e7e1d5;
  --accent: #c2410c;
  --accent-hover: #a83808;
  --accent-ink: #ffffff;
  --shadow: 0 1px 0 rgba(30, 20, 10, 0.04), 0 10px 30px -12px rgba(30, 20, 10, 0.25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #141311;
    --panel: #1b1a17;
    --well: #0d0c0b;
    --well-line: #1d1b18;
    --ink: #f1ede4;
    --ink2: #cbc5b8;
    --dim: #9e988c;
    --line: #2f2c27;
    --chip: #24221e;
    --chip-hover: #2e2b26;
    --accent: #ff8a4c;
    --accent-hover: #ffa06d;
    --accent-ink: #1c0e06;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 12px 32px -12px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: 96px; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
[hidden] { display: none !important; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; padding: 0; margin: -1px; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 6px; }

kbd {
  font: 500 11px/1 var(--mono);
  display: inline-block;
  min-width: 1.6em;
  padding: 3px 5px 2px;
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  border-bottom-width: 2px;
  border-radius: 5px;
  text-align: center;
  margin-left: 6px;
  vertical-align: 1px;
}
kbd + kbd { margin-left: 3px; }
@media (hover: none) { kbd { display: none; } .stage-note kbd { display: inline-block; } }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 14px;
  padding: 12px 16px 10px;
}
.mark {
  margin: 0;
  font: italic 600 30px/1 var(--serif);
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.mark-glyph { width: 24px; height: 24px; color: var(--accent); }
.tagline { margin: 0; color: var(--dim); font: italic 16px/1.3 var(--serif); }
.top-act { display: none; }
.private { margin: 0; color: var(--dim); font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.private .dot { width: 7px; height: 7px; border-radius: 50%; background: #2f9e5a; box-shadow: 0 0 0 3px color-mix(in srgb, #2f9e5a 22%, transparent); }

/* ---------- buttons ---------- */
.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--chip);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  white-space: nowrap;
  transition: background 0.15s, transform 0.15s var(--ease), border-color 0.15s;
}
.btn:hover { background: var(--chip-hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn[aria-busy="true"] { opacity: 0.7; cursor: progress; }
.link {
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}
.link:hover { color: var(--accent); }

/* ---------- stage ---------- */
.stage { display: contents; }
.stage-box {
  --rx: 14px;
  --rt: 28px;
  --rb: 12px;
  position: relative;
  height: clamp(220px, 44svh, 440px);
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background-color: var(--well);
  background-image:
    linear-gradient(var(--well-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--well-line) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.sheet { position: relative; transform: translateY(calc((var(--rt) - var(--rb)) / 2)); }
.sheet canvas { display: block; box-shadow: var(--shadow); }
.ghost {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-50% + (var(--rt) - var(--rb)) / 2));
  pointer-events: none;
  opacity: 0;
}
.ghost.on { opacity: 1; }
.ghost.out { opacity: 0; transition: opacity 0.26s var(--ease); }

.crop { position: absolute; width: 0; height: 0; color: var(--ink2); }
.crop::before, .crop::after { content: ""; position: absolute; background: currentColor; }
.crop::before { width: 9px; height: 1px; }
.crop::after { width: 1px; height: 9px; }
.crop.tl { left: 0; top: 0; } .crop.tl::before { right: 5px; top: 0; } .crop.tl::after { left: 0; bottom: 5px; }
.crop.tr { right: 0; top: 0; } .crop.tr::before { left: 5px; top: 0; } .crop.tr::after { left: -1px; bottom: 5px; }
.crop.bl { left: 0; bottom: 0; } .crop.bl::before { right: 5px; top: -1px; } .crop.bl::after { left: 0; top: 5px; }
.crop.br { right: 0; bottom: 0; } .crop.br::before { left: 5px; top: -1px; } .crop.br::after { left: -1px; top: 5px; }

.dim { position: absolute; color: var(--dim); font: 500 11px/1 var(--mono); letter-spacing: 0.02em; }
.dim-x { left: 0; right: 0; top: -17px; height: 1px; background: color-mix(in srgb, var(--dim) 55%, transparent); }
.dim-x::before, .dim-x::after { content: ""; position: absolute; top: -3px; width: 1px; height: 7px; background: currentColor; }
.dim-x::before { left: 0; } .dim-x::after { right: 0; }
.dim-x span { position: absolute; left: 50%; top: -6px; transform: translateX(-50%); background: var(--well); padding: 0 6px; }
.dim-y { display: none; top: 0; bottom: 0; left: -18px; width: 1px; background: color-mix(in srgb, var(--dim) 55%, transparent); }
.dim-y::before, .dim-y::after { content: ""; position: absolute; left: -3px; width: 7px; height: 1px; background: currentColor; }
.dim-y::before { top: 0; } .dim-y::after { bottom: 0; }
.dim-y span { position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%) rotate(-90deg); background: var(--well); padding: 0 6px; white-space: nowrap; }

.sample-chip {
  position: absolute;
  left: 10px;
  top: 10px;
  font: 600 10.5px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(20, 17, 14, 0.8);
  padding: 6px 8px 5px;
  border-radius: 6px;
}
.sample-chip[hidden] { display: none; }
@media (max-width: 899px) { .sample-chip { left: 6px; top: 6px; font-size: 8.5px; padding: 3px 5px 2px; border-radius: 4px; left: 5px; top: 5px; } }

.stage-note { margin: 10px 16px 4px; color: var(--dim); font-size: 13.5px; text-align: center; }
.stage-note kbd { margin-left: 2px; }
.stage-note kbd.mod { margin-left: 0; }
.stage-note .note-sample { color: var(--ink2); font-weight: 600; }
.stage-note .note-private { display: block; margin-top: 2px; }
.stage-note.own .note-sample { display: none; }

/* ---------- panel ---------- */
.panel { padding-bottom: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; gap: 12px; }
.panel-head h2 { margin: 0; font: italic 600 21px/1 var(--serif); }
.head-btns { display: flex; gap: 8px; }

.group { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 14px 16px 16px; min-inline-size: 0; }
.group legend {
  display: flex;
  align-items: baseline;
  width: 100%;
  padding: 0;
  margin-bottom: 10px;
  font-weight: 650;
  font-size: 14px;
  gap: 8px;
  float: left;
}
.group legend + * { clear: both; }
.group .n { font: 500 11px/1 var(--mono); color: var(--dim); }
.group .val { font-weight: 450; color: var(--dim); }
.group .keys { margin-left: auto; color: var(--dim); }

.swatches { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 7px; }
.sw { position: relative; display: block; aspect-ratio: 1; min-height: 40px; border-radius: 10px; cursor: pointer; }
.sw canvas, .sw .custom-face { width: 100%; height: 100%; display: block; border-radius: 10px; }
.sw::after { content: ""; position: absolute; inset: 0; border-radius: 10px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 16%, transparent); pointer-events: none; }
.sw input[type="radio"] { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.sw:has(input:checked) { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.sw:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 6px; }
.sw .custom-face { background: var(--custom, #e8501a); position: relative; }
.sw .custom-face::before, .sw .custom-face::after { content: ""; position: absolute; left: 50%; top: 50%; background: #fff; border-radius: 1px; transform: translate(-50%, -50%); box-shadow: 0 0 0 1px rgba(0,0,0,0.18); }
.sw .custom-face::before { width: 14px; height: 2.5px; }
.sw .custom-face::after { width: 2.5px; height: 14px; }
.sw input[type="color"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.sw.custom.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.sw.custom:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 6px; }

.seg { display: grid; gap: 6px; }
.seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opt { position: relative; display: block; cursor: pointer; }
.opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opt span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--chip);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.opt:hover span { background: var(--chip-hover); }
.opt input:checked + span { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.opt input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }
.opt input:disabled + span { opacity: 0.45; cursor: not-allowed; }
.opt svg { width: 22px; height: 18px; flex: none; }
.ratios .opt span { flex-direction: column; gap: 5px; min-height: 58px; font: 500 12.5px/1 var(--mono); }
.ratios .shape { display: block; border: 1.5px solid currentColor; border-radius: 2px; }
.ratios .shape.auto { border-style: dashed; }

.row-sub { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.row-sub .seg { width: 176px; }
.compact .opt span { min-height: 44px; font-size: 13.5px; }
.sub-label { color: var(--ink2); font-size: 13.5px; font-weight: 550; }
.row-sub[data-off] { opacity: 0.5; }

.field { display: grid; gap: 6px; margin-top: 12px; }
.field[hidden] { display: none; }
.field input {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--ground);
  padding: 0 12px;
  font: 500 14px/1 var(--mono);
}
.field input:focus-visible { outline-offset: 1px; }
.field.flash input { animation: flash 0.9s var(--ease); }
@keyframes flash { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent); } }

.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; margin-top: 2px; }
.slider output { font: 500 13px/1 var(--mono); color: var(--ink); }
.slider input { grid-column: 1 / -1; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 44px; background: transparent; margin: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--ink) var(--fill, 50%), var(--line) var(--fill, 50%)); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: var(--ink); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--ink); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--ink); }
input[type="range"]:focus-visible { outline-offset: 0; }

.readout { margin: 12px 0 6px; font: 500 13px/1.5 var(--mono); color: var(--ink); }
.readout .note { display: block; font: 13px/1.45 var(--sans); color: var(--dim); margin-top: 2px; }
.small-link { font-size: 13.5px; min-height: 44px; }

.tip { margin: 0; padding: 14px 16px 6px; border-top: 1px solid var(--line); color: var(--dim); font-size: 13.5px; }
.tip a { color: var(--ink); font-weight: 600; }

.actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.actions .btn { padding: 0 14px; }
.actions:has(#shareBtn:not([hidden])) { grid-template-columns: auto auto auto 1fr; }

.foot { padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); color: var(--dim); font-size: 12.5px; border-top: 1px solid var(--line); }
.foot a { color: var(--ink2); }

.drop {
  position: fixed;
  inset: 10px;
  z-index: 50;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--ground) 86%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.drop[hidden] { display: none; }
.drop p { margin: 0; font: italic 600 clamp(30px, 6vw, 56px)/1 var(--serif); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translate(-50%, 8px);
  max-width: min(92vw, 520px);
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--ground);
  font-weight: 550;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- wide ---------- */
@media (min-width: 900px) {
  body { overflow: hidden; }
  .app { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh; }
  .top { padding: 0 24px; min-height: 64px; border-bottom: 1px solid var(--line); flex-wrap: nowrap; gap: 18px; }
  .mark { font-size: 32px; }
  .mark-glyph { width: 26px; height: 26px; }
  .top-act { display: flex; align-items: center; gap: 16px; margin-left: auto; }
  .work { display: grid; grid-template-columns: minmax(0, 1fr) 384px; min-height: 0; }
  .stage { display: flex; flex-direction: column; min-height: 0; padding: 18px 24px 14px; }
  .stage-box { --rx: 30px; --rt: 34px; --rb: 22px; position: relative; height: auto; flex: 1; min-height: 0; border: 0; border-radius: 16px; }
  .dim-y { display: block; }
  .stage-note { margin-top: 12px; }
  .stage-note .note-private { display: none; }
  .panel { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; scroll-padding-bottom: 88px; display: flex; flex-direction: column; padding-bottom: 0; }
  .actions { position: sticky; bottom: 0; margin-top: auto; grid-template-columns: 1fr 1.5fr; padding: 12px 16px; background: var(--panel); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .actions:has(#shareBtn:not([hidden])) { grid-template-columns: 1fr 1fr 1.5fr; }
  .act-open { display: none; }
  .foot { padding: 9px 24px; }
  .toast { bottom: 28px; left: calc((100% - 384px) / 2); }
}

@media (min-width: 1280px) {
  .work { grid-template-columns: minmax(0, 1fr) 400px; }
  .toast { left: calc((100% - 400px) / 2); }
}

@media (max-width: 380px) {
  .actions { grid-template-columns: auto 1fr; }
  .actions .act-open { display: none; }
  .actions:has(#shareBtn:not([hidden])) { grid-template-columns: auto auto 1fr; }
}

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