/* /joleavatar: its own Christmas palette, light and dark after the reader's
   prefers-color-scheme (the /vis and /lesing posture). Deep green, a warm red
   for the one action that matters (Last ned), cream paper. Every pair is
   measured in test/contrast.test.js; the stickers carry their own colours. */

:root {
  --bg: #fbf6ec;
  --bg-rgb: 251, 246, 236;
  --flate: #fffdf8;
  --kant: #e6dcc8;
  --strek: #7a8f82;
  --ink: #1f2a24;
  --ink-2: #4a4438;
  --gran: #17402f;
  --paa-gran: #fbf6ec;
  --raud: #a3201b;
  --paa-raud: #ffffff;
  --scene: #cfe0d8;
  --gull: #c99a2e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1f19;
    --bg-rgb: 15, 31, 25;
    --flate: #17291f;
    --kant: #2a4034;
    --strek: #5f7d6c;
    --ink: #f1ece0;
    --ink-2: #c4bba8;
    --gran: #9fd4b4;
    --paa-gran: #0f1f19;
    --raud: #ff9a8c;
    --paa-raud: #2a0c08;
    --scene: #23392f;
    --gull: #d9ad4a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
}

a { color: var(--gran); text-underline-offset: 3px; }
a:hover { color: var(--raud); }

:focus-visible { outline: 3px solid var(--gull); outline-offset: 2px; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  padding: 10px 14px; border-radius: 10px;
  background: var(--gran); color: var(--paa-gran); font-weight: 600;
}
.skip-link:focus { top: 12px; }

.ja-side {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 16px 48px;
  display: flex; flex-direction: column; gap: 28px;
}

/* ── header ─────────────────────────────────────────────────────────────── */

.ja-topp {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px;
}
.ja-topp-tekst { display: flex; flex-direction: column; gap: 6px; max-width: 640px; }
.ja-heim { font-size: 13px; font-weight: 500; text-decoration: none; }
.ja-topp h1 {
  margin: 0;
  font: 700 clamp(38px, 7vw, 56px)/1.05 Fraunces, Georgia, serif;
  color: var(--gran);
}
.ja-ingress { margin: 0; font-size: 17px; color: var(--ink-2); }
.ja-pynt-topp { width: 240px; height: auto; flex: none; }

/* ── the two columns ────────────────────────────────────────────────────── */

.ja-arbeid { display: flex; flex-wrap: wrap; gap: 32px; align-items: flex-start; }
.ja-scenekol {
  flex: 1 1 440px; max-width: 620px; min-width: 0;
  display: flex; flex-direction: column; gap: 12px;
}
.ja-panel { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* ── the picture ────────────────────────────────────────────────────────── */

.ja-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 18px;
  background: var(--scene);
  box-shadow: 0 1px 0 var(--kant), 0 12px 32px rgba(23, 64, 47, 0.14);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}
.ja-scene.ja-slepp { outline: 3px dashed var(--gran); outline-offset: 4px; }
.ja-scene.ja-flytt-bilete { cursor: move; }

.ja-lag { position: absolute; inset: 0; }

.ja-bilete {
  position: absolute;
  max-width: none;
  pointer-events: none;
  -webkit-user-drag: none;
}

.ja-pynt {
  position: absolute;
  padding: 0; margin: 0;
  /* No border: it would take its width out of the sticker's own and make the
     DOM draw it smaller than the previews and the PNG. The selection is an
     outline, which takes no room. */
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: grab;
  touch-action: none;
  line-height: 0;
}
.ja-pynt img { display: block; width: 100%; height: auto; pointer-events: none; -webkit-user-drag: none; }
/* A shaped sticker (ADR 0075) is drawn as SVG in its square box. A tail
   pulled past the box is still drawn and still takes a press. */
.ja-pynt { overflow: visible; }
.ja-pynt .ja-form { display: block; width: 100%; height: auto; aspect-ratio: 1; overflow: visible; }
/* The selection ring and its handles are drawn in a layer of their own on top
   (.ja-valramme), so a sticker behind the person shows its ring as well. */
