:root {
  --bg: #08080B;
  --bg-2: #0E0E13;
  --surface: #13131A;
  --surface-2: #1A1A23;
  --surface-3: #22222D;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #EDEDF3;
  --text-2: #A3A3B2;
  --text-3: #6B6B7B;
  --accent: #8B87FF;
  --accent-2: #6C67F5;
  --accent-ink: #0B0A1F;
  --warn: #FFB35C;
  --radius: 12px;
  --radius-sm: 9px;
  --panel-w: 340px;
  --top-h: 60px;
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ───────── App grid ───────── */
#app {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  width: 100%; overflow: hidden;
  grid-template-rows: calc(var(--top-h) + var(--sat)) 1fr;
  grid-template-areas: "top top" "stage panel";
}

.topbar {
  grid-area: top; min-width: 0;
  display: flex; align-items: center; gap: 16px;
  padding: var(--sat) calc(16px + var(--sar)) 0 calc(16px + var(--sal));
  border-bottom: 1px solid var(--line);
  background: rgba(8, 8, 11, 0.8);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; flex: none; }
.brand-mark { width: 26px; height: 26px; stroke: none; }
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.divider { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; }

.seedbar { display: flex; align-items: center; gap: 6px; }
.seedbar--top { position: absolute; left: 50%; transform: translateX(-50%); bottom: 10px; top: calc(var(--sat) + 10px); }
.seedbar--mobile { display: none; }
.seed-field {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  cursor: text;
}
.seed-field span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.seed-field input {
  width: 7ch; border: 0; background: none; outline: none;
  font-family: var(--mono); font-size: 15px; font-weight: 500; letter-spacing: 0.02em; text-align: center;
}

/* ───────── Buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
  user-select: none; -webkit-user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: rgba(255,255,255,.18); }
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--text); color: #0A0A0E; border-color: transparent; }
.btn--primary:hover { background: #fff; }
.btn--accent {
  background: linear-gradient(180deg, #9A96FF, var(--accent-2));
  color: #fff; border-color: rgba(255,255,255,.14);
  box-shadow: 0 6px 20px -8px rgba(124, 118, 255, .7), inset 0 1px 0 rgba(255,255,255,.25);
}
.btn--accent:hover { background: linear-gradient(180deg, #A7A3FF, #7671FA); }
.btn--ghost { background: transparent; border-style: dashed; color: var(--text-2); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.is-on { color: var(--accent); }
.icon-btn--glass { background: rgba(20,20,28,.72); border-color: var(--line-2); color: var(--text); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.chip {
  display: inline-flex; align-items: center; height: 28px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface);
  font-size: 12px; color: var(--text-2);
}
.chip--warn { color: var(--warn); border-color: rgba(255,179,92,.3); background: rgba(255,179,92,.08); }
.chip--accent { color: var(--accent-ink); background: var(--accent); border-color: transparent; font-weight: 600; }

/* ───────── Stage ───────── */
.stage {
  grid-area: stage; position: relative; min-width: 0; min-height: 0;
  display: grid; place-items: center;
  padding: 40px 40px 64px;
  background:
    radial-gradient(1200px 600px at 50% 0%, rgba(124,118,255,.06), transparent 60%),
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.05) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  overflow: hidden;
}
.artboard {
  position: relative;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 30px 80px -20px rgba(0,0,0,.8), 0 10px 30px -10px rgba(0,0,0,.6);
  touch-action: none;
}
#view { display: block; width: 100%; height: 100%; border-radius: 6px; }
.handles { position: absolute; inset: 0; }
.handles.is-hidden { display: none; }
.handle {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  display: grid; place-items: center; touch-action: none; cursor: grab;
}
.handle::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  background: var(--c, #fff);
  box-shadow: 0 0 0 2px rgba(255,255,255,.95), 0 2px 10px rgba(0,0,0,.5);
  transition: transform .15s;
}
.handle:hover::before, .handle.is-drag::before { transform: scale(1.25); }
.handle.is-drag { cursor: grabbing; }
.stage-meta {
  position: absolute; left: 0; right: 0; bottom: 18px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--mono); font-size: 12px; color: var(--text-3);
}
.stage-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }
.stage-tools { position: absolute; right: 14px; bottom: 10px; display: flex; gap: 6px; }

