/* Klasse-app foundation. Contract: ../../DESIGN.md. Frozen after slice 0: page CSS goes in css/<page>.css.
   1 tokens  2 base  3 layout  4 components  5 motion  6 compat */

/* ================= 1 tokens ================= */
/* Brand "Lys": copied from 00_Admin/Brand/tokens.css (slide sizes are for 1920px slides; web uses --t-* / --s-*). */
:root {
  --bg: #F4F0E6;          /* paper */
  --surface: #FBF9F4;     /* raised paper: cards, table rows */
  --surface-2: #E9E3D5;   /* recessed paper: inactive, wells */
  --line: #B5AA94;        /* rules and grid lines (2px where structure depends on them), never text */
  --text: #17150F;        /* ink */
  --text-muted: #4B463F;  /* secondary ink */

  --vo: #1D4E9E;          /* Virksomhedsøkonomi: cobalt ink */
  --vo-ink: #FBF9F4;
  --af: #A8300C;          /* Afsætning: vermilion */
  --af-ink: #FBF9F4;
  --joint: linear-gradient(90deg, #1D4E9E 0%, #A8300C 100%); /* both subjects */
  --result: #0B5E3C;      /* bottom line: bank green */
  --result-ink: #FBF9F4;

  --font-display: "Newsreader", Georgia, serif;
  --font-body: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;

  --fs-hero: 168px;
  --fs-h1: 96px;
  --fs-h2: 64px;
  --fs-body: 36px;
  --fs-label: 28px;
  --fs-small: 24px;

  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 40px;
  --space-5: 64px;
  --space-6: 104px;
  --radius: 6px;
  --margin: 128px;
}

/* Web tokens. Fluid from 375px to 1920px viewport (min at 375, max at 1920). */
:root {
  --t-small: clamp(0.9375rem, 0.907rem + 0.129vw, 1.0625rem);  /* 15 -> 17 */
  --t-body:  clamp(1.0625rem, 1.017rem + 0.194vw, 1.25rem);    /* 17 -> 20 */
  --t-lead:  clamp(1.1875rem, 1.112rem + 0.324vw, 1.5rem);     /* 19 -> 24 */
  --t-h3:    clamp(1.25rem, 1.129rem + 0.518vw, 1.75rem);      /* 20 -> 28 */
  --t-h2:    clamp(1.625rem, 1.352rem + 1.17vw, 2.75rem);      /* 26 -> 44 */
  --t-h1:    clamp(2.25rem, 1.583rem + 2.85vw, 5rem);          /* 36 -> 80 */
  --t-hero:  clamp(2.75rem, 1.476rem + 5.44vw, 8rem);          /* 44 -> 128 */

  --s-1: clamp(0.375rem, 0.345rem + 0.129vw, 0.5rem);  /*  6 ->   8 */
  --s-2: clamp(0.75rem, 0.689rem + 0.259vw, 1rem);     /* 12 ->  16 */
  --s-3: clamp(1rem, 0.879rem + 0.518vw, 1.5rem);      /* 16 ->  24 */
  --s-4: clamp(1.5rem, 1.257rem + 1.04vw, 2.5rem);     /* 24 ->  40 */
  --s-5: clamp(2rem, 1.515rem + 2.07vw, 4rem);         /* 32 ->  64 */
  --s-6: clamp(3rem, 2.15rem + 3.62vw, 6.5rem);        /* 48 -> 104 */

  --gutter: clamp(1rem, 7.25vw - 0.699rem, 8rem);      /* 16 -> 128 page side margin */
  --page-max: 104rem;                                  /* 1664px = 1920 minus the 128px slide margins */
  --measure: 65ch;                                     /* prose line length */
  --rule: 2px;                                         /* structural lines */
  --bar: 6px;                                          /* subject bars */
  --tap: 2.75rem;                                      /* 44px minimum target */
  --header-h: 3.5rem;                                  /* .appbar height */

  --shadow-lift: 0 1px 2px color-mix(in srgb, var(--text) 14%, transparent),
                 0 14px 28px -10px color-mix(in srgb, var(--text) 32%, transparent);

  /* motion */
  --dur-1: 120ms;    /* press, hover, colour */
  --dur-2: 200ms;    /* small state change: tag, toggle, fade */
  --dur-3: 320ms;    /* move: FLIP, enter, settle */
  --dur-4: 480ms;    /* screen change, card turn, bar fill */
  --dur-count: 900ms;/* number count-up */
  --stagger: 50ms;   /* per item, max 6 items */
  --ease-out: cubic-bezier(.22, 1, .36, 1);       /* enter, arrive */
  --ease-in: cubic-bezier(.55, 0, 1, .45);        /* leave */
  --ease-move: cubic-bezier(.65, 0, .35, 1);      /* travel between two places on screen */
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);  /* lands with a small overshoot: settle, pop */
}

