/* ==========================================================================
   PIXELSTUDIO — retro 8-bit/16-bit drawing studio
   style.css · deep-space arcade theme, chunky 3D buttons, CRT scanlines
   ========================================================================== */

/* ------------------------------- TOKENS --------------------------------- */
:root {
  --bg-0: #07020f;
  --bg-1: #0b0418;
  --bg-2: #14082b;
  --bg-3: #1d0f3d;
  --panel: #170a30;
  --panel-2: #1f0f3f;
  --ink: #f4ecff;
  --ink-dim: #b7a8d8;
  --ink-faint: #7d6fa3;

  --pink: #ff2e88;
  --pink-dark: #b3125a;
  --cyan: #22e6ff;
  --cyan-dark: #0b8ba0;
  --yellow: #ffe14d;
  --yellow-dark: #b39300;
  --green: #5cff9d;
  --purple: #9b5cff;
  --red: #ff4d4d;
  --orange: #ff9f45;

  --line: #341c60;
  --line-soft: rgba(155, 92, 255, 0.28);
  --check-a: #241239;
  --check-b: #180a29;

  --font-pixel: "Press Start 2P", "Courier New", ui-monospace, monospace;
  --font-body: "Noto Sans Devanagari", ui-monospace, "Courier New", monospace;

  --r: 4px;
  --shadow-hard: 0 4px 0 #05010c, 0 8px 22px rgba(0, 0, 0, 0.55);
  --glow-pink: 0 0 0 2px rgba(255, 46, 136, 0.35), 0 0 18px rgba(255, 46, 136, 0.45);
  --glow-cyan: 0 0 0 2px rgba(34, 230, 255, 0.3), 0 0 18px rgba(34, 230, 255, 0.4);
  --zoom: 1;
}

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

/* The `hidden` attribute must always win, even over display:flex etc. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, #2a0f52 0%, rgba(42, 15, 82, 0) 70%),
    radial-gradient(ellipse 60% 50% at 100% 100%, #24003f 0%, rgba(36, 0, 63, 0) 70%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

img,
canvas,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--cyan);
  text-decoration-color: rgba(34, 230, 255, 0.45);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--yellow);
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 999;
  padding: 10px 14px;
  background: var(--yellow);
  color: #16081f;
  font-family: var(--font-pixel);
  font-size: 9px;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 8px;
}

/* ------------------------------ BACKDROP -------------------------------- */
.starfield {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 78% 8%, #b9f4ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 34% 62%, #ffe9a8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 88% 44%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 58% 82%, #e4c8ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 88%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 66% 30%, #a8fff0 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 22% 40%, #fff 50%, transparent 51%);
  background-size: 220px 210px, 190px 230px, 260px 240px, 210px 200px, 240px 250px, 180px 190px, 200px 220px, 170px 210px;
  opacity: 0.55;
  animation: twinkle 6s steps(2, end) infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.38; }
  to { opacity: 0.62; }
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(4, 0, 10, 0.28) 0px,
    rgba(4, 0, 10, 0.28) 1px,
    rgba(255, 255, 255, 0.012) 2px,
    rgba(255, 255, 255, 0.012) 3px
  );
  opacity: 0;
  transition: opacity 0.25s linear;
}

body.crt-on .scanlines {
  opacity: 1;
}

body.crt-on::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 61;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.5) 100%);
}

/* Scanlines + vignette are decoration: keep them under dialogs and out of print */
body.modal-open .scanlines,
body.modal-open::after {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .starfield,
  .marquee-track {
    animation: none !important;
  }
}

/* ------------------------------ HEADER ---------------------------------- */
.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(29, 15, 61, 0.96), rgba(13, 5, 29, 0.96));
  border-bottom: 3px solid var(--line);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  font-size: 24px;
  background: linear-gradient(160deg, #2a1250, #12062a);
  border: 3px solid var(--pink);
  border-radius: 6px;
  box-shadow: 0 0 14px rgba(255, 46, 136, 0.5), inset 0 0 12px rgba(255, 46, 136, 0.25);
  animation: bob 2.4s steps(2, end) infinite alternate;
}

@keyframes bob {
  from { transform: translateY(0); }
  to { transform: translateY(-3px); }
}

.brand-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 3px 0 #4a0d2b, 0 0 18px rgba(255, 46, 136, 0.65);
}

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

.brand-tag {
  font-size: 12px;
  color: var(--ink-dim);
  max-width: 44ch;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.lang-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: #0b0418;
  border: 2px solid var(--line);
  border-radius: var(--r);
}

.lang-btn {
  padding: 8px 10px;
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.4;
  color: var(--ink-dim);
  background: transparent;
  border: 2px solid transparent;
  border-radius: 3px;
  transition: transform 0.08s ease, background 0.15s ease, color 0.15s ease;
}

.lang-btn:hover {
  color: #fff;
  background: rgba(155, 92, 255, 0.18);
}

.lang-btn.is-active {
  color: #17071f;
  background: var(--yellow);
  border-color: #fff3b0;
  box-shadow: 0 3px 0 var(--yellow-dark);
}

.lang-sep {
  color: var(--ink-faint);
  font-size: 11px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  min-height: 40px;
  background: linear-gradient(180deg, #2a1450, #170a30);
  border: 2px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 3px 0 #05010c;
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.5px;
  transition: transform 0.08s ease, box-shadow 0.08s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--cyan);
  box-shadow: 0 3px 0 #05010c, var(--glow-cyan);
}

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: none;
}

