@import url('https://fonts.googleapis.com/css2?family=DotGothic16&family=Press+Start+2P&display=swap');

:root {
  color-scheme: dark;
  --bg: #05060f;
  --bg-raised: #0f1a24;
  --bg-panel: rgba(20, 28, 40, 0.95);
  --border: rgba(62, 226, 203, 0.45);
  --border-strong: rgba(62, 226, 203, 0.75);
  --fg: #f4f7ff;
  --fg-muted: rgba(244, 247, 255, 0.7);
  --accent: #3ee2cb;
  --accent-strong: #70f6ff;
  --danger: #ff6b6b;
  --shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
  --left-width: 250px;
  --right-width: 260px;
  font-family: "Press Start 2P", "DotGothic16", "M PLUS 1p", system-ui, sans-serif;
  font-size: 13px;
  --slider-track: rgba(18, 26, 38, 0.92);
  --slider-track-shadow: rgba(10, 15, 24, 0.85);
  --slider-border: rgba(88, 196, 255, 0.5);
  --slider-highlight: rgba(88, 196, 255, 0.24);
  --slider-thumb: #ffffff;
  --slider-thumb-shadow: rgba(4, 10, 18, 0.55);
  --slider-thumb-size: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background-color: var(--bg);
  background-image:
    linear-gradient(0deg, rgba(112, 246, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 1px 1px, rgba(112, 246, 255, 0.08) 0, transparent 40%);
  background-size: 8px 8px, 8px 8px, 32px 32px;
  color: var(--fg);
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

body {
  display: flex;
  min-height: 100vh;
  text-rendering: optimizeLegibility;
  image-rendering: pixelated;
}

button,
.button,
.button *,
.tool-button,
.tool-button *,
.pixel-button,
.pixel-button *,
.mobile-tab,
.mobile-tab *,
.mobile-shortcut,
.mobile-shortcut *,
.timeline-frame-button,
.timeline-frame-button *,
.timeline-layer-tag,
.timeline-layer-tag *,
.timeline-visibility,
.timeline-visibility *,
.timeline-slot,
.timeline-slot *,
.canvas-controls button,
.canvas-controls button * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-user-drag: none;
}

svg,
img,
.tab-icon,
.tab-icon-container,
.tab-swatch,
.pixel-frame {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-user-drag: none;
}

[hidden] {
  display: none !important;
}

.update-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  max-width: min(320px, 90vw);
  background: rgba(12, 20, 32, 0.94);
  border: 1px solid rgba(112, 246, 255, 0.35);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(6, 18, 36, 0.55);
  backdrop-filter: blur(12px);
  animation: toast-in 0.28s ease;
}

.update-toast__body {
  display: grid;
  gap: 0.9rem;
  padding: 1.1rem 1.2rem;
}

.update-toast__message {
  margin: 0;
  color: var(--fg);
  font-size: 0.88rem;
  line-height: 1.5;
}

.update-toast__actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.update-toast__btn {
  flex: 1 1 auto;
  min-width: 120px;
  padding: 0.55rem 1.1rem;
  border-radius: 12px;
  border: 1px solid rgba(112, 246, 255, 0.35);
  background: rgba(11, 26, 32, 0.75);
  color: var(--fg);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.update-toast__btn:hover,
.update-toast__btn:focus-visible {
  border-color: rgba(112, 246, 255, 0.7);
  transform: translateY(-1px);
  box-shadow: 0 12px 20px rgba(6, 20, 32, 0.4);
  outline: none;
}

.update-toast__btn--primary {
  background: linear-gradient(135deg, rgba(62, 226, 203, 0.95), rgba(112, 246, 255, 0.95));
  color: #031418;
  border-color: transparent;
}

.update-toast__btn--primary:hover,
.update-toast__btn--primary:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(62, 226, 203, 0.45);
}

@media (max-width: 640px) {
  .update-toast {
    left: 1rem;
    right: 1rem;
    bottom: env(safe-area-inset-bottom, 1rem);
  }
  .update-toast__actions {
    flex-direction: column;
  }
  .update-toast__btn {
    width: 100%;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

input[type='number'] {
  appearance: textfield;
}

input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.number-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.number-stepper input[type='number'] {
  width: 72px;
  text-align: center;
}

.number-stepper__btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 0;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    rgba(8, 20, 28, 0.9);
  background-size: 4px 4px;
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter 140ms ease;
}

.number-stepper__btn:hover {
  filter: brightness(1.08);
}

.number-stepper__btn:active {
  filter: brightness(1.15);
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tab-icon {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.45));
}

