/* Perleverkstedet
   Søsken av Mønsterverkstedet: toppstripe med sidene, én side om gangen, og
   mønsteret på et lyst perlebrett i midten. Utskriften er A4 i millimeter. */
:root {
  --bg: #f1eee8; --surface: #fffdf9; --sunk: #e8e4dc; --stage: #e9e5dd;
  --ink: #1d1d27; --muted: #5f5d68; --line: #d9d3c8;
  --accent: #c42f3f; --accent-ink: #ffffff; --accent-soft: #f7dfe0;
  --teal: #1f7a83; --teal-soft: #d8ecee;
  --warn: #ac2f29;
  --f-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --f-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --r: 8px; --shadow: 0 1px 2px rgba(40, 28, 20, .06), 0 4px 16px rgba(40, 28, 20, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #15171c; --surface: #1d2027; --sunk: #262a33; --stage: #1a1d23;
  --ink: #ecebef; --muted: #a3a1ad; --line: #333743;
  --accent: #ec6f7a; --accent-ink: #1d0b0e; --accent-soft: #42232a;
  --teal: #6cc3cb; --teal-soft: #1c3438; --warn: #f08378;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25); color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #15171c; --surface: #1d2027; --sunk: #262a33; --stage: #1a1d23;
  --ink: #ecebef; --muted: #a3a1ad; --line: #333743;
  --accent: #ec6f7a; --accent-ink: #1d0b0e; --accent-soft: #42232a;
  --teal: #6cc3cb; --teal-soft: #1c3438; --warn: #f08378;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25); color-scheme: dark;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.45; font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; text-wrap: balance; margin: 0; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 2.4vw, 2.1rem); font-weight: 800; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }
.lead { color: var(--muted); margin: .2rem 0 .9rem; max-width: 75ch; }

/* ---------- toppstripe ---------- */
.top { display: flex; align-items: center; gap: .6rem 1.4rem; padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .6rem; font-family: var(--f-display); font-weight: 800; font-size: 1.25rem; color: var(--ink); text-decoration: none; letter-spacing: -.02em; white-space: nowrap; }
.mark { display: grid; grid-template-columns: repeat(3, 7px); gap: 1px; }
.mark i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: inset 0 0 0 2px transparent; }
.mark i:nth-child(2n) { background: #f0b429; } .mark i:nth-child(3n) { background: var(--teal); } .mark i:nth-child(5) { background: var(--ink); }
.tabs { display: flex; gap: .2rem; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: .45rem .85rem; border-radius: 999px; color: var(--muted); font-weight: 700; text-decoration: none; white-space: nowrap; }
.tabs a:hover { color: var(--ink); background: var(--sunk); }
.tabs a[aria-current] { color: var(--ink); background: var(--accent-soft); }
.savestate { font-size: .85rem; color: var(--muted); white-space: nowrap; margin-left: auto; }

main { max-width: 1680px; margin: 0 auto; padding: 22px 16px 56px; }
.vhead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .8rem 1.2rem; margin-bottom: 20px; }
.vhead p { margin: .3rem 0 0; color: var(--muted); max-width: 72ch; }
.emptystate { max-width: 520px; margin: 6vh auto; text-align: center; display: flex; flex-direction: column; gap: .8rem; align-items: center; }
.emptystate p { color: var(--muted); margin: 0; }
.pegs { width: 140px; height: 84px; background: radial-gradient(circle, var(--line) 3px, transparent 3.5px) 0 0/14px 14px; border-radius: 10px; position: relative; }
.pegs::after { content: ""; position: absolute; left: 28px; top: 28px; width: 70px; height: 28px; background: radial-gradient(circle, var(--accent) 5px, transparent 5.5px) 0 0/14px 14px; }

/* ---------- knapper og felt ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .5rem .95rem; border-radius: var(--r); cursor: pointer; font-weight: 600; text-decoration: none; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--sunk); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: .32rem .65rem; font-size: .88rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--warn); }
.btn.icon { width: 2.4rem; padding: .45rem 0; font-size: 1.15rem; }
.btn[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal); }
.seg { display: flex; gap: .45rem; align-items: center; }
.seg.wrap { flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: .35rem; margin: 0 0 .95rem; }
.field > span:first-child { font-weight: 600; font-size: .92rem; }
.field.indent, .indent { margin-left: 1.7rem; }
.row2 { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row2.nowrap { flex-wrap: nowrap; }
.row2.nowrap input[type=range] { flex: 1; min-width: 0; }
.block { display: block; font-size: .82rem; line-height: 1.3; margin-top: .15rem; }
.mini { display: inline-flex; align-items: center; gap: .4rem; font-size: .92rem; }
input[type=number] { width: 4.6rem; padding: .35rem .45rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
select { padding: .45rem .55rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); max-width: 100%; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: flex-start; gap: .5rem; margin: 0 0 .6rem; cursor: pointer; }
.check input { margin-top: .25rem; accent-color: var(--accent); width: 1rem; height: 1rem; flex: none; }
.check.small { margin: 0; font-size: .85rem; align-items: center; }
.check.small input { margin-top: 0; }
details.more { border-top: 1px solid var(--line); padding-top: .7rem; margin-top: .4rem; }
details.more > summary { cursor: pointer; font-weight: 700; font-family: var(--f-display); margin-bottom: .7rem; }
.sect { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.sect > header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem 1rem; margin-bottom: .3rem; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .65rem 1rem; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: .8rem; align-items: center; z-index: 50; max-width: calc(100vw - 32px); }
.toast .btn { background: transparent; color: inherit; border-color: currentColor; }

/* ---------- mønstrene ---------- */
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 26px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card.aktiv { border-color: var(--accent); }
.thumb { border: 0; padding: 14px; background: radial-gradient(circle, var(--line) 1.2px, transparent 1.6px) 0 0/10px 10px, var(--stage); height: 220px; display: grid; place-items: center; cursor: pointer; }
.thumb canvas { max-width: 100%; max-height: 192px; image-rendering: pixelated; }
.cbody { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: .5rem; }
.cbody p { margin: 0; color: var(--muted); font-size: .9rem; }
.backup { max-width: 760px; }

/* ---------- fra bilde ---------- */
.bildegrid { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.drop { display: flex; flex-direction: column; gap: .6rem; align-items: center; justify-content: center; text-align: center; border: 2px dashed var(--line); border-radius: 10px; padding: 18px 12px; margin-bottom: 1rem; cursor: pointer; color: var(--muted); min-height: 120px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop img { max-width: 100%; max-height: 160px; border-radius: 6px; }
.stage { background: var(--stage); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-width: 0; }
.stagehead { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .6rem; margin-bottom: 10px; }
.canvaswrap { overflow: auto; display: grid; place-items: center; min-height: 360px; border-radius: 8px; }
.canvaswrap canvas { display: block; border-radius: 6px; box-shadow: var(--shadow); }
.canvaswrap.original { background: center/contain no-repeat; min-height: 60vh; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .2rem .65rem .2rem .3rem; font-size: .88rem; }
.chip i { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.chip small { color: var(--muted); }

/* ---------- rediger ---------- */
.edhead { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: 14px; }
.titlefield { flex: 1 1 260px; min-width: 0; display: flex; }
.titlefield input { flex: 1; min-width: 0; font-family: var(--f-display); font-weight: 800; font-size: 1.6rem; border: 1px solid transparent; background: transparent; border-radius: var(--r); padding: .15rem .45rem; }
.titlefield input:hover { border-color: var(--line); }
.titlefield input:focus { border-color: var(--teal); outline: none; background: var(--surface); }
.edgrid { display: grid; grid-template-columns: 74px 1fr 320px; gap: 14px; align-items: start; }
.tools { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; position: sticky; top: 76px; box-shadow: var(--shadow); }
.tools button { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; border-radius: 8px; padding: 7px 2px; cursor: pointer; font-size: .75rem; font-weight: 600; color: var(--muted); }
.tools button:hover { background: var(--sunk); color: var(--ink); }
.tools button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); }
.tools svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tools hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.edstage { position: sticky; top: 76px; }
.edstage .canvaswrap { height: calc(100vh - 210px); min-height: 420px; place-items: safe center; }
#edCanvas { touch-action: none; cursor: crosshair; }
#edCanvas[data-tool="pipette"] { cursor: copy; }
#edCanvas[data-tool="fyll"] { cursor: cell; }
.statusline { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; color: var(--muted); padding: 8px 4px 0; flex-wrap: wrap; }
.edpanel { display: flex; flex-direction: column; gap: 1rem; }
.edpanel h3 { margin-bottom: .45rem; }
.h3row { display: flex; justify-content: space-between; align-items: center; }
.h3row h3 { margin: 0; }
.current { display: flex; align-items: center; gap: .65rem; }
.current span { display: flex; flex-direction: column; line-height: 1.2; }
.current small { color: var(--muted); }
.sw { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; font-style: normal; font-size: .72rem; font-weight: 700; color: #fff; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.sw.lys { color: #1b1d24; }
.current .sw { width: 38px; height: 38px; }
.brukte { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow: auto; }
.frad { display: flex; align-items: center; gap: 2px; border: 1px solid transparent; border-radius: 8px; }
.frad:hover { background: var(--sunk); }
.frad.på { border-color: var(--accent); background: var(--accent-soft); }
.frad.bytter { border-color: var(--teal); background: var(--teal-soft); }
.fvelg { flex: 1; display: flex; align-items: center; gap: .55rem; border: 0; background: none; padding: 3px 6px; cursor: pointer; text-align: left; min-width: 0; }
.fbytt { border: 0; background: none; border-radius: 6px; padding: 4px 8px; cursor: pointer; color: var(--muted); font-size: 1rem; }
.fbytt:hover { background: var(--surface); color: var(--ink); }
.frad span { flex: 1; font-size: .92rem; line-height: 1.2; }
.frad small { color: var(--muted); }
.frad b { font-size: .85rem; font-weight: 600; color: var(--muted); }
#edKart { width: 100%; margin: .45rem 0 .6rem; }
.palett { display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 4px; max-height: 300px; overflow: auto; padding: 2px; }
.pf { aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); padding: 0; }
.pf span { font-size: .62rem; font-weight: 700; color: #fff; opacity: .85; }
.pf span.mørk { color: #1b1d24; }
.pf:hover { transform: scale(1.12); }
.pf.på { outline: 3px solid var(--teal); outline-offset: 1px; }
.bytte { grid-column: 1 / -1; margin: 0 0 .4rem; padding: .5rem .6rem; background: var(--teal-soft); border-radius: 8px; font-size: .9rem; }
.sizegrid { display: grid; grid-template-columns: 1fr auto auto; gap: .35rem .4rem; align-items: center; margin-bottom: .7rem; font-size: .92rem; }
.edpanel .seg.wrap { margin-bottom: .55rem; }

/* ---------- mine farger ---------- */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; margin-top: .9rem; }
.swatch { display: flex; align-items: center; gap: .55rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); }
.swatch:hover { background: var(--sunk); }
.swatch.har { border-color: var(--teal); background: var(--teal-soft); }
.swatch input { accent-color: var(--teal); }
.bead { width: 26px; height: 26px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); position: relative; }
.bead::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.sname { font-size: .9rem; line-height: 1.2; }
.sname small { color: var(--muted); display: block; }
.egne { display: flex; flex-direction: column; gap: 6px; }
.egen { display: flex; gap: .5rem; align-items: center; }
.egen input[type=color] { width: 42px; height: 34px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 2px; }
.egen input[type=text] { padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); min-width: 0; flex: 0 1 280px; }

