/* ------------------------------------------------------------------
   Pixel Forge — iOS 26 Liquid Glass redesign
   Translucent surfaces, concentric corners, vivid gradient accents.
   ------------------------------------------------------------------ */

:root {
  color-scheme: light dark;

  --r-card: 22px;
  --r-control: 14px;
  --r-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  --t-fast: 140ms;
  --t-base: 220ms;
  --t-slow: 360ms;
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);

  --tap: 44px;

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

  --tabbar-height: 68px;

  /* Light tokens (default) */
  --bg: #f3f3f8;
  --bg-tint-1: rgba(175, 82, 222, 0.18);
  --bg-tint-2: rgba(0, 122, 255, 0.18);
  --bg-tint-3: rgba(94, 92, 230, 0.16);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-hi: rgba(255, 255, 255, 0.88);
  --surface-press: rgba(0, 0, 0, 0.06);
  --separator: rgba(0, 0, 0, 0.08);
  --hairline: rgba(0, 0, 0, 0.06);
  --highlight-edge: rgba(255, 255, 255, 0.85);
  --shadow-card: 0 14px 38px -22px rgba(28, 28, 30, 0.45);
  --shadow-fab:
    0 18px 38px -16px rgba(94, 92, 230, 0.55),
    0 8px 18px -8px rgba(0, 122, 255, 0.4);

  --text: #050505;
  --text-2: rgba(5, 5, 5, 0.62);
  --text-3: rgba(5, 5, 5, 0.40);
  --text-on-accent: #ffffff;

  --accent: #007aff;
  --accent-press: #0064cc;
  --accent-grad: linear-gradient(135deg, #af52de 0%, #007aff 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(175, 82, 222, 0.16), rgba(0, 122, 255, 0.16));

  --success: #28a745;
  --warn: #ff9500;
  --danger: #ff3b30;

  --blur: blur(28px) saturate(180%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-tint-1: rgba(191, 90, 242, 0.32);
    --bg-tint-2: rgba(10, 132, 255, 0.32);
    --bg-tint-3: rgba(94, 92, 230, 0.28);
    --surface: rgba(28, 28, 30, 0.62);
    --surface-hi: rgba(58, 58, 62, 0.78);
    --surface-press: rgba(255, 255, 255, 0.10);
    --separator: rgba(255, 255, 255, 0.10);
    --hairline: rgba(255, 255, 255, 0.06);
    --highlight-edge: rgba(255, 255, 255, 0.18);
    --shadow-card: 0 18px 50px -22px rgba(0, 0, 0, 0.85);
    --shadow-fab:
      0 22px 48px -18px rgba(191, 90, 242, 0.55),
      0 12px 24px -10px rgba(10, 132, 255, 0.45);

    --text: #ffffff;
    --text-2: rgba(255, 255, 255, 0.62);
    --text-3: rgba(255, 255, 255, 0.38);

    --accent: #0a84ff;
    --accent-press: #409cff;
    --accent-grad: linear-gradient(135deg, #bf5af2 0%, #0a84ff 100%);
    --accent-grad-soft: linear-gradient(135deg, rgba(191, 90, 242, 0.24), rgba(10, 132, 255, 0.24));

    --success: #30d158;
    --warn: #ffd60a;
    --danger: #ff453a;
  }
}

* , *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
}

html { background: var(--bg); }

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
  font-feature-settings: "ss01", "ss02", "kern";
  font-size: 17px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  position: relative;
  min-height: 100svh;
}

/* Wallpaper — soft radial color blobs over base bg, fixed so it stays put. */
body::before {
  content: "";
  position: fixed;
  inset: -10%;
  z-index: -1;
  background:
    radial-gradient(40vw 40vh at 12% 8%, var(--bg-tint-1), transparent 60%),
    radial-gradient(36vw 36vh at 92% 12%, var(--bg-tint-2), transparent 65%),
    radial-gradient(50vw 50vh at 50% 110%, var(--bg-tint-3), transparent 70%),
    var(--bg);
  pointer-events: none;
  filter: blur(0.5px);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: transparent;
  cursor: pointer;
  letter-spacing: inherit;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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

img { max-width: 100%; }

.hidden { display: none !important; }

.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;
}