.tab-icon-container {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tab-icon-container img,
.tab-icon-container svg {
  width: 18px;
  height: 18px;
  display: block;
}

.tab-icon-container img {
  image-rendering: pixelated;
}

.pixel-frame {
  --pixel-frame-image: url('../icons/color.svg');
  background-image: var(--pixel-frame-image);
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.pixel-button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.86rem;
  line-height: 1;
  border: 2px solid var(--border);
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.18) 1px, transparent 1px),
    rgba(6, 18, 26, 0.9);
  background-size: 4px 4px;
  transition: filter 120ms ease, transform 120ms ease, border 120ms ease;
}

.pixel-button:active {
  transform: translateY(1px);
}

.pixel-button:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: 2px;
}

.tab-swatch {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 0;
}

.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  --left-toggle-offset: 12px;
  --right-toggle-offset: 12px;
}

.rail {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 0;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.08) 1px, transparent 1px),
    var(--bg-panel);
  background-size: 8px 8px;
  box-shadow:
    inset 0 0 0 2px rgba(5, 10, 16, 0.9),
    0 0 0 2px rgba(4, 12, 20, 0.85),
    var(--shadow);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  transition: transform 200ms ease;
  z-index: 20;
}

.rail::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.rail-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.rail-tab {
  flex: 1;
  padding: 6px 10px;
  border-radius: 0;
  border: 2px solid transparent;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.25) 1px, transparent 1px),
    rgba(8, 16, 24, 0.85);
  background-size: 4px 4px;
  color: var(--fg-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 160ms ease, color 160ms ease, border 160ms ease, filter 160ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.rail-tab:hover {
  color: var(--fg);
  border-color: var(--border);
  filter: brightness(1.1);
}

.rail-tab.is-active {
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.45) 1px, transparent 1px),
    rgba(12, 28, 36, 0.95);
  border-color: var(--border-strong);
  color: var(--fg);
}

.rail-tab:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.75);
  outline-offset: 2px;
}

.rail-tabpanes {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 16px;
}

.rail-tabpanes > .panel-section {
  flex: 1;
  overflow: auto;
}

.tool-group-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tool-group-button {
  padding: 8px 10px;
  border: 2px solid var(--border);
  border-radius: 0;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.18) 1px, transparent 1px),
    rgba(12, 16, 24, 0.86);
  background-size: 4px 4px;
  color: var(--fg-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: filter 160ms ease, color 160ms ease, border 160ms ease;
}

.tool-group-button:hover {
  filter: brightness(1.08);
  color: var(--fg);
  border-color: var(--border-strong);
}

.tool-group-button.is-active {
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.28) 1px, transparent 1px),
    rgba(16, 30, 42, 0.95);
  border-color: var(--border-strong);
  color: var(--fg);
}

.tool-group-button:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.75);
  outline-offset: 2px;
}

.tool-grid[data-active-group] {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 12px;
}

.rail--left {
  left: 0;
  width: var(--left-width);
  border-right: 1px solid var(--border);
  transform: translateX(0);
}

.rail--left[data-collapsed="true"] {
  transform: translateX(calc(-100% - 24px));
}

.rail--right {
  right: 0;
  width: var(--right-width);
  border-right: none;
  border-left: 2px solid var(--border);
  transform: translateX(0);
}

.rail--right[data-collapsed="true"] {
  transform: translateX(calc(100% + 24px));
}

.stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 24px;
  min-width: 0;
  z-index: 10;
}

.stage__canvas {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(112, 246, 255, 0.12) 1px, transparent 1px),
    linear-gradient(0deg, rgba(112, 246, 255, 0.12) 1px, transparent 1px),
    rgba(8, 18, 26, 0.85);
  background-size: 8px 8px;
  box-shadow:
    inset 0 0 0 2px rgba(5, 10, 16, 0.9),
    0 4px 0 rgba(8, 20, 28, 0.8),
    0 0 22px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.canvas-stack {
  position: relative;
  display: inline-flex;
  --tile-size: 16;
  --tile-screen-size: 16px;
  --tile-offset-x: 0px;
  --tile-offset-y: 0px;
  --tile-color-a: #ffffff;
  --tile-color-b: #f2f2f4;
  --grid-screen-step: 16px;
  --grid-major-step: 128px;
  --grid-offset-x: 0px;
  --grid-offset-y: 0px;
  --grid-major-offset-x: 0px;
  --grid-major-offset-y: 0px;
  --grid-color: rgba(255, 255, 255, 0.18);
  --grid-major-color: rgba(255, 255, 255, 0.35);
  --grid-line-width: 1px;
  --grid-major-line-width: 1px;
  background-color: var(--tile-color-b);
  background-image: repeating-conic-gradient(
    var(--tile-color-a) 0deg 90deg,
    var(--tile-color-b) 90deg 180deg
  );
  background-size: calc(var(--tile-screen-size) * 2) calc(var(--tile-screen-size) * 2);
  background-position: var(--tile-offset-x) var(--tile-offset-y);
  border: 1px solid var(--border-strong);
  border-radius: 0;
}

