/* ========== Design tokens ========== */
:root {
  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-lg: 0 24px 80px rgba(15, 23, 42, 0.12);
  --shadow-md: 0 12px 40px rgba(15, 23, 42, 0.08);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --bg0: #f4f6ff;
  --bg1: #eef2ff;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(148, 163, 184, 0.35);
  --accent: #6366f1;
  --accent2: #a855f7;
  --ring: rgba(99, 102, 241, 0.45);
  --dock-width: min(420px, 100vw - 24px);
}

body.dark {
  --bg0: #070a12;
  --bg1: #0f172a;
  --surface: rgba(15, 23, 42, 0.65);
  --surface-solid: #111827;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.2);
  --accent: #818cf8;
  --accent2: #c084fc;
  --ring: rgba(129, 140, 248, 0.5);
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 12px 40px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  min-height: 100svh;
  font-family: var(--font-sans);
  color: var(--text);
  background: transparent;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* RideWattly tool shell — measured height for iframe embeds */
#wrapper.rw-tool-root {
  min-height: min(100dvh, 100%);
  overflow-x: clip;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.25), transparent 55%),
    radial-gradient(900px 500px at 90% 10%, rgba(168, 85, 247, 0.2), transparent 50%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  transition: opacity 0.4s var(--ease-out);
}

body.dark .app-bg {
  background:
    radial-gradient(1000px 500px at 15% 0%, rgba(99, 102, 241, 0.18), transparent 50%),
    radial-gradient(800px 400px at 85% 20%, rgba(168, 85, 247, 0.12), transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
}

.glass {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

/* ========== Top bar ========== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  margin: 12px 16px 0;
  border-radius: var(--radius-lg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
  position: relative;
  overflow: hidden;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.25);
  transform: rotate(-8deg);
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.install-row {
  display: flex;
  gap: 10px;
  padding: 8px 22px 0;
  margin: 0 16px;
}

/* RideWattly chip buttons (install / home) */
.chip-btn.install-btn,
.chip-btn.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-btn .btn-icon {
  font-size: 1rem;
}

.chip-btn .btn-label {
  font-size: 0.82rem;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

/* ========== Buttons ========== */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  transition:
    transform 0.22s var(--ease-out),
    box-shadow 0.22s var(--ease-out),
    background 0.22s var(--ease-out),
    border-color 0.22s var(--ease-out);
  position: relative;
  overflow: hidden;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: #fff;
  box-shadow: 0 8px 24px rgba(79, 70, 229, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 12px 32px rgba(79, 70, 229, 0.45);
}

.btn-secondary {
  background: var(--surface-solid);
  color: var(--text);
  border-color: var(--border);
}

body.dark .btn-secondary {
  background: rgba(30, 41, 59, 0.9);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-chip {
  padding: 8px 14px;
  font-size: 0.8rem;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.15);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text);
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(148, 163, 184, 0.28);
}

/* Ripple */
.btn-ripple::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.45) 0%, transparent 60%);
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

.btn-ripple:active::after {
  opacity: 1;
  transform: scale(2.5);
  transition: transform 0.5s ease, opacity 0.35s ease;
}

/* ========== Layout ========== */
.layout {
  display: grid;
  grid-template-columns: 1fr var(--dock-width);
  gap: 20px;
  padding: 20px 20px 120px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.canvas-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* ========== Hero mock ========== */
.hero-mock {
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s var(--ease-out);
}

.hero-mock:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.hero-chrome {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.06);
  border-bottom: 1px solid var(--border);
}

body.dark .hero-chrome {
  background: rgba(0, 0, 0, 0.25);
}

.hero-chrome span:nth-child(1),
.hero-chrome span:nth-child(2),
.hero-chrome span:nth-child(3) {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fca5a5;
}

.hero-chrome span:nth-child(2) {
  background: #fcd34d;
}

.hero-chrome span:nth-child(3) {
  background: #86efac;
}

.hero-url {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.hero-body {
  padding: 22px 22px 8px;
}

.hero-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.logo-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.hero-nav nav {
  display: flex;
  gap: 10px;
  flex: 1;
}

.hero-nav nav span {
  width: 52px;
  height: 8px;
  border-radius: 99px;
  background: rgba(148, 163, 184, 0.35);
}

.hero-cta {
  width: 72px;
  height: 28px;
  border-radius: 99px;
  background: var(--text);
  opacity: 0.85;
}

.hero-headline h2 {
  margin: 0 0 8px;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
  letter-spacing: -0.03em;
}

.hero-headline p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 42ch;
}

.hero-wave-host {
  height: 120px;
  margin-top: 8px;
  position: relative;
}

.hero-wave-host svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ========== Live card ========== */
.live-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}

.live-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.live-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.live-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  border-radius: 99px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.12));
  color: var(--accent);
}