/* ───────── Panel ───────── */
.panel {
  grid-area: panel; min-height: 0; min-width: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--bg-2);
}
.tabs { display: none; }
.panel-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 18px calc(28px + var(--sab)); scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
.sec { padding: 18px 0 22px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec-title { margin: 0 0 14px; font-size: 11px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); }
.sec-sub { margin: 18px 0 10px; font-size: 12px; color: var(--text-3); }
.sec-note { margin: 0 0 14px; font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.stack { display: grid; gap: 8px; }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.field-label { font-size: 12.5px; color: var(--text-2); margin: 14px 0 8px; }
.field-row .field-label { margin: 0; }

/* Slider (value bar) */
.sliders { display: grid; gap: 6px; }
.slider {
  position: relative; height: 40px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  overflow: hidden; touch-action: pan-y; cursor: ew-resize;
  user-select: none; -webkit-user-select: none;
}
.slider-fill {
  position: absolute; inset: 0 auto 0 0;
  background: linear-gradient(90deg, rgba(139,135,255,.18), rgba(139,135,255,.32));
  border-right: 1.5px solid rgba(180,177,255,.9);
  pointer-events: none;
}
.slider.is-center .slider-fill { border-left: 1.5px solid rgba(180,177,255,.9); }
.slider-label, .slider-value {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center;
  font-size: 13px; pointer-events: none;
}
.slider-label { left: 12px; color: var(--text); }
.slider-value { right: 12px; font-family: var(--mono); font-size: 12.5px; color: var(--text-2); pointer-events: auto; cursor: text; padding-left: 8px; }
.slider.is-active { border-color: rgba(139,135,255,.5); }
.slider.is-active .slider-value { color: var(--text); }
.slider-input {
  position: absolute; right: 6px; top: 6px; bottom: 6px; width: 76px;
  background: var(--surface-3); border: 1px solid var(--accent); border-radius: 6px;
  font-family: var(--mono); font-size: 16px; text-align: right; padding: 0 8px; outline: none;
}

/* Segmented */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.seg button {
  flex: 1; height: 34px; border-radius: 8px; border: 0; background: transparent;
  color: var(--text-2); font-size: 13px; font-weight: 500; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.is-on { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
#grainModes { margin-bottom: 10px; }
.seg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.seg-grid button {
  height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
  color: var(--text-2); font-size: 12.5px; font-weight: 500; transition: all .15s;
}
.seg-grid button:hover { color: var(--text); border-color: var(--line-2); }
.seg-grid button.is-on { color: var(--text); border-color: rgba(139,135,255,.6); background: rgba(139,135,255,.12); }

/* Presets */
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.preset {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line-2); background: var(--surface);
  transition: transform .15s, box-shadow .15s;
}
.preset canvas { width: 100%; height: 100%; display: block; }
.preset:hover { transform: translateY(-1px); box-shadow: 0 0 0 1.5px rgba(255,255,255,.5); }
.preset span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 5px;
  font-size: 10.5px; font-weight: 500; text-align: left; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.55));
}