.canvas-stack[data-background='dark'] {
  --tile-color-a: #343844;
  --tile-color-b: #1c1f27;
  --grid-color: rgba(220, 225, 233, 0.3);
  --grid-major-color: rgba(242, 244, 248, 0.55);
}

.canvas-stack[data-background='light'] {
  --tile-color-a: #ffffff;
  --tile-color-b: #ececf0;
  border-color: rgba(0, 0, 0, 0.12);
  --grid-color: rgba(20, 26, 36, 0.27);
  --grid-major-color: rgba(10, 15, 25, 0.45);
}

.canvas-stack[data-background='pink'] {
  --tile-color-a: #ffeef5;
  --tile-color-b: #ffd5e6;
  border-color: rgba(215, 120, 150, 0.35);
  --grid-color: rgba(160, 40, 90, 0.28);
  --grid-major-color: rgba(180, 20, 80, 0.45);
}

.canvas-stack.is-flat {
  background-image: none;
}

.canvas-stack::before,
.canvas-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.canvas-stack::before {
  z-index: 1;
  background-image:
    repeating-linear-gradient(
      0deg,
      var(--grid-color),
      var(--grid-color) var(--grid-line-width),
      transparent var(--grid-line-width),
      transparent var(--grid-screen-step)
    ),
    repeating-linear-gradient(
      90deg,
      var(--grid-color),
      var(--grid-color) var(--grid-line-width),
      transparent var(--grid-line-width),
      transparent var(--grid-screen-step)
    );
  background-size: var(--grid-screen-step) var(--grid-screen-step), var(--grid-screen-step) var(--grid-screen-step);
  background-position:
    var(--grid-offset-x) var(--grid-offset-y),
    var(--grid-offset-x) var(--grid-offset-y);
}

.canvas-stack::after {
  z-index: 1;
  background-image:
    repeating-linear-gradient(
      0deg,
      var(--grid-major-color),
      var(--grid-major-color) var(--grid-major-line-width),
      transparent var(--grid-major-line-width),
      transparent var(--grid-major-step)
    ),
    repeating-linear-gradient(
      90deg,
      var(--grid-major-color),
      var(--grid-major-color) var(--grid-major-line-width),
      transparent var(--grid-major-line-width),
      transparent var(--grid-major-step)
    );
  background-size: var(--grid-major-step) var(--grid-major-step), var(--grid-major-step) var(--grid-major-step);
  background-position:
    var(--grid-major-offset-x) var(--grid-major-offset-y),
    var(--grid-major-offset-x) var(--grid-major-offset-y);
}

.canvas-stack[data-grid='true']::before {
  opacity: 1;
}

.canvas-stack[data-major-grid='true']::after {
  opacity: 1;
}

.canvas-stack canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  pointer-events: none;
}

#drawingCanvas {
  pointer-events: auto;
  touch-action: none;
}

#overlayCanvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}

#selectionCanvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  pointer-events: none;
}

#virtualCursorCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
  touch-action: none;
}

body.is-startup-active #virtualCursorCanvas {
  display: none;
}

.canvas-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  background: rgba(13, 17, 24, 0.6);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.canvas-controls[data-mobile='true'] {
  position: static;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  gap: 8px;
}

.canvas-controls[data-mobile='true'] .canvas-control-buttons {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.zoom-indicator {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 6px 12px;
  background: rgba(8, 18, 26, 0.85);
  border: 1px solid rgba(112, 246, 255, 0.35);
  color: var(--fg);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 160ms ease, transform 160ms ease;
  text-shadow: 0 0 6px rgba(5, 12, 18, 0.75);
  border-radius: 0;
  z-index: 4;
}

.zoom-indicator.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.floating-draw-button {
  --floating-draw-button-scale: 2;
  --floating-draw-button-x: 16px;
  --floating-draw-button-y: 16px;
  position: fixed;
  top: 0;
  left: 0;
  transform-origin: top left;
  transform:
    translate(var(--floating-draw-button-x), var(--floating-draw-button-y))
    scale(var(--floating-draw-button-scale));
  padding: 10px 18px;
  background: rgba(255, 168, 82, 0.28);
  color: var(--fg);
  font-weight: 600;
  border: 1px solid rgba(255, 168, 82, 0.78);
  border-radius: 0;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.65),
    0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  z-index: 2000;
}

.floating-draw-button.is-hidden {
  display: none;
}

.floating-draw-button:active {
  background: rgba(255, 168, 82, 0.4);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 2px 8px rgba(0, 0, 0, 0.36);
}

.floating-draw-button.is-disabled {
  opacity: 0.55;
  cursor: default;
  background: rgba(255, 168, 82, 0.16);
}

.floating-draw-button.is-disabled:active {
  background: rgba(255, 168, 82, 0.16);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.65),
    0 4px 12px rgba(0, 0, 0, 0.4);
}