/* ------------------------------------------------------------------
   Glass primitives
   ------------------------------------------------------------------ */

.glass {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    var(--shadow-card);
}

.glass-card {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    var(--shadow-card);
}

/* ------------------------------------------------------------------
   App shell + sections
   ------------------------------------------------------------------ */

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 24px);
}

.app-section {
  position: relative;
  padding: 0 max(var(--space-5), var(--safe-left)) var(--space-7)
           max(var(--space-5), var(--safe-right));
  scroll-margin-top: 12px;
}

.app-section + .app-section { padding-top: var(--space-6); }

/* ------------------------------------------------------------------
   Top navbar + large title
   ------------------------------------------------------------------ */

.app-navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(var(--space-2), var(--safe-top)) var(--space-5) var(--space-3);
  background: transparent;
  transition: background var(--t-base) var(--ease-out),
              backdrop-filter var(--t-base) var(--ease-out),
              border-color var(--t-base) var(--ease-out);
  border-bottom: 1px solid transparent;
  min-height: calc(44px + var(--safe-top));
}

.app-navbar.is-collapsed {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-bottom-color: var(--separator);
}

.navbar-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--t-base) var(--ease-out),
              transform var(--t-base) var(--ease-out);
  pointer-events: none;
}
.app-navbar.is-collapsed .navbar-title {
  opacity: 1;
  transform: none;
}

.navbar-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--r-control);
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
  background: transparent;
}
.navbar-action:hover { background: var(--surface-press); }
.navbar-action:active { opacity: 0.6; }

.large-title {
  margin: 0;
  padding: var(--space-3) max(var(--space-5), var(--safe-left)) var(--space-4);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.08;
}
.large-title small {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text-2);
}

/* ------------------------------------------------------------------
   Cards / list groups / list rows
   ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    var(--shadow-card);
}

.card + .card { margin-top: var(--space-4); }

.card-header {
  padding: var(--space-4) var(--space-5) 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
}

.card-body {
  padding: var(--space-4) var(--space-5);
}

.card-footer {
  padding: 0 var(--space-5) var(--space-3);
  font-size: 13px;
  color: var(--text-3);
}

.list-group {
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    var(--shadow-card);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap);
  padding: 12px var(--space-5);
  background: transparent;
  border: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
  font-size: 17px;
  border-radius: 0;
}
.list-row:hover { background: var(--surface-press); }
.list-row:active { background: var(--surface-press); }
.list-row + .list-row { border-top: 1px solid var(--separator); }

.list-row-title {
  flex: 1;
  font-size: 17px;
  color: var(--text);
}

.list-row-value {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  font-size: 15px;
  letter-spacing: -0.01em;
}

.list-row-chevron {
  color: var(--text-3);
  font-size: 14px;
  font-weight: 600;
  display: inline-block;
  transform: translateY(-1px);
}

.list-row-disclosure[open] .list-row-chevron { transform: rotate(180deg); }

/* ------------------------------------------------------------------
   Segmented control
   ------------------------------------------------------------------ */

.segmented {
  display: grid;
  grid-template-columns: repeat(var(--seg-count, 2), 1fr);
  gap: 2px;
  padding: 3px;
  background: var(--surface-press);
  border-radius: var(--r-control);
  border: 1px solid var(--hairline);
}

.segmented-option {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
  background: transparent;
  cursor: pointer;
  transition: background var(--t-base) var(--ease-out),
              color var(--t-base) var(--ease-out),
              transform var(--t-fast) var(--ease-out),
              box-shadow var(--t-base) var(--ease-out);
  min-height: 38px;
  letter-spacing: -0.01em;
  text-align: center;
}
.segmented-option:active { transform: scale(0.97); }
.segmented-option[disabled],
.segmented-option.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
.segmented-option .seg-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.segmented-option.is-active {
  background: var(--surface-hi);
  color: var(--text);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    0 4px 10px -6px rgba(0, 0, 0, 0.45);
}
.segmented-option.is-active .seg-sub { color: var(--text-2); }

/* ------------------------------------------------------------------
   Prompt textarea (Notes-style)
   ------------------------------------------------------------------ */

