/* ==========================================================================
   画框 - a private image workbench
   Palette: dusk. One accent. Warm near-black, vermilion.
   ========================================================================== */

:root {
  --bg: #0A0908;
  --surface: #16130F;
  --surface-2: #1E1A16;
  --line: rgba(244, 239, 230, 0.09);
  --line-strong: rgba(244, 239, 230, 0.18);
  --text: #F4EFE6;
  --muted: #9E968C;
  --muted-dim: #8A8279;
  --accent: #E85D3D;
  --accent-bright: #F47153;
  --accent-soft: rgba(232, 93, 61, 0.13);
  --accent-line: rgba(232, 93, 61, 0.38);

  --r: 16px;
  --r-sm: 10px;

  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

/* display: grid / flex on a component would otherwise beat the UA [hidden] rule */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

body.is-scrollable { overflow: auto; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

::selection { background: var(--accent); color: #0A0908; }

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

/* ---------------------------------------------------------- atmosphere --- */

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform;
  animation: drift 26s ease-in-out infinite;
}

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50%      { transform: translate3d(46px, 34px, 0) scale(1.12); }
}

.orb-a {
  width: 48vw; height: 48vw;
  top: -14vw; left: -10vw;
  background: radial-gradient(circle, rgba(232, 93, 61, 0.30), transparent 68%);
  animation-duration: 24s;
}

.orb-b {
  width: 40vw; height: 40vw;
  bottom: -16vw; right: -8vw;
  background: radial-gradient(circle, rgba(242, 166, 90, 0.16), transparent 70%);
  animation-duration: 32s;
  animation-direction: reverse;
}

.orb-c {
  width: 30vw; height: 30vw;
  top: 40%; left: 46%;
  background: radial-gradient(circle, rgba(120, 78, 110, 0.14), transparent 72%);
  animation-duration: 38s;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------------------------------------------------------- gate --- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(70% 55% at 72% 18%, rgba(232, 93, 61, 0.13), transparent 68%),
    radial-gradient(60% 50% at 22% 86%, rgba(120, 78, 110, 0.1), transparent 70%),
    var(--bg);
}

.gate-form {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
}

.gate-mark {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.32em;
  color: var(--accent);
  margin-bottom: 40px;
}

.gate-title {
  font-family: var(--serif);
  font-size: clamp(30px, 5vw, 42px);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: 0.01em;
  margin: 0 0 10px;
}

.gate-sub {
  margin: 0 0 32px;
  color: var(--muted);
  font-size: 14px;
}

.gate-input {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  padding: 12px 2px;
  font-size: 17px;
  letter-spacing: 0.16em;
  transition: border-color 0.3s var(--ease);
}

.gate-input::placeholder { color: var(--muted-dim); letter-spacing: 0; }
.gate-input:focus { outline: none; border-color: var(--accent); }

.gate-btn {
  margin-top: 22px;
  width: 100%;
  padding: 14px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #100C0A;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: background 0.25s var(--ease), transform 0.15s var(--ease);
}

.gate-btn:hover { background: var(--accent-bright); }
.gate-btn:active { transform: translateY(1px); }

.gate-err {
  min-height: 20px;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--accent-bright);
}

.gate.is-shaking { animation: shake 0.4s var(--ease); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* ----------------------------------------------------------------- app --- */

/* Entrance is CSS-driven on purpose: functional visibility must never depend on
   a JS animation finishing. GSAP only drives the ambient layer. */

@keyframes riseIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: none; }
}

@keyframes frameIn {
  from { opacity: 0; transform: scale(0.985); }
  to   { opacity: 1; transform: none; }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.32); opacity: 1; }
}

body.is-ready .topbar > * { animation: riseIn 0.6s var(--ease) both; }
body.is-ready .topbar > *:nth-child(2) { animation-delay: 0.06s; }
body.is-ready .topbar > *:nth-child(3) { animation-delay: 0.11s; }

body.is-ready .composer form > * { animation: riseIn 0.7s var(--ease) both; }
body.is-ready .composer form > *:nth-child(1) { animation-delay: 0.10s; }
body.is-ready .composer form > *:nth-child(2) { animation-delay: 0.16s; }
body.is-ready .composer form > *:nth-child(3) { animation-delay: 0.22s; }
body.is-ready .composer form > *:nth-child(4) { animation-delay: 0.28s; }
body.is-ready .composer form > *:nth-child(5) { animation-delay: 0.34s; }