.icon-btn[aria-pressed="false"] {
  color: var(--ink-faint);
  background: linear-gradient(180deg, #1a0d33, #100620);
  border-color: #2a1750;
}

.icon-btn[aria-pressed="false"] .icon {
  filter: grayscale(1) brightness(0.75);
}

.icon-btn-help {
  border-color: var(--pink);
  box-shadow: 0 3px 0 #05010c, 0 0 12px rgba(255, 46, 136, 0.35);
}

.icon {
  font-size: 15px;
  line-height: 1;
}

.icon-label {
  display: inline;
}

/* ------------------------------ MARQUEE --------------------------------- */
.marquee {
  position: relative;
  z-index: 10;
  overflow: hidden;
  border-bottom: 2px solid var(--line);
  background: repeating-linear-gradient(90deg, rgba(255, 46, 136, 0.12) 0 14px, rgba(34, 230, 255, 0.09) 14px 28px);
}

.marquee-track {
  display: flex;
  gap: 40px;
  width: max-content;
  padding: 5px 0;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--yellow);
  letter-spacing: 1px;
  animation: marquee 26s linear infinite;
}

@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.noscript {
  margin: 16px;
  padding: 14px;
  border: 3px solid var(--red);
  background: #2a0a15;
  font-family: var(--font-pixel);
  font-size: 10px;
  line-height: 1.8;
}

/* ------------------------------ STUDIO ---------------------------------- */
.studio {
  position: relative;
  z-index: 5;
  flex: 1;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 306px;
  gap: 14px;
  padding: 14px 16px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, rgba(31, 15, 63, 0.96), rgba(17, 8, 36, 0.97));
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-hard), inset 0 0 0 2px rgba(255, 255, 255, 0.03);
  padding: 12px;
}

.tools-panel,
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--purple) #12062a;
}

.tools-panel::-webkit-scrollbar,
.side-panel::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 10px;
}

.tools-panel::-webkit-scrollbar-track,
.side-panel::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
  background: #12062a;
}

.tools-panel::-webkit-scrollbar-thumb,
.side-panel::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--purple), var(--pink-dark));
  border-radius: 8px;
}

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

.panel-title {
  font-family: var(--font-pixel);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.5px;
  color: var(--yellow);
  text-shadow: 0 2px 0 #3c2400;
}

.panel-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.mini-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.5px;
  color: var(--ink-dim);
  text-transform: uppercase;
}

.drawer-bar,
.drawer-close {
  display: none;
}

.help-dot {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  padding: 0;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #12061f;
  background: var(--cyan);
  border: 2px solid #0a3a44;
  border-radius: 50%;
  cursor: help;
  box-shadow: 0 2px 0 #061f26;
}

.help-dot:hover {
  background: var(--yellow);
}

/* Panels scroll as a whole, so children must keep their natural height
   (otherwise flexbox squeezes the palette / frame strip). */
.tools-panel > *,
.side-panel > * {
  flex: 0 0 auto;
}

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

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px 8px;
  min-height: 62px;
  color: var(--ink);
  background: linear-gradient(180deg, #331a5e 0%, #1d0e3a 100%);
  border: 2px solid #43278a;
  border-radius: 5px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), 0 4px 0 #0d0520, 0 6px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.07s ease, box-shadow 0.07s ease, border-color 0.12s ease, background 0.15s ease;
}

.tool-btn:hover {
  border-color: var(--cyan);
  background: linear-gradient(180deg, #3d2072 0%, #22103f 100%);
}

.tool-btn:active {
  transform: translateY(4px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08), 0 0 0 #0d0520;
}

.tool-btn.is-active {
  border-color: var(--yellow);
  background: linear-gradient(180deg, #6a2a4e 0%, #3d1030 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 225, 77, 0.4), 0 4px 0 #20040f, 0 0 16px rgba(255, 225, 77, 0.35);
}

.tool-icon {
  font-size: 19px;
  line-height: 1;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.5));
}

.tool-name {
  font-family: var(--font-pixel);
  font-size: 7px;
  line-height: 1.4;
  letter-spacing: 0.3px;
  text-align: center;
  color: var(--ink-dim);
}

.tool-btn.is-active .tool-name {
  color: var(--yellow);
}

.tool-toggle[aria-pressed="true"] {
  border-color: var(--green);
  box-shadow: inset 0 0 0 2px rgba(92, 255, 157, 0.3), 0 4px 0 #052010;
}

/* ------------------------------ MIRROR ---------------------------------- */
.mirror-block {
  padding: 8px;
  background: rgba(9, 3, 20, 0.55);
  border: 2px dashed var(--line-soft);
  border-radius: var(--r);
}

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

.seg-btn {
  min-height: 32px;
  padding: 4px 2px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--ink-dim);
  background: #1b0d34;
  border: 2px solid #34205f;
  border-radius: 3px;
  box-shadow: 0 2px 0 #07020f;
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}

.seg-btn:hover {
  color: #fff;
  border-color: var(--purple);
}

.seg-btn.is-active {
  color: #10051f;
  background: var(--cyan);
  border-color: #b6faff;
  box-shadow: 0 2px 0 var(--cyan-dark);
}