.field-textarea {
  display: block;
  width: 100%;
  min-height: 132px;
  padding: var(--space-4) 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 17px;
  line-height: 1.45;
  resize: vertical;
  outline: none;
}
.field-textarea::placeholder { color: var(--text-3); }

textarea.field-textarea {
  font-size: 17px; /* iOS no-zoom */
}

.prompt-card .card-body { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.prompt-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--space-5) 12px;
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.02em;
  border-top: 1px solid var(--separator);
}

.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px var(--space-5) 14px;
  border-top: 1px solid var(--separator);
  flex-wrap: wrap;
}
.prompt-count {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}
.prompt-actions-buttons {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-prompt {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-press);
  border-color: transparent;
}
.btn-prompt:hover {
  background: var(--surface-hi);
  color: var(--text);
}

.btn-optimize {
  min-height: 40px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-on-accent);
  background-image: var(--accent-grad);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 6px 16px -8px rgba(0, 122, 255, 0.45);
}
.btn-optimize:hover { filter: brightness(1.06); }
.btn-optimize.is-busy { opacity: 0.65; pointer-events: none; }
.btn-optimize.is-busy::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  margin-right: 4px;
  animation: optimize-spin 0.7s linear infinite;
}
.btn-optimize[hidden] { display: none !important; }
.btn-prompt[hidden] { display: none !important; }

@keyframes optimize-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ------------------------------------------------------------------
   Chip rail (preset chips, horizontal scroll)
   ------------------------------------------------------------------ */

.chip-rail {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 var(--space-5) var(--space-3);
  margin: 0;
}
.chip-rail::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  scroll-snap-align: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: var(--surface-press);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out);
}
.chip:active { transform: scale(0.96); }
.chip:hover { background: var(--surface-hi); }
.chip.is-active {
  background: var(--accent-grad-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* ------------------------------------------------------------------
   Form control bits — sliders, custom selects, hints
   ------------------------------------------------------------------ */

.control-stack { display: grid; gap: var(--space-2); }

.control-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.control-value {
  font-size: 13px;
  color: var(--text-3);
  text-align: right;
  font-feature-settings: "tnum";
}

input[type="range"] {
  appearance: none;
  width: 100%;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--separator);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--separator);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.field-hint {
  font-size: 12px;
  color: var(--text-3);
}
.field-hint[hidden] { display: none; }
.field-hint.inline-hint {
  display: block;
  padding: 0 var(--space-5) 12px;
}

/* ------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--r-control);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-hi);
  border: 1px solid var(--hairline);
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out),
              opacity var(--t-fast) var(--ease-out);
}
.btn:hover { background: var(--surface-hi); }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background-image: var(--accent-grad);
  color: var(--text-on-accent);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 8px 22px -10px rgba(0, 122, 255, 0.55);
}
.btn-primary:hover { filter: brightness(1.05); }

.btn-danger {
  color: var(--danger);
}
.btn-danger:hover { background: rgba(255, 59, 48, 0.12); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.btn-ghost:hover { background: var(--surface-press); }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  background: var(--surface-hi);
  border: 1px solid var(--hairline);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
.icon-button:active { transform: scale(0.92); }
.icon-button.is-danger { color: var(--danger); }
.icon-button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ------------------------------------------------------------------
   FAB — floating action button
   ------------------------------------------------------------------ */

.fab {
  position: fixed;
  z-index: 50;
  right: max(var(--space-5), calc(var(--safe-right) + var(--space-3)));
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-4));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 60px;
  padding: 0 22px;
  border-radius: 30px;
  background-image: var(--accent-grad);
  color: var(--text-on-accent);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: var(--shadow-fab),
              inset 0 1px 0 rgba(255, 255, 255, 0.32);
  cursor: pointer;
  transition: transform var(--t-base) var(--ease-out),
              opacity var(--t-base) var(--ease-out),
              filter var(--t-base) var(--ease-out);
}
.fab:hover { filter: brightness(1.08); }
.fab:active { transform: scale(0.95); }
.fab[disabled] { opacity: 0.55; cursor: wait; }
.fab.is-hidden { transform: translateY(120px); opacity: 0; pointer-events: none; }