.canvas-control-buttons.is-clipboard-mode .chip {
  color: var(--fg);
}

.rail-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 72px;
  border-radius: 0;
  border: 2px solid var(--border);
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    rgba(7, 16, 24, 0.9);
  background-size: 4px 4px;
  color: var(--fg);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 0 0 2px rgba(4, 12, 20, 0.85), 0 10px 20px rgba(0, 0, 0, 0.45);
  z-index: 40;
}

.rail-toggle:hover {
  filter: brightness(1.1);
}

.rail-toggle--left {
  left: var(--left-toggle-offset);
}

.rail-toggle--right {
  right: var(--right-toggle-offset);
}

.rail-toggle.is-visible {
  display: inline-flex;
}


.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 0;
  border: 2px solid var(--border);
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    rgba(8, 20, 28, 0.9);
  background-size: 4px 4px;
  color: var(--fg);
  transition: filter 140ms ease, border 140ms ease, transform 140ms ease;
}
.chip.is-active {
  border-color: var(--border-strong);
  filter: brightness(1.05);
}

.chip:hover {
  filter: brightness(1.1);
}

.chip:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.chip:active {
  transform: translateY(1px);
}

.canvas-controls .chip {
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.canvas-control-buttons {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.canvas-control-buttons.is-clipboard-mode .chip {
  color: var(--fg);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.12) 1px, transparent 1px),
    rgba(8, 16, 22, 0.92);
  background-size: 6px 6px;
  border: 2px solid var(--border);
  border-radius: 0;
  padding: 18px;
  box-shadow:
    inset 0 0 0 2px rgba(5, 10, 16, 0.9),
    0 4px 0 rgba(8, 16, 22, 0.85),
    0 0 22px rgba(0, 0, 0, 0.6);
}

.panel-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-section__header h2 {
  font-size: 1.05rem;
  margin: 0;
  letter-spacing: 0.04em;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field span,
.field legend {
  font-size: 0.78rem;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
}

.field input,
.field select {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(11, 15, 20, 0.8);
  padding: 6px 10px;
  color: inherit;
  outline: none;
  transition: border 120ms ease, box-shadow 120ms ease;
}

.field input:focus-visible,
.field select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88, 196, 255, 0.35);
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: transparent;
  margin: 6px 0;
}

input[type='range']:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 8px;
  border: 2px solid var(--slider-border);
  background: var(--slider-track);
  box-shadow: none;
  border-radius: 0;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--slider-thumb-size);
  height: var(--slider-thumb-size);
  background: var(--slider-thumb);
  border: 1px solid var(--slider-border);
  box-shadow: none;
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 0);
  margin-top: calc(((var(--slider-thumb-size) - 8px) / -2) - 1px);
  cursor: pointer;
}

input[type='range']::-webkit-slider-thumb:active {
  filter: brightness(1.1);
}

input[type='range']::-moz-range-track {
  height: 8px;
  border: 2px solid var(--slider-border);
  background: var(--slider-track);
  box-shadow: none;
  border-radius: 0;
}

input[type='range']::-moz-range-thumb {
  width: var(--slider-thumb-size);
  height: var(--slider-thumb-size);
  border: 1px solid var(--slider-border);
  background: var(--slider-thumb);
  box-shadow: none;
  clip-path: polygon(0 0, 0 100%, 100% 100%, 100% 0);
  cursor: pointer;
}

input[type='range']::-moz-range-progress {
  background: rgba(88, 196, 255, 0.35);
}

input[type='range']::-moz-focus-outer {
  border: 0;
}

#paletteHue::-webkit-slider-runnable-track,
#paletteHue::-moz-range-track {
  background: linear-gradient(
    90deg,
    #ff001a 0%,
    #ffbe00 17%,
    #66ff35 33%,
    #00d0ff 50%,
    #3a2bff 67%,
    #ff2df6 83%,
    #ff001a 100%
  );
}

#paletteSaturation::-webkit-slider-runnable-track,
#paletteSaturation::-moz-range-track {
  background: linear-gradient(90deg, #5d6675 0%, var(--accent) 100%);
}

#paletteValue::-webkit-slider-runnable-track,
#paletteValue::-moz-range-track {
  background: linear-gradient(90deg, #0c0f16 0%, #ffffff 100%);
}

#paletteAlphaSlider::-webkit-slider-runnable-track,
#paletteAlphaSlider::-moz-range-track {
  background:
    linear-gradient(90deg, rgba(88, 196, 255, 0) 0%, rgba(88, 196, 255, 1) 100%),
    linear-gradient(135deg, #161c28 25%, #0d1118 25%, #0d1118 50%, #161c28 50%, #161c28 75%, #0d1118 75%, #0d1118 100%);
  background-size: 100% 100%, 12px 12px;
}

