/* Phoenicia-Modeling preview — dark studio, one accent, system fonts. */

:root {
  --bg: #0b0d10;
  --surface: #12151a;
  --surface-2: #181c22;
  --surface-3: #1f242c;
  --line: #262c35;
  --line-strong: #353d49;
  --text: #e7e9ec;
  --text-dim: #a0a7b2;
  --text-faint: #6d7480;
  --accent: #ff7a1a;
  --accent-ink: #1a0d02;
  --accent-soft: rgba(255, 122, 26, 0.14);
  --danger: #ff6b5e;
  --ok: #5fd39a;

  --rail: 64px;
  --panel: 328px;
  --motion: 300px;
  --stage-min: 420px;
  --motion-chip-h: 44px;
  --radius: 8px;
  --radius-sm: 6px;

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

a {
  color: inherit;
}

small {
  font-size: inherit;
}

[hidden] {
  display: none !important;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.app {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail) var(--panel) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.app[data-panel="closed"] {
  grid-template-columns: var(--rail) 0 minmax(0, 1fr);
}

.app[data-panel="closed"] .panel {
  display: none;
}

/* Explicit tracks: hiding the panel must not let the stage slide into its column. */
.rail {
  grid-column: 1;
}

.panel {
  grid-column: 2;
}

.stage {
  grid-column: 3;
}

/* -------------------------------------------------------------------- rail */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 14px 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
  z-index: 3;
}

.rail__brand {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--accent);
  border-radius: var(--radius);
}

.rail__brand img {
  display: block;
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.rail__tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  flex: 1;
  min-width: 0;
}

.rail__tab,
.rail__jump {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 10px 0 9px;
  background: none;
  border: 0;
  color: var(--text-faint);
  font-size: 10.5px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: color 0.15s;
}

.rail__tab svg,
.rail__jump svg {
  width: 21px;
  height: 21px;
}

.rail__tab span,
.rail__jump span {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rail__tab small,
.rail__jump small {
  color: inherit;
  opacity: 0.75;
}

.rail__tab::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  opacity: 0;
  transition: opacity 0.15s;
}

@media (hover: hover) {
  .rail__tab:hover,
  .rail__jump:hover {
    color: var(--text-dim);
  }
}

.rail__tab[aria-selected="true"] {
  color: var(--text);
}

.rail__tab[aria-selected="true"]::before {
  opacity: 1;
}

/* ------------------------------------------------------------------- panel */

.panel {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.panel__close {
  display: none;
}

.panel__section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 20px 28px;
}

.panel__head h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel__head h2 small,
.field__label small,
.doc summary small {
  margin-left: 6px;
  color: var(--text-faint);
  font-weight: 400;
}

.panel__head p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

code {
  padding: 1px 5px;
  background: var(--surface-3);
  border-radius: 4px;
  font: 12px/1.4 var(--font-mono);
  color: var(--text);
}

/* -------------------------------------------------------------- model list */

.model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-card {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}

@media (hover: hover) {
  .model-card:hover {
    border-color: var(--line-strong);
  }
}