/* Inline FAB inside prompt-actions (replaces the floating button) */
.prompt-actions-buttons .fab {
  position: static;
  z-index: auto;
  right: auto;
  bottom: auto;
  height: 36px;
  padding: 0 16px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: none;
  transition: transform var(--t-base) var(--ease-out),
              opacity var(--t-base) var(--ease-out),
              filter var(--t-base) var(--ease-out);
}

.fab-arrow {
  display: inline-block;
  transition: transform var(--t-base) var(--ease-out);
}
.fab:hover .fab-arrow { transform: translateX(3px); }

/* ------------------------------------------------------------------
   Tab bar
   ------------------------------------------------------------------ */

.tabbar {
  position: fixed;
  z-index: 45;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  backdrop-filter: blur(38px) saturate(200%);
  -webkit-backdrop-filter: blur(38px) saturate(200%);
  border-top: 1px solid var(--separator);
  padding: 6px max(var(--space-3), var(--safe-left))
           calc(6px + var(--safe-bottom)) max(var(--space-3), var(--safe-right));
  box-shadow: 0 -10px 28px -22px rgba(0, 0, 0, 0.5);
}

.tab-link {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-2);
  min-height: 56px;
  padding: 6px 4px;
  border-radius: var(--r-control);
  transition: color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.tab-link:active { transform: scale(0.94); }
.tab-link.is-active {
  color: var(--text);
  background: var(--surface-hi);
}
.tab-icon {
  font-size: 22px;
  line-height: 1;
  background: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}
.tab-link.is-active .tab-icon {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tab-badge {
  position: absolute;
  top: 4px;
  right: 22%;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.tab-badge[hidden] { display: none; }

/* ------------------------------------------------------------------
   Status pills, banners, loaders
   ------------------------------------------------------------------ */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: var(--surface-press);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}
.status-pill[data-state="queued"]::before { background: var(--warn); }
.status-pill[data-state="running"]::before {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-pill[data-state="succeeded"]::before { background: var(--success); }
.status-pill[data-state="failed"]::before,
.status-pill[data-state="timed_out"]::before { background: var(--danger); }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.55; }
}

.banner {
  display: grid;
  gap: 4px;
  margin-bottom: var(--space-3);
  padding: 12px 14px;
  border-radius: var(--r-control);
  background: var(--surface-press);
  font-size: 14px;
  color: var(--text);
}
.banner strong {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-2);
}
.banner[data-state="running"] { background: rgba(10, 132, 255, 0.14); }
.banner[data-state="succeeded"] { background: rgba(48, 209, 88, 0.14); }
.banner[data-state="failed"],
.banner[data-state="timed_out"] { background: rgba(255, 69, 58, 0.14); color: var(--danger); }

.banner-error {
  background: rgba(255, 69, 58, 0.14);
  color: var(--danger);
}

.pixel-loader {
  position: relative;
  width: 88px;
  height: 3px;
  margin: 0 auto;
  background: var(--separator);
  border-radius: 2px;
  overflow: hidden;
}
.pixel-loader::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 28px;
  background: var(--accent-grad);
  border-radius: 2px;
  animation: loader 1.2s linear infinite;
}
@keyframes loader {
  from { transform: translateX(-30px); }
  to { transform: translateX(96px); }
}

/* ------------------------------------------------------------------
   Compose section
   ------------------------------------------------------------------ */

.compose-form {
  display: grid;
  gap: var(--space-4);
}

.upload-card .card-body { padding-top: var(--space-3); padding-bottom: var(--space-3); }

.upload-zone {
  border-radius: var(--r-control);
}

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

.upload-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-control);
  overflow: hidden;
  background: var(--surface-press);
  border: 1px solid var(--hairline);
}
.upload-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.upload-tile-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-style: dashed;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
}
.upload-tile-add-icon {
  font-size: 22px;
  font-weight: 200;
  line-height: 1;
}

.upload-tile-controls {
  position: absolute;
  inset: auto 4px 4px 4px;
  display: flex;
  gap: 4px;
}
.upload-tile-controls .icon-button {
  width: 28px;
  height: 28px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  border-color: transparent;
}

.upload-tile-flag {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 10px;
  letter-spacing: 0.02em;
}
.upload-tile-flag.is-mask { background: var(--accent); }

