@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) 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);
  --field-border: rgba(255,255,255,0.12);
  --text: #f5f6f8;
  --muted: #8b8fa3;
  --accent: #7c6cff;
  --accent-2: #34e0a1;
  --danger: #ff6b6b;
  --radius: 12px;
  /* Buy Me a Coffee's brand yellow — only used on the support widget's cup. */
  --bmc: #ffdd00;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }

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 12% -10%, rgba(124,108,255,0.16), transparent 60%),
    radial-gradient(700px 500px at 100% 5%, rgba(52,224,161,0.10), transparent 55%),
    var(--bg);
}

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 20;
  padding: 10px 14px; border-radius: 10px;
  background: var(--accent); color: #fff; text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 12px; }

.app { max-width: 1400px; margin: 0 auto; padding: 28px 20px 60px; }

/* ── Header ────────────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 26px;
}
.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.03em; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }

.lang-switch { position: relative; }
.lang-button {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 999px;
  background: var(--field-bg); border: 1px solid var(--field-border);
  color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer;
}
.lang-button:hover { border-color: var(--accent); }
.lang-caret { width: 10px; height: 6px; opacity: 0.7; }
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10;
  margin: 0; padding: 6px; list-style: none; min-width: 150px;
  background: #14161d; border: 1px solid var(--panel-border);
  border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.lang-option { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 0.88rem; }
.lang-option:hover, .lang-option:focus-visible { background: rgba(124,108,255,0.18); outline: none; }
.lang-option[aria-selected="true"] { color: var(--accent-2); }

/* ── Page grid ─────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-title {
  margin: 0 0 12px; font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
}
.panel-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.panel-title-row .panel-title { margin-bottom: 12px; }
.subsection { margin-top: 16px; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label {
  display: block; margin-bottom: 6px;
  font-size: 0.8rem; font-weight: 500; color: var(--text);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }

.hint { margin: 6px 0 0; font-size: 0.76rem; color: var(--muted); line-height: 1.45; }
.formula {
  font-family: 'Courier New', monospace;
  color: var(--accent-2);
  background: rgba(52,224,161,0.07);
  border-radius: 8px; padding: 7px 9px;
}

/* ── Form controls ─────────────────────────────────────────────── */
input[type="text"], input[type="number"], textarea, select {
  width: 100%; padding: 9px 11px;
  background: var(--field-bg); border: 1px solid var(--field-border);
  border-radius: 9px; color: var(--text); font: inherit; font-size: 0.85rem;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
select { cursor: pointer; }
input[type="text"]:focus-visible, input[type="number"]:focus-visible,
textarea:focus-visible, select:focus-visible,
input[type="range"]:focus-visible, input[type="color"]:focus-visible,
input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-color: transparent;
}
input[type="color"] {
  width: 100%; height: 38px; padding: 3px;
  background: var(--field-bg); border: 1px solid var(--field-border);
  border-radius: 9px; cursor: pointer;
}
input[type="range"] {
  width: 100%; height: 22px; accent-color: var(--accent);
  background: transparent; cursor: pointer;
}
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

.btn {
  padding: 10px 14px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-size: 0.85rem; font-weight: 700; cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #6a58ff; }
.btn-ghost { background: var(--field-bg); border-color: var(--field-border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.link-btn {
  background: none; border: 0; padding: 2px 4px; margin: 0;
  color: var(--accent); font: inherit; font-size: 0.78rem; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Segmented control */
.segmented {
  display: flex; gap: 4px; padding: 4px;
  background: var(--field-bg); border: 1px solid var(--field-border); border-radius: 10px;
}
.segmented-btn {
  flex: 1; padding: 7px 4px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.segmented-btn:hover { color: var(--text); }
.segmented-btn.is-active { background: var(--accent); color: #fff; }
.segmented-btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }

/* Toggle switch */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 7px 0; font-size: 0.82rem;
}
.switch {
  position: relative; flex: none; width: 40px; height: 22px; padding: 0;
  border: 1px solid var(--field-border); border-radius: 999px;
  background: var(--field-bg); cursor: pointer; transition: background 0.15s ease;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s ease, background 0.15s ease;
}
.switch.is-on { background: rgba(124,108,255,0.35); border-color: var(--accent); }
.switch.is-on::after { transform: translateX(18px); background: var(--accent); }
.switch:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* Drop zone */
.dropzone {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-height: 66px; padding: 12px; text-align: center;
  border: 1px dashed var(--field-border); border-radius: 10px;
  background: var(--field-bg); color: var(--muted);
  font-size: 0.8rem; cursor: pointer; transition: border-color 0.15s ease, color 0.15s ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); color: var(--text); }
.dropzone-compact { flex: 1 1 auto; min-height: 42px; padding: 8px; }
.file-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.file-input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

/* Terms table */
.table-wrap { max-height: 320px; overflow: auto; margin-top: 10px; border-radius: 9px; }
.terms-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.terms-table th {
  position: sticky; top: 0; z-index: 1;
  background: #12141b; color: var(--muted);
  text-align: left; font-weight: 700; padding: 8px 6px;
  border-bottom: 1px solid var(--panel-border);
}
.terms-table td { padding: 6px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.terms-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.terms-table tr.is-off { color: var(--muted); text-decoration: line-through; }

/* ── Preview ───────────────────────────────────────────────────── */
.preview { position: sticky; top: 20px; min-width: 0; }
.preview:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: var(--radius); }
.preview-stage {
  position: relative;
  border: 1px solid var(--panel-border); border-radius: var(--radius);
  overflow: hidden;
  /* Chequerboard: shows where the background stays transparent. */
  background-color: #101219;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.035) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.035) 75%),
    linear-gradient(45deg, rgba(255,255,255,0.035) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.035) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 11px 11px;
}
#cloudCanvas { display: block; width: 100%; height: auto; }
.preview-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 20px;
}
.preview-empty p { margin: 0; font-weight: 700; }
.preview-empty .hint { font-weight: 500; }

.status { margin: 12px 2px 0; font-size: 0.8rem; color: var(--muted); min-height: 1.2em; }
.error {
  margin: 10px 0 0; padding: 10px 12px;
  background: rgba(255,107,107,0.1); border: 1px solid rgba(255,107,107,0.35);
  border-radius: 9px; color: var(--danger); font-size: 0.82rem;
}

.app-footer { margin-top: 34px; text-align: center; color: var(--muted); font-size: 0.76rem; }
.app-footer p { margin: 0; }

/* ── Support button ────────────────────────────────────────────── */
.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 span the full width, so a viewport-fixed
   button would sit on top of them — over the export buttons and the last slider,
   far enough to hide a focused control (WCAG 2.4.11). Anchor it to the end of
   the page instead: same button, just not hovering over the form. */
@media (max-width: 900px) {
  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) {
  * { transition: none !important; }
}