/* ================= 2 base ================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + var(--s-3)); }
body {
  min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: var(--t-body); line-height: 1.45;
  font-kerning: normal; font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
img, svg, video { display: block; max-width: 100%; }
a { color: inherit; text-underline-offset: 0.18em; }
button, input, textarea, select { font: inherit; color: inherit; }
button, a, label, summary, [role=button] { touch-action: manipulation; }
h1, h2, h3, h4 { text-wrap: balance; overflow-wrap: break-word; }
p, li, dd { text-wrap: pretty; }
::selection { background: var(--text); color: var(--bg); }
:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }
:focus:not(:focus-visible) { outline: none; }
[hidden] { display: none !important; }

/* type */
.hero { font-family: var(--font-display); font-weight: 500; font-size: var(--t-hero); line-height: 0.98; letter-spacing: -0.025em; }
.h1 { font-family: var(--font-display); font-weight: 500; font-size: var(--t-h1); line-height: 1.04; letter-spacing: -0.02em; }
.h2 { font-family: var(--font-display); font-weight: 500; font-size: var(--t-h2); line-height: 1.12; letter-spacing: -0.01em; }
.h3 { font-family: var(--font-body); font-weight: 600; font-size: var(--t-h3); line-height: 1.25; }
.lead { font-size: var(--t-lead); line-height: 1.4; max-width: 60ch; margin-top: var(--s-3); color: var(--text-muted); }
.small { font-size: var(--t-small); }
.serif { font-family: var(--font-display); }
.muted { color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums lining-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* ================= 3 layout ================= */
/* Breakpoints (viewport, mobile first): 600px tablet, 1024px laptop, 1600px projector.
   Components that live in different widths use container queries (see DESIGN.md). */
.wrap { width: 100%; max-width: calc(var(--page-max) + 2 * var(--gutter)); margin-inline: auto; padding-inline: var(--gutter); }
.wrap.wide { max-width: none; }
.top { padding-top: var(--s-5); }
.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.screen > .grow { flex: 1 0 auto; }
.stack > * + * { margin-top: var(--gap, var(--s-3)); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, var(--s-2)); }
.split { display: flex; flex-wrap: wrap; gap: var(--gap, var(--s-4)); }
.split > :first-child { flex: 1 1 var(--side, 18rem); }
.split > :last-child { flex: 999 1 0; min-width: min(100%, var(--main-min, 55%)); }
.autogrid { display: grid; gap: var(--gap, var(--s-3)); grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--min, 16rem)), 1fr)); }
.cq { container-type: inline-size; }
.measure { max-width: var(--measure); }

/* ================= 4 components ================= */
/* app header bar: <header class="appbar"><div class="appbar-in wrap"> back | title | end </div> [progress] </header> */
.appbar { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: var(--rule) solid var(--line); }
.appbar-in { display: flex; align-items: center; gap: var(--s-2) var(--s-4); min-height: var(--header-h); padding-block: var(--s-1); }
.appbar-title { min-width: 0; font-family: var(--font-display); font-weight: 500; font-size: var(--t-h3); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-end { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); white-space: nowrap; }
.appbar-progress { position: absolute; left: 0; right: 0; bottom: calc(-1 * var(--rule)); height: 4px; background: var(--surface-2); }
.appbar-progress > i { display: block; height: 100%; background: var(--text); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform var(--dur-3) var(--ease-out); }