body.dark .pill {
  color: #c7d2fe;
}

.svg-wrap {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(248, 250, 252, 0.3));
  border: 1px solid var(--border);
  min-height: 160px;
}

body.dark .svg-wrap {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.6), rgba(2, 6, 23, 0.85));
}

#liveSVG {
  display: block;
  width: 100%;
  height: 180px;
  transition: filter 0.4s var(--ease-out);
}

.pro-veil {
  position: absolute;
  inset: 12px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 5;
}

.pro-veil-inner {
  text-align: center;
  padding: 24px;
  max-width: 320px;
}

.pro-title {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
}

.pro-copy {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.85);
}

/* ========== Templates ========== */
.templates-panel {
  border-radius: var(--radius-lg);
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

.templates-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.template-card {
  flex: 0 0 140px;
  scroll-snap-align: start;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-solid);
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s;
}

.template-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-md);
}

.template-thumb {
  height: 72px;
  background: #e2e8f0;
}

.template-card span {
  display: block;
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

/* ========== Dock ========== */
.dock {
  position: sticky;
  top: 92px;
  border-radius: var(--radius-lg);
  padding: 18px 16px 24px;
  max-height: calc(100dvh - 110px);
  overflow: auto;
  transition: opacity 0.3s, transform 0.35s var(--ease-out);
}

.dock.is-collapsed {
  opacity: 0.55;
  transform: translateX(6px);
}

.dock-handle {
  width: 44px;
  height: 5px;
  border-radius: 99px;
  background: rgba(148, 163, 184, 0.45);
  margin: 0 auto 14px;
  cursor: pointer;
}

.dock-section {
  margin-bottom: 18px;
}

.dock-section h3 {
  margin: 0 0 10px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.layers-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.layer-actions {
  display: flex;
  gap: 8px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preset-btn {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.5);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: transform 0.2s var(--ease-out), border-color 0.2s, box-shadow 0.2s;
}

body.dark .preset-btn {
  background: rgba(30, 41, 59, 0.55);
}

.preset-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.preset-btn.is-locked {
  opacity: 0.65;
  position: relative;
}

.preset-btn .lock-tag {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.range {
  width: 100%;
  accent-color: var(--accent);
  height: 6px;
  border-radius: 99px;
  cursor: pointer;
}

.range:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.layers-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.layer-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.45);
  padding: 12px;
  transition: box-shadow 0.25s, transform 0.25s var(--ease-out);
}

body.dark .layer-card {
  background: rgba(15, 23, 42, 0.55);
}

.layer-card:hover {
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

.layer-card.is-dragging {
  opacity: 0.85;
  transform: scale(1.01);
}

.layer-card.is-drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.layer-card.is-hidden {
  opacity: 0.45;
}

.layer-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.drag-handle {
  cursor: grab;
  padding: 4px 6px;
  color: var(--muted);
  font-size: 1rem;
  user-select: none;
}

.layer-title {
  font-weight: 700;
  font-size: 0.85rem;
  flex: 1;
}

.layer-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  transition: transform 0.15s, background 0.2s;
}

.layer-icon-btn:hover {
  transform: translateY(-1px);
  background: rgba(99, 102, 241, 0.1);
}

.layer-icon-btn.is-on {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

select.input,
input.input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
}

.gradient-editor {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.gradient-type {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.gradient-type label {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.gradient-bar-wrap {
  position: relative;
  height: 28px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 8px;
}

.gradient-bar {
  position: absolute;
  inset: 0;
}

.gradient-stop {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 22px;
  margin-left: -7px;
  border-radius: 4px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transform: translateY(-50%);
  cursor: ew-resize;
  z-index: 2;
}

.gradient-stop:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.stop-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stop-tools input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.mobile-panels-hint {
  display: none;
}

@media (max-width: 1024px) {
  .dock {
    position: relative;
    top: auto;
    max-height: none;
  }

  .mobile-panels-hint {
    display: block;
  }
}

/* ========== Mobile dock & swipe ========== */
.mobile-dock {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  justify-content: space-around;
  gap: 8px;
}

.mobile-dock .m-tab {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 10px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.mobile-dock .m-tab.is-active {
  color: var(--text);
  background: rgba(99, 102, 241, 0.15);
}

.mobile-swipe {
  display: none;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 0 16px 100px;
  -webkit-overflow-scrolling: touch;
}

.mobile-panel {
  flex: 0 0 min(92vw, 420px);
  scroll-snap-align: center;
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

@media (max-width: 700px) {
  .top-actions .btn-ghost:first-of-type {
    order: 1;
  }

  .mobile-dock {
    display: flex;
  }

  .mobile-swipe {
    display: flex;
  }

  .layout {
    padding-bottom: 200px;
  }

  #presetGrid {
    display: none;
  }
}

@media (min-width: 701px) {
  #presetGridMobile {
    display: none;
  }
}

/* ========== Export drawer ========== */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}

.drawer.is-open {
  pointer-events: auto;
  opacity: 1;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.drawer-panel {
  position: absolute;
  right: 16px;
  top: 16px;
  bottom: 16px;
  width: min(520px, calc(100vw - 32px));
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  transform: translateX(110%);
  transition: transform 0.4s var(--ease-out);
  overflow: hidden;
}

.drawer.is-open .drawer-panel {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.export-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tab {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.tab.is-active {
  background: rgba(99, 102, 241, 0.18);
  color: var(--text);
  border-color: transparent;
}

.export-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.tab-pane textarea {
  width: 100%;
  min-height: 200px;
  margin: 10px 0 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(248, 250, 252, 0.85);
  color: var(--text);
  resize: vertical;
}

body.dark .tab-pane textarea {
  background: rgba(2, 6, 23, 0.85);
}

.tab-pane .btn {
  margin-right: 8px;
  margin-bottom: 8px;
}

/* ========== Tool extras & popups ========== */
.tool-extra-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 20px 32px;
  max-width: 1440px;
  margin: 0 auto;
}

.tool-toggle-btn {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(248, 250, 252, 0.85));
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.25s var(--ease-out), box-shadow 0.25s;
}

.tool-toggle-btn:hover {
  transform: translateY(-2px);
}

body.dark .tool-toggle-btn {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(17, 24, 39, 0.9));
  color: #e5e7eb;
}

.legal-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
  animation: fadeIn 0.35s ease;
}

.legal-popup-box {
  width: 100%;
  max-width: 480px;
  background: var(--surface-solid);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: popIn 0.4s var(--ease-out);
}

.legal-popup-icon {
  font-size: 36px;
  margin-bottom: 10px;
}

.legal-popup-box h3 {
  margin: 0 0 12px;
  font-size: 1.35rem;
}

.legal-popup-box p {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 18px;
}

.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
  min-height: 100%;
  min-height: 100dvh;
  min-height: 100svh;
}

.popup-overlay.active {
  display: flex;
  animation: fadeIn 0.25s ease;
}

.popup-box {
  width: 100%;
  max-width: 640px;
  background: var(--surface-solid);
  color: var(--text);
  border-radius: 22px;
  padding: 24px;
  position: relative;
  max-height: calc(100dvh - 40px);
  max-height: calc(100svh - 40px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.3s var(--ease-out);
}

.popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.2);
  cursor: pointer;
  font-size: 1rem;
}

