:root {
  --bg: #000;
  --panel: #121212;
  --panel-2: #1c1c1e;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f5f7;
  --muted: #9a9aa0;
  --accent: #f4c35a;
  --accent-ink: #1a1305;
  --danger: #ff6b5e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.inline { width: 1.1em; height: 1.1em; vertical-align: -0.2em; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- knapper ---------- */
.icon-btn { width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; background: rgba(255,255,255,0.08); }
.icon-btn.small { width: 34px; height: 34px; border-radius: 17px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; padding: 0 20px; border-radius: 25px; background: rgba(255,255,255,0.12); font-weight: 600; font-size: 17px; width: 100%; max-width: 320px; }
.btn svg { width: 22px; height: 22px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { min-height: 40px; font-size: 15px; }
.btn:active, .icon-btn:active, .chip:active, .style-chip:active { transform: scale(0.96); }

/* ---------- kamera ---------- */
#screen-camera { background: #000; }
.viewport { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; }
#viewfinder { width: 100%; height: 100%; object-fit: contain; background: #000; }
#viewfinder.mirror { transform: scaleX(-1); }
.grid { position: absolute; pointer-events: none; inset: 0; }
.grid i { position: absolute; background: rgba(255,255,255,0.28); }
.grid i:nth-child(1) { left: 33.33%; top: 0; bottom: 0; width: 1px; }
.grid i:nth-child(2) { left: 66.66%; top: 0; bottom: 0; width: 1px; }
.grid i:nth-child(3) { top: 33.33%; left: 0; right: 0; height: 1px; }
.grid i:nth-child(4) { top: 66.66%; left: 0; right: 0; height: 1px; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.35s ease-out; }
@keyframes flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }

.cam-fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 0 28px; text-align: center; background: radial-gradient(120% 70% at 50% 35%, #1d1a14 0%, #000 70%); }
.cam-fallback h2 { margin: 6px 0 0; font-size: 24px; }
.cam-fallback p { margin: 0 0 10px; color: var(--muted); line-height: 1.45; max-width: 340px; }
.big-icon { width: 56px; height: 56px; color: var(--accent); stroke-width: 1.4; }

.cam-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 14px) 8px calc(var(--safe-left) + 14px); display: flex; align-items: center; justify-content: space-between; background: linear-gradient(#000c, #0000); z-index: 2; }
.brand { font-weight: 700; letter-spacing: 0.02em; font-size: 19px; }
.brand-mark { color: var(--accent); }

.install-hint { position: absolute; z-index: 3; top: calc(var(--safe-top) + 62px); left: 12px; right: 12px; display: flex; gap: 10px; align-items: flex-start; padding: 12px 12px 12px 16px; background: rgba(28,28,30,0.92); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; line-height: 1.45; }
.install-hint > div { flex: 1; }

.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px calc(var(--safe-right) + 24px) calc(var(--safe-bottom) + 18px) calc(var(--safe-left) + 24px); background: linear-gradient(#0000, #000d 35%); z-index: 2; }
.mode-row { display: flex; justify-content: center; gap: 22px; margin-bottom: 14px; }
.mode { font-size: 13px; font-weight: 600; letter-spacing: 0.08em; color: rgba(255,255,255,0.75); padding: 6px 2px; }
.mode[aria-pressed="true"] { color: var(--accent); }
.controls { display: flex; align-items: center; justify-content: space-between; max-width: 420px; margin: 0 auto; }
.shutter { width: 78px; height: 78px; border-radius: 50%; border: 4px solid #fff; display: grid; place-items: center; }
.shutter span { width: 62px; height: 62px; border-radius: 50%; background: #fff; transition: transform 0.12s ease; }
.shutter:active span { transform: scale(0.88); }
.shutter.hq span { background: radial-gradient(circle at 50% 45%, #fff 0 55%, var(--accent) 56%); }
.shutter:disabled { opacity: 0.5; }
.thumb-btn { width: 52px; height: 52px; border-radius: 12px; overflow: hidden; background: rgba(255,255,255,0.12); display: grid; place-items: center; border: 2px solid rgba(255,255,255,0.85); }
.thumb-btn img { width: 100%; height: 100%; object-fit: cover; }
.thumb-btn img:not([hidden]) + svg { display: none; }
.round-btn { width: 52px; height: 52px; border-radius: 26px; background: rgba(255,255,255,0.14); display: grid; place-items: center; }
.zoom-chips { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; }
.zoom-chips button { min-width: 40px; height: 40px; border-radius: 20px; background: rgba(0,0,0,0.55); font-size: 13px; font-weight: 700; }
.zoom-chips button[aria-pressed="true"] { color: var(--accent); }

/* ---------- redigering ---------- */
#screen-editor { background: #000; }
.ed-top { flex: none; display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 12px) 8px calc(var(--safe-left) + 6px); min-height: 52px; }
.text-btn { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-size: 17px; height: 44px; padding: 0 8px 0 2px; }
.ed-title { font-weight: 600; font-size: 17px; }
.save-btn { background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; height: 36px; padding: 0 18px; border-radius: 18px; }
.save-btn:disabled { opacity: 0.4; }
.save-btn.working { opacity: 0.75; }

.stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; touch-action: none; }
#canvas { display: block; max-width: 100%; max-height: 100%; }
.badge { position: absolute; top: 10px; left: 12px; padding: 4px 10px; border-radius: 10px; background: rgba(0,0,0,0.6); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; pointer-events: none; }
.badge.right { left: auto; right: 12px; color: var(--accent); }
.zoom-badge { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); padding: 4px 10px; border-radius: 10px; background: rgba(0,0,0,0.6); font-size: 12px; font-weight: 600; pointer-events: none; }
.split-handle { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,0.9); pointer-events: none; }
.split-handle .knob { position: absolute; top: 50%; left: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 20px; background: #fff; color: #000; display: grid; place-items: center; box-shadow: 0 2px 10px rgba(0,0,0,0.4); }
.split-handle .knob svg { width: 20px; height: 20px; }

.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.55); transition: opacity 0.25s; }
.busy.done { opacity: 0; pointer-events: none; }
.busy-card { background: rgba(28,28,30,0.95); border: 1px solid var(--line); border-radius: 18px; padding: 20px 22px; display: flex; gap: 16px; align-items: flex-start; max-width: 320px; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; margin-top: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { list-style: none; margin: 0; padding: 0; font-size: 15px; line-height: 1.9; color: var(--muted); }
.steps li.active { color: var(--text); font-weight: 600; }
.steps li.done { color: var(--text); }
.steps li.done::after { content: " ✓"; color: var(--accent); }

.panel { flex: none; background: var(--panel); border-radius: 20px 20px 0 0; padding: 14px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 14px) calc(var(--safe-left) + 16px); display: flex; flex-direction: column; gap: 14px; }
.chips-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -2px; padding: 0 2px; }
.chips-row::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 18px; background: var(--panel-2); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip svg { width: 18px; height: 18px; }
.chip[aria-pressed="true"], .chip.holding { background: var(--text); color: #000; }

.label-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.label-row output { color: var(--accent); font-variant-numeric: tabular-nums; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 32px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) var(--fill, 50%), rgba(255,255,255,0.18) var(--fill, 50%)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255,255,255,0.18); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; margin-top: -11px; box-shadow: 0 1px 6px rgba(0,0,0,0.5); }
input[type=range]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 0; }
input[type=range].centered::-webkit-slider-runnable-track { background: rgba(255,255,255,0.18); }

