:root {
  --blue-950: #06184c;
  --blue-900: #0b2678;
  --blue-700: #0f46d8;
  --blue-600: #1b5cff;
  --blue-500: #3b7bff;
  --blue-100: #e7f0ff;
  --blue-50: #f3f7ff;
  --lime-500: #6ae64c;
  --lime-600: #4ccc2f;
  --lime-900: #103b07;
  --slate-900: #0f172a;
  --slate-700: #334155;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --white: #ffffff;
  --danger: #ef4444;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 12px 32px rgba(7, 29, 92, 0.08), 0 2px 6px rgba(7, 29, 92, 0.04);
  --shadow-stage: 0 20px 50px rgba(7, 29, 92, 0.14);
}

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

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(165deg, #eef4ff 0%, #f8fbff 48%, #ebf5ef 100%);
  color: var(--slate-900);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Soft ambient background orbs */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.42;
}

.bg-glow-1 {
  width: 440px;
  height: 440px;
  top: -140px;
  left: -120px;
  background: radial-gradient(circle, rgba(27, 92, 255, 0.35), transparent 70%);
}

.bg-glow-2 {
  width: 420px;
  height: 420px;
  bottom: -140px;
  right: -100px;
  background: radial-gradient(circle, rgba(106, 230, 76, 0.35), transparent 70%);
}

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

/* Header */
.topbar {
  background: linear-gradient(100deg, var(--blue-950) 0%, var(--blue-900) 50%, var(--blue-700) 100%);
  color: var(--white);
  border-bottom: 3px solid var(--lime-500);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(6, 24, 76, 0.18);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
  flex-wrap: wrap;
}

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

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(106, 230, 76, 0.16);
  border: 1px solid rgba(106, 230, 76, 0.55);
  color: var(--lime-500);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 5px 10px;
  border-radius: 999px;
}

.brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lime-500);
  box-shadow: 0 0 8px var(--lime-500);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.event-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 5px 11px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.chip svg {
  width: 14px;
  height: 14px;
  color: var(--lime-500);
  flex-shrink: 0;
}

/* Main Grid */
.main-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  padding-top: 28px;
  padding-bottom: 42px;
}

.stage-section,
.controls-section {
  min-width: 0;
}

/* Stage Section */
.stage-section {
  position: sticky;
  top: 84px;
}

.stage-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-stage);
}

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

.stage-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--blue-700);
  background: var(--blue-100);
  padding: 4px 10px;
  border-radius: 999px;
}

.status-pill.ready {
  color: #166534;
  background: #dcfce7;
}

.stage-res {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--slate-500);
}

.btn-ghost-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-700);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.btn-ghost-sm svg {
  width: 13px;
  height: 13px;
}

.btn-ghost-sm:hover:not(:disabled) {
  border-color: var(--blue-500);
  color: var(--blue-700);
  background: var(--blue-50);
}

.btn-ghost-sm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Canvas Container */
.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: min(100%, calc(68vh * 9 / 16));
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  border-radius: 14px;
  overflow: hidden;
  background: #0a2a85;
  box-shadow: 0 10px 28px rgba(7, 29, 92, 0.22);
  touch-action: none;
  user-select: none;
}

#twibbonCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-wrapper.has-photo {
  cursor: grab;
}

.canvas-wrapper.has-photo.is-dragging {
  cursor: grabbing;
}

/* Empty State CTA positioned cleanly inside the open Polaroid window */
.frame-drop-cta {
  position: absolute;
  left: 19%;
  top: 33.5%;
  width: 58%;
  height: 23.5%;
  border: 2px dashed rgba(27, 92, 255, 0.42);
  border-radius: 12px;
  background: rgba(240, 246, 255, 0.86);
  color: var(--blue-900);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.frame-drop-cta:hover {
  background: rgba(231, 240, 255, 0.96);
  border-color: var(--blue-600);
  transform: scale(1.015);
}

.frame-drop-cta.hidden {
  display: none;
}

.cta-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-700));
  color: var(--white);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(27, 92, 255, 0.3);
}

.cta-icon svg {
  width: 22px;
  height: 22px;
}

.cta-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--blue-950);
}

.cta-sub {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--slate-500);
}

/* Drag-over overlay */
.drag-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 24, 76, 0.68);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.canvas-wrapper.drag-over .drag-overlay {
  opacity: 1;
}

.drag-overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 28px;
  border: 2px dashed var(--lime-500);
  border-radius: 16px;
  color: var(--white);
  font-weight: 700;
  font-size: 0.95rem;
}

.drag-overlay-box svg {
  width: 34px;
  height: 34px;
  color: var(--lime-500);
}

/* Floating Canvas Hint */
.canvas-hint {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  background: rgba(6, 24, 76, 0.82);
  color: var(--white);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  padding: 7px 10px;
  border-radius: 10px;
  backdrop-filter: blur(6px);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.canvas-hint.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Quick Zoom Bar */
.quick-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 8px 10px;
  background: var(--slate-100);
  border-radius: 12px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-700);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.16s ease;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--blue-500);
  color: var(--blue-700);
}

.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zoom-badge {
  min-width: 44px;
  text-align: right;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--slate-700);
  font-variant-numeric: tabular-nums;
}