.embed-box textarea,
#embedCode {
  width: 100%;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.copy-btn {
  margin-top: 12px;
  background: #10b981;
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.similar-tools ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.similar-tools li {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}

.similar-tools a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.3s, transform 0.35s var(--ease-out);
  max-width: min(90vw, 420px);
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== Import dock ========== */
.dock-section-import .import-textarea {
  width: 100%;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--surface-solid);
  color: var(--text);
  resize: vertical;
  min-height: 88px;
}

.import-error {
  color: #dc2626;
  font-size: 0.82rem;
  margin: 8px 0 0;
}

body.dark .import-error {
  color: #f87171;
}

/* ========== PNG export background ========== */
.png-bg-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px 14px;
  margin: 12px 0;
}

.png-bg-fieldset .field-label {
  padding: 0 6px;
}

.png-bg-fieldset .field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 0.9rem;
}

.png-bg-fieldset #pngBgColor {
  margin-top: 8px;
  width: 100%;
  max-width: 120px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

/* ========== Focus mode (canvas-first) ========== */
body.is-focus-mode #controlDock,
body.is-focus-mode .templates-panel,
body.is-focus-mode .mobile-dock,
body.is-focus-mode #mobileSwipe,
body.is-focus-mode .tool-extra-actions,
body.is-focus-mode .install-row,
body.is-focus-mode .top-bar .top-actions {
  display: none !important;
}

.focus-mode-bar {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.focus-mode-bar:not([hidden]) {
  display: flex;
}

/* ========== Preset compare (Pro preview) ========== */
.preset-compare-overlay {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
}

.preset-compare-overlay[hidden] {
  display: none !important;
}

body.dark .preset-compare-overlay {
  background: rgba(0, 0, 0, 0.65);
}

.preset-compare-box {
  width: 100%;
  max-width: 920px;
  max-height: min(92vh, 880px);
  overflow: auto;
  padding: 22px 24px 20px;
  border-radius: var(--radius-lg);
}

.preset-compare-box h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.preset-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0 8px;
}

@media (max-width: 720px) {
  .preset-compare-grid {
    grid-template-columns: 1fr;
  }
}

.preset-compare-label {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preset-compare-svg {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface);
  line-height: 0;
}

.preset-compare-svg svg {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: top;
}

.preset-compare-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ========== Reduced motion ========== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
