/* ILLMOJI — layout modelled on a tablet drawing studio:
   a full-bleed canvas, a slim tool bar, a size rail, and one settings panel at a time.
   Three shapes: phone (bottom sheet), tablet (popover), desktop (docked side panel). */

:root {
  color-scheme: dark;
  --bg: #0b0b0a;
  --surface: #151513;
  --surface-2: #1e1d1a;
  --surface-3: #292724;
  --line: #2f2d29;
  --text: #f3efe4;
  --muted: #a29c90;
  --accent: #b92b3c;
  --accent-bright: #e2475a;
  --radius: 12px;
  --bar: 52px;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --font-ui: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Silkscreen", "Courier New", monospace;
}

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

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.35;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hidden,
[hidden] {
  display: none !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  flex: none;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

/* ---------- App shell ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

.device {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "left right"
    "stage stage"
    "timeline timeline";
  background: var(--bg);
}

.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: calc(var(--bar) + var(--safe-top));
  padding: var(--safe-top) 8px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.bar-left {
  grid-area: left;
  padding-left: calc(8px + var(--safe-left));
}

.bar-right {
  grid-area: right;
  padding-right: calc(8px + var(--safe-right));
}

.bar-button {
  flex: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 50px;
  height: 46px;
  padding: 0 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.bar-button:hover {
  background: var(--surface-2);
  color: var(--text);
}

.bar-button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface-3);
}

.tool-button.is-active {
  color: #fff;
  background: var(--accent);
}

.bar-button.is-open {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent-bright);
}

.tool-button.is-active.is-open {
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--text);
}

.bar-label {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.bar-button .icon {
  width: 20px;
  height: 20px;
}

.brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 0 8px 0 4px;
  gap: 6px;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.brand-name {
  color: var(--accent-bright);
}

.brand-mark {
  font-size: 20px;
  line-height: 1;
}

.brush-glyph {
  font-size: 19px;
  line-height: 1;
  max-width: 34px;
  overflow: hidden;
  white-space: nowrap;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", var(--font-ui);
}

.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--text);
  background: var(--accent);
}

.save-state {
  margin-left: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ---------- Stage ---------- */

.stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(185, 43, 60, 0.07), transparent 60%),
    var(--bg);
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px 16px 16px 68px;
  touch-action: none;
  cursor: crosshair;
}

.canvas-wrap.is-panning {
  cursor: grabbing;
}

.canvas-wrap.is-transform {
  cursor: move;
}

#drawCanvas {
  display: block;
  width: var(--canvas-display-width, 320px);
  height: var(--canvas-display-height, 320px);
  transform: translate(var(--view-x, 0px), var(--view-y, 0px)) scale(var(--view-zoom, 1));
  transform-origin: 50% 50%;
  background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 18px 60px rgba(0, 0, 0, 0.55);
  touch-action: none;
}

.rail {
  position: absolute;
  left: calc(8px + var(--safe-left));
  top: calc((100% - var(--sheet-inset, 0px)) / 2);
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(21, 21, 19, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 3;
}

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

.rail-caption {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.rail-label {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: center;
}

.rail-track {
  --rail-length: 132px;
  position: relative;
  width: 40px;
  height: var(--rail-length);
}

.rail-track input[type="range"] {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--rail-length);
  height: 40px;
  margin: -20px 0 0 calc(var(--rail-length) / -2);
  transform: rotate(-90deg);
}

.rail-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
}

.rail-button:hover,
.mini-button:hover {
  background: var(--surface-3);
}

/* With a sheet open on a phone there is little height left: keep undo, redo and size, drop the rest. */
.stage.has-sheet .rail-opacity {
  display: none;
}

.stage.has-sheet .rail-track {
  --rail-length: 76px;
}

.stage.has-sheet .rail {
  gap: 2px;
  padding: 2px 2px 4px;
}

.stage.has-sheet .rail-button {
  height: 38px;
}

