@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter-ExtraBold.woff2') format('woff2');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* The design is dark throughout. Declaring `light dark` made the browser render
     native widgets (range, colour picker, spinners, scrollbars) light on dark. */
  color-scheme: dark;
  --bg: #08090c;
  --panel: rgba(255,255,255,0.035);
  --panel-border: rgba(255,255,255,0.08);
  --field-bg: rgba(255,255,255,0.04);
  --text: #f5f6f8;
  --muted: #8b8fa3;
  --accent: #7c6cff;
  --accent-2: #34e0a1;
  --danger: #ff6b6b;
  /* Buy Me a Coffee's brand yellow — only used on the support widget's cup. */
  --bmc: #ffdd00;
}

* { box-sizing: border-box; }

/* Available to assistive technology, invisible on screen. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(124,108,255,0.16), transparent 60%),
    radial-gradient(700px 500px at 100% 10%, rgba(52,224,161,0.10), transparent 55%),
    var(--bg);
}

.app { max-width: 1140px; margin: 0 auto; padding: 32px 20px 70px; }

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 30px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { width: 40px; height: 40px; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5)); }
.app-header h1 { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }

/* Custom dropdown — a native <select> popup cannot be styled to match the rest. */
.lang-switch { position: relative; flex-shrink: 0; }

.lang-button {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--field-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.lang-button:hover { border-color: rgba(255,255,255,0.22); }
.lang-button[aria-expanded="true"] { border-color: var(--accent); }

.lang-caret {
  width: 10px;
  height: 6px;
  opacity: 0.65;
  transition: transform 0.15s ease;
}
.lang-button[aria-expanded="true"] .lang-caret { transform: rotate(180deg); }

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 100%;
  margin: 0;
  padding: 4px;
  list-style: none;
  /* Opaque, not translucent like the panels: this floats over the poster. */
  background: #15171e;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.55);
}

.lang-option {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.lang-option:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.lang-option[aria-selected="true"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0c10;
}
.lang-button:focus-visible,
.lang-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .app-header { flex-wrap: wrap; }
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 840px) {
  .layout { grid-template-columns: 1fr; }
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px;
  backdrop-filter: blur(20px);
}

.panel-title {
  margin: 0 0 14px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.panel-title-row .panel-title { margin: 0; }
.subsection .panel-title { margin: 0; }

.dimmed {
  opacity: 0.35;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }

.row-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.subsection {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--panel-border);
}

input[type="text"],
input[type="number"] {
  background: var(--field-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 0.88rem;
}

/* Drag & drop file zones */
.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 62px;
  padding: 12px;
  text-align: center;
  background: var(--field-bg);
  border: 1px dashed var(--panel-border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.dropzone:hover { border-color: rgba(255,255,255,0.22); color: var(--text); }
.dropzone.dragover {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(124,108,255,0.12);
  color: var(--text);
}
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.file-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Custom aspect ratio */
.custom-ratio { margin-top: 12px; }
.custom-ratio.hidden { display: none; }
.ratio-row { display: flex; align-items: center; gap: 8px; }
.ratio-row input[type="number"] { flex: 1; min-width: 0; text-align: center; }
.ratio-sep { color: var(--muted); font-size: 1rem; font-weight: 700; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="color"].swatch {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 11px;
  cursor: pointer;
  background: var(--field-bg);
}
input[type="color"].swatch::-webkit-color-swatch-wrapper { padding: 4px; }
input[type="color"].swatch::-webkit-color-swatch { border: none; border-radius: 8px; }
input[type="color"].swatch::-moz-color-swatch { border: none; border-radius: 8px; }

.hint { margin: 0; font-size: 0.76rem; color: var(--muted); }

.hidden { display: none; }

/* Segmented control */
.segmented {
  display: flex;
  gap: 4px;
  background: var(--field-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 4px;
}
.segmented-btn {
  flex: 1;
  padding: 9px 6px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented-btn:hover { color: var(--text); }
.segmented-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0c10;
}

/* A metric the loaded track has no data for: readable, but clearly inactive. */
.dimmed-label { opacity: 0.55; }

/* Toggle switch */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin-top: 14px;
  /* The 22px track alone would leave the tap target 2px under the 24px minimum;
     padding grows the hit area without changing how the switch looks. */
  padding: 1px 0;
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.toggle input:checked + .toggle-track {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}
.toggle-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }

.toggle-compact { margin-top: 0; }

/* The switch input is visually hidden, so mirror its focus onto the track. */
.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.segmented-btn:focus-visible,
.link-btn:focus-visible,
input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
#downloadBtn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
}

#downloadBtn {
  width: 100%;
  max-width: 400px;
  flex-shrink: 0;
  padding: 14px 16px;
  border: none;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0c10;
  font-size: 0.95rem;
  font-weight: 800;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
#downloadBtn:disabled { opacity: 0.35; cursor: not-allowed; }
#downloadBtn:not(:disabled):hover { opacity: 0.92; }
#downloadBtn:not(:disabled):active { transform: scale(0.98); }

.link-btn {
  background: none;
  border: none;
  /* Padding for a 24px+ tap target, negative margin so the layout is unchanged. */
  padding: 6px 0;
  margin: -6px 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}
.link-btn:hover { text-decoration: underline; }

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.82rem;
  text-align: center;
  max-width: 400px;
  min-height: 1.2em;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 20px;
  align-self: start;
}

.canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: min(460px, 100%);
  max-height: calc(100vh - 220px);
  background: #000;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}

#canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: min(460px, 100%);
  max-height: calc(100vh - 220px);
  cursor: grab;
  touch-action: none;
}

#canvas.dragging {
  cursor: grabbing;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 0.9rem;
  background: #0f1013;
}

.placeholder.hidden { display: none; }

@media (max-width: 840px) {
  /* Show the preview above the controls, so adjustments are visible while scrolling to them. */
  .preview { position: static; top: auto; order: -1; }
  .canvas-wrap,
  #canvas { max-height: 45vh; }
}

/* Windows high contrast strips gradients and backgrounds, which is exactly what
   carries the on/off and selected states here. Restate them with system colours. */
@media (forced-colors: active) {
  .toggle-track {
    background: ButtonFace;
    border: 1px solid ButtonBorder;
  }
  .toggle-thumb { background: ButtonBorder; }
  .toggle input:checked + .toggle-track { background: Highlight; }
  .toggle input:checked + .toggle-track .toggle-thumb { background: HighlightText; }

  .segmented-btn { border: 1px solid transparent; }
  .segmented-btn.active {
    background: Highlight;
    color: HighlightText;
    border-color: ButtonBorder;
  }

  .lang-option[aria-selected="true"] {
    background: Highlight;
    color: HighlightText;
  }

  #downloadBtn { border: 1px solid ButtonBorder; }
  #downloadBtn:disabled { color: GrayText; }

  .dropzone.dragover { border-color: Highlight; }
}

/* Support widget, floating in the bottom-right corner the way Buy Me a Coffee's
   own does — but wearing this page's clothes rather than the brand's full yellow
   slab: the same glass surface, hairline border and muted label as every panel,
   with the yellow kept to the cup. Below .lang-menu's z-index so the dropdown
   always wins. */
.bmc-fab {
  position: fixed;
  right: 20px;
  /* Keep clear of the home indicator on iOS, where the bottom inset is not 0. */
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border-radius: 999px;
  /* Opaque enough that page content scrolling underneath stays out of the label. */
  background: rgba(20,21,27,0.82);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease,
              transform 0.15s ease, box-shadow 0.15s ease;
}
/* The class is the selector, but any svg in here gets the size: an index.html
   cached from before the pill existed has no .bmc-cup, and an unsized inline SVG
   either collapses or fills the button. */
.bmc-fab svg { flex: none; width: 18px; height: 18px; color: var(--bmc); }

/* The space before the label lives on the label, not as a gap on the button.
   A gap is reserved even when the label is empty or absent — which pushes a
   lone cup off centre by half of it — while a margin disappears with it. */
.bmc-fab-label:not(:empty) { margin-left: 8px; }
.bmc-fab:hover {
  color: var(--text);
  border-color: rgba(255,221,0,0.45);
  background: rgba(30,27,12,0.88);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.5);
}
.bmc-fab:active { transform: translateY(0); }
.bmc-fab:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* Single-column layout: the controls now span the full width, so a viewport-fixed
   button would sit on top of them — it covered the last 21px of the pan sliders,
   enough to hide the focused thumb completely (WCAG 2.4.11). Anchor it to the end
   of the page instead: same button, just not hovering over the form. */
@media (max-width: 840px) {
  body { position: relative; }
  .bmc-fab { position: absolute; bottom: 20px; }
}

/* Narrow screens: smaller, and tucked in tighter. */
@media (max-width: 480px) {
  .bmc-fab {
    right: 14px;
    bottom: 14px;
    padding: 8px 12px;
    font-size: 0.74rem;
  }
  .bmc-fab svg { width: 16px; height: 16px; }
  .bmc-fab-label:not(:empty) { margin-left: 7px; }
}

@media (forced-colors: active) {
  .bmc-fab { border: 1px solid ButtonBorder; }
}

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