body.is-ready .frame { animation: frameIn 0.9s var(--ease) both 0.14s; }
body.is-ready .stage-bar { animation: riseIn 0.6s var(--ease) both 0.4s; }

.app {
  position: relative;
  z-index: 10;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  height: 68px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 clamp(20px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.glyph { color: var(--accent); flex: 0 0 auto; }

.brand-text {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 0.2em;
  padding-left: 2px;
}

.brand-note {
  font-size: 12px;
  color: var(--muted-dim);
  letter-spacing: 0.06em;
  padding-top: 2px;
}

.topbar .ghost-btn { margin-left: auto; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 8px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
}

/* ----------------------------------------------------------- workbench --- */

.workbench {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: clamp(24px, 3.4vw, 64px);
  padding: clamp(18px, 2.6vw, 34px) clamp(20px, 3vw, 48px) clamp(18px, 2.4vw, 30px);
  min-height: 0;
}

.composer {
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.composer::-webkit-scrollbar { width: 5px; }
.composer::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.composer form {
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-height: 100%;
  padding-bottom: 8px;
}

.field { display: flex; flex-direction: column; gap: 10px; }

.label {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.label-note {
  color: var(--muted-dim);
  letter-spacing: 0.04em;
  margin-left: 6px;
}

/* textarea ---------------------------------------------------------------- */

.prompt {
  width: 100%;
  min-height: 96px;
  resize: none;
  padding: 14px 15px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  line-height: 1.72;
  color: var(--text);
  transition: border-color 0.28s var(--ease), background 0.28s var(--ease);
}

.prompt::placeholder { color: var(--muted-dim); }

.prompt:focus {
  outline: none;
  border-color: var(--accent-line);
  background: var(--surface-2);
}

.field-foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  color: var(--muted-dim);
}

.counter { font-family: var(--mono); letter-spacing: 0.04em; }
.counter.is-full { color: var(--accent); }

/* chips ------------------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 7px 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  transition: color 0.24s var(--ease), border-color 0.24s var(--ease),
              background 0.24s var(--ease), transform 0.14s var(--ease);
}

.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip:active { transform: scale(0.97); }

.chip[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

/* dropzone ---------------------------------------------------------------- */

.dropzone {
  position: relative;
  border-radius: var(--r);
  border: 1px dashed var(--line-strong);
  background: var(--surface);
  min-height: 92px;
  display: grid;
  place-items: center;
  padding: 12px;
  transition: border-color 0.26s var(--ease), background 0.26s var(--ease);
  overflow: hidden;
}

.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent-line); }

.dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-idle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.drop-idle svg { color: var(--muted-dim); }

.drop-filled {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.drop-filled img {
  width: 62px;
  height: 62px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.drop-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.drop-meta span:first-child {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.drop-tip { font-size: 11px; color: var(--muted-dim); }

.drop-clear {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.drop-clear:hover { color: var(--accent); border-color: var(--accent-line); }

.drop-loading {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 8, 0.72);
  display: grid;
  place-items: center;
  backdrop-filter: blur(2px);
}

.drop-loading span {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* segmented --------------------------------------------------------------- */

.pair { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; margin-top: auto; }

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
}

.segmented button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--muted);
  transition: color 0.24s var(--ease), background 0.24s var(--ease);
}

.segmented button:hover { color: var(--text); }

.segmented button.on {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.shape {
  display: block;
  border: 1.2px solid currentColor;
  border-radius: 2px;
  opacity: 0.85;
}

.shape.sq { width: 9px; height: 9px; }
.shape.wide { width: 12px; height: 8px; }
.shape.tall { width: 8px; height: 12px; }

/* primary ----------------------------------------------------------------- */

.primary {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 16px;
  margin-top: 0;
  margin-bottom: 0;
  border-radius: var(--r);
  background: var(--accent);
  color: #120C0A;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  overflow: hidden;
  transition: background 0.26s var(--ease), transform 0.14s var(--ease),
              opacity 0.26s var(--ease);
}

.primary:hover:not(:disabled) { background: var(--accent-bright); }
.primary:active:not(:disabled) { transform: translateY(1px) scale(0.995); }

.primary:disabled {
  background: #4A2A22;
  color: rgba(244, 239, 230, 0.66);
  cursor: not-allowed;
}

.primary-keys {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  opacity: 0.55;
}

.primary.is-busy .primary-keys { display: none; }

.primary.is-busy .primary-label::after {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-left: 10px;
  vertical-align: -1px;
  border-radius: 50%;
  border: 1.6px solid rgba(18, 12, 10, 0.35);
  border-top-color: #120C0A;
  animation: spin 0.75s linear infinite;
}

.form-err {
  min-height: 0;
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--accent-bright);
}

.form-err:not(:empty) { min-height: 20px; }

@keyframes nudgeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to   { opacity: 1; transform: none; }
}

.form-err.is-flash { animation: nudgeIn 0.35s var(--ease); }

/* --------------------------------------------------------------- stage --- */

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  min-width: 0;
}