/* back link: small, underlined, full tap height */
.back { display: inline-flex; align-items: center; min-height: var(--tap); font-size: var(--t-small); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

/* buttons: ink fill = action. Green is reserved for "rigtigt"/"sendt". */
.btn {
  --btn-bg: var(--text); --btn-fg: var(--bg); --btn-bd: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.6em;
  min-height: 3rem; padding: 0.5rem 1.4em; border: var(--rule) solid var(--btn-bd); border-radius: var(--radius);
  background: var(--btn-bg); color: var(--btn-fg); font-weight: 600; font-size: var(--t-body); line-height: 1.15;
  text-decoration: none; text-align: center; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background-color var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out),
              color var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
}
.btn.secondary, .btn.ghost { --btn-bg: transparent; --btn-fg: var(--text); }
.btn.lg { min-height: 3.5rem; padding-inline: 1.6em; font-size: var(--t-lead); }
.btn.block { display: flex; width: 100%; }
@media (hover: hover) {
  .btn:hover { --btn-bg: var(--text-muted); --btn-bd: var(--text-muted); }
  .btn.secondary:hover, .btn.ghost:hover { --btn-bg: var(--surface-2); --btn-bd: var(--text); }
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled, .btn[aria-disabled=true] { --btn-bg: var(--surface-2); --btn-bd: var(--surface-2); --btn-fg: var(--text-muted); cursor: not-allowed; transform: none; }
.btn[aria-busy=true] { cursor: progress; }
.linkbtn {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0; border: 0; background: none;
  font-size: var(--t-small); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* inputs */
.field { display: grid; gap: var(--s-1); }
.field > label, .label { font-weight: 600; }
.hint { font-size: var(--t-small); color: var(--text-muted); }
.inp {
  width: 100%; min-height: 3rem; padding: 0.625rem 0.875rem;
  border: var(--rule) solid var(--line); border-radius: var(--radius); background: var(--surface);
  font-size: max(16px, var(--t-body)); font-variant-numeric: tabular-nums lining-nums;
  transition: border-color var(--dur-1) var(--ease-out);
}
@media (hover: hover) { .inp:hover { border-color: var(--text-muted); } }
.inp:focus { border-color: var(--text); outline: 3px solid var(--text); outline-offset: 1px; }
.inp[aria-invalid=true] { border-color: var(--text); background: var(--surface-2); }
.inp:disabled { background: var(--surface-2); color: var(--text-muted); }
.inp::placeholder { color: var(--text-muted); opacity: 1; }
textarea.inp { min-height: 8.75rem; resize: vertical; line-height: 1.45; }

/* status tags: always a filled block with a word */
.tag { display: inline-flex; align-items: center; min-height: 1.75rem; padding: 0.125rem 0.625rem; border-radius: var(--radius); font-size: var(--t-small); font-weight: 600; line-height: 1.2; white-space: nowrap; }
.tag.ok { background: var(--result); color: var(--result-ink); }
.tag.wait { background: var(--text); color: var(--bg); }
.tag.idle { background: var(--surface-2); color: var(--text); }

/* subject markers: colour = subject, always with the subject word */
.subj { padding-top: var(--s-1); border-top: var(--bar) solid var(--text); font-weight: 600; }
.subj.vo { border-top-color: var(--vo); }
.subj.af { border-top-color: var(--af); }
.subj.none { border-top-color: var(--text); }
.subj.joint { border-top: 0; padding-top: calc(var(--bar) + var(--s-1)); background: var(--joint) top left / 100% var(--bar) no-repeat; }
.bar6 { display: inline-block; width: 2rem; height: var(--bar); vertical-align: middle; background: var(--text); }
.bar6.vo { background: var(--vo); } .bar6.af { background: var(--af); } .bar6.none { background: var(--text); } .bar6.joint { background: var(--joint); }
.subjtag { display: inline-flex; align-items: center; min-height: 1.75rem; padding: 0.125rem 0.625rem; border-radius: var(--radius); font-size: var(--t-small); font-weight: 600; line-height: 1.2; white-space: nowrap; color: var(--vo-ink); background: var(--text); }
.subjtag.vo { background: var(--vo); color: var(--vo-ink); }
.subjtag.af { background: var(--af); color: var(--af-ink); }
.subjtag.joint { background: var(--joint); color: var(--vo-ink); }

/* surfaces: one level only, never a surface inside a surface */
.surface { background: var(--surface); border: var(--rule) solid var(--line); border-radius: var(--radius); padding: var(--s-3); }
.well { background: var(--surface-2); border-radius: var(--radius); padding: var(--s-3); }
.ruled { border-top: var(--rule) solid var(--text); padding-top: var(--s-3); }
.ruled.soft { border-top-color: var(--line); }
.lifted { box-shadow: var(--shadow-lift); }

/* meter: progress or share. A correct share also needs a word next to it. */
.meter { height: 0.5rem; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--text-muted); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform var(--dur-4) var(--ease-out); }
.meter.result > i { background: var(--result); }

/* small print under a block */
.note { margin-top: var(--s-3); font-size: var(--t-small); color: var(--text-muted); max-width: 70ch; }

/* ================= 5 motion ================= */
@keyframes enter-up { from { opacity: 0; transform: translateY(var(--enter-y, 0.75rem)); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop { from { opacity: 0.4; transform: scale(0.9); } }
@keyframes settle { 0% { transform: scale(1.05); } 60% { transform: scale(0.985); } 100% { transform: none; } }
@keyframes turn-in { from { opacity: 0; transform: perspective(70rem) rotateY(-90deg); } }
@keyframes grow-x { from { transform: scaleX(0); } }

.anim-enter { animation: enter-up var(--dur-3) var(--ease-out) both; animation-delay: calc(var(--i, 0) * var(--stagger)); }
.anim-fade { animation: fade-in var(--dur-2) var(--ease-out) both; animation-delay: calc(var(--i, 0) * var(--stagger)); }
.anim-pop { animation: pop var(--dur-2) var(--ease-spring) both; }
.anim-settle { animation: settle var(--dur-3) var(--ease-out) both; }
.anim-turn { animation: turn-in var(--dur-4) var(--ease-out) both; backface-visibility: hidden; }
.anim-grow { animation: grow-x var(--dur-4) var(--ease-out) both; transform-origin: left center; }

/* screens glide between pages (cross-document View Transitions, Chrome/Edge/Safari 18.2+) */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: var(--dur-2) var(--ease-in) both vt-leave; }
::view-transition-new(root) { animation: var(--dur-3) var(--ease-out) both vt-arrive; }
@keyframes vt-leave { to { opacity: 0; transform: translateY(-0.5rem); } }
@keyframes vt-arrive { from { opacity: 0; transform: translateY(0.75rem); } }

@media (prefers-reduced-motion: reduce) {
  :root { --dur-1: 0ms; --dur-2: 0ms; --dur-3: 0ms; --dur-4: 0ms; --dur-count: 0ms; --stagger: 0ms; }
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important; transition-delay: 0ms !important; scroll-behavior: auto !important;
  }
  @view-transition { navigation: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ================= 6 compat ================= */
/* COMPAT (slice 0): old token names still read by css/kort.css and css/laerer.css. Page slices should
   stop using them; the block is deleted once, after all page slices are merged. .btn.ghost (= .secondary)
   is kept above for js/laerer.js. */
:root {
  --w-hero: var(--t-hero); --w-h1: var(--t-h1); --w-h2: var(--t-h2); --w-h3: var(--t-h3);
  --w-body: var(--t-body); --w-small: var(--t-small);
}
