/* SchoolTutor på nett. Farger og former følger Android-appen. Ingen skrifter eller bilder hentes utenfra. */
:root {
  --bakgrunn: #F6F3EC;
  --kort: #FFFFFF;
  --marine: #1B3A63;
  --blekk: #14213D;
  --dempet: #55617A;
  --myk-marine: #E4ECF7;
  --gull: #F2B134;
  --gronn: #1E7145;
  --rod: #D32F2F;
  --kant: #D9D5CA;
  --ark: #FFFEFA;
  --rute: #C9D6EA;
  --serif: Georgia, "Times New Roman", "Noto Serif", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --haand: "Segoe Print", "Bradley Hand", "Chalkboard SE", "Comic Sans MS", "Marker Felt", cursive;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bakgrunn); color: var(--blekk); font: 16px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
.serif { font-family: var(--serif); font-weight: 700; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
:focus-visible { outline: 3px solid var(--gull); outline-offset: 2px; }

.skjerm { min-height: 100%; min-height: 100dvh; padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.midtstilt { display: flex; align-items: center; justify-content: center; }
.luft { flex: 1; }
.demp { color: var(--dempet); font-size: .92rem; }
.sentrert { text-align: center; }
.rad { display: flex; gap: 10px; align-items: center; }
.rad.mellom { justify-content: space-between; }
.rad.to > * { flex: 1; padding: 0 12px; }

.kort { background: var(--kort); border: 1px solid var(--kant); border-radius: 22px; padding: 18px; box-shadow: 0 1px 3px rgba(20, 33, 61, .08); }
.kort.smal { width: min(100%, 520px); display: flex; flex-direction: column; gap: 14px; }
.kort h1 { font-size: 1.6rem; line-height: 1.2; }
.kort h2 { font-size: 1.15rem; }
.kort h2.stort { font-size: 1.45rem; }

.merkelinje { display: flex; align-items: center; gap: 10px; justify-content: center; }
.merke { width: 34px; height: 34px; flex: none; }
.merkenavn { font-size: 1.35rem; color: var(--marine); }
.merkelinje.stor .merke { width: 44px; height: 44px; }
.merkelinje.stor .merkenavn { font-size: 1.7rem; }

.ikon { width: 22px; height: 22px; flex: none; }
.pille {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1.5px solid transparent; background: var(--myk-marine); color: var(--marine);
  font-weight: 600; font-size: 1rem; line-height: 1.15; text-align: center; user-select: none; -webkit-user-select: none;
}
.pille.hoved { background: var(--marine); color: #fff; }
.pille.gronn { background: var(--gronn); color: #fff; }
.pille.kant { background: var(--kort); border-color: var(--marine); }
.pille.myk { background: var(--myk-marine); }
.pille.tekstknapp { background: transparent; }
.pille.bred { width: 100%; }
.pille.hoy { min-height: 56px; font-size: 1.08rem; }
.pille.liten { min-height: 40px; padding: 0 14px; font-size: .92rem; }
.pille.rund { width: 48px; padding: 0; flex: none; }
.pille:active:not(:disabled) { filter: brightness(.94); }
.ikonknapp { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: transparent; color: var(--blekk); }
.ikonknapp:active:not(:disabled) { background: var(--myk-marine); }
[dir="rtl"] .ikonknapp .ikon, [dir="rtl"] #k-fortsett .ikon, [dir="rtl"] #k-send .ikon { transform: scaleX(-1); }

.felt { width: 100%; border: 1.5px solid #8794AD; border-radius: 14px; background: #EEF2F8; padding: 12px 14px; font-size: 1.05rem; min-height: 48px; resize: vertical; }
.felt::placeholder { color: #7A8598; }
.felt:focus { outline: 3px solid var(--gull); outline-offset: 1px; background: #fff; }
.stabel { display: flex; flex-direction: column; gap: 14px; }
.stabel[hidden] { display: none; }
.pille.bred { width: 100%; }
.kodefelt { text-align: center; font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 1.25rem; letter-spacing: .06em; text-transform: uppercase; }
.feiltekst { color: var(--rod); font-weight: 600; }
.kryss { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.kryss input { width: 24px; height: 24px; margin: 1px 0 0; flex: none; accent-color: var(--marine); }
.lenkerad { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.pris { font-weight: 700; font-size: 1.1rem; color: var(--marine); }
.lenke { color: var(--marine); font-weight: 600; }
.lenke:focus-visible { outline: 3px solid var(--gull); outline-offset: 2px; }

.dialog { border: 1px solid var(--kant); border-radius: 22px; padding: 20px; width: min(92vw, 440px); color: var(--blekk); background: var(--kort); box-shadow: 0 12px 40px rgba(20, 33, 61, .3); }
.dialog::backdrop { background: rgba(20, 33, 61, .45); }
.dialog p { margin-bottom: 16px; font-size: 1.05rem; }
.dialog h2 { margin-bottom: 10px; }
.dialog textarea { width: 100%; margin: 12px 0 10px; }
.dialog p.demp { font-size: .92rem; margin-bottom: 12px; }
.pille.velg[aria-pressed="true"] { background: var(--marine); color: #fff; }

/* ---------- første gang ---------- */
.spraakliste { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.spraakliste .pille { background: var(--kort); border-color: var(--kant); font-weight: 500; }
.spraakliste .pille.valgt { background: var(--marine); color: #fff; border-color: var(--marine); }
.ai-hode { display: flex; align-items: center; gap: 14px; }
.portrett { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--kant); }
.portrett.stor { width: 72px; height: 72px; }

/* ---------- startsiden ---------- */
.start { display: flex; flex-direction: column; }
.startlinje { display: flex; align-items: center; gap: 8px; }
.startinnhold { width: min(100%, 760px); margin: 6px auto 0; display: flex; flex-direction: column; gap: 14px; }
.undertittel { text-align: center; color: var(--dempet); margin-top: -6px; }
#startskjema { display: flex; flex-direction: column; gap: 12px; }
.radkort { display: flex; align-items: center; gap: 12px; }
.fortsett-tekst { flex: 1; min-width: 0; }
.liten-tittel { font-weight: 700; color: var(--marine); }
#fortsett-hva { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sider { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.side { position: relative; width: 84px; height: 108px; border-radius: 12px; overflow: hidden; border: 1px solid var(--kant); background: #eee; }
.side img { width: 100%; height: 100%; object-fit: cover; display: block; }
.side .nr { position: absolute; left: 5px; bottom: 5px; width: 22px; height: 22px; border-radius: 50%; background: var(--marine); color: #fff; font-size: .8rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.side button { position: absolute; right: 3px; top: 3px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .92); display: flex; align-items: center; justify-content: center; }
.side button .ikon { width: 16px; height: 16px; }

/* ---------- arbeidssiden ---------- */
.arbeid { height: 100vh; height: 100dvh; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding-top: max(6px, env(safe-area-inset-top)); overflow-x: hidden; overflow-y: auto; }
.arbeid[hidden] { display: none; }
.topp { display: flex; align-items: center; gap: 6px; min-height: 46px; }
.topp h1 { font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.oppgavekort { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 18px; max-height: 30vh; overflow: auto; }
.oppg-nr { width: 38px; height: 38px; border-radius: 50%; background: var(--marine); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.oppg-nr:empty { display: none; }
.oppg-tekst { flex: 1; min-width: 0; }
.oppg-tittel { font-weight: 700; color: var(--marine); font-size: .95rem; }
.oppg-problem { font-size: 1.15rem; line-height: 1.5; overflow-wrap: anywhere; }
.oppg-problem .katex { font-size: 1.12em; }
.oppgavekort.tom .oppg-problem { font-size: 1rem; color: var(--dempet); }

.flate { flex: 1 1 0; min-height: 150px; overflow: hidden; display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(210px, 300px); gap: 10px; }
/* Plassene i rutenettet er faste, så de andre ikke flytter seg når verktøyene er skjult (tavla vises). */
.verktoy { grid-column: 1; grid-row: 1; }
.midt { grid-column: 2; grid-row: 1; }
.handlinger { grid-column: 3; grid-row: 1; }
.verktoy { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 6px; background: var(--kort); border: 1px solid var(--kant); border-radius: 18px; align-self: start; max-height: 100%; overflow-y: auto; scrollbar-width: none; box-shadow: 0 1px 3px rgba(20, 33, 61, .08); }
.vknapp { width: 46px; height: 46px; border: 0; border-radius: 12px; background: transparent; color: var(--blekk); display: flex; align-items: center; justify-content: center; }
.vknapp.valgt { background: var(--marine); color: #fff; }
.skille { width: 28px; height: 1px; background: var(--kant); margin: 2px 0; }
.farger { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.fargeknapp { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: var(--f); box-shadow: 0 0 0 1px var(--kant); padding: 0; }
.fargeknapp.valgt { box-shadow: 0 0 0 3px var(--gull); }

.midt { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.faner { display: flex; gap: 8px; flex-wrap: wrap; }
.fane { min-height: 40px; padding: 0 16px; background: var(--kort); border-color: var(--marine); font-size: .95rem; }
.fane.valgt { background: var(--marine); color: #fff; }

.ark-rulle { flex: 1; min-height: 120px; overflow-y: scroll; overflow-x: hidden; border: 1px solid var(--kant); border-radius: 14px; background: var(--ark); overscroll-behavior: contain; position: relative; }
.ark-flate {
  position: relative; width: 100%; direction: ltr;
  background-color: var(--ark);
  background-image: linear-gradient(to right, var(--rute) 1px, transparent 1px), linear-gradient(to bottom, var(--rute) 1px, transparent 1px);
}
.ark-blekk, .ark-rodt { position: absolute; left: 0; top: 0; display: block; }
.ark-blekk { touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; z-index: 1; }
.ark-rodt, .ark-tekster, .ark-peker { pointer-events: none; z-index: 2; }
.ark-tekster { position: absolute; inset: 0; }
.ark-retting { position: absolute; color: var(--rod); font-family: var(--haand); line-height: 1.25; max-width: 96%; white-space: normal; text-shadow: 0 0 3px var(--ark), 0 0 3px var(--ark); }
.ark-retting .katex { font-size: 1.05em; }
.ark-merknad { font-size: .6em; margin-top: .1em; }
.ark-peker { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 4px solid var(--gull); background: rgba(242, 177, 52, .25); }
.ark-peker.blink { animation: pek 0.65s ease-in-out 4; }
@keyframes pek { 0%, 100% { transform: scale(.7); opacity: .9; } 50% { transform: scale(1.25); opacity: .55; } }

.tavle { flex: 1; min-height: 120px; overflow-y: auto; border: 1px solid #C9DBCB; border-radius: 14px; background: #F7FAF7; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.tavle-tema { font-family: var(--serif); font-weight: 700; font-size: 1.2rem; color: var(--marine); }
.tavle-tom { color: var(--dempet); }
.tavle-ting { background: #fff; border: 1px solid var(--kant); border-radius: 16px; padding: 12px 14px; animation: inn .35s ease-out; }
@keyframes inn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tavle-steg-hode { display: flex; gap: 10px; align-items: baseline; font-weight: 600; color: var(--marine); }
.tavle-nr { width: 26px; height: 26px; border-radius: 50%; background: var(--myk-marine); color: var(--marine); font-size: .85rem; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.tavle-nr:empty { display: none; }
.tavle-formel { margin-top: 8px; font-size: 1.2rem; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.tavle-formel .katex-display { margin: .2em 0; text-align: start; }
.tavle-formel .katex-display > .katex { text-align: start; }
.tavle-lerret { display: block; width: 100%; max-width: 640px; height: auto; margin: 0 auto; }
.tavle-tegning-tittel { font-weight: 600; color: var(--marine); margin-bottom: 4px; }
.formel-tekst { font-family: var(--serif); }

.handlinger { display: flex; flex-direction: column; gap: 10px; align-content: start; overflow-y: auto; min-height: 0; }
.handlinger .pille { width: 100%; min-height: 50px; }

.bunn { display: flex; flex-direction: column; gap: 8px; flex: none; }
.bunnrad { display: flex; gap: 10px; align-items: stretch; }
.boble { flex: 1.4; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: start; background: var(--kort); border: 1px solid var(--kant); border-radius: 20px; padding: 6px 14px 6px 8px; box-shadow: 0 1px 3px rgba(20, 33, 61, .1); min-height: 60px; }
.boble-inni { display: flex; flex-direction: column; min-width: 0; }
.boble-navn { font-size: .72rem; font-weight: 700; letter-spacing: .06em; color: var(--marine); text-transform: uppercase; }
.boble-tekst { font-size: 1.05rem; line-height: 1.3; max-height: 4.2em; overflow-y: auto; overflow-wrap: anywhere; }
.boble-tekst.tenker { color: var(--dempet); font-style: italic; }
.skriv { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; }
.skriv .felt { border-radius: 999px; padding: 0 18px; background: var(--kort); }

.feil { display: flex; align-items: center; gap: 10px; background: #FDECEA; border: 1px solid #F3B4AE; color: #8C1D18; border-radius: 16px; padding: 6px 8px 6px 14px; font-weight: 600; }
.feil span { flex: 1; }
.logg { max-height: 26vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 12px; }
.logg-linje { max-width: 86%; padding: 7px 12px; border-radius: 14px; background: var(--myk-marine); align-self: flex-start; overflow-wrap: anywhere; }
.logg-linje.elev { align-self: flex-end; background: #F0EBDD; }
.logg-hvem { display: block; font-size: .7rem; font-weight: 700; letter-spacing: .05em; color: var(--dempet); text-transform: uppercase; }

/* ---------- smal skjerm (telefon, og nettbrett på høykant) ---------- */
@media (max-width: 820px) {
  .flate { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; }
  .verktoy { grid-column: 1; grid-row: 1; }
  .midt { grid-column: 1; grid-row: 2; }
  .handlinger { grid-column: 1; grid-row: 3; }
  .verktoy { flex-direction: row; align-self: auto; justify-content: flex-start; padding: 4px 6px; gap: 4px; border-radius: 16px; overflow-x: auto; scrollbar-width: none; }
  .verktoy::-webkit-scrollbar { display: none; }
  .vknapp { width: 44px; height: 44px; flex: none; }
  .skille { width: 1px; height: 26px; margin: 0 2px; flex: none; }
  .farger { display: flex; gap: 8px; }
  .fargeknapp { flex: none; }
  .handlinger { flex-direction: row; flex-wrap: wrap; gap: 8px; overflow: visible; }
  .handlinger .pille { width: auto; flex: 1 1 44%; min-height: 46px; padding: 0 12px; font-size: .95rem; }
  .bunnrad { flex-direction: column; gap: 8px; }
  .boble { min-height: 54px; }
  .boble-tekst { max-height: 3.9em; }
  .oppg-problem { font-size: 1.05rem; }
  .topp h1 { font-size: 1.12rem; }
  .oppgavekort { max-height: 22vh; }
}
@media (max-height: 520px) and (min-width: 821px) {
  .oppgavekort { padding: 6px 10px; }
  .handlinger .pille { min-height: 44px; }
  .boble { min-height: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  .tavle-ting, .ark-peker.blink { animation: none; }
}