/* Colors */
.color-field {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 6px 0 5px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  min-width: 0;
}
.swatch {
  position: relative; width: 30px; height: 30px; border-radius: 7px; flex: none; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
}
.swatch input { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); opacity: 0; cursor: pointer; border: 0; padding: 0; }
.hex-input {
  width: 8ch; min-width: 0; flex: 1; border: 0; background: none; outline: none;
  font-family: var(--mono); font-size: 13px; text-transform: uppercase; letter-spacing: .02em;
}
.palette-list { display: grid; gap: 6px; margin: 4px 0 10px; }
.pal-item { display: grid; grid-template-columns: 1fr 104px 40px; gap: 6px; align-items: center; }
.pal-item .slider { height: 40px; }
.pal-item .slider-label { display: none; }
.pal-item .slider-value { right: 10px; }
.pal-item .icon-btn { color: var(--text-3); }
.pal-item .icon-btn:hover { color: #ff8b8b; }
.duo { display: flex; gap: 6px; }
.duo .color-field { width: 116px; }
.grain-duo { margin-top: 10px; }

/* Size */
.ratio-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.ratio-grid button {
  height: 54px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; gap: 4px; padding: 6px 0 4px;
  font-size: 11px; color: var(--text-2);
}
.ratio-grid button i { display: block; border: 1.5px solid currentColor; border-radius: 2px; }
.ratio-grid button.is-on { color: var(--text); border-color: rgba(139,135,255,.6); background: rgba(139,135,255,.12); }
.wh { display: grid; grid-template-columns: 1fr 40px 1fr; gap: 6px; align-items: center; }
.num-field {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line);
}
.num-field span { color: var(--text-3); font-size: 12px; }
.num-field input { width: 100%; border: 0; background: none; outline: none; font-family: var(--mono); font-size: 14px; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ───────── Infinite canvas ───────── */
.infinite { position: fixed; inset: 0; z-index: 40; background: #050507; animation: fadeIn .2s ease; }
.inf-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; outline: none;
  background: radial-gradient(circle at 1px 1px, rgba(255,255,255,.045) 1px, transparent 0) 0 0 / 24px 24px; }
.inf-viewport.is-panning { cursor: grabbing; }
.inf-world { position: absolute; left: 0; top: 0; will-change: transform; }
.tile {
  position: absolute; border-radius: 8px; overflow: hidden;
  background: #111117; box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 12px 30px -14px rgba(0,0,0,.8);
  transition: box-shadow .15s;
}
.tile canvas { display: block; width: 100%; height: 100%; opacity: 0; transition: opacity .25s; }
.tile.is-ready canvas { opacity: 1; }
.tile-label {
  position: absolute; left: 8px; bottom: 7px; padding: 2px 7px; border-radius: 6px;
  font-family: var(--mono); font-size: 10.5px; color: rgba(255,255,255,.92);
  background: rgba(0,0,0,.32); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}
.tile-heart { position: absolute; right: 8px; top: 8px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); pointer-events: none; }
.tile-heart svg { width: 13px; height: 13px; fill: currentColor; stroke: none; }
.tile.is-origin { box-shadow: 0 0 0 2px rgba(255,255,255,.55), 0 12px 30px -14px rgba(0,0,0,.8); }
.tile.is-selected { box-shadow: 0 0 0 2.5px var(--accent), 0 0 0 7px rgba(139,135,255,.22), 0 12px 30px -14px rgba(0,0,0,.8); }