.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.style-chip { height: 40px; border-radius: 12px; background: var(--panel-2); font-size: 14px; font-weight: 600; }
.style-chip[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }

.disclosure { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--muted); height: 32px; }
.disclosure svg { width: 20px; height: 20px; }
.disclosure .chev { display: inline-block; transition: transform 0.2s; }
.disclosure[aria-expanded="true"] .chev { transform: rotate(90deg); }
.adjust { display: flex; flex-direction: column; gap: 2px; max-height: 32vh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 2px 0 0; }
.adj { display: grid; grid-template-columns: 76px 1fr 38px; align-items: center; gap: 10px; font-size: 14px; }
.adj output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.adj output.changed { color: var(--accent); }
#btn-reset { align-self: center; margin-top: 4px; }

/* ---------- ark ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 10; }
.sheet { position: fixed; z-index: 11; left: 0; right: 0; bottom: 0; max-height: 86vh; background: var(--panel); border-radius: 20px 20px 0 0; transform: translateY(105%); transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); display: flex; flex-direction: column; padding-bottom: var(--safe-bottom); max-width: 640px; margin: 0 auto; }
.sheet.open { transform: translateY(0); }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.25); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 6px 20px; }
.sheet-head h2 { font-size: 20px; margin: 0; }
.sheet-body { overflow-y: auto; padding: 4px 20px 20px; -webkit-overflow-scrolling: touch; }
.sheet-body h3 { font-size: 15px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.reasons, .promises { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.reasons li, .promises li { display: flex; gap: 12px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); line-height: 1.4; font-size: 15px; }
.reasons li svg { color: var(--accent); width: 22px; height: 22px; margin-top: -1px; }
.promises li { color: var(--muted); font-size: 14px; }
.promises li svg { width: 18px; height: 18px; color: #7fd68f; margin-top: 1px; }
.meta { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

.group { background: var(--panel-2); border-radius: var(--radius); margin: 0 0 14px; overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); font-size: 16px; }
.row:last-child { border-bottom: 0; }
.row.col { flex-direction: column; align-items: stretch; }
.row small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; line-height: 1.35; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { flex: none; width: 51px; height: 31px; border-radius: 16px; background: rgba(255,255,255,0.18); position: relative; transition: background 0.2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.switch input:checked + i { background: #34c759; }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: rgba(255,255,255,0.08); border-radius: 10px; padding: 2px; margin-top: 8px; }
.segmented button { height: 34px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: #3a3a3c; color: var(--text); }
.about p { margin: 0; padding: 13px 14px; font-size: 14px; line-height: 1.5; }
.about .muted { color: var(--muted); padding-top: 0; }

.toast { position: fixed; z-index: 20; left: 50%; top: calc(var(--safe-top) + 58px); width: max-content; transform: translate(-50%, -16px); opacity: 0; pointer-events: none; background: rgba(40,40,42,0.96); border: 1px solid var(--line); padding: 12px 16px; border-radius: 14px; font-size: 15px; font-weight: 500; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); transition: opacity 0.2s, transform 0.2s; box-shadow: 0 6px 30px rgba(0,0,0,0.5); }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 8px 14px; border-radius: 10px; font-size: 15px; white-space: nowrap; }

/* liggende telefon: kontroller i siden */
@media (orientation: landscape) and (max-height: 520px) {
  .cam-bottom { top: 0; left: auto; width: auto; padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 10px) 16px; display: flex; flex-direction: column; justify-content: center; background: linear-gradient(90deg, #0000, #000d 35%); }
  .controls { flex-direction: column-reverse; gap: 26px; }
  .mode-row { flex-direction: column; gap: 8px; margin: 0 0 18px; align-items: center; }
  .cam-top { right: auto; bottom: 0; flex-direction: column; padding: calc(var(--safe-top) + 12px) 8px calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 10px); background: linear-gradient(90deg, #000c, #0000); }
  .brand { writing-mode: vertical-rl; transform: rotate(180deg); }
  #screen-editor { flex-direction: row; flex-wrap: wrap; }
  .ed-top { width: 100%; padding-top: calc(var(--safe-top) + 2px); min-height: 44px; }
  .stage { height: calc(100% - 52px); flex: 1 1 50%; }
  .panel { width: min(360px, 45vw); height: calc(100% - 52px); overflow-y: auto; border-radius: 20px 0 0 0; }
  .adjust { max-height: none; overflow: visible; }
}
@media (min-width: 700px) and (orientation: portrait) {
  .panel { max-width: 640px; width: 100%; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
