:root {
  --bg: #140d0a;
  --bg2: #1e1511;
  --card: #251a15;
  --line: #3a2a22;
  --text: #f6ede6;
  --muted: #b8a397;
  --accent: #ff7a2f;
  --accent2: #ffb347;
  --good: #4fd18b;
  --ok: #ffc94d;
  --low: #ff6b5b;
  --right: #ff8a3d;
  --left: #3dd6ff;
  --radius: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 60% at 50% -10%, #3a1d0f 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px 48px; }
h1 { font-size: 1.5rem; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 4px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--low); margin-top: 10px; }
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 640px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; color: var(--text); font-weight: 700; font-size: 1.1rem; padding: 0; cursor: pointer; }
.logo { width: 28px; height: 28px; border-radius: 50%; background: url(/icon.svg) center/cover; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 14px 0; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.hero { text-align: center; padding: 28px 0 8px; }
.section-title { margin-top: 26px; }

button, .btn-like {
  font: inherit; border-radius: 12px; padding: 12px 18px; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; min-height: 46px; touch-action: manipulation;
}
.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #1a0d05; font-weight: 700; }
.secondary { background: var(--bg2); color: var(--text); border-color: var(--line); }
.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.danger { background: transparent; color: var(--low); border-color: var(--low); margin-top: 10px; }
.big { width: 100%; padding: 16px; font-size: 1.05rem; margin-top: 14px; }
button.small { min-height: 0; padding: 6px 12px; }
button:focus-visible, .btn-like:focus-within, input:focus-visible { outline: 3px solid var(--accent2); outline-offset: 2px; }

input[type=password], input:not([type]), input[type=text] {
  width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); margin: 6px 0 12px;
}
#loginForm button { width: 100%; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 8px 0; }
.field { display: block; margin: 12px 0 4px; }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.row.two > * { flex: 1 1 45%; }
.actions { margin-top: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip { background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; min-height: 0; }
.chip.on { border-color: var(--accent); background: #3a1f10; box-shadow: 0 0 0 1px var(--accent) inset; }

.frame-wrap { position: relative; background: #000; border-radius: 12px; overflow: hidden; }
#frameCanvas, #workCanvas { display: block; width: 100%; height: auto; max-height: 60vh; object-fit: contain; margin: 0 auto; }
#workCanvas { border-radius: 12px; background: #000; image-rendering: auto; }
.pick-hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #1a0d05; font-weight: 700; padding: 6px 12px; border-radius: 999px;
  pointer-events: none; animation: pulse 1.2s infinite alternate;
}
@keyframes pulse { to { opacity: 0.6; } }
.swatch { background: var(--bg2); color: var(--text); border-color: var(--line); justify-content: flex-start; }
.swatch span { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--text); flex: none; }
.swatch span.empty { background: repeating-linear-gradient(45deg, #444 0 4px, #222 4px 8px); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.swatch small { color: var(--muted); }
details.more { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent2); font-weight: 600; padding: 4px 0; }
.tipsbox ul { padding-left: 20px; margin: 10px 0 0; }
.tipsbox li { margin-bottom: 6px; }

.bar { height: 10px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin: 14px 0 8px; }
.bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s; }

.history { display: grid; gap: 10px; }
.hist {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); color: var(--text); padding: 8px; border-radius: 14px;
}
.hist img, .noimg { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: #000; flex: none; }
.hist-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hist-main b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-weight: 800; font-size: 1.1rem; min-width: 46px; text-align: center; padding: 6px 8px; border-radius: 10px; background: var(--bg2); }
.badge.good { color: var(--good); } .badge.ok { color: var(--ok); } .badge.low { color: var(--low); }
.empty { text-align: center; padding: 20px; }