#brushSize::-webkit-slider-runnable-track,
#brushSize::-moz-range-track {
  background: linear-gradient(90deg, #252d3c 0%, #58c4ff 100%);
}

#zoomSlider::-webkit-slider-runnable-track,
#zoomSlider::-moz-range-track {
  background: linear-gradient(90deg, #1a2230 0%, rgba(88, 196, 255, 0.85) 100%);
}

#virtualCursorButtonScale::-webkit-slider-runnable-track,
#virtualCursorButtonScale::-moz-range-track {
  background: linear-gradient(90deg, rgba(62, 226, 203, 0.25) 0%, rgba(112, 246, 255, 0.85) 100%);
}

#exportScaleSlider::-webkit-slider-runnable-track,
#exportScaleSlider::-moz-range-track {
  background: linear-gradient(90deg, rgba(88, 196, 255, 0.2) 0%, rgba(88, 196, 255, 0.9) 100%);
}

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

.field--inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.field--list {
  gap: 16px;
}

.toggle-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-option {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  color: inherit;
}

.toggle-option input[type='checkbox'] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.virtual-cursor-scale {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.virtual-cursor-scale__control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
}

.virtual-cursor-scale__label {
  color: var(--fg-muted);
}

#virtualCursorButtonScale {
  width: 100%;
}

.virtual-cursor-scale__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--fg-muted);
}

.virtual-cursor-scale__ticks {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex: 1;
}

.virtual-cursor-scale__value {
  font-weight: 600;
  color: var(--fg);
}

.field--list > .chip {
  align-self: flex-start;
}

.field--compact input {
  max-width: 120px;
}

.field--tiny {
  gap: 4px;
}

.field--tiny input {
  width: 64px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 12px;
}

.tool-button {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 12px 8px 10px;
  border: 2px solid var(--border);
  border-radius: 0;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.16) 1px, transparent 1px),
    rgba(9, 18, 26, 0.9);
  background-size: 4px 4px;
  color: var(--fg-muted);
  transition: filter 160ms ease, color 160ms ease, border 160ms ease;
}

.tool-icon,
.tool-button img {
  display: block;
  width: 32px;
  height: 32px;
}

.tool-button span {
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

.tool-button:hover {
  filter: brightness(1.1);
  color: var(--fg);
}

.tool-button.is-active {
  border-color: var(--border-strong);
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.28) 1px, transparent 1px),
    rgba(12, 26, 34, 0.95);
  color: var(--fg);
  box-shadow: 0 0 0 2px rgba(112, 246, 255, 0.32) inset;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 10px;
  gap: 12px;
}

.palette-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
  box-sizing: border-box;
}

.palette-swatch {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: none;
  cursor: pointer;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
  transition: transform 120ms ease, filter 120ms ease;
}

.palette-swatch::after {
  content: attr(data-index);
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 0.7rem;
  color: #0d0f14;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 2px 6px;
  pointer-events: none;
  z-index: 2;
}

.palette-swatch:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.75);
  outline-offset: 3px;
}

.palette-swatch:hover {
  transform: translateY(-1px) scale(1.02);
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.36));
}

.palette-swatch.is-active {
  filter: drop-shadow(0 10px 20px rgba(88, 196, 255, 0.35));
  outline: 2px solid rgba(88, 196, 255, 0.55);
  outline-offset: 2px;
}

.palette-editor {
  display: grid;
  gap: 14px;
  margin: 0 -18px;
  padding: 18px;
  border-radius: 0;
  border: 0;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.08) 1px, transparent 1px),
    rgba(6, 16, 22, 0.92);
  background-size: 6px 6px;
  overflow: hidden;
}

.palette-hsv {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-start;
  justify-content: center;
}

.palette-wheel {
  position: relative;
  width: min(176px, 100%);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.palette-wheel canvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.45);
  cursor: crosshair;
  display: block;
}

.palette-wheel__cursor {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.palette-sliders {
  flex: 0 0 auto;
  width: min(176px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 auto;
}

.palette-sliders .field {
  margin-bottom: 6px;
}

.palette-preview {
  width: 100%;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: repeating-conic-gradient(#1e1e1e 0 25%, #2c2c2c 0 50%);
  background-size: 16px 16px;
  position: relative;
  overflow: hidden;
}

.palette-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: transparent;
}

.palette-preview.is-filled::after {
  background: var(--palette-preview-color, transparent);
}

.palette-alpha-field {
  position: relative;
}

.palette-alpha-field output {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  font-size: 0.78rem;
  color: var(--fg-muted);
}

.timeline-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border-radius: 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
}


.timeline-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.timeline-toolbar__group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.timeline-toolbar__label {
  font-size: 0.72rem;
  color: var(--fg-muted);
  letter-spacing: 0.08em;
}

.timeline-matrix-wrapper {
  --timeline-cell-size: 32px;
  overflow: auto;
  border-radius: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(7, 10, 16, 0.7);
  max-height: 260px;
}

.timeline-matrix {
  display: grid;
  position: relative;
  width: max-content;
  min-width: 100%;
}

.timeline-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 2px;
  min-width: var(--timeline-cell-size);
  min-height: var(--timeline-cell-size);
  max-width: var(--timeline-cell-size);
  max-height: var(--timeline-cell-size);
}