/* Controls Section */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.panel-highlight {
  border: 1.5px solid rgba(106, 230, 76, 0.6);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(242, 253, 239, 0.92) 100%);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.step-num {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-900));
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.step-num-green {
  background: linear-gradient(135deg, var(--lime-500), var(--lime-600));
  color: var(--lime-900);
}

.step-num-outline {
  background: var(--blue-100);
  color: var(--blue-700);
}

.panel-heading h2 {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--slate-900);
  letter-spacing: -0.015em;
}

.panel-desc {
  font-size: 0.82rem;
  color: var(--slate-500);
  margin-top: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  box-shadow: none !important;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 9px 12px;
  font-size: 0.8rem;
  border-radius: 10px;
}

.btn-sm svg {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue-600), var(--blue-700));
  color: var(--white);
  box-shadow: 0 8px 20px rgba(27, 92, 255, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #2766ff, #0c3ec4);
  box-shadow: 0 10px 24px rgba(27, 92, 255, 0.36);
}

.btn-accent {
  background: linear-gradient(135deg, var(--lime-500), #4bd12b);
  color: var(--lime-900);
  box-shadow: 0 8px 22px rgba(76, 204, 47, 0.32);
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(135deg, #79ef5b, #43c224);
  box-shadow: 0 10px 26px rgba(76, 204, 47, 0.42);
}

.btn-secondary {
  background: var(--slate-100);
  color: var(--slate-900);
  border: 1px solid var(--slate-200);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--blue-50);
  border-color: var(--blue-500);
  color: var(--blue-700);
}

.btn-secondary.active {
  background: var(--blue-100);
  border-color: var(--blue-600);
  color: var(--blue-700);
}

.btn-danger-ghost {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 12px 14px;
  flex-shrink: 0;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: #fee2e2;
}

.upload-actions,
.download-actions {
  display: flex;
  gap: 10px;
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--slate-100);
  padding: 5px;
  border-radius: 12px;
  margin-bottom: 16px;
}

.tab {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--slate-500);
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.tab.active {
  background: var(--white);
  color: var(--blue-700);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Range Sliders */
.control-group {
  margin-bottom: 14px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.control-label-row label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--slate-700);
}

.control-val {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--blue-700);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--slate-200);
  outline: none;
  cursor: pointer;
}

input[type="range"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue-600);
  border: 3px solid var(--white);
  box-shadow: 0 2px 8px rgba(27, 92, 255, 0.4);
  cursor: pointer;
  transition: transform 0.14s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue-600);
  border: 3px solid var(--white);
  box-shadow: 0 2px 8px rgba(27, 92, 255, 0.4);
  cursor: pointer;
}

.quick-transform-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 14px;
}

/* Filter Presets */
.preset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 16px;
}

.preset-chip {
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  background: var(--white);
  color: var(--slate-700);
  cursor: pointer;
  transition: all 0.16s ease;
}

.preset-chip:hover:not(:disabled) {
  border-color: var(--blue-500);
  color: var(--blue-700);
}

.preset-chip.active:not(:disabled) {
  background: var(--blue-600);
  border-color: var(--blue-600);
  color: var(--white);
}

.preset-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Export Selects */
.export-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

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

.select-field span {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--slate-700);
}

.select-field select {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--slate-900);
  background: var(--white);
  border: 1px solid var(--slate-300);
  border-radius: 10px;
  padding: 9px 10px;
  outline: none;
  cursor: pointer;
}

.select-field select:focus {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(27, 92, 255, 0.15);
}

/* Caption */
.caption-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.caption-inputs input,
#captionPreview {
  width: 100%;
  font-family: inherit;
  font-size: 0.84rem;
  color: var(--slate-900);
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.caption-inputs input:focus,
#captionPreview:focus {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(27, 92, 255, 0.12);
}

#captionPreview {
  resize: vertical;
  line-height: 1.5;
  background: var(--slate-100);
  color: var(--slate-700);
  margin-bottom: 10px;
}

/* Footer */
.footer {
  border-top: 1px solid rgba(15, 23, 42, 0.07);
  background: rgba(255, 255, 255, 0.65);
  margin-top: auto;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 16px;
  padding-bottom: 16px;
  font-size: 0.78rem;
  color: var(--slate-500);
}

.footer-inner strong {
  color: var(--blue-900);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--blue-950);
  color: var(--white);
  font-size: 0.84rem;
  font-weight: 700;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid rgba(106, 230, 76, 0.55);
  box-shadow: 0 12px 30px rgba(6, 24, 76, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 60;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Responsive */
@media (max-width: 880px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
    padding-top: 18px;
  }

  .stage-section {
    position: static;
  }

  .canvas-wrapper {
    width: 100%;
    max-width: 340px;
    max-height: none;
  }

  .chip-hide-sm {
    display: none;
  }
}

@media (max-width: 520px) {
  .container {
    padding: 0 14px;
  }

  .stage-card,
  .panel-card {
    padding: 14px;
  }

  .topbar-inner {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .event-chips {
    width: 100%;
  }

  .preset-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .caption-inputs,
  .export-options {
    grid-template-columns: 1fr;
  }
}