.frame {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 20px;
  border: 1px solid var(--line);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(232, 93, 61, 0.05), transparent 62%),
    var(--surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(244, 239, 230, 0.045);
}

.frame > * {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

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

.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 32px;
}

.empty-art {
  position: relative;
  width: 116px;
  height: 116px;
  display: grid;
  place-items: center;
  margin-bottom: 26px;
}

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--accent-line);
  opacity: 0.55;
  animation: haloPulse 3.6s ease-in-out infinite;
}

.ring.delay { inset: 16px; border-color: var(--line-strong); animation-delay: 0.8s; }

@keyframes haloPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50%      { transform: scale(1.12); opacity: 0.18; }
}

.core {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, var(--accent-bright), var(--accent) 60%, #8C2E19);
  box-shadow: 0 0 30px rgba(232, 93, 61, 0.55), 0 0 70px rgba(232, 93, 61, 0.28);
  animation: breathe 2.8s ease-in-out infinite;
}

.empty-title {
  font-family: var(--serif);
  font-size: clamp(28px, 2.4vw, 36px);
  letter-spacing: 0.06em;
  margin: 0;
  color: var(--text);
}

.empty-body {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 2;
  color: var(--muted);
}

/* pending ----------------------------------------------------------------- */

.panel-pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(420px, 88%);
  height: auto;
  text-align: center;
}

.pending-line {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.06em;
  min-height: 20px;
}

/* snake ------------------------------------------------------------------- */

.snake-hud {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: min(340px, 40dvh);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted-dim);
}

.snake-score {
  font-size: 15px;
  color: var(--text);
  transition: color 0.25s var(--ease);
}

.snake-score.is-pop { color: var(--accent); }

.snake-best b { font-weight: 500; color: var(--muted); }

.snake-wrap {
  width: min(340px, 40dvh);
  aspect-ratio: 1;
}

.snake-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 14px;
  background: #14110E;
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(244, 239, 230, 0.035);
  touch-action: none;
}

.snake-pad {
  display: none;
  grid-template-columns: repeat(4, 38px);
  gap: 6px;
  justify-content: center;
  margin-top: 2px;
}

.snake-pad button {
  height: 34px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease),
              transform 0.12s var(--ease);
}

.snake-pad button:active {
  color: var(--accent);
  border-color: var(--accent-line);
  transform: scale(0.94);
}

@media (pointer: coarse) {
  .snake-pad { display: grid; }
}

.progress {
  width: 100%;
  height: 2px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s linear;
}

/* result ------------------------------------------------------------------ */

.panel-result {
  width: 100%;
  height: 100%;
  padding: clamp(10px, 1.4vw, 18px);
  display: grid;
  place-items: center;
}

.result-strip {
  display: grid;
  gap: clamp(8px, 1vw, 12px);
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-auto-rows: minmax(0, 1fr);
}

