/* Tagning — en kamera, ett manus, en röd lampa. */
:root {
  --black: #000;
  --steel: #1d232b;      /* paneler */
  --steel-2: #2a323c;    /* fält, kanter */
  --steel-3: #3b4552;
  --paper: #f3eee2;      /* prompterns text */
  --dim: #9aa5b1;        /* sekundär text */
  --tally: #e5281e;      /* röd lampa: bara inspelning */
  --amber: #f2b33d;      /* läsraden */
  --ok: #57c28a;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif;
  --prompt-size: 38px;
  --line-pos: 28%;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: calc(58px + var(--safe-b));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--black); color: var(--paper); font-family: var(--font); font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.5rem; }
.muted { color: var(--dim); }
.grow { flex: 1; }
.err { color: #ff8a80; min-height: 1.4em; margin: 0; }

/* ---------- Knappar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--steel-3);
  background: var(--steel-2); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--steel-3); }
.btn.primary { background: var(--paper); color: var(--black); border-color: var(--paper); }
.btn.primary:hover { background: #fff; }
.btn.danger-ghost { background: transparent; border-color: transparent; color: #ff8a80; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Inloggning ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--steel); }
.login-card { width: min(340px, 100%); display: grid; gap: 10px; }
.login-card h1 { font-size: 2.2rem; margin-bottom: 18px; }
.login-card input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--steel-3); background: var(--black); font-size: 1.1rem; }
.lamp { width: 18px; height: 18px; border-radius: 50%; background: var(--tally); box-shadow: 0 0 24px 4px rgba(229, 40, 30, .55); }

/* ---------- Layout ---------- */
.app { position: fixed; inset: 0; }
.view { position: absolute; inset: 0 0 var(--tabs-h) 0; }
.page { overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--steel); padding-top: var(--safe-t); }
.page-inner { padding: 20px 16px 40px; max-width: 1100px; margin: 0 auto; }
.page-inner.narrow { max-width: 640px; }
.col-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 14px; }
.col-head.spaced { margin-top: 36px; }
.lead { margin-top: -6px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabs-h); padding-bottom: var(--safe-b);
  display: flex; background: var(--black); border-top: 1px solid var(--steel-2); z-index: 20;
}
.tabs button { flex: 1; border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 2px; color: var(--dim); font-size: .72rem; font-weight: 600; }
.tabs svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--paper); }
.tabs button[data-go="record"] svg { color: var(--tally); }
.recording .tabs { display: none; }
.recording .view { bottom: 0; }

/* Desktop: navigering till vänster */
@media (min-width: 900px) {
  :root { --tabs-h: 0px; }
  .tabs { top: 0; right: auto; width: 96px; height: auto; flex-direction: column; justify-content: flex-start; padding: 18px 0; gap: 6px; border-top: 0; border-right: 1px solid var(--steel-2); }
  .tabs button { flex: 0 0 72px; }
  .view { left: 96px; }
  .recording .view { left: 0; }
  .page-inner { padding: 36px 40px 60px; }
}

/* ---------- Inspelning ---------- */
.record { background: var(--black); }
.stage { position: absolute; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
/* Visa hela bilden som spelas in; "Fyll skärmen" beskär bara förhandsvisningen */
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#cam.fill { object-fit: cover; }
#cam.mirror { transform: scaleX(-1); }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 32px; text-align: center; color: var(--dim); }
.cam-msg .btn { margin-top: 14px; }

.prompter {
  position: absolute; left: 0; right: 0; top: 0; height: 54%;
  background: linear-gradient(to bottom, rgba(0,0,0,.82) 0%, rgba(0,0,0,.72) 70%, rgba(0,0,0,0) 100%);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.prompter-scroll {
  position: absolute; inset: 0; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--safe-t) + 48px), #000 82%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--safe-t) + 48px), #000 82%, transparent 100%);
}
.prompter-text {
  position: absolute; left: 0; right: 0; top: 0;
  padding: 0 max(22px, 6vw);
  font-size: var(--prompt-size); line-height: 1.32; font-weight: 700; letter-spacing: .005em;
  will-change: transform; color: var(--paper);
}
.prompter-text.mirror { transform-origin: center; }
.prompter-text p { margin: 0 0 .7em; }
.prompter-text .w { transition: color .25s; }
.prompter-text .w.done { color: rgba(243, 238, 226, .42); }
.prompter-text .w.here { color: var(--amber); }
.prompter-text .placeholder { color: var(--dim); font-weight: 500; font-size: .7em; }
.reading-line { position: absolute; left: 0; width: 10px; top: var(--line-pos); height: calc(var(--prompt-size) * 1.32); background: var(--amber); border-radius: 0 4px 4px 0; transform: translateY(-50%); opacity: .9; }
.prompter-paused { position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%); padding: 6px 12px; border-radius: 99px; background: rgba(0,0,0,.7); color: var(--dim); font-size: .85rem; white-space: nowrap; }
@media (min-width: 900px) {
  .prompter-text { max-width: 980px; margin: 0 auto; right: 0; }
  .prompter { height: 50%; }
}