.seg-btn:active {
  transform: translateY(2px);
  box-shadow: none;
}

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

/* ------------------------------- BUTTONS -------------------------------- */
.btn,
.tool-btn,
.swatch,
.recent-swatch,
.stamp-btn,
.seg-btn,
.palette-tab,
.lang-btn,
.icon-btn,
.frame-card,
.modal-close,
.help-dot {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 11px;
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1.6;
  letter-spacing: 0.3px;
  color: var(--ink);
  background: linear-gradient(180deg, #2f1758 0%, #1a0c34 100%);
  border: 2px solid #442a7c;
  border-radius: var(--r);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.1), 0 4px 0 #08030f;
  transition: transform 0.07s ease, box-shadow 0.07s ease, filter 0.12s ease, border-color 0.12s ease;
  text-align: center;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.16);
  border-color: var(--cyan);
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 #08030f;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.65);
}

.btn-wide {
  width: 100%;
  justify-content: flex-start;
  padding-inline: 12px;
}

.btn-sq {
  min-width: 40px;
  padding: 8px;
  font-size: 12px;
}

.btn-zoom {
  min-width: 74px;
  font-size: 9px;
}

.btn-cyan {
  color: #041b20;
  background: linear-gradient(180deg, #5ef1ff 0%, #23c8e0 100%);
  border-color: #b8fbff;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55), 0 4px 0 #0a6f7d;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-pink {
  color: #2a0212;
  background: linear-gradient(180deg, #ff67a5 0%, #ff2e88 100%);
  border-color: #ffc2da;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), 0 4px 0 #a30d53;
}

.btn-yellow {
  color: #241c00;
  background: linear-gradient(180deg, #ffef9c 0%, #ffdc32 100%);
  border-color: #fff9cf;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 4px 0 #a88700;
}

.btn-danger {
  color: #ffd9d9;
  background: linear-gradient(180deg, #4a1024 0%, #2c0715 100%);
  border-color: #8a2540;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08), 0 4px 0 #120207;
}

.btn-danger:hover:not(:disabled) {
  border-color: var(--red);
  filter: brightness(1.2);
}

/* -------------------------------- STAGE --------------------------------- */
.stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(31, 15, 63, 0.95), rgba(15, 7, 32, 0.95));
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-hard);
}

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

.field-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--ink-dim);
  letter-spacing: 0.5px;
}

.select {
  padding: 8px 26px 8px 9px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--yellow);
  background-color: #0e0520;
  background-image: linear-gradient(45deg, transparent 50%, var(--cyan) 50%), linear-gradient(135deg, var(--cyan) 50%, transparent 50%);
  background-position: calc(100% - 13px) 15px, calc(100% - 8px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 2px solid #3b2369;
  border-radius: 3px;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.4);
  appearance: none;
  cursor: pointer;
}

.select:hover {
  border-color: var(--cyan);
}

.zoom-group {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.stamp-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12px;
  color: #0a1c22;
  background: linear-gradient(180deg, #9ff7ff, #4fdcf0);
  border: 2px solid #065361;
  border-radius: var(--r);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}

.stamp-hint-cancel {
  margin-left: auto;
  padding: 4px 8px;
  font-family: var(--font-pixel);
  font-size: 7px;
  color: #fff;
  background: #0b2530;
  border: 2px solid #065361;
  border-radius: 3px;
}

.canvas-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background:
    linear-gradient(180deg, rgba(21, 9, 43, 0.96), rgba(10, 3, 22, 0.98));
  border: 3px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-hard), inset 0 0 0 2px rgba(255, 255, 255, 0.03);
}

.canvas-shell {
  position: relative;
  display: flex;
  height: clamp(220px, 45vh, 560px);
  overflow: auto;
  padding: 6px;
  background:
    radial-gradient(ellipse at center, rgba(155, 92, 255, 0.16) 0%, rgba(0, 0, 0, 0) 72%),
    #0a0316;
  border: 2px solid #291650;
  border-radius: 6px;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.85);
  touch-action: none;
}

.pixel-canvas {
  margin: auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  cursor: crosshair;
  background-color: transparent;
  background-image:
    linear-gradient(45deg, var(--check-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--check-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--check-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--check-a) 75%);
  background-size: var(--check-size, 16px) var(--check-size, 16px);
  background-position: 0 0, 0 calc(var(--check-size, 16px) / 2), calc(var(--check-size, 16px) / 2) calc(var(--check-size, 16px) / -2), calc(var(--check-size, 16px) / -2) 0;
  background-color: var(--check-b);
  border: 2px solid #4b2a86;
  border-radius: 2px;
  box-shadow: 0 0 0 3px #0a0316, 0 0 22px rgba(155, 92, 255, 0.4);
  max-width: 100%;
  height: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.pixel-canvas.is-playing {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px #0a0316, 0 0 26px rgba(255, 46, 136, 0.55);
}

.play-badge {
  position: absolute;
  top: 18px;
  left: 18px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #150019;
  background: var(--pink);
  border: 2px solid #ffd0e4;
  border-radius: 3px;
  box-shadow: 0 3px 0 #8c0a45;
}

.play-dot {
  width: 7px;
  height: 7px;
  background: #150019;
  border-radius: 50%;
  animation: blink 0.7s steps(1, end) infinite;
}

@keyframes blink {
  50% { opacity: 0.15; }
}

.stage-status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-family: var(--font-pixel);
  font-size: 7px;
  letter-spacing: 0.4px;
  color: var(--ink-faint);
}