.result-strip[data-count="1"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.result-strip[data-count="2"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.result-strip[data-count="3"],
.result-strip[data-count="4"] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
.result-strip[data-count="3"] > :last-child { grid-column: 1 / -1; justify-self: center; width: 50%; }

.shot {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  cursor: zoom-in;
  transition: border-color 0.3s var(--ease);
}

.shot:hover { border-color: var(--line-strong); }

.shot { animation: reveal 0.95s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 90ms); }

@keyframes reveal {
  from { clip-path: inset(9% 9% 9% 9%); opacity: 0; transform: scale(0.975); }
  to   { clip-path: inset(0 0 0 0); opacity: 1; transform: none; }
}

.shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center;
}

/* error ------------------------------------------------------------------- */

.panel-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  text-align: center;
  max-width: 440px;
  height: auto;
}

.err-title {
  font-family: var(--serif);
  font-size: 26px;
  letter-spacing: 0.04em;
  margin: 0;
}

.err-body {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.85;
  color: var(--muted);
}

.err-detail {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.7;
  color: var(--muted-dim);
  max-height: 44px;
  overflow: hidden;
  word-break: break-all;
}

/* stage bar --------------------------------------------------------------- */

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  min-height: 34px;
}

.stage-meta {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--muted-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-tools { display: flex; gap: 8px; flex: 0 0 auto; }

/* ------------------------------------------------------------- buttons --- */

.ghost-btn {
  display: inline-flex;
  align-items: center;
  padding: 9px 15px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: color 0.24s var(--ease), border-color 0.24s var(--ease),
              background 0.24s var(--ease), transform 0.14s var(--ease);
}

.ghost-btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface); }
.ghost-btn:active { transform: translateY(1px); }
.ghost-btn.sm { padding: 7px 12px; font-size: 12px; }

/* --------------------------------------------------------------- drawer --- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(6, 5, 5, 0.62);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s var(--ease), visibility 0s 0.35s;
}

.scrim.is-on { opacity: 1; visibility: visible; transition: opacity 0.35s var(--ease), visibility 0s 0s; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  width: min(440px, 100vw);
  background: #0D0C0B;
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  visibility: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.58s var(--ease), visibility 0s 0.58s;
}

.drawer[aria-hidden="false"] {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.58s var(--ease), visibility 0s 0s;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.14em;
  margin: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}

.drawer-body::-webkit-scrollbar { width: 5px; }
.drawer-body::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.thumb-card {
  position: relative;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  aspect-ratio: 1;
  cursor: pointer;
  transition: border-color 0.26s var(--ease), transform 0.26s var(--ease);
  animation: thumbIn 0.5s var(--ease) backwards;
}

@keyframes thumbIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.thumb-card:hover { border-color: var(--accent-line); transform: translateY(-2px); }

.thumb-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-card .del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(10, 9, 8, 0.78);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.2s var(--ease), color 0.2s var(--ease);
}

.thumb-card:hover .del { opacity: 1; }
.thumb-card .del:hover { color: var(--accent); }

.drawer-empty {
  grid-column: 1 / -1;
  padding: 60px 0;
  text-align: center;
  color: var(--muted-dim);
  font-size: 13px;
  line-height: 1.9;
}

/* ------------------------------------------------------------- lightbox --- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(6, 5, 5, 0.94);
  display: grid;
  place-items: center;
  padding: 28px;
  cursor: zoom-out;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s var(--ease), visibility 0s 0.3s;
}

.lightbox.is-on { opacity: 1; visibility: visible; transition: opacity 0.3s var(--ease), visibility 0s 0s; }

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
  transform: scale(0.97);
  transition: transform 0.4s var(--ease);
}

.lightbox.is-on img { transform: scale(1); }

/* ------------------------------------------------------------ responsive --- */

@media (max-width: 1023px) {
  body { overflow: auto; }

  .app { height: auto; min-height: 100dvh; }

  .workbench {
    grid-template-columns: 1fr;
    gap: 26px;
    padding-bottom: 44px;
  }

  .composer { overflow: visible; order: 1; }

  .composer form { min-height: auto; }

  .pair { margin-top: 0; }

  .hint,
  .primary-keys { display: none; }

  .snake-hud,
  .snake-wrap { width: min(300px, 62vw, 27dvh); }

  .stage { order: 2; min-height: 58dvh; }

  .frame { min-height: 46dvh; }

  .topbar { height: 60px; }

  .brand-note { display: none; }

  .drawer-body { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
  .pair { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------- reduced motion --- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