.timeline-cell--corner,
.timeline-cell--frame-header {
  position: sticky;
  top: 0;
  backdrop-filter: blur(6px);
  z-index: 4;
  justify-content: center;
}

.timeline-cell--corner {
  left: 0;
  z-index: 5;
}

.timeline-cell--layer {
  position: sticky;
  left: 0;
  backdrop-filter: blur(6px);
  z-index: 3;
  justify-content: space-between;
  padding: 0 4px;
}

.timeline-cell--layer.is-active-layer {
  box-shadow: inset 3px 0 0 rgba(88, 196, 255, 0.7);
}

.timeline-cell--layer.is-placeholder {
  justify-content: center;
  color: var(--fg-muted);
  font-size: 0.72rem;
  opacity: 0.6;
  pointer-events: none;
}

.timeline-layer-tag {
  flex: 1;
  text-align: center;
  background: transparent;
  border: none;
  color: inherit;
  font-size: 0.72rem;
  padding: 0;
  cursor: pointer;
  letter-spacing: 0.02em;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.timeline-layer-tag:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.65);
  outline-offset: 2px;
}

.timeline-cell--layer.is-active-layer .timeline-layer-tag {
  font-weight: 600;
}

.timeline-visibility {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(88, 196, 255, 0.6);
  color: rgba(10, 14, 20, 0.9);
  font-size: 0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 140ms ease, border 140ms ease, color 140ms ease;
}

.timeline-visibility[aria-pressed='false'] {
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  border-color: rgba(255, 255, 255, 0.2);
}

.timeline-visibility:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.65);
  outline-offset: 1px;
}

.timeline-cell--frame-header.is-active-frame {
  box-shadow: inset 0 -3px 0 rgba(88, 196, 255, 0.7);
}

.timeline-frame-button {
  width: 100%;
  height: 100%;
  padding: 0;
  border-radius: 4px;
  border: none;
  background: none;
  color: inherit;
  text-align: center;
  font-size: 0.78rem;
  transition: transform 140ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timeline-frame-button:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.7);
  outline-offset: 2px;
}

.timeline-slot {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 140ms ease;
}

.timeline-slot:focus-visible {
  outline: 2px solid rgba(88, 196, 255, 0.7);
  outline-offset: 2px;
}

.timeline-slot.is-hidden {
  opacity: 0.55;
}

.timeline-slot.is-active .timeline-slot__marker {
  transform: scale(1.2);
}

.timeline-slot.is-disabled {
  pointer-events: none;
  opacity: 0.35;
}

.timeline-slot__marker {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(88, 196, 255, 0.7);
  transition: transform 140ms ease, background 140ms ease;
}

.timeline-slot.is-hidden .timeline-slot__marker {
  background: rgba(125, 132, 150, 0.45);
}

.timeline-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline-playback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  max-width: 160px;
  margin: 0 auto;
}

.timeline-playback .pixel-button {
  flex: 0 0 36px;
}

.timeline-fps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.timeline-fps-control {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.timeline-fps-control > span {
  line-height: 1;
}

.timeline-fps-control .number-stepper {
  flex: 0 0 auto;
}

.timeline-fps-hint {
  font-size: 0.875rem;
  opacity: 0.8;
  flex: 0 0 auto;
}
.list-actions {
  display: inline-flex;
  gap: 8px;
}

.visibility-toggle {
  width: 28px;
  height: 28px;
  border-radius: 0;
  border: 2px solid var(--border);
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.18) 1px, transparent 1px),
    rgba(6, 16, 24, 0.9);
  background-size: 4px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 0;
  border: 2px solid var(--border);
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.2) 1px, transparent 1px),
    rgba(8, 20, 28, 0.9);
  background-size: 4px 4px;
  color: var(--fg);
  transition: filter 140ms ease, border 140ms ease, transform 140ms ease;
}

.button:hover {
  filter: brightness(1.08);
  border-color: var(--border-strong);
}

#clearCanvas {
  background: rgba(255, 107, 107, 0.22);
  border-color: rgba(255, 107, 107, 0.4);
}

#clearCanvas:hover {
  background: rgba(255, 107, 107, 0.32);
  border-color: rgba(255, 107, 107, 0.52);
}

.button--ghost {
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.12) 1px, transparent 1px),
    rgba(6, 16, 24, 0.9);
  border-color: rgba(62, 226, 203, 0.35);
}

.button--ghost:hover {
  filter: brightness(1.1);
}

