:root {
  --bg: #fff7e8; --kort: #fff; --tekst: #3b2f2a; --aksent: #ff8a3d;
  --skygge: 0 4px 0 rgba(0, 0, 0, .12);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--tekst);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
#app {
  height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.topp { display: flex; align-items: center; gap: 10px; padding: 12px 16px; flex: none; }
.topp h1 { margin: 0; font-size: 26px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.knapp {
  min-width: 56px; height: 56px; border-radius: 18px; background: var(--kort); box-shadow: var(--skygge);
  font-size: 26px; display: grid; place-items: center; padding: 0 10px; text-decoration: none; color: inherit;
}
.knapp:active, .flis:active, .modus:active, .farge:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .12); }
.knapp.valgt { background: var(--aksent); }

/* hjem og motivvalg */
.fliser {
  flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px;
  padding: 8px 16px 24px; align-content: start; overflow: auto;
}
.flis {
  aspect-ratio: 1; border-radius: 28px; background: var(--kort); box-shadow: var(--skygge);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; color: inherit; font-size: 21px; font-weight: 700; position: relative;
}
.flis .ikon { font-size: 60px; }
.flis.av { opacity: .45; }
.flis small { font-size: 14px; font-weight: 600; }
.motiv { aspect-ratio: auto; padding: 12px; }
.motiv svg { width: 100%; height: auto; aspect-ratio: 1; border-radius: 14px; display: block; }
.motiv .navn { font-size: 18px; }
.motiv .stjerne { position: absolute; top: 4px; right: 8px; font-size: 30px; }
.moduser { display: flex; gap: 10px; padding: 0 16px 8px; }
.modus {
  flex: 1; height: 64px; border-radius: 20px; background: var(--kort); box-shadow: var(--skygge);
  font-size: 20px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.modus.valgt { background: var(--aksent); color: #fff; }

/* testinstans: rødt banner, så testdata og ekte data ikke blandes */
body.testmiljo::before {
  content: "TESTMILJØ"; position: fixed; z-index: 20; top: 0; left: 50%; transform: translateX(-50%);
  background: #c62828; color: #fff; font-weight: 800; font-size: 12px; padding: 2px 10px; border-radius: 0 0 8px 8px;
}

/* hvem leker, for voksne */
.hvem { display: flex; gap: 12px; padding: 0 16px 10px; overflow-x: auto; }
.barn {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 14px;
  border-radius: 20px; background: var(--kort); box-shadow: var(--skygge); font-weight: 700; font-size: 16px;
}
.barn span { font-size: 40px; }
.barn.valgt { background: var(--aksent); color: #fff; }
.knapp.voksen { font-size: 20px; opacity: .6; position: relative; overflow: hidden; }
.knapp.voksen.holder { opacity: 1; background: linear-gradient(to top, #ffd2b0 0 100%) no-repeat bottom / 100% 0; animation: fyllopp 1.5s linear forwards; }
@keyframes fyllopp { to { background-size: 100% 100%; } }
.voksenside { padding: 0 16px 24px; overflow: auto; font-size: 17px; -webkit-user-select: text; user-select: text; }
.voksenside h2 { margin: 18px 0 8px; }
.tekstknapp { display: inline-flex; width: auto; font-size: 18px; font-weight: 700; padding: 0 18px; }
.barneliste { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.barneliste li { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px; padding: 6px 6px 6px 12px; font-weight: 700; }
.barneliste .ik { font-size: 30px; }
.barneliste .knapp { margin-left: auto; height: 44px; min-width: 44px; font-size: 20px; }
.nytt-barn { display: grid; gap: 10px; margin: 14px 0; }
.nytt-barn input[name=navn] { font: inherit; font-size: 18px; padding: 12px; border-radius: 12px; border: 1px solid #ccc; }
.ikonvalg { display: flex; flex-wrap: wrap; gap: 6px; }
.ikonvalg input { position: absolute; opacity: 0; }
.ikonvalg span { display: grid; place-items: center; width: 48px; height: 48px; font-size: 28px; border-radius: 14px; background: #fff; box-shadow: var(--skygge); }
.ikonvalg input:checked + span { outline: 4px solid var(--aksent); }

/* nivå, kategorier, personer */
.nivamerke { font-weight: 800; font-size: 15px; background: #fff; border-radius: 14px; padding: 8px 12px; box-shadow: var(--skygge); white-space: nowrap; }
.barn small { font-size: 12px; font-weight: 600; opacity: .75; }
.kategorier { display: flex; gap: 8px; padding: 0 16px 10px; overflow-x: auto; scrollbar-width: none; }
.kat { flex: none; padding: 8px 14px; border-radius: 16px; background: var(--kort); box-shadow: var(--skygge); font-weight: 700; font-size: 16px; }
.kat.valgt { background: var(--tekst); color: #fff; }
.motiv canvas { width: 100%; height: auto; aspect-ratio: 1; display: block; border-radius: 14px; background: #f4f1ec; }
.motiv.nytt { justify-content: center; }
.motiv.nytt .ikon { font-size: 56px; }
.personer li { flex-wrap: wrap; }
.personer .pnavn { min-width: 80px; }
.personer label { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.personer input, .personer select, .voksenside select, .koble input, .ny-enhet input, .nytt-barn input[name=fodselsar] {
  font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 10px; border: 1px solid #ccc; background: #fff;
}
.personer input { width: 90px; }
.koble, .ny-enhet { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.koble input { width: 140px; font-size: 22px; letter-spacing: 4px; text-align: center; }
.feil { color: #c62828; font-weight: 700; }
.kodevisning { background: #fff; border-radius: 16px; padding: 12px 16px; margin: 8px 0; }
.kode { font-size: 44px; font-weight: 800; letter-spacing: 6px; }
.bilderad { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; margin-top: 12px; }
.forhand { width: 300px; height: 300px; border-radius: 14px; background: #f4f1ec; touch-action: none; display: block; }
.bildevalg { display: grid; gap: 10px; min-width: 220px; }
.bildevalg label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.bildevalg label.hake { flex-direction: row; align-items: center; }
.bildevalg input:not([type]), .bildevalg input[type=number], .bildevalg select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid #ccc; }
.filvalg { cursor: pointer; }
.tekstknapp:disabled { opacity: .45; }
/* nivå 1: større fargeknapper */
.verktoy.stor .farge { width: 68px; height: 68px; }

/* tegneflate */
.flate {
  flex: 1; min-height: 0; display: grid;
  grid-template: "topp" auto "scene" 1fr "verktoy" auto / minmax(0, 1fr);
}
.flate > .topp { grid-area: topp; }
.scene { grid-area: scene; min-height: 0; container-type: size; display: grid; place-items: center; padding: 4px 8px; }
.ark {
  position: relative; width: min(100cqw, 100cqh); height: min(100cqw, 100cqh);
  background: #fff; border-radius: 18px; box-shadow: 0 2px 12px rgba(0, 0, 0, .12);
  overflow: hidden; isolation: isolate;
}
.ark > * { position: absolute; inset: 0; width: 100%; height: 100%; }
.ark .bunn { touch-action: none; }
.ark .bunn [data-r] { transition: fill .25s; }
.ark .linjer { mix-blend-mode: multiply; pointer-events: none; }
.ark canvas { pointer-events: none; touch-action: none; }
.ark.tegner canvas { pointer-events: auto; }
.ark.perleark { background: #f4f1ec; }
.perlebrett { touch-action: none; }
.perle { stroke: #b9b2a8; stroke-width: .5; transition: fill .15s; }
.perle.fylt { stroke: rgba(0, 0, 0, .35); }
.nr { font-size: 5.6px; font-weight: 800; fill: #333; pointer-events: none; }
.nr.rist { animation: rist .4s; transform-box: fill-box; transform-origin: center; }
@keyframes rist { 20% { transform: translateX(-1.5px); } 40% { transform: translateX(1.5px); } 60% { transform: translateX(-1px); } 80% { transform: translateX(1px); } }

.verktoy { grid-area: verktoy; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 10px 12px 14px; }
.verktoy .skille { flex-basis: 100%; height: 0; }
.farge {
  width: 56px; height: 56px; border-radius: 50%;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .15), var(--skygge);
  display: grid; place-items: center;
}
.farge.valgt { outline: 5px solid var(--tekst); outline-offset: 3px; }
.tallfarge span {
  font-size: 24px; font-weight: 800; color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, .8), 0 1px 2px rgba(0, 0, 0, .6);
}
.farge.ferdig { opacity: .55; }
.farge.hint { animation: puls .5s 2; }
@keyframes puls { 50% { transform: scale(1.25); } }
.str i { display: block; border-radius: 50%; background: var(--tekst); }

@media (orientation: landscape) {
  .flate { grid-template: "topp topp" auto "scene verktoy" 1fr / minmax(0, 1fr) auto; }
  .verktoy {
    display: grid; grid-template-columns: repeat(2, auto); align-content: center;
    gap: 10px; padding: 8px 16px 12px 4px; overflow: auto;
  }
  .verktoy .skille { grid-column: 1 / -1; height: 2px; background: rgba(0, 0, 0, .08); }
}
@media (orientation: landscape) and (max-height: 520px) {
  .knapp, .farge { width: 44px; min-width: 44px; height: 44px; font-size: 20px; border-radius: 14px; }
  .farge { border-radius: 50%; }
  .verktoy { grid-template-columns: repeat(3, auto); gap: 6px; }
  .topp { padding: 6px 12px; }
  .topp h1 { font-size: 20px; }
}

@media (max-width: 480px) {
  .flate .topp { gap: 6px; padding: 10px 10px; }
  .flate .topp .knapp { min-width: 46px; height: 46px; font-size: 21px; border-radius: 14px; padding: 0 6px; }
  .flate .topp h1 { font-size: 20px; }
}

@media (orientation: portrait) and (max-width: 600px) {
  .verktoy { gap: 6px; padding: 6px 8px 10px; }
  .verktoy .knapp { min-width: 46px; width: 46px; height: 46px; font-size: 21px; border-radius: 14px; padding: 0; }
  .farge { width: 44px; height: 44px; }
  .tallfarge span { font-size: 20px; }
  .farge.valgt { outline-width: 4px; outline-offset: 2px; }
  .scene { padding: 2px 4px; }
}

/* telling, bokstaver, memory */
.quiz { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.prikker { display: flex; justify-content: center; gap: 8px; padding: 0 16px 6px; }
.prikker i { width: 14px; height: 14px; border-radius: 50%; background: #e6dccd; }
.prikker i.naa { outline: 3px solid var(--aksent); }
.prikker i.full { background: #43a047; } .prikker i.halv { background: #fdd835; }
.oppgave { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; padding: 8px 16px 20px; gap: 12px; text-align: center; overflow: auto; }
.sporsmal { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.ting { font-size: clamp(34px, 9vw, 64px); line-height: 1.15; }
.regnebilde { display: flex; align-items: center; gap: 12px; }
.regnebilde .ting { font-size: clamp(20px, 5vw, 34px); }
.regnebilde > span { font-size: 40px; font-weight: 800; }
.regnestykke { font-size: clamp(34px, 8vw, 54px); font-weight: 800; }
.regnestykke.stort { font-size: clamp(44px, 11vw, 76px); }
.bilde { font-size: clamp(80px, 22vw, 140px); line-height: 1; }
.ledetekst { margin: 0; font-size: 28px; font-weight: 700; }
.stor-bokstav { font-size: 64px; color: var(--aksent); }
.ordvis { margin: 0; font-size: clamp(40px, 10vw, 64px); font-weight: 800; letter-spacing: 6px; }
.hull { color: var(--aksent); }
.svar { display: grid; grid-template-columns: repeat(2, minmax(110px, 180px)); gap: 14px; }
.svar.svar3 { grid-template-columns: repeat(3, minmax(90px, 160px)); }
.svarknapp {
  min-height: 96px; border-radius: 24px; background: var(--kort); box-shadow: var(--skygge);
  font-size: 44px; font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.svarknapp:active { transform: translateY(3px); }
.svarknapp.riktig { background: #c8e6c9; }
.svarknapp:disabled { opacity: .25; }
.smaaprikker { font-size: 20px; letter-spacing: 2px; color: var(--aksent); line-height: 1; }
.bokstav { font-size: 56px; }
.rist { animation: ristx .4s; }
@keyframes ristx { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
.ordrad { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.rute { width: 54px; height: 64px; border-radius: 12px; background: #fff; box-shadow: inset 0 -4px 0 #e6dccd; font-size: 40px; font-weight: 800; display: grid; place-items: center; }
.rute.neste { box-shadow: inset 0 -4px 0 var(--aksent); }
.ordrad.riktig .rute { background: #c8e6c9; }
.brikker { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 560px; }
.brikke { width: 64px; height: 64px; border-radius: 16px; background: var(--kort); box-shadow: var(--skygge); font-size: 34px; font-weight: 800; }
.brikke:disabled { opacity: .2; }
.resultat { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 22px; font-weight: 700; }
.stjernerad { font-size: 64px; }
.stjernerad .tom { opacity: .2; }
.trekk { margin: 0 16px 6px; font-weight: 700; }
.memorybrett { flex: 1; min-height: 0; display: grid; gap: 10px; padding: 4px 16px 20px; align-content: center; justify-content: center;
  overflow: hidden; }
.mkort { position: relative; width: 100%; height: 100%; perspective: 600px; }
.mkort > span { position: absolute; inset: 0; border-radius: 16px; backface-visibility: hidden; transition: transform .35s; box-shadow: var(--skygge); overflow: hidden; }
.mkort .bak { background: var(--aksent); color: #fff; font-size: 44px; font-weight: 800; display: grid; place-items: center; }
.mkort .fram { background: #fff; transform: rotateY(180deg); }
.mkort .fram svg { width: 100%; height: 100%; display: block; }
.mkort.opp .bak { transform: rotateY(180deg); }
.mkort.opp .fram { transform: rotateY(0); }
.mkort.funnet .fram { box-shadow: 0 0 0 4px #43a047; }

@media (max-width: 480px) {
  .quiz .topp, .topp:has(.nivamerke) { gap: 6px; padding: 10px; }
  .quiz .topp h1, .topp:has(.nivamerke) h1 { font-size: 20px; }
  .quiz .topp .knapp, .topp:has(.nivamerke) .knapp { min-width: 46px; height: 46px; font-size: 21px; border-radius: 14px; padding: 0 6px; }
  .nivamerke { font-size: 13px; padding: 6px 8px; }
}

/* overlegg */
.overlegg { position: fixed; inset: 0; background: rgba(40, 30, 20, .35); display: grid; place-items: center; z-index: 10; }
.boks {
  position: relative; background: #fff; border-radius: 28px; padding: 24px 28px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2); font-size: 26px; font-weight: 700;
}
.boks p { margin: 8px 0 18px; }
.rad { display: flex; gap: 16px; justify-content: center; }
.knapp.stor { height: 72px; min-width: 96px; font-size: 30px; }
.stor-stjerne { font-size: 90px; animation: sprett .8s ease-out; }
@keyframes sprett { 0% { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.konfetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.konfetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* utskriftsside */
body.utskrift { -webkit-user-select: text; user-select: text; }
body.utskrift #app { height: auto; min-height: 100dvh; }
.valg { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; padding: 0 16px 12px; font-size: 16px; }
.valg label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.valg select, .valg input { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid #ccc; background: #fff; min-width: 120px; }
.merk { flex-basis: 100%; margin: 0; font-size: 14px; }
.ark-print { background: #fff; margin: 0 16px 24px; padding: 16px; border-radius: 12px; overflow: auto; }
.ark-print h2 { margin: 0 0 4px; }
.info { margin: 0 0 10px; font-size: 13px; color: #555; }
.malboks svg { display: block; }
.fargeliste { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; }
.prikk { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid #555; vertical-align: -2px; margin-right: 6px; }
.kontroll span { display: block; width: 100mm; height: 0; border-top: 1px solid #000; margin-top: 8px; position: relative; }
.kontroll span::before, .kontroll span::after { content: ""; position: absolute; top: -5px; height: 9px; border-left: 1px solid #000; }
.kontroll span::before { left: 0; } .kontroll span::after { right: 0; }
.kontroll small { font-size: 11px; color: #555; }

@media print {
  @page { size: A4; margin: 10mm; }
  html, body { background: #fff; height: auto; }
  #app { padding: 0; }
  .ikke-print { display: none !important; }
  .ark-print { margin: 0; padding: 0; border-radius: 0; overflow: visible; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