.ja-pynt:focus-visible { outline: 3px solid var(--gull); outline-offset: 2px; }
.ja-pynt:active { cursor: grabbing; }

.ja-maske {
  position: absolute; inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 100vmax rgba(var(--bg-rgb), 0.62);
  outline: 2px dashed var(--strek);
  outline-offset: -2px;
  pointer-events: none;
}

.ja-merke {
  position: absolute; left: 12px; top: 12px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--gran); color: var(--paa-gran);
  font-size: 12px; font-weight: 600;
  pointer-events: none;
}

/* ── the selected sticker's tools, and the zoom ─────────────────────────── */

/* Two rows, always the same height, whether a sticker is selected or not, so
   nothing under it jumps when a sticker is tapped, and every tool is in sight:
   the layer switch, «Meir» and «Angre» on top, size, turn and remove under. */
.ja-verktoy {
  height: 120px; box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--flate);
  border: 1px solid var(--kant);
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
}
.ja-verktoy-topp { display: flex; align-items: center; gap: 6px; min-height: 44px; }
.ja-verktoy-rom { flex: 1 1 auto; }
.ja-verktoy-rad { display: flex; align-items: center; min-height: 44px; }
.ja-verktoy-hjelp { margin: 0; color: var(--ink-2); font-size: 14px; }
.ja-verktoy-knappar { display: flex; align-items: center; gap: 6px; }
.ja-verktoy-knappar[hidden], .ja-lagval[hidden], .ja-meir[hidden] { display: none; }
.ja-meir { position: relative; }
.ja-verktoy-knapp {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; min-width: 44px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--strek);
  background: var(--bg);
  color: var(--gran);
  font: 500 14px/1.2 Inter, system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
}
.ja-verktoy-knapp:hover { border-color: var(--gran); }
.ja-verktoy-knapp[disabled] { opacity: 0.5; cursor: default; }
.ja-ikon { flex: none; }

.ja-meir > summary { list-style: none; }
.ja-meir > summary::-webkit-details-marker { display: none; }
.ja-meir[open] > summary { background: var(--gran); color: var(--paa-gran); border-color: var(--gran); }
.ja-meir-meny {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 6;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
  border-radius: 14px;
  background: var(--flate);
  border: 1px solid var(--kant);
  box-shadow: 0 8px 24px rgba(23, 64, 47, 0.18);
}
.ja-meir-meny .ja-verktoy-knapp { justify-content: flex-start; }

.ja-hint { margin: 0; font-size: 13px; color: var(--ink-2); }
.ja-hint-touch { display: none; }
@media (pointer: coarse) {
  .ja-hint-mus { display: none; }
  .ja-hint-touch { display: inline; }
}

.ja-zoom { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--ink-2); }
.ja-zoom input { flex: 1 1 auto; accent-color: var(--gran); min-height: 44px; }

/* ── buttons ────────────────────────────────────────────────────────────── */

.ja-knapp {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--strek);
  background: transparent;
  color: var(--gran);
  font: 500 15px/1.2 Inter, system-ui, sans-serif;
  cursor: pointer;
  text-decoration: none;
}
.ja-knapp:hover { background: rgba(var(--bg-rgb), 0.6); border-color: var(--gran); }
.ja-knapp[disabled] { opacity: 0.55; cursor: default; }
.ja-knapp-fare { color: var(--raud); font-weight: 600; }
.ja-knapp-hovud { background: var(--gran); border-color: var(--gran); color: var(--paa-gran); font-weight: 600; }
.ja-knapp-hovud:hover { background: var(--gran); color: var(--paa-gran); filter: brightness(1.1); }
.ja-knapp-last {
  width: 100%; min-height: 52px;
  border: 0; border-radius: 14px;
  background: var(--raud); color: var(--paa-raud);
  font-size: 16px; font-weight: 600;
}
.ja-knapp-last:hover { background: var(--raud); color: var(--paa-raud); filter: brightness(1.08); }

.ja-fil { position: relative; overflow: hidden; }
.ja-fil input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 0;
}
.ja-fil:focus-within { outline: 3px solid var(--gull); outline-offset: 2px; }

