:root {
  --bg: #0e0d0c; --surface: #191715; --surface2: #23201d; --line: #2e2a26;
  --cream: #fdf6ec; --text: #fdf6ec; --muted: #9d958b; --dim: #6b645c;
  --accent: #fc5603; --accent2: #fc8a03;          /* the logo's orange (and its lighter end), used rarely */
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --side: 300px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); padding-top: var(--safe-t); }
.top { display: flex; align-items: center; height: 48px; padding: 0 10px 0 16px; }
.top .mark { height: 26px; width: auto; opacity: .95; }
.spacer { flex: 1; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); border-radius: 12px; }
.icon-btn:active { background: var(--surface); }

.stage { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.frame { position: relative; line-height: 0; }
#view { display: block; background: #000; }
.welcome { display: none; text-align: center; padding: 24px; max-width: 360px; }
.welcome .wordmark { width: min(62vw, 260px); height: auto; margin-bottom: 18px; }
.welcome p { color: var(--muted); margin: 0 0 28px; }
#app.empty .welcome { display: block; }
#app.empty .frame, #app.empty .tools, #app.empty .debug { display: none; }

.busy { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: rgba(14, 13, 12, .72); color: var(--muted); z-index: 5; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--cream); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.debug { position: absolute; left: 8px; bottom: 6px; margin: 0; font: 10px/1.35 ui-monospace, "SF Mono", Menlo, monospace; color: #cfc6bb; background: rgba(0, 0, 0, .55); padding: 5px 7px; border-radius: 6px; pointer-events: none; white-space: pre; max-width: calc(100% - 16px); overflow: hidden; z-index: 4; }
.debug:empty, #app.nodebug .debug { display: none; }

/* tools: phone layout (one slider at a time, chips below) */
.tools { min-width: 0; background: var(--bg); padding: 4px 0 calc(8px + var(--safe-b)); border-top: 1px solid var(--surface); }
.sliders { padding: 6px 18px 2px; min-height: 58px; }
.slider { display: none; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; }
.slider.on { display: grid; }
.slider label { color: var(--muted); font-size: 13px; }
.slider .val { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); min-width: 34px; text-align: right; padding: 4px 0 4px 8px; }
.slider input { grid-column: 1 / -1; width: 100%; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 32px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: linear-gradient(to right, var(--line) 0, var(--line) var(--lo, 50%), var(--cream) var(--lo, 50%), var(--cream) var(--hi, 50%), var(--line) var(--hi, 50%)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9.5px; border-radius: 50%; background: var(--cream); box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
input[type=range]::-moz-range-track { height: 3px; background: var(--line); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--cream); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 8px 14px; border-radius: 18px; background: var(--surface); color: var(--muted); font-size: 14px; position: relative; }
.chip.on { background: var(--surface2); color: var(--text); }
.chip.changed::after { content: ""; position: absolute; top: 6px; right: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cropbar { display: flex; gap: 6px; padding: 8px 12px; }
.cropbar button { flex: 1; padding: 11px 0; border-radius: 12px; background: var(--surface); }
.cropbar .done { background: var(--surface2); font-weight: 600; }
.bar { display: flex; align-items: center; gap: 8px; padding: 4px 12px 0; }
.side-only { display: none; }

.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-weight: 600; padding: 11px 22px; border-radius: 14px; }
.primary:active { filter: brightness(.92); }
.primary.big { padding: 14px 34px; font-size: 17px; border-radius: 16px; }
.primary:disabled { opacity: .5; }
.ghost { background: var(--surface); padding: 11px 18px; border-radius: 14px; }
.ghost:active, .cropbar button:active, .chip:active { background: var(--surface2); }
.link { color: var(--muted); padding: 12px; }
.wide { display: block; width: 100%; margin-top: 10px; }

/* crop overlay */
.crop { position: absolute; inset: 0; touch-action: none; }
.crop .box { position: absolute; border: 1.5px solid var(--cream); box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55); touch-action: none; cursor: move; }
.crop .box::before, .crop .box::after { content: ""; position: absolute; inset: 33.33% 0; border-top: 1px solid rgba(253, 246, 236, .3); border-bottom: 1px solid rgba(253, 246, 236, .3); pointer-events: none; }
.crop .box::after { inset: 0 33.33%; border: 0; border-left: 1px solid rgba(253, 246, 236, .3); border-right: 1px solid rgba(253, 246, 236, .3); }
.crop i { position: absolute; width: 34px; height: 34px; }
.crop i::before { content: ""; position: absolute; width: 16px; height: 16px; border: 3.5px solid var(--cream); }
.crop i[data-h=nw] { left: -17px; top: -17px; cursor: nwse-resize; } .crop i[data-h=nw]::before { left: 14px; top: 14px; border-right: 0; border-bottom: 0; }
.crop i[data-h=ne] { right: -17px; top: -17px; cursor: nesw-resize; } .crop i[data-h=ne]::before { right: 14px; top: 14px; border-left: 0; border-bottom: 0; }
.crop i[data-h=sw] { left: -17px; bottom: -17px; cursor: nesw-resize; } .crop i[data-h=sw]::before { left: 14px; bottom: 14px; border-right: 0; border-top: 0; }
.crop i[data-h=se] { right: -17px; bottom: -17px; cursor: nwse-resize; } .crop i[data-h=se]::before { right: 14px; bottom: 14px; border-left: 0; border-top: 0; }

/* sheets */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: 100%; max-width: 440px; background: var(--surface); border-radius: 20px 20px 0 0; padding: 22px 18px calc(14px + var(--safe-b)); }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet .meta { color: var(--muted); font-size: 13px; margin: 4px 0 6px; white-space: pre-line; }
.sheet .wordmark.small { height: 34px; width: auto; display: block; margin: 0 auto 6px; }
.sheet .version { text-align: center; color: var(--muted); margin: 0 0 14px; font-size: 13px; }
.sheet .row { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px; color: var(--text); }
.sheet .row input { width: 20px; height: 20px; accent-color: var(--accent); }
.sheet textarea { width: 100%; height: 140px; margin-top: 10px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); border-radius: 10px; font: 10px/1.3 ui-monospace, Menlo, monospace; -webkit-user-select: text; user-select: text; }
.toast { position: fixed; left: 50%; bottom: calc(120px + var(--safe-b)); transform: translateX(-50%); background: var(--surface2); color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; }