.inf-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + var(--sat)) calc(14px + var(--sar)) 24px calc(14px + var(--sal));
  background: linear-gradient(rgba(5,5,7,.9), rgba(5,5,7,0));
  pointer-events: none;
}
.inf-top > * { pointer-events: auto; }
.inf-title { display: grid; line-height: 1.25; min-width: 0; }
.inf-title strong { font-size: 14px; font-weight: 600; }
.inf-title span { font-size: 12px; color: var(--text-2); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inf-actions { margin-left: auto; display: flex; gap: 6px; }
.inf-hint {
  position: absolute; left: 50%; bottom: calc(22px + var(--sab)); transform: translateX(-50%);
  padding: 9px 14px; border-radius: 999px; font-size: 12.5px; color: var(--text-2);
  background: rgba(20,20,28,.78); border: 1px solid var(--line-2);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  white-space: nowrap; pointer-events: none; transition: opacity .4s;
}
.inf-sheet {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + var(--sab));
  width: min(560px, calc(100% - 24px - var(--sal) - var(--sar)));
  padding: 10px; border-radius: 16px;
  background: rgba(20,20,28,.86); border: 1px solid var(--line-2);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,.9);
  animation: slideUp .2s ease;
}
.inf-sheet-row { display: flex; align-items: center; gap: 8px; }
.inf-sel-info { display: grid; margin-right: auto; padding-left: 6px; min-width: 0; }
.inf-sel-info strong { font-family: var(--mono); font-size: 15px; font-weight: 500; }
.inf-sel-info span { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
#tileCollectBtn.is-on { color: var(--accent); border-color: rgba(139,135,255,.5); }
#tileCollectBtn.is-on svg { fill: currentColor; }
.inf-collection {
  position: absolute; right: calc(14px + var(--sar)); top: calc(70px + var(--sat));
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border-radius: 999px;
  background: rgba(20,20,28,.86); border: 1px solid var(--line-2); font-size: 12.5px; color: var(--text-2);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}

/* ───────── Modal ───────── */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fadeIn .15s ease; }
.modal-card {
  position: relative; width: min(420px, 100%); max-height: calc(100dvh - 40px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 18px;
  box-shadow: 0 40px 100px -20px rgba(0,0,0,.9);
  animation: pop .18s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px 20px; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.modal-body { padding: 0 20px 6px; }
.modal-body .seg { background: var(--bg-2); }
.modal-foot { display: flex; gap: 8px; padding: 16px 20px calc(20px); justify-content: flex-end; }
.modal-foot .btn--primary { min-width: 130px; }
.ex-summary { margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); font-family: var(--mono); font-size: 12px; color: var(--text-2); line-height: 1.6; }
.progress { margin-top: 14px; display: grid; gap: 8px; }
.progress > div { height: 6px; border-radius: 99px; background: var(--bg-2); overflow: hidden; position: relative; }
.progress-bar::after { content: ""; position: absolute; inset: 0; width: var(--p, 0%); background: linear-gradient(90deg, var(--accent-2), #B9B6FF); border-radius: 99px; transition: width .15s; }
.progress span { font-family: var(--mono); font-size: 12px; color: var(--text-2); }

/* ───────── Toast ───────── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--sab)); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; font-size: 13px;
  background: var(--text); color: #0A0A0E; font-weight: 500;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.8);
  transition: opacity .2s, transform .2s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
@keyframes slideUp { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ───────── Responsive ───────── */
@media (max-width: 1180px) {
  .seedbar--top .btn span { display: none; }
  .seedbar--top .btn { width: 40px; padding: 0; }
}
@media (max-width: 1020px) and (min-width: 861px) {
  :root { --panel-w: 310px; }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 40px; padding: 0; }
}

@media (max-width: 860px), (pointer: coarse) and (max-height: 500px) {
  :root { --top-h: 54px; }
  body { font-size: 15px; }
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: calc(var(--top-h) + var(--sat)) minmax(0, 1fr) auto auto;
    grid-template-areas: "top" "stage" "seed" "panel";
  }
  .topbar { gap: 8px; padding-left: calc(12px + var(--sal)); padding-right: calc(10px + var(--sar)); }
  .hide-mobile { display: none !important; }
  .seedbar--top { display: none; }
  .seedbar--mobile {
    grid-area: seed; display: flex; gap: 8px;
    padding: 10px calc(12px + var(--sar)) 10px calc(12px + var(--sal));
    border-top: 1px solid var(--line);
    background: var(--bg-2);
  }
  .seedbar--mobile .seed-field { flex: 1; justify-content: center; height: 44px; }
  .seedbar--mobile .seed-field input { font-size: 17px; width: 7ch; }
  .seedbar--mobile .icon-btn { width: 44px; height: 44px; background: var(--surface); border-color: var(--line-2); color: var(--text); }
  .seedbar--mobile .btn { height: 44px; }
  .btn { height: 40px; }
  .stage { padding: 10px calc(10px + var(--sar)) 28px calc(10px + var(--sal)); }
  .stage-meta { bottom: 9px; font-size: 11px; }
  .stage-tools { right: 6px; bottom: 0; }
  .stage-tools .icon-btn { width: 36px; height: 36px; }
  .handle { width: 48px; height: 48px; margin: -24px 0 0 -24px; }

  .panel {
    grid-area: panel; border-left: 0; border-top: 1px solid var(--line);
    height: clamp(190px, 36dvh, 380px);
  }
  .tabs {
    display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
    padding: 8px calc(10px + var(--sar)) 8px calc(10px + var(--sal));
    border-bottom: 1px solid var(--line); flex: none;
    scroll-snap-type: x proximity;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button {
    flex: none; height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid transparent;
    background: transparent; color: var(--text-2); font-size: 14px; font-weight: 500;
    scroll-snap-align: start;
  }
  .tabs button.is-on { background: var(--surface-2); color: var(--text); border-color: var(--line-2); }
  .panel-scroll { padding: 4px calc(14px + var(--sar)) calc(18px + var(--sab)) calc(14px + var(--sal)); }
  .sec { display: none; border: 0; padding-top: 12px; }
  .sec.is-active { display: block; }
  .sec-title { display: none; }
  .slider { height: 46px; }
  .slider-label { font-size: 14.5px; }
  .slider-value { font-size: 13.5px; }
  .seg button { height: 38px; font-size: 14px; }
  .seg-grid button { height: 42px; font-size: 13.5px; }
  .color-field, .num-field { height: 46px; }
  .hex-input, .num-field input { font-size: 16px; }
  .pal-item { grid-template-columns: 1fr 96px 44px; }
  .pal-item .slider { height: 46px; }
  .presets { grid-template-columns: repeat(4, 1fr); }
  .duo .color-field { width: 124px; }
  .btn--block { height: 46px; }

  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; border-radius: 20px 20px 0 0; max-height: 92dvh; animation: sheetUp .22s ease; border-bottom: 0; }
  .modal-foot { padding-bottom: calc(16px + var(--sab)); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; height: 48px; }
  .inf-title strong { font-size: 13.5px; }
  .inf-title span { font-size: 11px; }
  .inf-hint { font-size: 12px; width: max-content; max-width: calc(100% - 32px); white-space: normal; text-align: center; }
  .inf-sheet .btn { height: 44px; }
  .inf-collection { top: calc(64px + var(--sat)); }
}
@media (max-width: 400px) {
  .seedbar--mobile .btn span { display: none; }
  .seedbar--mobile .btn { width: 44px; padding: 0; }
  .hide-xs { display: none; }
  .topbar-actions .btn { padding: 0 11px; }
}
@media (max-width: 360px) {
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { width: 40px; padding: 0; }
}
/* Landscape phones: side-by-side layout */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 1000px), (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  :root { --top-h: 50px; }
  #app {
    grid-template-columns: 1fr minmax(280px, 42vw);
    grid-template-rows: calc(var(--top-h) + var(--sat)) minmax(0, 1fr) auto;
    grid-template-areas: "top top" "stage panel" "seed panel";
  }
  .panel { height: auto; border-top: 0; border-left: 1px solid var(--line); }
  .seedbar--mobile { padding-bottom: calc(10px + var(--sab)); }
}
@keyframes sheetUp { from { transform: translateY(30px); opacity: 0; } }

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