.empty-hint {
  position: absolute;
  left: calc(50% + 26px);
  top: calc((100% - var(--sheet-inset, 0px)) / 2);
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 18px;
  background: rgba(21, 21, 19, 0.8);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

.size-bubble {
  position: absolute;
  left: calc(50% + 26px);
  top: calc((100% - var(--sheet-inset, 0px)) / 2);
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #000;
  pointer-events: none;
  z-index: 4;
}

.tool-chip {
  position: absolute;
  top: 10px;
  right: calc(12px + var(--safe-right));
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(21, 21, 19, 0.92);
  color: var(--text);
  font-size: 13px;
  z-index: 3;
}

.tool-chip .icon {
  width: 18px;
  height: 18px;
}

.zoom-chip {
  position: absolute;
  right: calc(12px + var(--safe-right));
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(21, 21, 19, 0.92);
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  z-index: 3;
}

.zoom-chip .icon {
  width: 16px;
  height: 16px;
}

.toast {
  position: absolute;
  left: 50%;
  top: 58px;
  transform: translateX(-50%);
  max-width: min(86%, 420px);
  padding: 8px 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(21, 21, 19, 0.94);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  z-index: 4;
}

.progress-pop {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(320px, 80%);
  padding: 10px 14px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(21, 21, 19, 0.96);
  font-size: 13px;
  z-index: 5;
}

.progress-track {
  height: 4px;
  margin-top: 8px;
  border-radius: 2px;
  background: var(--surface-3);
  overflow: hidden;
}

#progressBar {
  height: 100%;
  width: 0;
  background: var(--accent-bright);
  transition: width 0.18s ease;
}

.progress-pop.is-indeterminate #progressBar {
  width: 40%;
  animation: progress-slide 1s linear infinite;
}

@keyframes progress-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(260%); }
}

/* ---------- Timeline ---------- */

.timeline {
  grid-area: timeline;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px calc(8px + var(--safe-right)) 6px calc(8px + var(--safe-left));
  background: var(--surface);
  border-top: 1px solid var(--line);
  min-width: 0;
}

.timeline-actions {
  display: flex;
  gap: 2px;
  flex: none;
}

.frame-list {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 2px;
}

.frame-button {
  flex: none;
  position: relative;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #000;
  overflow: hidden;
}

.frame-button canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.frame-button.is-active {
  border-color: var(--accent-bright);
}

.frame-number {
  position: absolute;
  left: 3px;
  bottom: 2px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Dock and panels ---------- */

.dock {
  position: fixed;
  z-index: 20;
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.dock.is-open {
  display: flex;
}

.dock-grip {
  display: none;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 4px 6px 4px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.panel-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.panel-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 16px;
}

.panel-body > * {
  flex: none;
}

.panel-body h3 {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.note,
.status-line {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

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

/* ---------- Controls ---------- */

.field {
  display: grid;
  gap: 4px;
}

.field > span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.field output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.field.is-disabled,
.motion-settings.is-disabled {
  opacity: 0.45;
}

input[type="text"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  -webkit-user-select: text;
  user-select: text;
}

textarea {
  resize: vertical;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  touch-action: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--text);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--text);
}

input[type="range"]:disabled {
  opacity: 0.4;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  font-size: 14px;
  cursor: pointer;
}

.toggle-field input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: none;
}

.button-row,
.size-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button-row.three {
  grid-template-columns: repeat(3, 1fr);
}

.inline-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.button-row button,
.inline-row button,
.wide-button,
.primary-button,
.chip-row button {
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.button-row button:hover,
.inline-row button:hover,
.wide-button:hover,
.chip-row button:hover {
  background: var(--surface-3);
}

.button-row button .icon {
  width: 18px;
  height: 18px;
  vertical-align: -4px;
}

.button-row button small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.wide-button {
  width: 100%;
}

.button-row .primary-button,
.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.button-row .primary-button:hover,
.primary-button:hover {
  background: var(--accent-bright);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.button-row .danger-button,
.danger-button {
  color: #ff8a97;
}

.meter {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}

#weightBar {
  height: 100%;
  width: 3%;
  border-radius: 4px;
  background: #6fbf73;
  transition: width 0.3s ease;
}

#weightBar.is-heavy {
  background: var(--accent-bright);
}

.chip-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.chip-row button {
  padding: 8px 4px;
  font-size: 13px;
}

.chip-row button.is-active {
  border-color: var(--accent-bright);
  color: #fff;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
}

.tab {
  flex: 1;
  min-height: 38px;
  padding: 6px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.tab.is-active {
  background: var(--text);
  color: #111;
}

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

.brush-preview {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #070706;
}

.brush-preview canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 440 / 150;
}

.preview-dice {
  position: absolute;
  right: 6px;
  top: 6px;
  background: rgba(21, 21, 19, 0.85);
  border: 1px solid var(--line);
}

.emoji-tools {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 8px;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
}

.picker-scroll {
  max-height: min(40vh, 320px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  align-content: start;
}

.emoji-frequent {
  padding: 2px;
}

.frequent-block {
  display: grid;
  gap: 6px;
}

.frequent-block h3 {
  margin-top: 0;
}

.export-preview {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #000;
  overflow: hidden;
}

.export-preview canvas {
  display: block;
  max-width: 100%;
  max-height: 200px;
}

.color-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.color-custom .color-swatch-input {
  width: 30px;
  height: 30px;
  border: 0;
  background: none;
}

.picker-button {
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", var(--font-ui);
  overflow: hidden;
}

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

.picker-button.is-active {
  background: var(--surface-3);
  border-color: var(--accent-bright);
}

.picker-empty {
  grid-column: 1 / -1;
  padding: 14px 8px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.picker-sentinel {
  grid-column: 1 / -1;
  height: 1px;
}

#shapePicker .picker-button,
#symbolPicker .picker-button {
  font-size: 20px;
  color: var(--text);
}

.paint-template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.paint-template {
  display: grid;
  gap: 6px;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  text-align: left;
  font-size: 13px;
}

.paint-template.is-active {
  border-color: var(--accent-bright);
}

.paint-template-sample {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--text));
  opacity: 0.8;
}