.listening { position: absolute; left: 12px; top: calc(var(--safe-t) + 14px); display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 99px; background: rgba(0,0,0,.6); color: var(--dim); font-size: .8rem; font-weight: 600; z-index: 6; pointer-events: none; }
.listening span { width: 8px; height: 8px; border-radius: 50%; background: var(--steel-3); }
.listening.on { color: var(--paper); }
.listening.on span { background: var(--amber); }
.speed-hud { position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%); padding: 10px 22px; border-radius: 16px; background: rgba(0,0,0,.72); color: var(--amber); font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; pointer-events: none; z-index: 6; }
.recording .stage { touch-action: none; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30vmin; font-weight: 800; color: var(--paper); text-shadow: 0 4px 40px rgba(0,0,0,.7); pointer-events: none; }

.rec-top { position: absolute; top: calc(var(--safe-t) + 10px); left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; z-index: 5; }
.chip { max-width: 60%; padding: 7px 14px; border-radius: 99px; border: 0; background: rgba(29, 35, 43, .82); backdrop-filter: blur(8px); font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 99px; background: var(--tally); font-weight: 800; font-variant-numeric: tabular-nums; }
.tally-dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.upload-state { margin-left: auto; padding: 6px 12px; border-radius: 99px; background: rgba(29, 35, 43, .82); font-size: .85rem; color: var(--dim); }
.recording .chip { display: none; }

.rec-panel { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(14px + var(--safe-b)); background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,0)); display: grid; gap: 12px; justify-items: center; }
.recording .rec-settings, .recording #btnMore, .recording #btnFlip, .recording .more { visibility: hidden; }
.rec-settings { width: min(520px, 100%); display: grid; gap: 8px; }
.rec-buttons { display: flex; align-items: center; justify-content: center; gap: 44px; }
.rec-btn { width: 78px; height: 78px; border-radius: 50%; border: 4px solid var(--paper); background: transparent; display: grid; place-items: center; padding: 0; }
.rec-inner { width: 60px; height: 60px; border-radius: 50%; background: var(--tally); transition: width .2s, height .2s, border-radius .2s; }
.recording .rec-inner { width: 30px; height: 30px; border-radius: 6px; }
.rec-btn[disabled] { opacity: .4; }
.round { width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(29, 35, 43, .82); display: grid; place-items: center; }

.seg { display: flex; padding: 3px; border-radius: 10px; background: rgba(29, 35, 43, .88); }
.seg button { flex: 1; border: 0; background: none; padding: 7px 8px; border-radius: 8px; font-weight: 600; font-size: .9rem; color: var(--dim); }
.seg button[aria-checked="true"] { background: var(--paper); color: var(--black); }
.slider { display: grid; grid-template-columns: 44px 1fr 38px; align-items: center; gap: 10px; font-size: .85rem; color: var(--dim); }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--paper); }
input[type=range] { width: 100%; accent-color: var(--amber); }
.more { width: min(520px, 100%); display: grid; gap: 8px; padding: 12px 14px; border-radius: 12px; background: rgba(29, 35, 43, .92); }
.check { display: flex; gap: 10px; align-items: center; font-size: .92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--amber); }