#statusTool {
  color: var(--cyan);
}

/* ------------------------------ COLORS ---------------------------------- */
.active-colors {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 6px;
}

.color-slot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: rgba(9, 3, 20, 0.5);
  border: 2px solid #2c1854;
  border-radius: var(--r);
}

.color-slot.is-target {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(255, 225, 77, 0.18), 0 0 14px rgba(255, 225, 77, 0.18);
}

.color-slot-label {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--ink-faint);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.color-slot.is-target .color-slot-label {
  color: var(--yellow);
}

.color-chip {
  width: 100%;
  height: 34px;
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease;
}

.color-chip:hover {
  transform: scale(1.03);
}

.color-hex {
  font-family: var(--font-pixel);
  font-size: 6px;
  color: var(--ink-dim);
  text-align: center;
  letter-spacing: 0.3px;
}

.btn-swap {
  min-width: 32px;
  padding: 6px 4px;
  margin-bottom: 26px;
  font-size: 13px;
}

.tiny {
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-faint);
}

.hint-line {
  margin-top: -4px;
}

.palette-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.palette-tab {
  flex: 1 1 auto;
  padding: 6px 5px;
  font-family: var(--font-pixel);
  font-size: 6.5px;
  letter-spacing: 0.2px;
  color: var(--ink-faint);
  background: #170b2d;
  border: 2px solid #2c1854;
  border-radius: 3px;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.palette-tab:hover {
  color: #fff;
  border-color: var(--purple);
}

.palette-tab.is-active {
  color: #17071f;
  background: var(--yellow);
  border-color: #fff6b8;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  padding: 6px;
  background: rgba(6, 2, 14, 0.65);
  border: 2px solid #251345;
  border-radius: var(--r);
  max-height: clamp(132px, 21vh, 300px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.swatch {
  position: relative;
  width: 100%;
  height: 0;
  padding: 0 0 100%;
  background-color: var(--swatch, #000);
  border: 1px solid rgba(0, 0, 0, 0.65);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}

.swatch:hover {
  transform: scale(1.14);
  z-index: 2;
  box-shadow: 0 0 0 2px var(--yellow);
}

.swatch.is-selected {
  box-shadow: 0 0 0 2px var(--yellow), 0 0 10px rgba(255, 225, 77, 0.6);
  z-index: 2;
}

.swatch.is-secondary-mark::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 5px;
  height: 5px;
  background: var(--cyan);
  border: 1px solid #052a33;
  border-radius: 50%;
}

#paletteNote {
  min-height: 16px;
  margin-top: -4px;
}

.custom-color {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 4px;
  border-top: 2px dashed var(--line-soft);
}

.custom-row {
  display: flex;
  gap: 5px;
  align-items: stretch;
}

.color-input {
  width: 42px;
  height: 38px;
  padding: 2px;
  background: #0e0520;
  border: 2px solid #3b2369;
  border-radius: 3px;
  cursor: pointer;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.text-input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink);
  background: #0b0418;
  border: 2px solid #3b2369;
  border-radius: 3px;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.4);
}

.text-input:focus {
  border-color: var(--cyan);
}

.hex-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-pixel);
  font-size: 9px;
  text-transform: uppercase;
}

.recent-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.recent-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 3px;
  min-height: 24px;
}

.recent-swatch {
  width: 100%;
  height: 0;
  padding: 0 0 100%;
  background-color: var(--swatch, #000);
  border: 1px solid rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  transition: transform 0.08s ease;
}

.recent-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--cyan);
}

.recent-empty {
  grid-column: 1 / -1;
  font-size: 10px;
  color: var(--ink-faint);
}

/* ------------------------------- STAMPS --------------------------------- */
.stamps-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 2px solid var(--line);
}

.stamp-grid {
  display: grid;
  gap: 5px;
}

.stamp-grid-side {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-height: 214px;
  overflow-y: auto;
  padding: 4px;
  background: rgba(6, 2, 14, 0.6);
  border: 2px solid #251345;
  border-radius: var(--r);
  scrollbar-width: thin;
}

.stamp-grid-modal {
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

.stamp-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 3px;
  background: linear-gradient(180deg, #2a1450, #170a30);
  border: 2px solid #3a2270;
  border-radius: 4px;
  box-shadow: 0 3px 0 #08030f;
  transition: transform 0.07s ease, box-shadow 0.07s ease, border-color 0.12s ease;
}

.stamp-btn:hover {
  border-color: var(--cyan);
  transform: translateY(-2px);
  box-shadow: 0 5px 0 #08030f, 0 0 14px rgba(34, 230, 255, 0.35);
}

.stamp-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #08030f;
}

.stamp-btn.is-active {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(255, 225, 77, 0.4), 0 3px 0 #08030f;
}