.paint-controls,
.char-controls,
.font-controls,
.motion-settings {
  display: grid;
  gap: 10px;
}

/* ---------- Colour ---------- */

.swatch-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

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

.swatch {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
}

.swatch.is-active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--accent-bright);
}

.color-swatch-input {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}

.effect-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.effect-button {
  min-height: 40px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
}

.effect-button.is-active {
  background: var(--text);
  color: #111;
  border-color: var(--text);
}

/* ---------- Lists: layers, presets, gallery ---------- */

.layer-list,
.project-list {
  display: grid;
  gap: 6px;
}

.layer-row,
.project-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.project-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.layer-row.is-active {
  border-color: var(--accent-bright);
}

.layer-row.is-hidden .layer-select {
  opacity: 0.5;
}

.layer-select {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-thumb {
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #000;
}

.layer-text {
  min-width: 0;
}

.row-button .icon {
  width: 18px;
  height: 18px;
}

.row-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
}

.row-button:hover {
  background: var(--surface-3);
  color: var(--text);
}

.layer-select,
.project-load {
  min-width: 0;
  min-height: 40px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.project-name {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-moves {
  display: flex;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
}

.gallery-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}

.gallery-card.is-current {
  border-color: var(--accent-bright);
}

.gallery-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.gallery-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #000;
}

.gallery-thumb.is-empty {
  display: grid;
  place-items: center;
  font-size: 28px;
}

.gallery-label {
  display: block;
  padding: 6px 8px 8px;
}

.gallery-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(11, 11, 10, 0.8);
  color: var(--text);
}

.gallery-delete .icon {
  width: 16px;
  height: 16px;
}

.gallery-empty {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Share sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
}

.share-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.share-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
}

/* ---------- Splash ---------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(6, 6, 5, 0.94);
  overflow-y: auto;
}

.rain-layer {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-around;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.16;
}

.rain-layer span {
  writing-mode: vertical-rl;
  font-size: 28px;
  letter-spacing: 12px;
  animation: rain-fall 16s linear infinite;
}

.rain-layer span:nth-child(2n) {
  animation-duration: 22s;
  animation-delay: -6s;
}

.rain-layer span:nth-child(3n) {
  animation-duration: 27s;
  animation-delay: -12s;
}

@keyframes rain-fall {
  from { transform: translateY(-60%); }
  to { transform: translateY(110%); }
}

.splash-card {
  position: relative;
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px 22px 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}

.splash-kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.splash-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(34px, 9vw, 52px);
  line-height: 1;
  color: var(--accent-bright);
  letter-spacing: 0.04em;
}

.splash-lede {
  margin: 0;
  font-size: 16px;
}

.splash-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.splash-points li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.splash-points li > span {
  font-size: 22px;
  line-height: 1.1;
}

.splash-points strong {
  color: var(--text);
}

.splash-gestures {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.gesture-set h2 {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.gesture-set p {
  margin: 0;
  font-size: 13px;
}

@media (hover: none) and (pointer: coarse) {
  .gesture-set[data-input="mouse"] { display: none; }
}

@media (hover: hover) and (pointer: fine) {
  .gesture-set[data-input="touch"] { display: none; }
}

.splash-start {
  min-height: 52px;
  font-size: 16px;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  background: var(--bg);
  z-index: 99;
}

/* ---------- Phone: tools along the bottom, panels as a bottom sheet ---------- */