/* ── the steps ──────────────────────────────────────────────────────────── */

.ja-steg {
  padding: 20px;
  border-radius: 16px;
  background: var(--flate);
  border: 1px solid var(--kant);
  display: flex; flex-direction: column; gap: 12px;
}
.ja-steg h2 {
  margin: 0;
  display: flex; align-items: center; gap: 10px;
  font: 700 22px/1.2 Fraunces, Georgia, serif;
  color: var(--gran);
}
.ja-valfritt {
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--kant); background: var(--bg); color: var(--ink-2);
  font: 600 12px/1.3 Inter, system-ui, sans-serif;
}
.ja-rad { display: flex; flex-wrap: wrap; gap: 10px; }
.ja-notis { margin: 0; font-size: 13px; color: var(--ink-2); }

.ja-pyntknappar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}
.ja-pyntknapp {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 8px;
  border-radius: 12px;
  border: 1px solid var(--kant);
  background: var(--bg);
  color: var(--ink);
  font: 500 12px/1.25 Inter, system-ui, sans-serif;
  text-align: center;
  cursor: pointer;
}
.ja-pyntknapp:hover { border-color: var(--strek); }
.ja-pyntknapp img { width: 52px; height: 52px; object-fit: contain; pointer-events: none; }

.ja-forhand { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.ja-forhand figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ja-forhand canvas {
  display: block;
  background: var(--scene);
  box-shadow: 0 0 0 1px var(--kant);
  border-radius: 6px;
}
.ja-forhand.ja-rund canvas { border-radius: 50%; }
.ja-forhand figcaption { font-size: 12px; color: var(--ink-2); }

.ja-kryss { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.ja-kryss input { width: 20px; height: 20px; accent-color: var(--gran); }

/* What just happened, said on the picture where the eye is, and gone again
   after a few seconds. It is also the live region a screen reader hears. */
.ja-status {
  position: absolute; left: 50%; bottom: 14px; z-index: 4;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  margin: 0;
  padding: 8px 14px; border-radius: 12px;
  background: var(--gran); color: var(--paa-gran);
  font-size: 14px; font-weight: 500; text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.ja-status.ja-vis { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) { .ja-status { transition: none; } }

/* ── layers: the person and the background (ADR 0071) ─────────────────── */

/* The cut-out and the mask overlay are canvases laid exactly over the photo.
   Neither takes a pointer, so a sticker behind the person can still be picked
   up through them. */
.ja-utklipp, .ja-maskevis {
  position: absolute;
  max-width: none;
  pointer-events: none;
}
.ja-maskevis { opacity: 0.5; }
.ja-bakgrunn { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
/* The ring is dark green with a white edge inside, so it reads on a light
   photo and on a night sky alike. Its handles take the pointer: the right
   corner sets the size, the left one (drawn as a turning arc) turns it. */
.ja-valramme {
  position: absolute; z-index: 3;
  outline: 2px dashed var(--gran);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #ffffff;
  border-radius: 10px;
  line-height: 0;
  pointer-events: none;
}
.ja-valramme img { display: block; width: 100%; height: auto; visibility: hidden; }
.ja-valboks { display: block; width: 100%; aspect-ratio: 1; }
/* The point handles of a shaped sticker sit in the sticker's own box, in a
   layer of their own so a keyboard can reach them (the ring is aria-hidden).
   Gold, unlike the green size and turn knobs: these change the shape. */
.ja-formramme {
  position: absolute; z-index: 4;
  aspect-ratio: 1;
  pointer-events: none;
}
.ja-formpunkt {
  position: absolute;
  width: 22px; height: 22px;
  margin: 0; padding: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--gull);
  border: 2px solid var(--gran);
  box-shadow: 0 0 0 2px #ffffff;
  box-sizing: border-box;
  pointer-events: auto;
  touch-action: none;
  cursor: move;
}
.ja-formpunkt::after { content: ""; position: absolute; inset: -11px; border-radius: 50%; }
.ja-formpunkt:focus-visible { outline: 3px solid var(--gran); outline-offset: 3px; }
.ja-formtal[hidden], #form-std[hidden] { display: none; }
.ja-formtal { padding: 4px 8px; }
.ja-formtal-rad { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }
.ja-formtal-rad input { width: 100%; }
.ja-handtak {
  position: absolute;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--gran);
  box-sizing: border-box;
  pointer-events: auto;
  touch-action: none;
}
/* A 44 px target around the 22 px knob. */
.ja-handtak::after { content: ""; position: absolute; inset: -11px; border-radius: 50%; }
.ja-handtak-storleik { right: -15px; bottom: -15px; cursor: nwse-resize; }
/* Both knobs sit on bottom corners: a sticker near the top edge of the
   picture would have a knob above it cut off. */
.ja-handtak-vri { left: -15px; bottom: -15px; cursor: grab; }
.ja-handtak-vri::before {
  content: ""; position: absolute; inset: 4px;
  border: 2px solid var(--gran); border-left-color: transparent;
  border-radius: 50%;
}
.ja-scene.ja-penselmodus { cursor: crosshair; }
.ja-penselmodus .ja-pynt { pointer-events: none; }
.ja-penselring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px var(--gran);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.ja-leitar {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(var(--bg-rgb), 0.7);
}
.ja-leitar span {
  padding: 10px 16px; border-radius: 12px;
  background: var(--gran); color: var(--paa-gran); font-weight: 600;
}

.ja-lagval {
  display: inline-flex;
  border: 1px solid var(--strek);
  border-radius: 12px;
  overflow: hidden;
}
.ja-lagknapp {
  min-height: 44px; padding: 0 12px;
  border: 0; background: var(--bg); color: var(--gran);
  font: 600 14px/1.2 Inter, system-ui, sans-serif;
  cursor: pointer;
}
.ja-lagknapp + .ja-lagknapp { border-left: 1px solid var(--strek); }
.ja-lagknapp[aria-pressed="true"], .ja-knapp[aria-pressed="true"] { background: var(--gran); color: var(--paa-gran); border-color: var(--gran); }
.ja-lagknapp[disabled] { opacity: 0.55; cursor: default; }
#lag-hjelp { flex-basis: 100%; }
#lag-hjelp:empty { display: none; }

.ja-pyntknapp { position: relative; }
/* «bak» only means something once the person is found. */
.ja-arbeid:not(.ja-funnen) .ja-bak-merke { display: none; }
.ja-bak-merke {
  position: absolute; top: 4px; right: 4px;
  padding: 0 6px; border-radius: 999px;
  background: var(--gran); color: var(--paa-gran);
  font: 600 10px/16px Inter, system-ui, sans-serif;
}

.ja-notis-stor { margin: 0; font-size: 14px; color: var(--ink); }
.ja-notis-stor strong { color: var(--gran); }
#person-start, #person-funnen { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.ja-pensel { align-items: center; }
.ja-penselstorleik { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.ja-penselstorleik input { width: 100px; accent-color: var(--gran); min-height: 40px; }

.ja-sceneknappar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}
.ja-scene-knapp {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 4px 8px;
  border-radius: 12px;
  border: 2px solid var(--kant);
  background: var(--bg);
  color: var(--ink);
  font: 500 12px/1.25 Inter, system-ui, sans-serif;
  cursor: pointer;
}
.ja-scene-knapp[aria-pressed="true"] { border-color: var(--gran); }
.ja-scene-knapp[disabled] { opacity: 0.5; cursor: default; }
.ja-scene-bilete {
  display: block; width: 100%; aspect-ratio: 1; height: auto;
  border-radius: 8px; object-fit: cover;
}
.ja-scene-eige { background: var(--scene) url(/joleavatar/doeme.svg) center / cover no-repeat; }

/* ── tips and the footer ────────────────────────────────────────────────── */

.ja-tips { font-size: 14px; color: var(--ink-2); }
.ja-tips summary { cursor: pointer; color: var(--gran); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.ja-tips ul { margin: 4px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.ja-tips kbd {
  font: 500 12px ui-monospace, monospace;
  padding: 1px 6px; border-radius: 6px;
  border: 1px solid var(--strek); background: var(--bg); color: var(--ink);
}

.ja-fot {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--ink-2);
  border-top: 1px solid var(--kant);
  padding-top: 16px;
}
.ja-fot p { margin: 0; }

.ja-utan-js {
  padding: 16px; border-radius: 14px;
  background: var(--flate); border: 1px solid var(--kant);
  color: var(--ink);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* On a narrow screen the steps fall under the picture, and «Last opp bilete»
   would then sit below a full screen of example. The panel dissolves into the
   column so step 1 can come first, above the picture. */
@media (max-width: 820px) {
  .ja-arbeid { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 16px; }
  /* Both columns dissolve, so the picture, its tools and the sticker tray sit
     together on one screen: choosing a sticker and seeing it are one act. */
  .ja-panel, .ja-scenekol { display: contents; }
  .ja-steg-bilete { order: -1; }
  .ja-scene { order: 0; }
  .ja-verktoy { order: 1; }
  .ja-steg-pynt { order: 2; }
  .ja-hint { order: 3; }
  .ja-zoom { order: 4; }
  .ja-tips { order: 5; }
  .ja-steg-person { order: 6; }
  .ja-steg-bakgrunn { order: 7; }
  .ja-steg-last { order: 8; }
  /* The stickers as one row that scrolls sideways, right under the tools.
     `min-width: 0` on every item, or a sideways row widens its card to its own
     length and the phone zooms the whole page out to fit. */
  .ja-steg, .ja-verktoy, .ja-scene, .ja-hint, .ja-zoom, .ja-tips { min-width: 0; }
  .ja-steg-pynt { padding: 12px; gap: 10px; }
  .ja-steg-pynt h2 { font-size: 17px; }
  .ja-steg-pynt .ja-pyntknappar {
    display: flex; overflow-x: auto; scroll-snap-type: x proximity;
    padding-bottom: 4px;
  }
  .ja-steg-pynt .ja-pyntknapp { flex: 0 0 76px; scroll-snap-align: start; }
  .ja-lagknapp { white-space: nowrap; }
  /* On a phone the size, turn, «Meir» and «Angre» buttons are icons; their names stay
     for a screen reader. */
  .ja-verktoy-knappar .ja-verktoy-knapp > span, .ja-meir > summary > span, #angre > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
  .ja-verktoy-knappar { gap: 8px; }
  .ja-verktoy-knapp { padding: 0 8px; }
  /* A column flex sizes an auto-fill grid as if it had no width and leaves
     rows of empty space under the buttons, so the phone counts its columns. */
  .ja-sceneknappar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  /* While the brush is on, its controls stay at the foot of the screen, so a
     phone can paint and reach «Angre» and «Ferdig» without scrolling. */
  .ja-steg-person.ja-penselmodus {
    position: sticky; bottom: 0; z-index: 5;
    box-shadow: 0 -8px 24px rgba(23, 64, 47, 0.18);
    padding: 12px 14px;
    gap: 8px;
  }
  /* …and only the brush itself: the heading, the intro, the mask switch and
     «Byrj på nytt» wait until the brush is put away. */
  .ja-steg-person.ja-penselmodus h2,
  .ja-steg-person.ja-penselmodus .ja-notis-stor,
  .ja-steg-person.ja-penselmodus .ja-kryss,
  .ja-steg-person.ja-penselmodus #nullstill { display: none; }
  .ja-steg-person.ja-penselmodus { order: 1; }
  .ja-steg-person.ja-penselmodus #person-funnen { gap: 8px; }
}
@media (max-width: 420px) {
  .ja-sceneknappar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .ja-side { padding-top: 20px; gap: 20px; }
  .ja-pynt-topp { display: none; }
  .ja-steg { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* The smallest phones: the layer switch, «Meir» and «Angre» share one row. */
@media (max-width: 360px) {
  .ja-verktoy { padding: 10px 8px; }
  .ja-verktoy-topp { gap: 4px; }
  .ja-lagval { flex: none; }
  .ja-lagknapp { padding: 0 8px; font-size: 13px; }
}