/* computer / wide: photo left, tool column right */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  #app { grid-template-columns: minmax(0, 1fr) var(--side); grid-template-rows: auto minmax(0, 1fr); }
  .top { grid-column: 1 / -1; }
  .stage { grid-row: 2; grid-column: 1; }
  .tools { grid-row: 2; grid-column: 2; border-top: 0; border-left: 1px solid var(--surface); display: flex; flex-direction: column; padding: 12px 0 calc(12px + var(--safe-b)); overflow-y: auto; }
  #app.empty { grid-template-columns: minmax(0, 1fr); }
  .sliders { padding: 4px 20px; }
  .slider, .slider.on { display: grid; margin-bottom: 10px; }
  .chips { display: none; }
  .side-only { display: inline-block; }
  .cropbar { flex-wrap: wrap; padding: 8px 20px; }
  .cropbar button { flex: 1 1 40%; }
  .bar { margin-top: auto; padding: 12px 20px 0; flex-wrap: wrap; }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; }
}
/* phone held sideways: tool column on the right too, narrower */
@media (max-width: 899px) and (min-aspect-ratio: 4/3) {
  #app { grid-template-columns: minmax(0, 1fr) 250px; grid-template-rows: auto minmax(0, 1fr); }
  .top { grid-column: 1 / -1; height: 40px; }
  .stage { grid-row: 2; grid-column: 1; }
  .tools { grid-row: 2; grid-column: 2; border-top: 0; border-left: 1px solid var(--surface); display: flex; flex-direction: column; overflow-y: auto; padding-bottom: calc(6px + var(--safe-b)); }
  #app.empty { grid-template-columns: minmax(0, 1fr); }
  .slider, .slider.on { display: grid; }
  .sliders { padding: 0 14px; }
  .chips { display: none; }
  .side-only { display: inline-block; }
  .cropbar { flex-wrap: wrap; }
  .cropbar button { flex: 1 1 40%; }
  .bar { margin-top: auto; padding: 4px 10px 0; gap: 6px; flex-wrap: wrap; }
  .bar .ghost, .bar .primary { padding: 10px 14px; }
}