/* ---------- Manus ---------- */
.split { display: grid; grid-template-columns: 1fr; height: 100%; }
.list-col { padding: 20px 16px 40px; }
.editor-col { display: none; }
.split.editing .list-col { display: none; }
.split.editing .editor-col { display: block; padding: 16px; }
@media (min-width: 900px) {
  .split { grid-template-columns: 320px 1fr; }
  .list-col { border-right: 1px solid var(--steel-2); overflow-y: auto; padding: 36px 20px; }
  .editor-col, .split.editing .editor-col { display: block; padding: 36px 40px; overflow-y: auto; }
  .split.editing .list-col { display: block; }
  .back-link { display: none; }
}
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.items li > button { width: 100%; text-align: left; border: 0; background: none; padding: 12px 12px; border-radius: 10px; display: grid; gap: 2px; }
.items li > button:hover { background: var(--steel-2); }
.items li > button[aria-current="true"] { background: var(--steel-2); box-shadow: inset 3px 0 0 var(--amber); }
.items .t { font-weight: 700; }
.items .s { font-size: .82rem; color: var(--dim); }
.empty { color: var(--dim); max-width: 46ch; }
.editor { display: grid; gap: 12px; grid-template-rows: auto auto 1fr auto; height: 100%; min-height: calc(100vh - var(--tabs-h) - 40px); }
.back-link { justify-self: start; border: 0; background: none; color: var(--dim); padding: 4px 0; }
.ed-title { font-size: 1.6rem; font-weight: 800; border: 0; background: transparent; padding: 4px 0; outline: none; border-bottom: 1px solid var(--steel-2); }
.ed-text { width: 100%; min-height: 50vh; resize: none; border: 1px solid var(--steel-2); border-radius: 12px; background: var(--black); padding: 16px; font-size: 1.15rem; line-height: 1.6; max-width: 72ch; }
.lang-pick { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: .9rem; }
.lang-pick select { max-width: none; padding: 6px 10px; }
.chip .lang { margin-left: 8px; padding: 1px 6px; border-radius: 6px; background: var(--steel-3); font-size: .75rem; color: var(--paper); }
.ed-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Tagningar ---------- */
select { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--steel-3); background: var(--steel-2); max-width: 55%; }
.group { margin-bottom: 30px; }
.group h3 { font-size: 1.05rem; margin-bottom: 10px; color: var(--dim); font-weight: 700; }
.takes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.take { position: relative; display: grid; gap: 6px; }
.take .thumb { position: relative; aspect-ratio: 9 / 16; border-radius: 10px; overflow: hidden; background: var(--steel-2); border: 0; padding: 0; }
.take .thumb.wide { aspect-ratio: 16 / 9; }
.take .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.take .dur { position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.7); font-size: .78rem; font-variant-numeric: tabular-nums; }
.take .state { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 10px; color: var(--dim); font-size: .85rem; }
.take .row { display: flex; align-items: center; gap: 4px; }
.take .name { font-weight: 700; font-size: .95rem; }
.take .meta { font-size: .78rem; color: var(--dim); }
.icon-btn { border: 0; background: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; color: var(--dim); }
.icon-btn:hover { background: var(--steel-2); color: var(--paper); }
.icon-btn.star[aria-pressed="true"] { color: var(--amber); }
.icon-btn svg { width: 20px; height: 20px; }
.take.starred .thumb { box-shadow: 0 0 0 2px var(--amber); }

/* ---------- Klippningar ---------- */
.renders { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.render { display: grid; grid-template-columns: 88px 1fr auto; gap: 14px; align-items: center; padding: 10px; border-radius: 12px; background: var(--steel-2); }
.render .thumb { width: 88px; height: 88px; border-radius: 8px; overflow: hidden; background: var(--black); border: 0; padding: 0; }
.render .thumb img { width: 100%; height: 100%; object-fit: cover; }
.render .t { font-weight: 700; }
.render .s { font-size: .85rem; color: var(--dim); }
.render .bar { height: 4px; border-radius: 2px; background: var(--steel-3); margin-top: 6px; overflow: hidden; }
.render .bar i { display: block; height: 100%; background: var(--amber); }
.render .actions { display: flex; gap: 4px; }
.render.failed .s { color: #ff8a80; }
.render details { grid-column: 1 / -1; font-size: .8rem; color: var(--dim); }
.render pre { white-space: pre-wrap; max-height: 200px; overflow: auto; }

/* ---------- Inställningar ---------- */
.steps { padding-left: 1.3em; display: grid; gap: 8px; max-width: 60ch; }
.copy-row { display: flex; gap: 8px; margin-top: 16px; }
.copy-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--steel-3); background: var(--black); font-size: .85rem; }

/* ---------- Dialoger ---------- */
dialog { border: 0; padding: 0; color: var(--paper); }
dialog::backdrop { background: rgba(0,0,0,.65); }
.sheet { width: min(480px, calc(100% - 24px)); max-height: 80vh; border-radius: 16px; background: var(--steel); padding: 18px; }
.sheet h3 { margin-bottom: 12px; }
.sheet .items { max-height: 50vh; overflow-y: auto; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.player { width: min(960px, calc(100% - 24px)); background: var(--black); border-radius: 14px; overflow: hidden; }
.player video { display: block; width: 100%; max-height: 78vh; background: #000; }
.player-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--steel); }

.toast { pointer-events: none; position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 18px); transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; background: var(--paper); color: var(--black); font-weight: 600; z-index: 50; max-width: calc(100% - 32px); }
@media (prefers-reduced-motion: reduce) { .rec-inner, .prompter-text .w { transition: none; } .tally-dot { animation: none; } }

/* På inspelningsvyn: visa meddelanden upptill så de inte täcker rec-knappen */
body.on-record .toast { bottom: auto; top: calc(var(--safe-t) + 64px); }