.stamp-preview {
  width: 100%;
  max-width: 46px;
  aspect-ratio: 1 / 1;
  image-rendering: pixelated;
  background:
    linear-gradient(45deg, #241239 25%, transparent 25%),
    linear-gradient(-45deg, #241239 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #241239 75%),
    linear-gradient(-45deg, transparent 75%, #241239 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #180a29;
  border-radius: 2px;
}

.stamp-grid-modal .stamp-preview {
  max-width: 76px;
}

.stamp-label {
  font-family: var(--font-pixel);
  font-size: 5.5px;
  line-height: 1.4;
  text-align: center;
  color: var(--ink-faint);
  letter-spacing: 0.2px;
}

.stamp-btn.is-active .stamp-label {
  color: var(--yellow);
}

/* ------------------------------- FRAMES --------------------------------- */
.frames-bar {
  position: relative;
  z-index: 5;
  margin: 0 16px 10px;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(27, 13, 55, 0.97), rgba(13, 5, 28, 0.98));
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-hard);
}

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

.frames-counter {
  margin-left: auto;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--cyan);
}

.frame-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 3px 2px 8px;
  scrollbar-width: thin;
  min-height: 76px;
}

.frame-card {
  position: relative;
  flex: 0 0 auto;
  width: 66px;
  padding: 4px;
  background: #100624;
  border: 2px solid #33205f;
  border-radius: 4px;
  box-shadow: 0 3px 0 #06020d;
  transition: border-color 0.12s ease, transform 0.1s ease;
}

.frame-card:hover {
  border-color: var(--purple);
}

.frame-card.is-current {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(255, 225, 77, 0.35), 0 3px 0 #06020d;
  transform: translateY(-2px);
}

.frame-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  image-rendering: pixelated;
  background:
    linear-gradient(45deg, #241239 25%, transparent 25%),
    linear-gradient(-45deg, #241239 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #241239 75%),
    linear-gradient(-45deg, transparent 75%, #241239 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #180a29;
  border: 1px solid #0a0316;
  border-radius: 2px;
  cursor: pointer;
}

.frame-num {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-top: 3px;
  font-family: var(--font-pixel);
  font-size: 6.5px;
  color: var(--ink-faint);
}

.frame-card.is-current .frame-num {
  color: var(--yellow);
}

.frame-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 9px;
  line-height: 1;
  color: #fff;
  background: var(--pink-dark);
  border: 2px solid #ffb3cf;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.frame-card:hover .frame-del,
.frame-card:focus-within .frame-del {
  opacity: 1;
  transform: scale(1);
}

.frames-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.frame-btn-group {
  display: flex;
  gap: 5px;
}

.frames-spacer {
  flex: 1 1 12px;
}

.fps-field {
  gap: 5px;
}

.btn-play {
  min-width: 104px;
}

/* ------------------------------- FOOTER --------------------------------- */
.site-footer {
  position: relative;
  z-index: 5;
  margin-top: auto;
  padding: 10px 16px 14px;
  text-align: center;
  background: linear-gradient(180deg, rgba(11, 4, 24, 0), rgba(11, 4, 24, 0.9) 40%);
  border-top: 2px solid var(--line);
}

.credits {
  font-size: 12px;
  color: var(--ink-dim);
}

.credits strong {
  color: var(--yellow);
}

.credits a {
  word-break: break-word;
}

.credits-sub {
  margin-top: 3px;
  font-family: var(--font-pixel);
  font-size: 7px;
  letter-spacing: 0.6px;
  color: var(--ink-faint);
}

/* --------------------------- MOBILE DRAWER ------------------------------ */
.tools-fab {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 80;
  width: 54px;
  height: 54px;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: linear-gradient(180deg, #ff67a5, #ff2e88);
  border: 3px solid #ffd0e4;
  border-radius: 50%;
  box-shadow: 0 6px 0 #8c0a45, 0 10px 24px rgba(0, 0, 0, 0.5);
}

.tools-fab:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #8c0a45;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(4, 1, 10, 0.7);
  backdrop-filter: blur(2px);
}

body.modal-open {
  overflow: hidden;
}

/* -------------------------------- MODALS -------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 0, 9, 0.82);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(88dvh, 780px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #25104b 0%, #130727 100%);
  border: 4px solid var(--pink);
  border-radius: 8px;
  box-shadow: 0 0 0 4px #0a0316, 0 24px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(255, 46, 136, 0.28);
  animation: pop 0.16s steps(3, end);
}

@keyframes pop {
  from { transform: scale(0.92); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.modal-wide {
  width: min(760px, 100%);
}

.modal-small {
  width: min(420px, 100%);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 46, 136, 0.12), transparent);
}

.modal-title {
  font-family: var(--font-pixel);
  font-size: 13px;
  line-height: 1.6;
  color: var(--yellow);
  text-shadow: 0 2px 0 #43122c;
}

.modal-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-dim);
}

.modal-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 14px;
  color: #fff;
  background: #3a1024;
  border: 2px solid #ff9cc4;
  border-radius: 4px;
  box-shadow: 0 3px 0 #1a0410;
}

.modal-close:hover {
  background: var(--pink);
}

.modal-close:active {
  transform: translateY(3px);
  box-shadow: none;
}

.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-text {
  font-size: 13px;
  color: var(--ink-dim);
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 2px solid var(--line);
  background: rgba(6, 2, 14, 0.55);
}

.modal-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
  border-top: 2px dashed var(--line-soft);
}

.error-text {
  color: #ff8fa3;
  font-size: 11px;
  min-height: 14px;
}

/* -------------------------------- HELP ---------------------------------- */
.help-body {
  gap: 14px;
}

.help-welcome {
  padding: 12px;
  background: linear-gradient(160deg, rgba(34, 230, 255, 0.12), rgba(155, 92, 255, 0.12));
  border: 2px solid #3c2a72;
  border-radius: 6px;
}

.help-welcome h3 {
  font-family: var(--font-pixel);
  font-size: 10px;
  line-height: 1.8;
  color: var(--cyan);
  margin-bottom: 6px;
}

.help-welcome p {
  font-size: 13px;
  color: var(--ink-dim);
}

.help-section-title {
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.8;
  color: var(--yellow);
  letter-spacing: 0.4px;
  margin-top: 4px;
}

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

.help-tool {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(9, 3, 20, 0.6);
  border: 2px solid #2b1752;
  border-radius: 4px;
}

.help-tool-icon {
  font-size: 16px;
  line-height: 1.2;
}

.help-tool strong {
  display: block;
  color: var(--ink);
  font-size: 12px;
}

.help-shortcuts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-shortcuts li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(9, 3, 20, 0.5);
  border-radius: 3px;
  border-left: 3px solid var(--purple);
}

kbd {
  padding: 2px 5px;
  font-family: var(--font-pixel);
  font-size: 7px;
  color: var(--yellow);
  background: #0b0418;
  border: 1px solid #4a2f83;
  border-radius: 3px;
  box-shadow: 0 2px 0 #04010a;
  white-space: nowrap;
}

.help-tips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-tips li {
  padding: 7px 9px 7px 26px;
  position: relative;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(255, 225, 77, 0.07);
  border: 1px dashed rgba(255, 225, 77, 0.35);
  border-radius: 4px;
}

.help-tips li::before {
  content: "★";
  position: absolute;
  left: 9px;
  top: 6px;
  color: var(--yellow);
  font-size: 11px;
}

/* ------------------------------- EXPORT --------------------------------- */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 9px;
}