/* ───────── Touch / iOS hardening ───────── */
html { overscroll-behavior: none; }
button, .tabs, .seedbar, .topbar, .stage-tools, .inf-top, .inf-sheet, .modal-card { touch-action: manipulation; }
button, .preset, .tile, .tabs button, .seg button, .ratio-grid button, .slider, .handle {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
@media (pointer: coarse) {
  input, select, textarea, .hex-input, .num-field input, .seed-field input, .slider-input { font-size: 16px !important; }
}
@media (hover: none) {
  .btn:hover { background: var(--surface); border-color: var(--line-2); }
  .btn--primary:hover { background: var(--text); }
  .btn--accent:hover { background: linear-gradient(180deg, #9A96FF, var(--accent-2)); }
  .btn--ghost:hover { background: transparent; }
  .icon-btn:hover { background: transparent; color: var(--text-2); }
  .icon-btn--glass:hover { background: rgba(20,20,28,.72); color: var(--text); }
  .preset:hover { transform: none; box-shadow: none; }
  .handle:hover::before { transform: none; }
  .seg button:hover, .seg-grid button:hover { color: var(--text-2); }
  .seg button.is-on:hover, .seg-grid button.is-on:hover { color: var(--text); }
}

.edited-chip { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; height: 32px; }
.handle.is-out::before { background: transparent; box-shadow: 0 0 0 2px rgba(255,255,255,.75), 0 0 0 4px var(--c, #fff); }
.seed-hint { display: none; }
.icon-btn--sm { width: 32px; height: 32px; }
.inf-collection .chip { height: 32px; padding: 0 12px; }
.duo .color-field { flex: 1; min-width: 0; }
.pack-link {
  display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 12px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid rgba(139,135,255,.35); background: rgba(139,135,255,.08);
  text-align: left; color: var(--text);
}
.pack-link span { display: grid; flex: 1; min-width: 0; }
.pack-link strong { font-size: 13.5px; font-weight: 600; }
.pack-link small { font-size: 12px; color: var(--text-2); }
.pack-link svg:first-child { color: var(--accent); }
.pack-link svg:last-child { color: var(--text-3); }
@media (hover: hover) { .pack-link:hover { background: rgba(139,135,255,.14); } }

@media (max-width: 860px), (pointer: coarse) and (max-height: 500px) {
  #app { grid-template-rows: calc(var(--top-h) + var(--sat)) minmax(0, 1fr) auto auto auto; grid-template-areas: "top" "stage" "seed" "hint" "panel"; }
  .seed-hint {
    grid-area: hint; display: block; margin: 0; padding: 0 calc(14px + var(--sar)) 8px calc(14px + var(--sal));
    background: var(--bg-2); font-size: 11.5px; color: var(--text-3); text-align: center;
  }
  .seedbar--mobile { padding-bottom: 6px; border-top: 1px solid var(--line); }
  .topbar .icon-btn, .topbar .btn { height: 44px; }
  .topbar .icon-btn { width: 44px; }
  .stage-tools { right: calc(4px + var(--sar)); bottom: -4px; }
  .stage-tools .icon-btn { width: 44px; height: 44px; }
  .stage-meta { bottom: 8px; }
  .tabs {
    -webkit-mask-image: linear-gradient(90deg, #000 82%, transparent);
    mask-image: linear-gradient(90deg, #000 82%, transparent);
    padding-right: 40px;
  }
  .tabs button { height: 40px; }
  .panel.is-collapsed { height: auto; }
  .panel.is-collapsed .panel-scroll { display: none; }
  .panel.is-collapsed .tabs { padding-bottom: calc(8px + var(--sab)); border-bottom: 0; }
  .panel.is-collapsed .tabs button.is-on { background: transparent; border-color: transparent; color: var(--text-2); }
  .seg button { height: 42px; }
  .icon-btn--glass { width: 44px; height: 44px; }
  .inf-top .btn { height: 44px; }
  .icon-btn--sm { width: 36px; height: 36px; }
  .inf-collection .chip { height: 36px; }
  .modal-foot .btn--primary { min-width: 0; }
  .toast { top: calc(64px + var(--sat)); bottom: auto; transform: translate(-50%, -14px); }
  .toast.is-on { transform: translate(-50%, 0); }
  .inf-top { background: linear-gradient(rgba(5,5,7,.96) 55%, rgba(5,5,7,0)); padding-bottom: 30px; }
}
@media (max-width: 400px) {
  .brand-name { display: none; }
}
@media (max-height: 500px) and (orientation: landscape) and (max-width: 1000px), (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  #app { grid-template-rows: calc(var(--top-h) + var(--sat)) minmax(0, 1fr) auto auto; grid-template-areas: "top top" "stage panel" "seed panel" "hint panel"; }
  .seed-hint { padding-bottom: calc(6px + var(--sab)); }
  .modal { place-items: center; padding: 12px; }
  .modal-card { width: min(460px, 100%); border-radius: 18px; max-height: calc(100dvh - 24px); border-bottom: 1px solid var(--line-2); }
  .modal-foot { padding-bottom: 16px; }
  .toast { top: auto; bottom: calc(16px + var(--sab)); }
}
