/* Tre kolonner: innstillinger | platen | oversikt og trekkeguide. Stables på smale skjermer. */
:root {
  --ui-font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ui-text-xs: 12px;
  --ui-text-sm: 12px;
  --ui-text-md: 14px;
  --t-meta: 12px;
  --t-body: 14px;
  --t-head: 18px;
  --t-title: 24px;
  --stage: #e6e4df;
  --stage-ink: #5b5850;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  font: 400 var(--t-body)/1.45 var(--ui-font);
  color: var(--ui-text-color);
  background: var(--ui-page);
}
/* Ingen fet eller liten fet tekst i komponentene */
.ds-primary-button, .ds-secondary-button, .ds-neutral-button, .ds-destructive-button,
.ds-segment-button, .ds-chip, .ds-switch-row, .ds-stepper button, .ds-stepper output,
details.ds-accordion > summary { font-weight: 400 !important; }
.ds-segment-button { font-size: var(--t-body) !important; }
/* Ikon foran teksten i valgknappene */
.ds-segment-button:has(> .ds-icon) { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.ds-segment-button > .ds-icon { width: 20px; height: 20px; flex: 0 0 20px; }

h1, h2 { font-weight: 400; margin: 0; text-wrap: balance; }
h1 { font-size: var(--t-title); line-height: 1.2; }
h2 { font-size: var(--t-head); line-height: 1.3; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 320px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top top top" "settings stage info" "foot foot foot";
}
/* Uten resultat er det ingen høyrekolonne */
.app.no-info { grid-template-columns: 340px minmax(0, 1fr); grid-template-areas: "top top" "settings stage" "foot foot"; }
.app.no-info .info-panel { display: none; }
/* Første besøk: bare bildevalget */
.app.empty .after-start { display: none !important; }
.app:not(.empty) .only-empty { display: none !important; }
.topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-divider);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: 'Schibsted Grotesk', var(--ui-font); font-weight: 700; font-size: 24px; line-height: 1; letter-spacing: -0.035em; color: var(--ui-text-color); }
.brand-mark { width: 32px; height: 32px; flex: none; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

/* relative: skjulte etiketter (.sr) langt nede i panelet skal ikke gjøre siden høyere enn vinduet */
.panel { position: relative; background: var(--ui-surface); overflow-y: auto; min-width: 0; }
.settings { grid-area: settings; border-right: 1px solid var(--ui-divider); display: flex; flex-direction: column; }
.info-panel { grid-area: info; border-left: 1px solid var(--ui-divider); }
.group { display: flex; flex-direction: column; gap: 12px; padding: 20px; border-bottom: 1px solid var(--ui-divider); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.settings > details.ds-accordion { margin: 20px; }
/* Innholdet skal rulle, ikke krympes: ellers klemmes trekkspillene flate */
.settings > * { flex-shrink: 0; }
.advanced { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { color: var(--ui-text-secondary); font-size: var(--t-meta); display: flex; justify-content: space-between; gap: 8px; }
.field output { color: var(--ui-text-color); font-variant-numeric: tabular-nums; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 120px; }
.field-row.align-end { align-items: flex-end; }
.field-row > .field.wide { flex-basis: 100%; }
.field.grow { flex: 1 1 auto; }
input[type="number"], select {
  height: var(--ui-control-height);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-control);
  padding: 0 10px;
  font: 400 var(--t-body) var(--ui-font);
  color: var(--ui-text-color);
  background: var(--ui-surface);
  width: 100%;
  font-variant-numeric: tabular-nums;
}
/* Egen pil med luft til kanten, ellers ligger pila klistret mot rammen */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%235b6079' d='M12 15.6 5.7 9.4a.5.5 0 0 1 0-.7l.8-.8a.5.5 0 0 1 .7 0L12 12.6l4.8-4.7a.5.5 0 0 1 .7 0l.8.8a.5.5 0 0 1 0 .7Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
.views-more { padding-left: 16px; }
input[type="color"] {
  height: var(--ui-control-height); width: 56px; padding: 3px;
  border: 1px solid var(--ui-border); border-radius: var(--ui-radius-control); background: var(--ui-surface);
}
input[type="range"] { width: 100%; }
textarea {
  border: 1px solid var(--ui-border); border-radius: var(--ui-radius-control); padding: 8px 10px;
  font: 400 var(--t-body)/1.45 var(--ui-font); color: var(--ui-text-color); background: var(--ui-surface); width: 100%; resize: vertical;
}
input[type="text"], input[type="email"] {
  height: var(--ui-control-height); border: 1px solid var(--ui-border); border-radius: var(--ui-radius-control);
  padding: 0 10px; font: 400 var(--t-body) var(--ui-font); color: var(--ui-text-color); background: var(--ui-surface); width: 100%;
}
/* Glider med hakk (ds-stepped-slider): ett merke per steg under sporet */
input.ds-stepped-slider {
  height: 34px;
  background:
    repeating-linear-gradient(to right, rgba(29,35,71,.28) 0 2px, transparent 2px calc((100% - 2px) / var(--ticks, 4))) 13px calc(100% - 1px) / calc(100% - 26px) 5px no-repeat;
}
.ds-switch-row { margin: 0; }

.file-button { cursor: pointer; }
.wide { width: 100%; }
.small-button { min-height: 32px !important; padding: 0 12px !important; font-size: var(--t-body) !important; }
.ds-primary-button, .ds-secondary-button, .ds-neutral-button { gap: 8px; }
.ds-primary-button .ds-icon, .ds-neutral-button .ds-icon, .ds-secondary-button .ds-icon { width: 18px; height: 18px; flex: 0 0 18px; }

.info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 999px;
  background: transparent; color: var(--ui-text-muted); cursor: help;
}
.info:hover { background: var(--ui-surface-hover); color: var(--ui-text-color); }
.info .ds-icon { width: 18px; height: 18px; }
.info[aria-expanded="true"] { background: var(--ui-surface-hover); color: var(--ui-primary); }
.tip {
  position: fixed; z-index: 50; padding: 12px 14px; border-radius: var(--ui-radius-card);
  background: var(--ui-text-color); color: #fff; box-shadow: 0 10px 30px rgba(20, 18, 12, .22);
  font-size: var(--t-body); line-height: 1.45;
}

/* Grupper som kan lukkes: verdien står i overskriften */
details.fold { gap: 0; }
details.fold > summary { list-style: none; display: flex; align-items: center; gap: 12px; cursor: pointer; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h2 { flex: 0 0 auto; }
.fold-value { flex: 1; min-width: 0; text-align: right; color: var(--ui-text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-chevron { width: 18px; height: 18px; flex: 0 0 18px; color: var(--ui-text-muted); transition: transform .15s; }
details.fold[open] .fold-chevron { transform: rotate(90deg); }
.fold-body { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; }
.group-head .grow { flex: 1; }

.thumb { width: 100%; border-radius: var(--ui-radius-control); background: var(--stage); }

.swatches { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.swatches li {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) 32px; align-items: center; gap: 10px;
  padding: 4px 4px 4px 6px; border-radius: var(--ui-radius-control);
}
.swatches li:hover { background: var(--ui-surface-hover); }
.swatch-color { position: relative; width: 28px; height: 28px; border-radius: 999px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.swatch-color input { position: absolute; inset: -8px; width: 44px; height: 44px; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.swatch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch-remove {
  width: 32px; height: 32px; border: 0; border-radius: 999px; background: transparent;
  color: var(--ui-text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.swatch-remove:hover { background: var(--ui-danger-soft); color: var(--ui-danger); }
.swatch-remove .ds-icon { width: 14px; height: 14px; }

.run-bar { position: sticky; bottom: 0; margin-top: auto; padding: 16px 20px; background: var(--ui-surface); border-top: 1px solid var(--ui-divider); }
.run-bar .ds-primary-button { min-height: 48px; }

.stage { grid-area: stage; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--stage); }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; flex-wrap: wrap; }
.views { overflow-x: auto; max-width: 100%; }
.views-more { width: auto; min-width: 96px; border-radius: 999px; }
.views-more.active { border-color: var(--ui-primary); color: var(--ui-primary); }
.stage-bar .zoom { margin-left: auto; }
.zoom { display: flex; align-items: center; gap: 4px; }
.lift { display: flex; align-items: center; gap: 8px; color: var(--stage-ink); font-variant-numeric: tabular-nums; }
.view3d { position: absolute; inset: 0; background: var(--stage); }
.view3d canvas { display: block; width: 100%; height: 100%; }
.view3d .note { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--stage-ink); }
.view3d .loading3d { flex-direction: column; gap: 12px; background: var(--stage); }
.viewport { position: relative; flex: 1; min-height: 320px; overflow: hidden; touch-action: none; cursor: grab; }
.viewport.dragging { cursor: grabbing; }
.viewport.picking { cursor: crosshair; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Lyd */
.sound { position: absolute; inset: 0; overflow-y: auto; padding: 8px 16px 24px; cursor: default; touch-action: auto; }
.sound-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; max-width: 1200px; margin: 0 auto; }
.card { display: flex; flex-direction: column; gap: 16px; padding: 20px; border-radius: var(--ui-radius-card); background: var(--ui-surface); }
.chart { position: relative; height: 240px; }
.drop {
  position: absolute; inset: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  border: 2px dashed #b9b5aa; border-radius: var(--ui-radius-panel); color: var(--stage-ink); cursor: pointer;
  font-size: var(--t-head);
}
.drop .ds-icon { width: 48px; height: 48px; flex: 0 0 48px; }
.drop.over { background: rgba(255,255,255,.4); border-color: var(--ui-primary); }

.progress {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: min(440px, calc(100% - 32px));
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; align-items: center;
  padding: 12px 16px; border-radius: var(--ui-radius-card); background: var(--ui-surface);
  box-shadow: 0 8px 28px rgba(20, 18, 12, .18);
}
.progress-text { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.progress-track { grid-column: 1; height: 6px; border-radius: 3px; background: var(--ui-surface-subtle); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ui-primary); transition: width .2s ease; }
.progress .small-button { grid-column: 2; grid-row: 1 / span 2; }

.figures { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0; }
.figures div { display: flex; flex-direction: column; gap: 2px; }
.figures dt { color: var(--ui-text-secondary); font-size: var(--t-meta); }
.figures dd { margin: 0; font-size: var(--t-head); font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }
.shop { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.shop th { text-align: left; font-weight: 400; color: var(--ui-text-secondary); font-size: var(--t-meta); padding: 0 6px 6px 0; }
.shop td { padding: 6px 6px 6px 0; border-top: 1px solid var(--ui-divider); }
.shop .num { text-align: right; }
.shop tr.total td { border-top: 1px solid var(--ui-border-strong); }
.color-cell { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dot { display: inline-block; width: 14px; height: 14px; flex: 0 0 14px; border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

.download-list { display: flex; flex-direction: column; gap: 8px; }
.download-list .ds-neutral-button { justify-content: flex-start; }

.guide-step { color: var(--ui-text-secondary); font-variant-numeric: tabular-nums; }
.guide-color { display: flex; align-items: center; gap: 10px; font-size: var(--t-head); }
.guide-color .dot { width: 22px; height: 22px; flex-basis: 22px; }
.guide-move { font-size: 40px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.guide-note { padding: 10px 12px; border-radius: var(--ui-radius-control); background: var(--ui-closed-soft); }
.guide-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.guide-body { display: flex; flex-direction: column; gap: 12px; }
.guide-lock { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 24px 0; color: var(--ui-text-muted); }
.guide-lock > .ds-icon { width: 40px; height: 40px; flex: 0 0 40px; }

/* Underseksjoner i Avansert */
.adv-section { display: flex; flex-direction: column; gap: 12px; padding-bottom: 20px; border-bottom: 1px solid var(--ui-divider); }
.adv-section:last-child { border-bottom: 0; padding-bottom: 0; }
.adv-section h3 { font-size: var(--t-head); font-weight: 400; line-height: 1.3; margin: 0; }

/* Lyd: klasse med ord */
.verdict { display: flex; align-items: center; gap: 16px; }
.grade {
  display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; flex: 0 0 56px;
  border-radius: 999px; font-size: var(--t-title); background: var(--ui-surface-subtle); color: var(--ui-text-color);
}
.grade[data-cls="A"], .grade[data-cls="B"] { background: #d9f0e1; color: #0f5b2e; }
.grade[data-cls="C"] { background: #fff1c7; color: #6b4e00; }
.grade[data-cls="D"], .grade[data-cls="E"] { background: #fde4d6; color: #7a2e0b; }
.verdict-text { display: flex; flex-direction: column; gap: 2px; font-size: var(--t-head); }
.verdict-sub { font-size: var(--t-body); color: var(--ui-text-secondary); }
.sound-more { grid-column: 1 / -1; }
.sound-more .fold-chevron { margin-left: auto; }
.field-row.three > .field { flex: 1 1 80px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

/* Pris og bestilling */
.price-block { display: flex; flex-direction: column; gap: 12px; }
.price-big { font-size: 32px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.info-panel details.ds-accordion { margin: 0; }
.order { width: min(480px, calc(100% - 32px)); }
.order-step { display: flex; flex-direction: column; gap: 16px; }
.order-thumb { width: 100%; max-height: 260px; object-fit: contain; border-radius: var(--ui-radius-control); background: var(--stage); }
.order-total { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--t-head); font-variant-numeric: tabular-nums; padding-top: 12px; border-top: 1px solid var(--ui-divider); }
.order-thanks { margin: 0; }
.pay-buttons.single { grid-template-columns: 1fr; }

/* Betaling */
.pay { border: 0; padding: 0; border-radius: var(--ui-radius-card); width: min(380px, calc(100% - 32px)); color: var(--ui-text-color); box-shadow: 0 16px 48px rgba(20, 18, 12, .24); }
.pay::backdrop { background: rgba(29, 35, 71, .35); }
.pay-body { display: flex; flex-direction: column; gap: 16px; padding: 24px; }
.pay-price { font-size: var(--t-title); font-variant-numeric: tabular-nums; }
.pay-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pay-list li { display: flex; align-items: center; gap: 10px; }
.pay-list .ds-icon { width: 18px; height: 18px; flex: 0 0 18px; color: var(--ui-primary); }
.pay-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pay-consent { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.pay-consent input { width: 18px; height: 18px; margin: 3px 0 0; flex: 0 0 18px; accent-color: var(--ui-primary); }
.terms-link { color: var(--ui-primary); }

/* Firmaopplysninger nederst (krav fra Vipps og forbrukerloven) */
.foot { grid-area: foot; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; padding: 8px 20px; background: var(--ui-surface); border-top: 1px solid var(--ui-divider); color: var(--ui-text-secondary); font-size: var(--t-meta); }
.foot .terms-link { margin-left: auto; }

@media (max-width: 1100px) {
  .app, .app.no-info { grid-template-columns: 300px minmax(0, 1fr); grid-template-areas: "top top" "settings stage" "info info" "foot foot"; grid-template-rows: auto minmax(560px, 1fr) auto auto; height: auto; }
  .info-panel { border-left: 0; border-top: 1px solid var(--ui-divider); display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}
@media (max-width: 760px) {
  .app, .app.no-info { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage" "settings" "info" "foot"; grid-template-rows: auto 70vh auto auto auto; }
  .app.empty { grid-template-areas: "top" "settings" "stage" "foot"; grid-template-rows: auto auto 60vh auto; }
  .sound-grid { grid-template-columns: minmax(0, 1fr); }
  .settings { border-right: 0; }
  .topbar { padding: 12px 16px; }
  .group { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { .progress-fill { transition: none; } }