.export-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  text-align: left;
  color: var(--ink);
  background: linear-gradient(180deg, #2c1654, #170a2f);
  border: 2px solid #3d2574;
  border-radius: 5px;
  box-shadow: 0 4px 0 #08030f;
  transition: transform 0.07s ease, box-shadow 0.07s ease, border-color 0.12s ease;
}

.export-option:hover {
  border-color: var(--cyan);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #08030f, 0 0 16px rgba(34, 230, 255, 0.25);
}

.export-option:active {
  transform: translateY(4px);
  box-shadow: none;
}

.export-option:disabled {
  opacity: 0.5;
  cursor: progress;
}

.export-icon {
  font-size: 20px;
  line-height: 1;
}

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

.export-text strong {
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1.6;
  color: var(--yellow);
}

.export-text small {
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink-faint);
}

.export-option-gif {
  border-color: var(--pink);
  background: linear-gradient(180deg, #4a1030, #20081a);
}

.export-note {
  margin-top: 2px;
}

.export-status {
  padding: 8px 10px;
  font-size: 12px;
  color: #0a1c22;
  background: var(--green);
  border: 2px solid #0c5a30;
  border-radius: 4px;
}

.export-status.is-error {
  color: #2a0007;
  background: #ff8fa3;
  border-color: #7a1024;
}

/* ------------------------------- GALLERY -------------------------------- */
.gallery-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.gallery-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  background: linear-gradient(180deg, #2a1450, #150826);
  border: 2px solid #3a2270;
  border-radius: 5px;
  box-shadow: 0 4px 0 #08030f;
}

.gallery-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 140px;
  object-fit: contain;
  image-rendering: pixelated;
  background:
    linear-gradient(45deg, #241239 25%, transparent 25%),
    linear-gradient(-45deg, #241239 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #241239 75%),
    linear-gradient(-45deg, transparent 75%, #241239 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-color: #180a29;
  border: 1px solid #0a0316;
  border-radius: 3px;
}

.gallery-name {
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1.6;
  color: var(--yellow);
  overflow-wrap: anywhere;
}

.gallery-meta {
  font-size: 10px;
  color: var(--ink-faint);
}

.gallery-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.gallery-actions .btn {
  flex: 1 1 auto;
  min-height: 30px;
  padding: 5px 6px;
  font-size: 6.5px;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 22px 14px;
  text-align: center;
  color: var(--ink-faint);
  border: 3px dashed var(--line-soft);
  border-radius: 6px;
}

.empty-state .empty-emoji {
  display: block;
  font-size: 30px;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 12px;
  margin-top: 5px;
}

/* -------------------------------- TOASTS -------------------------------- */
.toast-stack {
  position: fixed;
  left: 50%;
  top: 84px;
  bottom: auto;
  z-index: 150;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 9px 14px;
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1.7;
  text-align: center;
  color: #12061f;
  background: var(--yellow);
  border: 3px solid #fff8c9;
  border-radius: 5px;
  box-shadow: 0 5px 0 #7c6300, 0 12px 30px rgba(0, 0, 0, 0.55);
  animation: toastIn 0.18s steps(3, end);
}

.toast.toast-error {
  color: #2c0009;
  background: #ff8fa3;
  border-color: #ffd6df;
  box-shadow: 0 5px 0 #7a1024, 0 12px 30px rgba(0, 0, 0, 0.55);
}

.toast.toast-info {
  color: #041b20;
  background: var(--cyan);
  border-color: #d6fdff;
  box-shadow: 0 5px 0 #0a6f7d, 0 12px 30px rgba(0, 0, 0, 0.55);
}

.toast.toast-save {
  color: #2a0212;
  background: var(--pink);
  border-color: #ffd0e4;
  box-shadow: 0 5px 0 #8c0a45, 0 12px 30px rgba(0, 0, 0, 0.55);
}

.toast.is-leaving {
  animation: toastOut 0.2s steps(3, end) forwards;
}

@keyframes toastIn {
  from { transform: translateY(14px) scale(0.9); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toastOut {
  to { transform: translateY(-10px); opacity: 0; }
}

/* ------------------------------- TOOLTIP -------------------------------- */
.tooltip {
  position: fixed;
  z-index: 200;
  max-width: 250px;
  padding: 7px 9px;
  font-family: var(--font-body);
  font-size: 11.5px;
  line-height: 1.5;
  color: #0c0618;
  background: var(--yellow);
  border: 2px solid #6b5500;
  border-radius: 3px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.1s linear, transform 0.1s linear;
}

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

/* ------------------------------ CONFETTI -------------------------------- */
.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 140;
  pointer-events: none;
  display: none;
}

.confetti-canvas.is-active {
  display: block;
}

/* ------------------------------- PRINT ---------------------------------- */
.print-area {
  display: none;
}

@media print {
  @page {
    margin: 12mm;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
    height: auto !important;
    overflow: visible !important;
  }

  .scanlines,
  .starfield,
  .marquee,
  body::after {
    display: none !important;
  }

  body > *:not(.print-area) {
    display: none !important;
  }

  .print-area {
    display: block !important;
    text-align: center;
    padding: 10mm;
  }

  .print-title {
    font-family: var(--font-pixel);
    font-size: 22px;
    letter-spacing: 3px;
    margin-bottom: 8mm;
    color: #000;
  }

  .print-area img {
    display: block;
    margin: 0 auto;
    width: 80%;
    max-width: 160mm;
    max-height: 170mm;
    object-fit: contain;
    image-rendering: pixelated;
    border: 4px solid #000;
    padding: 4mm;
  }

  .print-credit {
    margin-top: 5mm;
    font-family: var(--font-body);
    font-size: 10pt;
    color: #222;
  }
}

/* ------------------------------ POSTER ---------------------------------- */
.poster-template {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 720px;
  height: 900px;
  z-index: -1;
  overflow: hidden;
}

.poster-inner {
  position: relative;
  width: 720px;
  height: 900px;
  padding: 44px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background:
    radial-gradient(ellipse at 50% 0%, #3a1470 0%, #160830 55%, #0a0316 100%);
  color: #f4ecff;
  border: 10px solid #ff2e88;
  box-sizing: border-box;
  font-family: var(--font-pixel);
}

.poster-stars {
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image:
    radial-gradient(2px 2px at 10% 14%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 84% 22%, #8ef8ff 50%, transparent 51%),
    radial-gradient(2px 2px at 30% 78%, #ffe14d 50%, transparent 51%),
    radial-gradient(2px 2px at 72% 64%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 52% 38%, #ffb3d9 50%, transparent 51%);
  background-size: 140px 160px, 120px 140px, 160px 150px, 130px 120px, 150px 170px;
}

.poster-kicker {
  position: relative;
  font-size: 15px;
  letter-spacing: 4px;
  color: #ffe14d;
  text-shadow: 0 3px 0 #a30d53;
}

.poster-subtitle {
  position: relative;
  font-size: 9px;
  letter-spacing: 3px;
  color: #22e6ff;
}

.poster-art-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 520px;
  height: 520px;
  margin-top: 8px;
  padding: 16px;
  background:
    repeating-conic-gradient(#241239 0% 25%, #180a29 0% 50%) 50% / 24px 24px;
  border: 6px solid #22e6ff;
  box-shadow: 0 0 0 6px #0a0316, 0 0 40px rgba(34, 230, 255, 0.4);
}

.poster-art-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.poster-title {
  position: relative;
  margin-top: 8px;
  max-width: 600px;
  font-size: 16px;
  line-height: 1.6;
  text-align: center;
  color: #fff;
  overflow-wrap: anywhere;
}

.poster-meta {
  position: relative;
  font-size: 8px;
  letter-spacing: 1px;
  color: #b7a8d8;
}

.poster-credit {
  position: relative;
  font-size: 7px;
  letter-spacing: 1px;
  color: #8d7cb5;
  text-align: center;
}

.poster-inner .poster-meta + .poster-credit {
  margin-top: auto;
}

/* -------------------- DESKTOP APP SHELL (no page scroll) ----------------- */
@media (min-width: 901px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .topbar,
  .marquee,
  .frames-bar,
  .site-footer {
    flex: 0 0 auto;
  }

  .studio {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
  }

  .tools-panel,
  .side-panel {
    max-height: none;
    min-height: 0;
    overflow-y: auto;
  }

  .stage {
    min-height: 0;
    overflow: hidden;
  }

  .stage-toolbar {
    flex: 0 0 auto;
  }

  .canvas-card {
    flex: 1 1 auto;
    min-height: 0;
  }

  .canvas-shell {
    flex: 1 1 auto;
    height: auto;
    min-height: 150px;
  }

  .frames-bar {
    margin-bottom: 8px;
  }
}

/* ------------------------------ RESPONSIVE ------------------------------ */
@media (max-width: 1240px) {
  .studio {
    grid-template-columns: 226px minmax(0, 1fr) 278px;
  }

  .brand-title {
    font-size: 17px;
  }
}

@media (max-width: 1080px) {
  .studio {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .side-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    align-items: start;
    max-height: none;
  }

  .side-panel > .panel-head {
    grid-column: 1 / -1;
  }

  .side-panel .stamps-side {
    border-top: none;
    padding-top: 0;
  }
}

@media (max-width: 900px) {
  body {
    padding-bottom: 0;
  }

  .icon-label {
    display: none;
  }

  .icon-btn {
    padding: 8px;
    min-width: 42px;
    justify-content: center;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 19px;
  }

  .brand-title {
    font-size: 14px;
  }

  .brand-tag {
    font-size: 11px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  /* Drop the studio's stacking context so the fixed tool drawer can float
     above its own backdrop while the stage stays above the starfield. */
  .studio {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px;
    gap: 10px;
    z-index: auto;
  }

  .stage,
  .side-panel {
    position: relative;
    z-index: 5;
  }

  .stage-toolbar {
    gap: 8px;
  }

  .stage-actions {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }

  .stage-actions .btn {
    flex: 1 1 auto;
  }

  /* Tools become a bottom drawer */
  .tools-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    max-height: 78dvh;
    overflow-y: auto;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    padding-bottom: max(18px, env(safe-area-inset-bottom));
    transform: translateY(105%);
    transition: transform 0.22s steps(4, end);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.65);
  }

  .tools-panel.is-open {
    transform: translateY(0);
  }

  .drawer-bar {
    display: block;
    width: 56px;
    height: 4px;
    margin: 0 auto 6px;
    background: #4a2f83;
    border-radius: 4px;
  }

  .drawer-close {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 13px;
    color: #fff;
    background: #3a1024;
    border: 2px solid #ff9cc4;
    border-radius: 4px;
  }

  .tool-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tool-btn {
    min-height: 56px;
  }

  .tools-fab {
    display: flex;
  }

  .frames-bar {
    margin: 0 10px 10px;
  }

  .side-panel {
    display: flex;
    flex-direction: column;
    max-height: none;
  }

  .canvas-shell {
    height: clamp(200px, 46dvh, 460px);
  }

  .stamp-grid-side {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    max-height: none;
  }

  .toast-stack {
    top: auto;
    bottom: 84px;
  }
}

@media (max-width: 560px) {
  .brand-title {
    font-size: 12px;
  }

  .lang-btn {
    padding: 7px 7px;
    font-size: 8px;
  }

  .marquee-track {
    font-size: 7px;
  }

  .tool-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .frames-controls {
    justify-content: space-between;
  }

  .frame-btn-group {
    order: 2;
    width: 100%;
    justify-content: space-between;
  }

  .btn-play {
    min-width: 90px;
  }

  .credits {
    font-size: 11px;
  }

  .modal-head,
  .modal-body,
  .modal-foot {
    padding-left: 12px;
    padding-right: 12px;
  }

  .modal-title {
    font-size: 11px;
  }

  .stamp-grid-modal {
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  }
}

@media (max-height: 820px) and (min-width: 901px) {
  .brand-tag {
    display: none;
  }

  .marquee {
    display: none;
  }

  .frame-card {
    width: 54px;
  }

  .frame-strip {
    min-height: 64px;
  }

  .frames-head {
    display: none;
  }

  .topbar {
    padding-block: 8px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 19px;
  }

  .brand-title {
    font-size: 16px;
  }
}

@media (max-height: 700px) and (min-width: 901px) {
  .frames-bar {
    padding-block: 6px;
  }

  .frame-strip {
    min-height: 56px;
  }

  .frame-card {
    width: 46px;
  }

  .btn-play,
  .frame-btn-group .btn {
    min-height: 32px;
  }
}

/* Print + reduced motion helpers */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Hindi typography: Press Start 2P has no Devanagari glyphs, so the app
   switches to a clean readable face with slightly tighter tracking. */
html[lang="hi"] {
  --font-pixel: "Noto Sans Devanagari", "Courier New", monospace;
}

html[lang="hi"] .brand-title {
  font-family: var(--font-pixel);
  letter-spacing: 0;
}

html[lang="hi"] .tool-name,
html[lang="hi"] .stamp-label,
html[lang="hi"] .frames-counter,
html[lang="hi"] .frame-num {
  font-size: 8px;
  line-height: 1.5;
}

html[lang="hi"] .mini-label,
html[lang="hi"] .field-label,
html[lang="hi"] .color-slot-label,
html[lang="hi"] .color-hex {
  font-size: 9px;
  letter-spacing: 0;
}

html[lang="hi"] .brand-tag {
  font-size: 13px;
}

html[lang="hi"] .marquee-track {
  font-size: 10px;
}

html[lang="hi"] .btn,
html[lang="hi"] .tool-name,
html[lang="hi"] .field-label,
html[lang="hi"] .mini-label,
html[lang="hi"] .palette-tab,
html[lang="hi"] .seg-btn,
html[lang="hi"] .toast,
html[lang="hi"] .modal-title,
html[lang="hi"] .help-section-title,
html[lang="hi"] .export-text strong {
  font-weight: 700;
  letter-spacing: 0;
}