.model-card[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.model-card__tag {
  min-width: 46px;
  padding: 4px 6px;
  text-align: center;
  font: 600 11px/1.3 var(--font-mono);
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.model-card[aria-checked="true"] .model-card__tag {
  color: var(--accent);
  border-color: var(--accent);
}

.model-card__poster {
  width: 64px;
  height: 46px;
  object-fit: contain;
  border-radius: 4px;
  background: var(--surface-2);
}

.model-card__name {
  font-weight: 600;
  font-size: 14px;
}

.model-card__name small {
  margin-left: 8px;
  color: var(--text-dim);
  font-weight: 400;
}

/* ------------------------------------------------------------------ fields */

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

.field__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.field__label small {
  letter-spacing: 0.02em;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segmented button {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 44px;
  justify-content: center;
  padding: 5px 4px;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.25;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.segmented button small {
  font-size: 11px;
  color: var(--text-faint);
}

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

.segmented button[aria-checked="true"] {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.segmented button[aria-checked="true"] small {
  color: var(--accent);
}

.switches {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px 8px 14px;
  background: var(--surface-2);
  border: 0;
  border-top: 1px solid var(--line);
  text-align: left;
}

.switch:first-child {
  border-top: 0;
}

.switch__text small {
  margin-left: 6px;
  color: var(--text-faint);
}

.switch__knob {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}

.switch__knob::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}

.switch[aria-checked="true"] .switch__knob {
  background: var(--accent);
  border-color: var(--accent);
}

.switch[aria-checked="true"] .switch__knob::after {
  transform: translateX(14px);
  background: var(--accent-ink);
}

.switch[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 8px;
}

/* Motion Library. Two columns at every width; the right rail is a grid column when it fits. */
body[data-clips="on"] .dock__button[data-toggle="death"] {
  display: none;
}

.motion-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 16px 14px;
  padding-left: calc(14px + var(--safe-left));
  padding-right: calc(14px + var(--safe-right));
  background: var(--surface);
  border-left: 1px solid var(--line);
  z-index: 2;
  overflow: hidden;
}

.motion-panel__head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
}

.motion-panel__head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.motion-panel__head h2 small {
  margin-left: 6px;
  color: var(--text-faint);
  font-weight: 400;
}

.motion-panel__badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 4px 8px;
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font: 600 10px/1.3 var(--font-mono);
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.motion-panel__dot,
.motion-chip__dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
}

.motion-panel__badge[data-phase="playing"] .motion-panel__dot,
.motion-chip[data-phase="playing"] .motion-chip__dot {
  background: var(--ok);
}

.motion-panel__badge[data-phase="held"] .motion-panel__dot,
.motion-panel__badge[data-phase="ended"] .motion-panel__dot {
  background: var(--text-dim);
}

.motion-panel__legend {
  grid-column: 1 / -1;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.4;
}

.motion-panel__legend p {
  margin: 0;
  word-break: keep-all;
  line-break: strict;
}

.motion-hide,
.motion-open {
  touch-action: manipulation;
}

.motion-hide {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.motion-hide small {
  margin-left: 4px;
  color: var(--text-faint);
  font-weight: 400;
  word-break: keep-all;
}

.motion-panel__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.motion-panel__foot {
  flex: 0 0 auto;
}

#world-action { display: grid; gap: 8px; }
.button.world-enter { width: 100%; min-height: 66px; display: flex; align-items: center; justify-content: flex-start; gap: 14px; padding: 12px 16px; text-align: left; text-decoration: none; }
.world-enter svg { width: 24px; height: 24px; flex: 0 0 auto; color: var(--accent); }
.world-enter span { display: grid; gap: 4px; font-size: 16px; line-height: 1.2; }
.world-enter small { color: var(--text-dim); font-size: 12px; font-weight: 400; }
.world-enter[aria-disabled="true"] { color: var(--text-dim); cursor: default; }
.world-enter[aria-disabled="true"] svg { color: var(--text-faint); }
.world-enter[aria-disabled="true"]:hover { background: var(--surface-2); border-color: var(--line-strong); }
.world-overlay { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.world-overlay__bar { display: flex; justify-content: flex-end; align-items: center; gap: 12px; position: absolute; top: calc(16px + var(--safe-top, 0px)); left: 20px; right: 20px; }
.world-overlay__bar p { margin: 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(12, 14, 17, .85); color: var(--text-dim); font-size: 13px; }
#world-exit { pointer-events: auto; min-height: 44px; width: auto; padding: 0 18px; flex: 0 0 auto; }
.world-pad { display: none; position: absolute; bottom: calc(22px + var(--safe-bottom)); left: 22px; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); gap: 6px; pointer-events: auto; }
.world-pad button { border: 1px solid #6b6158; border-radius: var(--radius); background: rgba(17, 18, 21, .88); color: #f4eee7; font-size: 24px; touch-action: none; user-select: none; }
.world-pad button:active { background: #5b4432; }
[data-world-move="forward"] { grid-column: 2; }
[data-world-move="left"] { grid-column: 1; grid-row: 2; }
[data-world-move="back"] { grid-column: 2; grid-row: 2; }
[data-world-move="right"] { grid-column: 3; grid-row: 2; }
body[data-walking="on"] .app { grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: minmax(0, 1fr); }
body[data-walking="on"] .stage { grid-column: 1; grid-row: 1; }
body[data-walking="on"] .rail, body[data-walking="on"] .panel,
body[data-walking="on"] .stage-tools, body[data-walking="on"] .plate { display: none; }
body[data-world="on"] #motion-badge, body[data-world="on"] .motion-panel__legend,
body[data-world="on"] .motion-panel__foot, body[data-world="on"] .motion-chip__now,
body[data-world="on"] .motion-chip__phase { display: none; }
body[data-world="on"] .motion-panel__head { grid-template-columns: 1fr auto; }
body[data-world="on"] .motion-chip__brand { display: inline-flex; }
@media (pointer: coarse), (max-width: 760px) {
  .world-pad { display: grid; }
  .world-overlay__bar { align-items: flex-start; left: 12px; right: 12px; gap: 8px; }
  .world-overlay__bar p { max-width: 210px; font-size: 12px; line-height: 1.6; padding: 7px 10px; }
}

.clip-transport:not([hidden]) { display: grid; gap: 5px; padding-bottom: 9px; }
.clip-transport__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#clip-play { min-height: 34px; }
#clip-time { font-size: 12px; font-variant-numeric: tabular-nums; }
#clip-timeline { width: 100%; margin: 0; min-height: 24px; accent-color: var(--accent, #4478c8); cursor: pointer; }

#motion-stop {
  width: 100%;
  min-height: 44px;
  flex: none;
  touch-action: manipulation;
}

#motion-stop small {
  word-break: keep-all;
  white-space: nowrap;
}

#motion-stop:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.motion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.motion-clip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 16px;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 6px;
  min-width: 0;
  min-height: 44px;
  padding: 6px 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-align: left;
  touch-action: manipulation;
}

.motion-clip__index {
  grid-row: 1 / span 2;
  color: var(--text-faint);
  font: 600 10px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.motion-clip__name {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  word-break: normal;
  overflow-wrap: break-word;
}

.motion-clip__name small {
  display: block;
  margin: 1px 0 0;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0;
  word-break: keep-all;
  line-break: strict;
  white-space: nowrap;
}

.motion-clip__mode {
  grid-column: 3;
  grid-row: 1 / span 2;
  width: 16px;
  height: 16px;
  color: inherit;
  font-size: 12px;
  line-height: 16px;
  text-align: center;
}

.motion-clip--showcase {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) 16px;
}

.motion-clip--showcase .motion-clip__name {
  grid-column: 1;
}

.motion-clip[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.motion-clip[aria-checked="true"] .motion-clip__name {
  color: var(--text);
}

.motion-clip[aria-checked="true"] .motion-clip__name small,
.motion-clip[aria-checked="true"] .motion-clip__mode {
  color: var(--accent);
}

.motion-clip:disabled,
.motion-clip--placeholder {
  cursor: not-allowed;
  opacity: 0.5;
}

.motion-clip--placeholder {
  display: flex;
  align-items: center;
}

.motion-clip__bar {
  display: block;
  width: 40%;
  height: 8px;
  border-radius: 4px;
  background: var(--text-faint);
  opacity: 0.4;
}

@media (hover: hover) {
  .motion-clip:hover:not(:disabled) {
    background: var(--surface-3);
    border-color: var(--line-strong);
    color: var(--text);
  }

  .motion-hide:hover {
    color: var(--text);
  }
}

.motion-chip,
.motion-open {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  height: var(--motion-chip-h);
  min-height: 44px;
  background: rgba(18, 21, 26, 0.88);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  touch-action: manipulation;
}

.motion-chip {
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  bottom: 10px;
  gap: 8px;
  padding: 0 12px;
}

.motion-chip__brand {
  flex: 0 0 auto;
  font-weight: 600;
  white-space: nowrap;
}

.motion-chip__brand small,
.motion-open small {
  margin-left: 4px;
  color: var(--text-faint);
  font-weight: 400;
}

.motion-chip__now {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.motion-chip__now small {
  margin-left: 4px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 400;
}

.motion-chip__phase {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
  font: 600 10px/1 var(--font-mono);
  letter-spacing: 0.06em;
}

.motion-chip__chevron {
  flex: 0 0 auto;
  color: var(--text-dim);
}

.motion-open {
  top: 18px;
  right: 18px;
  padding: 0 14px;
  font-weight: 600;
  white-space: nowrap;
}

@media (min-width: 761px) {
  .app[data-motion="open"][data-motion-mode="column"] {
    grid-template-columns: var(--rail) var(--panel) minmax(0, 1fr) var(--motion);
  }

  .app[data-panel="closed"][data-motion="open"][data-motion-mode="column"] {
    grid-template-columns: var(--rail) 0 minmax(0, 1fr) var(--motion);
  }

  .app[data-motion="open"][data-motion-mode="column"] .motion-panel {
    grid-column: 4;
  }

  .app[data-motion="open"][data-motion-mode="overlay"] .motion-panel {
    position: absolute;
    inset: 0 0 0 auto;
    width: var(--motion);
    z-index: 2;
  }

  .app[data-motion="open"] .stage-tools {
    right: 12px;
    bottom: 24px;
  }

  .app[data-motion="open"][data-motion-mode="overlay"] .stage-tools {
    right: calc(var(--motion) + 12px);
  }

  .motion-chip {
    display: none !important;
  }

  /* Title and Hide stay on one row. The status pill drops to its own row so the clip name is not clipped. */
  .motion-panel__head {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .motion-panel__head h2 {
    grid-column: 1;
    grid-row: 1;
  }

  .motion-hide {
    grid-column: 2;
    grid-row: 1;
  }

  .motion-panel__badge {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
    width: max-content;
    max-width: 100%;
    overflow: hidden;
    text-overflow: clip;
  }

  .motion-panel__badge span {
    flex: 0 0 auto;
    min-width: max-content;
  }

  .motion-panel__legend {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}

/* 44px rows (Replay / Idle of the death clip). */
.actions--tall .button {
  min-height: 44px;
}

.actions--tall .button[disabled] {
  cursor: not-allowed;
}

.button {
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.button small {
  display: inline-block;
  margin-left: 4px;
  white-space: nowrap;
  color: var(--text-faint);
  font-weight: 400;
}

@media (hover: hover) {
  .button:hover {
    background: var(--surface-3);
  }
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.button--primary small {
  color: inherit;
  opacity: 0.7;
}

@media (hover: hover) {
  .button--primary:hover {
    background: #ff8b36;
  }
}

.button[disabled] {
  opacity: 0.55;
  cursor: progress;
}

/* Tap targets: the Export / Generate family is 44px tall (the other .button rows stay at 40px). */
#export-button,
#gen-run,
#gen-stop,
#gen-retry,
#gen-run-code,
#gen-forget {
  min-height: 44px;
}

/* ----------------------------------------------------------- module loader */

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

.code-input,
.text-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  /* 16px keeps iOS Safari from zooming the page on focus. */
  font: 16px/1.45 var(--font-mono);
}

.code-input {
  min-height: 200px;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

@media (min-width: 761px) {
  .code-input,
  .text-input {
    font-size: 12px;
  }
}

.code-input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 12px;
}

.notice {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.notice strong {
  display: block;
  margin-bottom: 2px;
  font-weight: 600;
}

.notice--error {
  background: rgba(255, 107, 94, 0.1);
  border: 1px solid rgba(255, 107, 94, 0.45);
  color: #ffb4ac;
}

.notice--ok {
  background: rgba(95, 211, 154, 0.08);
  border: 1px solid rgba(95, 211, 154, 0.35);
  color: #a6e8c6;
}

.doc {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.doc summary {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.doc p {
  margin: 0;
  padding: 0 12px 12px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.doc__code {
  margin: 0 12px 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: 11.5px/1.5 var(--font-mono);
  color: var(--text-dim);
  overflow-x: auto;
  tab-size: 2;
}

/* ---------------------------------------------------------------- generate */

/* The toggle sits right under the Export hint; open, it and the composer read as one card. */
.generate {
  display: flex;
  flex-direction: column;
}

.hint--line {
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button.gen-toggle {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.gen-toggle__star,
.gen-toggle__chevron {
  color: var(--accent);
}

.gen-toggle__label small {
  margin-left: 4px;
  color: var(--text-faint);
}

.gen-toggle__chevron {
  display: inline-block;
  transition: transform 0.15s;
}

.gen-toggle[aria-expanded="true"] .gen-toggle__chevron {
  transform: rotate(180deg);
}

@media (hover: hover) {
  .button.gen-toggle:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
  }
}

.button.gen-toggle[aria-expanded="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

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

.gen-composer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Reference images */
.refs {
  gap: 8px;
}

.refs__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.refs__head .field__label small {
  margin-left: 6px;
  color: var(--text-faint);
  font-weight: 400;
}

.refs__count {
  color: var(--text-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 88px;
  padding: 0 10px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.dropzone__main {
  color: var(--text-dim);
  font-size: 14px;
}

/* 拖入或点选图片 / 松开即可添加 are one unit: never split 点|选. If the English line plus the Chinese does not fit,
   the Chinese drops to its own line whole. 13px keeps it under ~100px, well inside the 242px mobile / 256px desktop
   content width. */
.dropzone__main small {
  display: inline-block;
  margin-left: 4px;
  color: var(--text-faint);
  font-size: 13px;
  white-space: nowrap;
}

.dropzone__sub {
  color: var(--text-faint);
  font-size: 12px;
}

.dropzone__over {
  display: none;
}

@media (hover: hover) {
  .dropzone:hover {
    border-color: var(--accent);
  }
}

.dropzone:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.refs[data-drag="true"] .dropzone,
.refs[data-drag="true"] .thumb--add {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.refs[data-drag="true"] .dropzone__rest {
  display: none;
}

.refs[data-drag="true"] .dropzone__over {
  display: inline;
}

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

/* 56px, not the 64px of SPEC §5.2: the desktop panel leaves 256px inside the composer, and 4 x 56 + 3 x 8 = 248 is
   the largest square that still keeps four to a row there. */
.thumb {
  position: relative;
  flex: none;
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.15s, opacity 0.15s;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius-sm) - 1px);
}

@media (hover: hover) {
  .thumb:hover {
    border-color: var(--accent);
  }
}

.thumb__remove {
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: 0;
  color: #fff;
}

.thumb__remove::before {
  content: "×";
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  background: rgba(11, 13, 16, 0.8);
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
}

.thumb--add {
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
}

.thumb--add:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.generate[data-state="busy"] .thumb img {
  opacity: 0.6;
}

.generate[data-state="busy"] .thumb--add,
.generate[data-state="busy"] .dropzone,
.generate[data-state="busy"] .thumb__remove {
  pointer-events: none;
  cursor: progress;
}

.generate[data-state="busy"] .thumb--add,
.generate[data-state="busy"] .dropzone {
  opacity: 0.6;
}

.refs__error {
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.4;
  transition: opacity 0.4s;
}

.refs__error.is-fading {
  opacity: 0;
}

/* Summary rows: title left, status dot and info button right */
.doc summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  position: relative;
  list-style: none;
}

.doc summary::-webkit-details-marker {
  display: none;
}

.doc summary::before {
  content: "▸";
  flex: none;
  color: var(--text-faint);
  transition: transform 0.15s;
}

.doc[open] > summary::before {
  transform: rotate(90deg);
}

.doc__title {
  flex: 1;
  min-width: 0;
}

.doc__tools {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}

.dot[data-saved="true"] {
  background: var(--ok);
}

.info {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
}

.tip {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 4;
  width: 260px;
  max-width: calc(100vw - 32px);
  padding: 8px 10px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  cursor: default;
  pointer-events: none;
}

.tip span {
  color: var(--text-faint);
}

.tip.is-open {
  display: block;
}

@media (hover: hover) {
  .doc__tools:hover ~ .tip {
    display: block;
  }
}

#gen-code {
  min-height: 0;
}

.doc__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 12px 12px;
}

.doc__body .hint {
  margin: 0;
}

.code-input--prose {
  min-height: 84px;
  white-space: pre-wrap;
  font-family: var(--font-ui);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  /* The whole row is the hit area (the label wraps the checkbox): at least 44px tall. */
  min-height: 44px;
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
}

.check input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.check small {
  margin-left: 4px;
  color: var(--text-faint);
}

.hint--status:empty {
  display: none;
}

.generate[data-state="busy"] .hint--status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* ------------------------------------------------------------------- about */

.keys {
  display: flex;
  flex-direction: column;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.keys > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.keys > div:first-child {
  border-top: 0;
}

.keys dt small {
  margin-left: 6px;
  color: var(--text-faint);
}

.keys dd {
  margin: 0;
  color: var(--text-dim);
}

.prose {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.links a {
  color: var(--accent);
  text-decoration: none;
}

@media (hover: hover) {
  .links a:hover {
    text-decoration: underline;
  }
}

.links small {
  margin-left: 6px;
  color: var(--text-faint);
}

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

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #101318;
}

/* Checkerboard shows through the canvas only when the background is transparent. */
.stage[data-background="grid"] {
  background-color: #14171c;
  background-image: linear-gradient(45deg, #1b1f26 25%, transparent 25%, transparent 75%, #1b1f26 75%),
    linear-gradient(45deg, #1b1f26 25%, transparent 25%, transparent 75%, #1b1f26 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.stage__canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline-offset: -2px;
  cursor: grab;
}

.stage__canvas:active {
  cursor: grabbing;
}

/* Model-name plate: the signature element. */
.plate {
  position: absolute;
  left: 28px;
  bottom: 26px;
  max-width: min(460px, calc(100% - 110px));
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.55);
}

.plate__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.plate__tag {
  padding: 3px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font: 600 11px/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-shadow: none;
}

.plate__index {
  color: var(--text-faint);
  font: 11px/1.3 var(--font-mono);
  letter-spacing: 0.1em;
}

.plate__name {
  margin: 0;
  font-size: clamp(24px, 3.2vw, 38px);
  font-weight: 650;
  line-height: 1.08;
  letter-spacing: -0.022em;
}

.plate__zh {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: clamp(14px, 1.5vw, 17px);
  letter-spacing: 0.14em;
}

.plate__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  position: relative;
}

.plate__stats::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 44px;
  height: 1px;
  background: var(--accent);
}

.plate__stats dt {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.plate__stats dt small {
  margin-left: 4px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.plate__stats dd {
  margin: 1px 0 0;
  font: 500 15px/1.3 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.loading-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg);
  pointer-events: none;
}

.loading-panel {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 12px;
  width: min(352px, calc(100% - 32px));
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(18, 21, 26, 0.97);
  box-shadow: 0 12px 36px #0005;
}

.loading-panel__content { display: grid; gap: 4px; min-width: 0; }
.loading-panel__target { font-size: 14px; font-weight: 600; }
.loading-panel__phase { color: var(--text-dim); font-size: 12px; }
.loading-panel__detail { color: var(--text); font: 11px/1.5 var(--font-mono); font-variant-numeric: tabular-nums; }
.loading-panel__detail:empty { display: none; }
.loading-panel__spinner {
  width: 17px;
  height: 17px;
  margin-top: 3px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.85s linear infinite;
}
.loading-panel[data-phase="error"] .loading-panel__spinner { border-color: var(--danger); animation: none; }
.loading-panel__progress { grid-column: 1 / -1; height: 3px; overflow: hidden; border-radius: 2px; background: var(--line); }
.loading-panel__progress::before { content: ""; display: block; height: 100%; width: 30%; background: var(--accent); animation: loading-sweep 1.4s ease-in-out infinite; }
.loading-panel__progress[data-determinate="true"]::before { width: var(--loading-progress, 0%); animation: none; }
.loading-panel__actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.loading-panel__actions .button { min-height: 36px; padding: 6px 12px; font-size: 12px; }
.model-card[aria-busy="true"] { border-color: var(--accent); }
@keyframes loading-spin { to { transform: rotate(360deg); } }
@keyframes loading-sweep { 0%, 100% { transform: translateX(-100%); } 50% { transform: translateX(330%); } }
@media (max-width: 760px) { .loading-panel { top: 68px; } .loading-panel__actions .button { min-height: 44px; } }
@media (prefers-reduced-motion: reduce) { .loading-panel__spinner, .loading-panel__progress::before { animation: none; } }

/* Quick controls */
.dock__modes { display: flex; gap: 2px; grid-column: 1 / -1; }
.dock__modes .dock__button { grid-template-rows: 20px 12px; align-content: center; gap: 2px; }
.dock__modes span { font-size: 10px; line-height: 1; white-space: nowrap; }
.stage-tools {
  position: absolute;
  right: 18px;
  bottom: 24px;
  display: grid;
  gap: 8px;
}

.dock, .scene-quick {
  padding: 4px;
  background: rgba(18, 21, 26, 0.82);
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.scene-quick { display: flex; justify-content: center; gap: 2px; }
.scene-quick .dock__button { grid-template-rows: 20px 12px; align-content: center; gap: 2px; font-size: 10px; line-height: 1; }
.scene-quick [data-scene-preset="lighting"][data-preset="warm"]:enabled svg { color: #ffb475; }
.scene-quick [data-scene-preset="lighting"][data-preset="lab"]:enabled svg { color: #8fdced; }
.scene-quick [data-scene-preset="background"]:is([data-preset="solid"], [data-preset="grid"]):enabled svg { color: var(--accent); }

.dock { display: flex; flex-direction: column; align-items: center; gap: 2px; }

.dock__button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.dock__button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.dock__button svg {
  width: 20px;
  height: 20px;
}

@media (hover: hover) {
  .dock__button:hover {
    background: var(--surface-3);
    color: var(--text);
  }
}

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

.dock__rule {
  height: 1px;
  margin: 3px 6px;
  background: var(--line);
}

.toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  padding: 9px 14px;
  background: rgba(18, 21, 26, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  overflow-wrap: anywhere;
}

.toast[data-kind="error"] {
  border-color: rgba(255, 107, 94, 0.6);
  color: #ffb4ac;
}

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 5;
}

.fallback__box {
  max-width: 420px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.fallback__box h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.fallback__box p {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 760px) {
  :root {
    --rail-h: calc(58px + var(--safe-bottom));
  }

  /* Stage on top, the panel as a sheet under it, tab bar at the bottom.
     The sheet is in flow, so the stage shrinks and the model stays in view. */
  .app,
  .app[data-panel="closed"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto var(--rail-h);
  }

  .stage {
    grid-row: 1;
    grid-column: 1;
  }

  .rail {
    grid-row: 3;
    grid-column: 1;
    flex-direction: row;
    gap: 0;
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  /* Keep the spider mark on mobile, compact so the tab bar does not overflow. */
  .rail__brand {
    flex: 0 0 auto;
    width: 40px;
    height: 100%;
    margin-left: 6px;
  }

  .rail__brand img {
    width: 28px;
    height: 28px;
  }

  .rail__tabs {
    flex: 1 1 auto;
    flex-direction: row;
    gap: 0;
    width: auto;
    height: 100%;
  }

  .rail__tab,
  .rail__jump {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    justify-content: center;
    gap: 2px;
    padding: 5px 0 4px;
  }

  .rail__tab svg,
  .rail__jump svg {
    width: 18px;
    height: 18px;
  }

  .rail__tab span,
  .rail__jump span {
    max-width: 100%;
    line-height: 1.05;
  }

  .rail__tab small,
  .rail__jump small {
    font-size: 9px;
  }

  .rail__tab::before {
    left: 22%;
    right: 22%;
    top: 0;
    bottom: auto;
    width: auto;
    height: 2px;
    border-radius: 0 0 2px 2px;
  }

  .panel {
    grid-row: 2;
    grid-column: 1;
    max-height: min(54vh, calc(100vh - var(--rail-h) - 250px));
    max-height: min(54dvh, calc(100dvh - var(--rail-h) - 250px));
    border-right: 0;
    border-top: 1px solid var(--line-strong);
  }

  .motion-panel {
    grid-row: 2;
    grid-column: 1;
    height: auto;
    max-height: min(54vh, calc(100vh - var(--rail-h) - 250px));
    max-height: min(54dvh, calc(100dvh - var(--rail-h) - 250px));
    border-left: 0;
    border-top: 1px solid var(--line-strong);
  }

  .motion-open {
    display: none !important;
  }

  /* With the sheet open the stage is short: keep only the name on the plate. */
  .app:not([data-panel="closed"]) .plate__zh,
  .app:not([data-panel="closed"]) .plate__stats,
  .app[data-motion="open"] .plate__zh,
  .app[data-motion="open"] .plate__stats {
    display: none;
  }

  .app:not([data-panel="closed"]) .plate__name,
  .app[data-motion="open"] .plate__name {
    font-size: 20px;
  }

  .panel__close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text-dim);
    z-index: 1;
  }

  .panel__close svg {
    width: 16px;
    height: 16px;
  }

  .panel__section {
    gap: 16px;
    padding: 18px 16px 22px;
  }

  .panel__head {
    padding-right: 44px;
  }

  /* Tighter composer on phones (the 44px rows above add height): smaller gaps and padding, same order, no tap target
     below 44px. */
  .gen-composer {
    gap: 10px;
    padding: 10px 12px;
  }

  .refs {
    gap: 6px;
  }

  .dropzone {
    height: 76px;
  }

  .plate {
    left: 16px;
    bottom: 14px;
    max-width: calc(100% - 84px);
  }

  /* Chip sits on the stage floor; lift the plate above it. The open sheet puts the plate back. */
  body[data-clips="on"] .app[data-motion="closed"] .plate {
    bottom: 66px;
  }

  .app[data-motion="open"] .plate {
    bottom: 14px;
  }

  .plate__meta {
    margin-bottom: 7px;
  }

  .plate__zh {
    margin-top: 4px;
  }

  .plate__stats {
    gap: 4px 16px;
    margin-top: 11px;
    padding-top: 9px;
  }

  .plate__stats dd {
    font-size: 13px;
  }

  .plate__stats dt small {
    display: none;
  }

  .stage-tools {
    right: 10px;
    bottom: auto;
    top: 12px;
  }

  /* With the sheet open the stage can be as short as 250px: six buttons go in two columns. */
  .app:not([data-panel="closed"]) .dock,
  .app[data-motion="open"] .dock {
    display: grid;
    grid-template-columns: repeat(2, 44px);
  }

  .app:not([data-panel="closed"]) .dock__rule,
  .app[data-motion="open"] .dock__rule {
    display: none;
  }

  .toast {
    top: 12px;
    left: 12px;
    right: 70px;
    transform: none;
    max-width: none;
  }

  .app:not([data-panel="closed"]) .toast,
  .app[data-motion="open"] .toast {
    right: 116px;
  }
}

@media (max-width: 360px) {
  .motion-panel {
    gap: 4px;
    padding-top: 6px;
    padding-bottom: 4px;
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
  }

  /* Title and Hide stay on one row. The status pill drops to its own row so the clip name is not clipped. */
  .motion-panel__head {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 8px;
  }

  .motion-panel__head h2 {
    grid-column: 1;
    grid-row: 1;
  }

  .motion-panel__legend {
    grid-column: 1 / -1;
    grid-row: 3;
    line-height: 1.2;
  }

  .motion-panel__badge {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
    width: max-content;
    max-width: 100%;
    padding-top: 2px;
    padding-bottom: 2px;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: clip;
  }

  .motion-panel__badge span {
    flex: 0 0 auto;
    min-width: max-content;
  }

  /* Recover the extra badge row so eight clips still clear the stop control at 720px. */
  .motion-grid {
    gap: 4px;
  }

  /* The row stays short enough for 8 clips. The hit area stays 44px. */
  .motion-hide {
    grid-column: 2;
    grid-row: 1;
    min-height: 32px;
    height: 32px;
  }

  .motion-hide::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 0;
    bottom: -6px;
    left: 0;
  }

  .motion-chip__brand {
    display: none;
  }
}

/* 54dvh still covers the last clip on short phones. 720px-tall viewports keep the cap above. */
@media (max-width: 760px) and (max-height: 719px) {
  .motion-panel {
    max-height: min(70vh, calc(100vh - var(--rail-h) - 170px));
    max-height: min(70dvh, calc(100dvh - var(--rail-h) - 170px));
  }
}

@media (max-height: 480px) and (min-width: 761px) {
  .plate__stats {
    display: none;
  }
}

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

/* Paired captures occupy the gallery stage while the World actions stay available. */
.world-compare {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(8px, 1.4vw, 16px);
  overflow: auto;
  padding: clamp(12px, 2vw, 24px);
  background: #101318;
}
.world-compare__bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.world-compare__bar .button { display: grid; place-items: center; flex: 0 0 auto; min-height: 40px; padding: 0 15px; text-decoration: none; }
.world-compare__bar .world-compare__enter { color: var(--accent); }
.world-compare__main { display: grid; place-items: center; min-width: 0; min-height: 0; container-type: size; }
.world-compare__content { display: flex; width: 100%; flex-direction: column; align-items: center; gap: 12px; }
.world-compare__main [role="status"] { margin: 0; color: var(--text-dim); text-align: center; }
.world-compare__images {
  --frame-ratio: 3 / 2;
  --split: 50%;
  position: relative;
  isolation: isolate;
  width: min(100%, calc(max(120px, 100cqh - 90px) * (var(--frame-ratio))));
  min-width: 0;
  aspect-ratio: var(--frame-ratio);
  overflow: hidden;
  box-shadow: 0 0 0 1px #4b4f56;
  background: #212226;
}
.world-compare__images img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.world-compare__images img:nth-of-type(2) { clip-path: inset(0 0 0 var(--split)); }
.world-compare__tag {
  position: absolute;
  top: 12px;
  z-index: 1;
  padding: 5px 8px;
  border-radius: 4px;
  background: rgba(18, 19, 17, .86);
  color: #fff;
  font-size: clamp(12px, 1.25vw, 16px);
  pointer-events: none;
}
.world-compare__tag--left { left: 12px; }
.world-compare__tag--right { right: 12px; }
.world-compare__divider {
  position: absolute;
  inset-block: 0;
  left: var(--split);
  z-index: 2;
  width: 2px;
  transform: translateX(-50%);
  background: #fffaf0;
  box-shadow: 0 0 5px #292a27;
  pointer-events: none;
}
.world-compare__divider span {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fffaf0;
  color: #232720;
  font-size: 24px;
}
.world-compare__images input[type="range"] {
  appearance: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  margin: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: ew-resize;
  touch-action: none;
}
.world-compare__images input::-webkit-slider-thumb { appearance: none; width: 1px; height: 100%; }
.world-compare__images input::-moz-range-thumb { width: 1px; }
.world-compare__images:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }
.world-compare__cameras { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.world-compare__cameras .button { flex: 0 0 auto; min-height: 39px; padding: 4px 9px; }
.world-compare__cameras button[aria-pressed="true"], #world-compare-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
@media (min-width: 761px) {
  .app[data-motion="open"][data-motion-mode="overlay"] .world-compare { inset-inline-end: var(--motion); }
}
@media (max-width: 760px) {
  .world-compare { gap: 8px; }
  .world-compare__cameras .button { min-height: 38px; font-size: 12px; }
}