.button--primary {
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.38) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.38) 1px, transparent 1px),
    rgba(20, 48, 60, 0.95);
  border-color: var(--accent);
  color: var(--fg);
  font-weight: 600;
}

.button--primary:hover {
  filter: brightness(1.1);
}

#panelSettings .button {
  display: flex;
  width: 100%;
}

#panelSettings .button + .button {
  margin-top: 8px;
}

body.is-startup-active {
  overflow: hidden;
}

.startup-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 520;
}

.startup-screen[hidden] {
  display: none;
}

.startup-screen__backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top, rgba(88, 196, 255, 0.22), rgba(6, 12, 20, 0.86));
  backdrop-filter: blur(8px);
}

.startup-screen__content {
  position: relative;
  width: min(100%, 420px);
  padding: 36px 40px;
  border-radius: 24px;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.14) 1px, transparent 1px),
    var(--bg-panel);
  border: 1px solid rgba(112, 246, 255, 0.28);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
}

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

.startup-screen__title {
  margin: 0;
  font-size: clamp(1.8rem, 2.4vw + 1.2rem, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.startup-screen__subtitle {
  margin: 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.95rem;
}

.startup-screen__actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.startup-screen__actions .button {
  width: 100%;
  font-size: 1rem;
  padding-block: 14px;
}

.startup-screen__link {
  background: none;
  border: none;
  font: inherit;
  color: rgba(112, 246, 255, 0.85);
  cursor: pointer;
  text-decoration: underline;
}

.startup-screen__link:hover {
  color: #70f6ff;
}

.startup-screen__hint {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
}

.startup-screen__recent {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.startup-screen__recent-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
}

.startup-recent-list {
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  width: 100%;
  overflow-x: auto;
  padding: 4px 4px 12px;
  margin: 0 -4px;
  scroll-snap-type: x mandatory;
}

.startup-recent-list::-webkit-scrollbar {
  height: 6px;
}

.startup-recent-list::-webkit-scrollbar-thumb {
  background: rgba(112, 246, 255, 0.28);
  border-radius: 999px;
}

.startup-recent-list::-webkit-scrollbar-track {
  background: rgba(6, 12, 20, 0.4);
}

.startup-recent-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background:
    linear-gradient(0deg, rgba(112, 246, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(112, 246, 255, 0.08) 1px, transparent 1px),
    rgba(10, 22, 32, 0.92);
  border: 1px solid rgba(112, 246, 255, 0.2);
  cursor: pointer;
  color: inherit;
  font: inherit;
  text-align: center;
  outline: none;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  scroll-snap-align: start;
  flex: 0 0 148px;
}

.startup-recent-card:hover,
.startup-recent-card:focus-visible {
  border-color: rgba(112, 246, 255, 0.6);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  transform: translateY(-2px);
}

.startup-recent-card:disabled {
  opacity: 0.6;
  cursor: progress;
}

.startup-recent-card__thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(20, 30, 44, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(112, 246, 255, 0.12);
}

.startup-recent-card__thumb img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  object-fit: contain;
}

.startup-recent-card__thumb-placeholder {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
}

.startup-recent-card__name {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.82);
  word-break: break-all;
}

@media (min-width: 600px) {
  .startup-screen__actions {
    flex-direction: row;
  }

  .startup-screen__actions .button {
    flex: 1 1 auto;
  }
}

.modal {
  border: none;
  border-radius: 18px;
  padding: 0;
  background: var(--bg-panel);
  color: inherit;
  box-shadow: var(--shadow);
  min-width: 320px;
  max-width: min(420px, 90vw);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.modal__form {
  display: flex;
  flex-direction: column;
}

.modal__header,
.modal__body,
.modal__footer {
  padding: 20px;
}

.modal__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 0;
}