/* ---------- utskrift ---------- */
.printopts { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 10px; margin-bottom: 18px; max-width: 900px; box-shadow: var(--shadow); }
.pages { display: flex; flex-wrap: wrap; gap: 18px; zoom: .62; }
.page { width: 210mm; height: 297mm; padding: 10mm; background: #fff; color: #111; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; gap: 4mm; font-size: 10pt; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.page h2 { font-size: 16pt; }
.page h3 { font-size: 11pt; }
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: 6mm; }
.phead span { color: #555; font-size: 9.5pt; display: block; margin-top: 1mm; }
.phead > span { margin-top: 2.5mm; }
.kart { flex: none; }
.over { display: flex; justify-content: center; }
.overwrap { position: relative; }
.overwrap svg { display: block; }
.etiketter span { position: absolute; font: 700 9pt var(--f-display); color: #fff; background: #c42f3f; padding: 0 1.2mm; border-radius: 1mm; }
.brettsvg { display: flex; justify-content: center; }
.brettsvg svg { display: block; }
.mål { margin: 0; font-size: 8.5pt; color: #555; display: flex; align-items: center; gap: 2mm; justify-content: center; }
.cm10 { display: inline-block; width: 100mm; height: 2mm; border: .3mm solid #333; border-top: 0; }
.legends { display: grid; gap: 0 6mm; align-items: start; }
.legends.s2 { grid-template-columns: 1fr 1fr; } .legends.s3 { grid-template-columns: 1fr 1fr 1fr; font-size: 8pt; }
.legend { border-collapse: collapse; font-size: 9pt; width: 100%; }
.legend th { text-align: left; font-weight: 600; color: #555; border-bottom: .3mm solid #999; padding: .6mm 2mm; }
.legend td { padding: .5mm 2mm; border-bottom: .1mm solid #ddd; }
.legend .tall { text-align: right; }
.lsw { display: inline-grid; place-items: center; width: 5mm; height: 5mm; border-radius: .6mm; font-weight: 700; font-size: 8pt; box-shadow: inset 0 0 0 .2mm rgba(0,0,0,.3); }

@media (max-width: 1100px) {
  .edgrid { grid-template-columns: 64px 1fr; }
  .edpanel { grid-column: 1 / -1; }
  .edstage .canvaswrap { height: 62vh; }
}
@media (max-width: 760px) {
  .bildegrid { grid-template-columns: 1fr; }
  .edgrid { grid-template-columns: 1fr; }
  .tools { flex-direction: row; flex-wrap: wrap; position: static; }
  .edstage { position: static; }
  .pages { zoom: .42; }
  body { font-size: 16px; }
}

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .top, .noprint, .toast, .view:not(#v-utskrift) { display: none !important; }
  main { padding: 0; max-width: none; }
  .pages { zoom: 1; display: block; gap: 0; }
  .page { box-shadow: none; break-after: page; page-break-after: always; }
  .page:last-child { break-after: auto; page-break-after: auto; }
}