@media (max-width: 699px) {
  .device {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "left"
      "stage"
      "timeline"
      "right";
  }

  .bar-right {
    justify-content: space-around;
    min-height: calc(var(--bar) + var(--safe-bottom));
    padding: 0 calc(8px + var(--safe-right)) var(--safe-bottom) calc(8px + var(--safe-left));
    border-bottom: 0;
    border-top: 1px solid var(--line);
  }

  .bar-left {
    padding-right: calc(8px + var(--safe-right));
  }

  .brand,
  .save-state {
    display: none;
  }

  /* Six buttons share the width evenly, so none is cut off on a small phone. */
  .bar .bar-button {
    flex: 1 1 0;
    min-width: 0;
  }

  .empty-hint,
  .size-bubble {
    left: calc(50% + 24px);
  }

  .canvas-wrap {
    padding: 10px 10px 10px 58px;
  }

  .rail {
    left: calc(4px + var(--safe-left));
    padding: 6px 2px;
  }

  .dock {
    left: 0;
    right: 0;
    bottom: calc(var(--bar) + var(--safe-bottom));
    max-height: min(50vh, 480px);
    max-height: min(50dvh, 480px);
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
  }

  .dock-grip {
    display: block;
    flex: none;
    width: 40px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 2px;
    background: var(--surface-3);
  }

  .frame-button {
    width: 48px;
    height: 48px;
  }
}

/* Short screens (phones in landscape): shrink the rail sliders. */
@media (max-height: 560px) {
  .rail-track {
    --rail-length: 78px;
  }

  .rail {
    gap: 2px;
    padding: 4px 2px;
  }

  .rail-button {
    height: 34px;
  }
}

@media (max-height: 400px) {
  .rail-slider:nth-of-type(2) {
    display: none;
  }
}

/* Narrow tablets: no room for words under the left-hand icons. */
@media (min-width: 700px) and (max-width: 899px) {
  /* The Save button keeps its word, because that word is the save status. */
  .bar-left .bar-button:not(#saveButton) .bar-label {
    display: none;
  }
}

/* The left-hand buttons give up a little width before anything is cut off. */
@media (min-width: 700px) {
  .bar-left .bar-button {
    flex: 0 1 50px;
    min-width: 38px;
  }
}

/* Widths where the left-hand bar is tight: the mark stays, the wordmark goes. */
@media (min-width: 700px) and (max-width: 899px), (min-width: 1100px) and (max-width: 1239px) {
  .brand-name {
    display: none;
  }
}

/* ---------- Tablet: panels drop down from the bar as popovers ---------- */

@media (min-width: 700px) and (max-width: 1099px) {
  .dock {
    top: calc(var(--bar) + var(--safe-top) + 8px);
    right: calc(10px + var(--safe-right));
    width: 350px;
    max-height: min(calc(100% - var(--bar) - var(--safe-top) - 24px), 620px);
    border-radius: 16px;
  }

  .tool-chip {
    left: calc(50% + 26px);
    right: auto;
    transform: translateX(-50%);
  }

  .dock[data-side="left"] {
    right: auto;
    left: calc(10px + var(--safe-left));
  }
}

/* ---------- Desktop: a tablet-shaped studio with the settings docked beside it ---------- */

@media (min-width: 1100px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 360px;
  }

  .dock {
    position: static;
    display: flex;
    border-width: 0 0 0 1px;
    box-shadow: none;
    padding-right: var(--safe-right);
  }

  .panel-close,
  .tool-chip {
    display: none;
  }

  .toast {
    top: 12px;
  }

  .canvas-wrap {
    padding: 24px 24px 24px 76px;
  }
}

/* With a mouse the studio sits inside a tablet-style frame; on a real tablet the screen is the frame. */
@media (min-width: 1100px) and (hover: hover) and (pointer: fine) {
  .app {
    gap: 16px;
    padding: 18px;
  }

  .device {
    border: 10px solid #050505;
    border-radius: 30px;
    outline: 1px solid var(--line);
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  }

  .dock {
    border-width: 1px;
    border-radius: 20px;
    padding-right: 0;
  }
}

/* While an export runs the drawing is locked, so the result matches what was on screen. */
.is-exporting .bar,
.is-exporting .dock,
.is-exporting .timeline,
.is-exporting .rail,
.is-exporting .tool-chip,
.is-exporting .zoom-chip {
  pointer-events: none;
  opacity: 0.55;
}

@media (prefers-reduced-motion: reduce) {
  .rain-layer span,
  .progress-pop.is-indeterminate #progressBar {
    animation: none;
  }

  #progressBar {
    transition: none;
  }
}

/* The Save button dims once everything is stored, so an unsaved change stands out. */
#saveButton.is-saved {
  opacity: 0.62;
}

#saveButton.is-failed {
  color: var(--accent-bright);
}