.spark { width: 100%; height: auto; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.spark .pt { fill: var(--accent2); }
.spark .grid { stroke: var(--line); stroke-dasharray: 4 4; }

.result-head { display: flex; gap: 16px; align-items: center; }
.ring { width: 96px; height: 96px; flex: none; }
.ring .track { fill: none; stroke: var(--bg2); stroke-width: 10; }
.ring .val { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; }
.ring.good .val { stroke: var(--good); } .ring.ok .val { stroke: var(--ok); } .ring.low .val { stroke: var(--low); }
.ring text { fill: var(--text); font-size: 26px; font-weight: 800; }
.metrics { display: grid; gap: 14px; margin-top: 16px; }
.metric-top { display: flex; justify-content: space-between; }
.meter { height: 8px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin: 4px 0; }
.meter div { height: 100%; border-radius: 999px; background: var(--accent); }
.meter .good { background: var(--good); } .meter .ok { background: var(--ok); } .meter .low { background: var(--low); }
.progress { background: #1c2a1f; border: 1px solid #2f5a3c; padding: 10px 12px; border-radius: 12px; }
.strengths { list-style: none; padding: 0; margin: 10px 0; }
.strengths li::before { content: "✓ "; color: var(--good); font-weight: 800; }
.tips { padding-left: 22px; margin: 0; }
.tips li { margin-bottom: 14px; }
.tips li::marker { color: var(--accent); font-weight: 800; }
.tips p { margin: 4px 0 0; color: #e8dcd3; }
.notes { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 0.9rem; color: var(--muted); }
.details { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 10px; }
.details th, .details td { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--line); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 6px 0 2px; vertical-align: middle; }
.dot.right { background: var(--right); } .dot.left { background: var(--left); }
.legend { margin-top: 8px; color: var(--muted); font-size: 0.85rem; }
.saved-thumb { display: block; width: 100%; border-radius: var(--radius); margin: 14px 0; }

.player { position: relative; background: #000; border-radius: 12px; overflow: hidden; }
.player video { display: block; width: 100%; max-height: 70vh; }
#overlay { position: absolute; top: 0; left: 0; pointer-events: none; }
.offscreen { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0.01; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #2f2018; border: 1px solid var(--accent); color: var(--text); padding: 10px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); z-index: 10; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

/* colour picking controls */
.swatch-wrap { display: flex; gap: 6px; flex: 1 1 140px; }
.swatch-wrap .swatch { flex: 1; }
.clear-btn { background: var(--bg2); color: var(--muted); border: 1px solid var(--line); padding: 0 14px; min-width: 46px; }
.clear-btn:hover { color: var(--low); border-color: var(--low); }
.tools { margin-top: 10px; }
.tools button { font-size: 0.95rem; }
#removeSpotBtn.active { border-color: var(--low); box-shadow: 0 0 0 2px var(--low) inset; }
#staticInfo { margin-top: 8px; }
.big-btn { min-height: 64px; font-size: 1.1rem; }
#workCanvas[width="0"] { display: none; }

/* add to home screen */
.install-card { display: flex; align-items: center; gap: 12px; border-color: var(--accent); }
.install-card img { border-radius: 12px; flex: none; }
.install-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.install-close { background: none; border: 0; color: var(--muted); min-height: 0; padding: 6px; font-size: 1rem; }
.install-link { text-align: center; margin-top: 24px; }
.sheet {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  width: min(420px, calc(100% - 32px)); padding: 20px;
}
.sheet::backdrop { background: rgba(0,0,0,0.6); }
.sheet ol { padding-left: 22px; margin: 0 0 16px; }
.sheet li { margin-bottom: 10px; }
.sheet form button { width: 100%; }
.kbd { display: inline-block; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg2); }
.top-actions { display: flex; gap: 8px; align-items: center; }
#installTop { white-space: nowrap; }

/* trim step */
.length-tip { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 14px 0 8px; }
.trim-bar { position: relative; height: 10px; background: var(--bg2); border-radius: 999px; margin: 14px 0 4px; overflow: hidden; }
.trim-bar div { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; }
.length-note { border-radius: 12px; padding: 10px 12px; margin: 12px 0 0; font-weight: 600; }
.length-note.good { background: #1c2a1f; color: var(--good); border: 1px solid #2f5a3c; }
.length-note.ok { background: #2e2714; color: var(--ok); border: 1px solid #5c4a1c; }
.length-note.low { background: #2e1714; color: var(--low); border: 1px solid #5c261f; }
#trimBackBtn { margin-top: 10px; width: 100%; }