/* ------------------------------------------------------------------
   Preview section
   ------------------------------------------------------------------ */

.preview-stack {
  display: grid;
  gap: var(--space-3);
}

.preview-hero {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-card);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-hero img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.preview-counter {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  letter-spacing: 0.02em;
  backdrop-filter: blur(10px);
}

.result-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.result-strip::-webkit-scrollbar { display: none; }
.result-thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  background: var(--surface-press);
  cursor: pointer;
  position: relative;
  transition: transform var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out);
}
.result-thumb:active { transform: scale(0.94); }
.result-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.result-thumb.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.preview-meta { display: grid; gap: var(--space-2); }

.preview-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.preview-prompt {
  margin: 0;
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.45;
}

.preview-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 13px;
  color: var(--text-3);
  font-feature-settings: "tnum";
}
.preview-specs span::before {
  content: "·";
  margin-right: 6px;
  color: var(--text-3);
}
.preview-specs span:first-child::before { display: none; }

.preview-time {
  margin: 0;
  font-size: 13px;
  color: var(--text-3);
  font-feature-settings: "tnum";
  letter-spacing: 0.02em;
}

.preview-details {
  margin: 4px 0 0;
  padding: 12px;
  border-radius: var(--r-control);
  background: var(--surface-press);
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
}
.preview-details-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.preview-details-row dt {
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.preview-details-row dd {
  margin: 0;
  color: var(--text);
  font-feature-settings: "tnum";
  text-align: right;
  word-break: break-word;
}

.preview-toolbar {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}
.empty-state-mark {
  font-size: 48px;
  line-height: 1;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.empty-state p {
  margin: 0;
  max-width: 36ch;
  font-size: 17px;
  color: var(--text-2);
  line-height: 1.45;
}

/* ------------------------------------------------------------------
   Queue list
   ------------------------------------------------------------------ */

.queue-list {
  display: grid;
  gap: var(--space-3);
}

.queue-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--r-card);
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    var(--shadow-card);
  font-family: inherit;
  color: inherit;
  transition: transform var(--t-fast) var(--ease-out);
}
.queue-row:active { transform: scale(0.98); }
.queue-row.is-selected { outline: 1px solid var(--accent); }

.queue-row-main {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  width: 100%;
  padding: 0;
  text-align: left;
  color: inherit;
  background: transparent;
}

.queue-status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-3);
}
.queue-status-dot[data-state="queued"] { background: var(--warn); }
.queue-status-dot[data-state="running"] {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.queue-status-dot[data-state="succeeded"] { background: var(--success); }
.queue-status-dot[data-state="failed"],
.queue-status-dot[data-state="timed_out"] { background: var(--danger); }

.queue-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.queue-prompt {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  letter-spacing: -0.01em;
}
.queue-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.02em;
  font-feature-settings: "tnum";
}

.queue-error {
  display: block;
  margin: 2px 0 0;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 69, 58, 0.12);
  color: var(--danger);
  font-size: 12px;
  line-height: 1.4;
}

.queue-retry {
  white-space: nowrap;
  align-self: center;
}

.queue-empty {
  text-align: center;
  padding: var(--space-7) var(--space-5);
  color: var(--text-3);
  font-size: 15px;
}

/* ------------------------------------------------------------------
   Library tile grid
   ------------------------------------------------------------------ */

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0 max(var(--space-5), var(--safe-left)) var(--space-3);
  font-size: 13px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.library-pager {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  background: var(--surface-press);
  padding: 0;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out);
}
.tile:active { transform: scale(0.97); }
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--t-base) var(--ease-out);
}
.tile:hover img { transform: scale(1.04); }
.tile.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.tile-count {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  letter-spacing: 0.02em;
}

.library-empty {
  text-align: center;
  padding: var(--space-7) var(--space-5);
  color: var(--text-3);
  font-size: 15px;
}

/* ------------------------------------------------------------------
   Action sheet (bottom-sheet picker, mask sheet)
   ------------------------------------------------------------------ */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn 180ms ease-out;
  overflow: hidden;
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 86dvh;
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid var(--hairline);
  border-bottom: 0;
  box-shadow: 0 -22px 48px -10px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: max(var(--space-5), var(--safe-bottom));
  animation: sheetUp 200ms ease-out;
}