.modal__title {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

.modal__form .field {
  margin-bottom: 16px;
}

.modal__form .field:last-of-type {
  margin-bottom: 0;
}

.modal__form .field--inline {
  align-items: flex-start;
}

.modal__form .field--inline > span {
  padding-top: 8px;
}

.modal__form .field--inline .field--tiny {
  align-items: flex-start;
}

.new-project__name-field {
  gap: 8px;
}

.new-project__name-input {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.new-project__name-input input {
  flex: 0 1 220px;
  min-width: 160px;
  max-width: 100%;
}

.new-project__name-suffix {
  font-size: 0.85rem;
  color: var(--fg-muted);
  white-space: nowrap;
}

.new-project__size-fields {
  align-items: center;
  gap: 12px 16px;
}

.new-project__size-fields > span {
  padding-top: 0;
  min-width: 100px;
}

.new-project__size-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.new-project__size-inputs .field {
  margin: 0;
}

.help-text {
  margin-top: 8px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--fg-muted);
}

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

.export-guidance .help-text:first-child {
  margin-top: 0;
}

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

@media (min-width: 600px) {
  .export-actions {
    flex-direction: row;
  }

  .export-actions .button {
    flex: 1 1 0;
  }
}

.mobile-topbar {
  display: none;
  background: rgba(12, 16, 24, 0.92);
  border-bottom: 1px solid var(--border);
}

.mobile-topbar__inner {
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.mobile-shortcuts {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.mobile-drawer {
  position: relative;
  display: block;
  background: rgba(12, 16, 24, 0.92);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.mobile-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  flex: 1 1 auto;
}

.mobile-tab {
  flex: 1 1 0;
  padding: 10px 6px;
  color: var(--fg-muted);
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-tab.is-active {
  color: var(--fg);
  border-color: var(--accent);
  background: rgba(88, 196, 255, 0.14);
}

.mobile-panels {
  position: relative;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: none;
}

.mobile-panels::-webkit-scrollbar {
  display: none;
}

.mobile-panel {
  display: none;
}

.mobile-panel.is-active {
  display: block;
}

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

@media (max-width: 1280px) {
  :root {
    --left-width: 220px;
    --right-width: 240px;
  }
}

@media (max-width: 1024px) {
  :root {
    --left-width: 200px;
    --right-width: 220px;
  }
  .tool-grid {
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  }
}

@media (max-width: 900px) {
  :root {
    --left-width: 180px;
    --right-width: 200px;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  :root {
    --mobile-banner-height: 48px;
    --mobile-drawer-height: 38vh;
    --mobile-stage-padding: 1px;
    --mobile-topbar-height: 110px;
    --mobile-safe-area-bottom: env(safe-area-inset-bottom, 0px);
  }
  body {
    min-height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
  }
  .app {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .app-banner {
    display: flex;
    min-height: var(--mobile-banner-height);
  }
  .mobile-topbar {
    display: block;
  }
  .mobile-tab .tab-icon-container,
  .mobile-tab .tab-icon-container img,
  .mobile-tab .tab-icon-container svg {
    width: 22px;
    height: 22px;
  }
  .panel-section[data-section='tools'] .tool-group-tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 12px;
  }
  .panel-section[data-section='tools'] .tool-group-button {
    padding: 6px 8px;
    font-size: 0.86rem;
    letter-spacing: 0.02em;
    min-width: 0;
    white-space: nowrap;
  }
  .layout {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }
  .rail--left,
  .rail--right {
    display: none;
  }
  .stage {
    position: relative;
    inset: auto;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    padding: var(--mobile-stage-padding);
    width: 100%;
    overflow: hidden;
    contain: layout paint size;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .stage__canvas {
    position: relative;
    width: min(
      calc(100vw - (var(--mobile-stage-padding) * 2)),
      calc(100vh - var(--mobile-banner-height) - var(--mobile-topbar-height) - var(--mobile-drawer-height))
    );
    height: min(
      calc(100vw - (var(--mobile-stage-padding) * 2)),
      calc(100vh - var(--mobile-banner-height) - var(--mobile-topbar-height) - var(--mobile-drawer-height))
    );
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .canvas-stack {
    max-width: none;
    max-height: none;
  }
  .mobile-drawer {
    display: block !important;
    flex: none;
    height: var(--mobile-drawer-height);
    max-height: var(--mobile-drawer-height);
    min-height: 0;
    overflow: hidden;
    border-radius: 0;
    contain: layout paint size;
  }
  .mobile-panels {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 10px;
    padding-bottom: calc(10px + max(24px, var(--mobile-safe-area-bottom)));
    scroll-padding-bottom: calc(24px + var(--mobile-safe-area-bottom));
  }
  .mobile-panel.is-active {
    display: block;
    height: 100%;
    overflow: visible;
  }
  .mobile-panel.is-active > .panel-section {
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .mobile-panel.is-active > .panel-section .panel-section__body {
    flex: 1 1 auto;
    overflow-y: auto;
    scrollbar-width: none;
    padding-bottom: max(24px, var(--mobile-safe-area-bottom));
  }

  .mobile-panel.is-active > .panel-section .panel-section__body::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 600px) {
  .panel-section {
    padding: 14px;
  }
  .palette-editor {
    margin: 0;
    padding: 16px;
    width: 100%;
    box-sizing: border-box;
  }
  .palette-grid {
    gap: 6px;
  }
  .tool-grid {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  }
}

.panel-section--mobile {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}

.panel-section--mobile .panel-section__header {
  padding: 0 0 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}

.panel-section--mobile .panel-section__body {
  padding-left: 0;
  padding-right: 0;
  overflow-x: hidden;
}

.mobile-panel .panel-section {
  margin-bottom: 16px;
}
:root {
*** End Patch
  .tool-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  .tool-grid .tool-button {
    flex: 1 1 calc(33.333% - 12px);
    min-width: 80px;
  }
}
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