@media (min-width: 720px) {
  .sheet-backdrop {
    align-items: center;
    padding: var(--space-5);
  }
  .sheet {
    border-radius: 24px;
    border-bottom: 1px solid var(--hairline);
    max-height: min(86dvh, 720px);
    box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
    padding-bottom: var(--space-5);
  }
}

@keyframes sheetUp {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet-grabber {
  align-self: center;
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--separator);
  margin: 8px auto 0;
}

.sheet-header {
  padding: 12px var(--space-5) 4px;
  text-align: center;
}
.sheet-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sheet-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-3);
  letter-spacing: 0.01em;
}

.sheet-body {
  padding: var(--space-3) var(--space-3) 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-options {
  display: grid;
  gap: 4px;
  padding: 0;
  list-style: none;
  margin: 0;
}

.sheet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--r-control);
  background: var(--surface-press);
  font-size: 17px;
  color: var(--text);
  border: 0;
  text-align: left;
  cursor: pointer;
}
.sheet-option:hover { background: var(--surface-hi); }
.sheet-option[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.sheet-option.is-active {
  color: var(--accent);
  background: var(--accent-grad-soft);
}
.sheet-option-check {
  width: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
}

.sheet-actions {
  display: grid;
  gap: 8px;
  padding: var(--space-3) var(--space-3) 0;
}

/* Mask sheet (full sheet for canvas) */
.mask-sheet .sheet {
  max-width: 1024px;
  max-height: 96dvh;
  height: 96dvh;
  border-radius: 24px 24px 0 0;
}
@media (min-width: 720px) {
  .mask-sheet .sheet {
    border-radius: 24px;
    max-height: min(86dvh, 720px);
    height: auto;
  }
}
.mask-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-press);
  border-radius: var(--r-card);
  margin: var(--space-3);
  padding: 12px;
  overflow: auto;
}
#maskCanvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
  background: #fff;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.18);
}
.mask-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  padding: 0 var(--space-5) var(--space-3);
  font-size: 14px;
  color: var(--text-2);
}
.mask-tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.mask-tool input[type="range"] { width: 140px; }
.mask-tool select {
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-press);
  border: 1px solid var(--hairline);
  color: var(--text);
  font-size: 14px;
}
.mask-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: var(--space-3) var(--space-5) 0;
}

body.modal-open { overflow: hidden; }

/* ------------------------------------------------------------------
   Auth (login)
   ------------------------------------------------------------------ */

.auth-body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(var(--space-5), var(--safe-top))
           var(--space-5)
           max(var(--space-5), var(--safe-bottom));
}

.auth-card {
  width: min(100%, 420px);
  padding: var(--space-7) var(--space-6) var(--space-6);
  border-radius: var(--r-card);
  background: var(--surface);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--hairline);
  box-shadow:
    inset 0 1px 0 var(--highlight-edge),
    var(--shadow-card);
  display: grid;
  gap: var(--space-4);
}

.auth-logo {
  margin: 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background-image: var(--accent-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.04em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.32),
    0 14px 28px -16px rgba(0, 122, 255, 0.55);
}

.auth-title {
  text-align: center;
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-subtitle {
  text-align: center;
  margin: 0;
  font-size: 15px;
  color: var(--text-2);
}

.auth-form { display: grid; gap: var(--space-3); }

.field-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-control);
  border: 1px solid var(--hairline);
  background: var(--surface-press);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  outline: none;
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-grad-soft);
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--r-control);
  background: rgba(255, 59, 48, 0.14);
  color: var(--danger);
  font-size: 13px;
}

/* ------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------ */

@media (min-width: 720px) {
  .tile-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1100px) {
  .tabbar { display: none; }
  .app-shell {
    padding-bottom: var(--space-7);
  }
  .app-shell-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: var(--space-7);
    padding: 0 max(var(--space-7), var(--safe-left))
             0 max(var(--space-7), var(--safe-right));
    align-items: start;
  }
  .app-shell-grid > .app-section { padding: 0 0 var(--space-7); }
  .tile-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .preview-hero { aspect-ratio: 16 / 10; }
  .fab { position: fixed; }
}

@media (min-width: 1380px) {
  .tile-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
  .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

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