/* Tidskalkylaren (/tidskalkyler). Its own palette, light and dark after
 * prefers-color-scheme like /vis and /lesing. One almanac column: the input
 * first, then the readings of one life, each section one question.
 *
 * The six --s* colours are the visitor's things. Each is text somewhere (the
 * share figures), so each clears 4.5:1 on --flate in its scheme; the pairs are
 * gated in test/contrast.test.js. The future is always hatched or dashed, the
 * rule the rest of msge.no keeps for what has not happened yet.
 *
 * The reading card is dark in both schemes, through the fixed --kort-* tokens,
 * so the big number reads the same way whatever the visitor's setting. */
:root {
  --bg: #eef1f5;
  --flate: #ffffff;
  --ink: #141b26;
  --ink-2: #4b5667;
  --line: #d2d9e3;
  --fyll: #8693a5;
  --tom: #e3e8ef;
  --aksent: #2b3fd1;
  --no: #c23a25;
  --s0: #23786f;
  --s1: #c63c55;
  --s2: #6c4fd0;
  --s3: #94640a;
  --s4: #2672b5;
  --s5: #93408a;
  --kort-bg: #141b26;
  --kort-flate: #1f2835;
  --kort-ink: #eef1f5;
  --kort-dim: #aab4c3;
  --kort-strek: #3a4657;
  --f-disp: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-tekst: "Instrument Sans", system-ui, -apple-system, sans-serif;
  --f-tal: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131a;
    --flate: #161d27;
    --ink: #e7ebf1;
    --ink-2: #9ba7b9;
    --line: #29333f;
    --fyll: #5f6c7e;
    --tom: #1f2833;
    --aksent: #8f9cff;
    --no: #ff7b63;
    --s0: #4fb6a9;
    --s1: #f2788a;
    --s2: #a48ef3;
    --s3: #e3b046;
    --s4: #66aae8;
    --s5: #cf82c2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--f-tekst);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 10;
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 6px;
}
.skip-link:focus { left: 16px; }
:focus-visible { outline: 2px solid var(--aksent); outline-offset: 2px; }
a { color: var(--aksent); }
h1, h2, h3 { font-family: var(--f-disp); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: clamp(1.45rem, 1.1rem + 1.2vw, 1.9rem); font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; max-width: 65ch; }
button, input, select { font: inherit; }

.tk-ramme { max-width: 1040px; margin: 0 auto; padding-block: 24px 56px; display: grid; gap: 56px; }
.tk-sti { display: flex; gap: 8px; font: 500 .82rem var(--f-tal); color: var(--ink-2); }
.tk-sti a { color: var(--ink-2); }
.tk-liten { font-size: .86rem; color: var(--ink-2); }
.tk-auge { font: 500 .74rem/1 var(--f-tal); text-transform: uppercase; letter-spacing: .12em; color: var(--ink-2); }
.tk-tomt { color: var(--ink-2); padding: 18px; border: 1px dashed var(--line); border-radius: 12px; }

/* Controls */
.tk-felt { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
input[type="date"], input[type="text"], input[type="number"], select {
  font: 500 1rem var(--f-tal); color: var(--ink); background: var(--flate);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-width: 0; width: 100%;
}
input[type="text"] { font-family: var(--f-tekst); }
input:focus, select:focus { border-color: var(--aksent); outline: none; box-shadow: 0 0 0 3px var(--tom); }
input[aria-invalid="true"] { border-color: var(--no); }
button {
  font: 600 .88rem var(--f-tekst); color: var(--ink); background: var(--flate);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px; cursor: pointer;
}
button:hover { border-color: var(--ink-2); }
button:disabled { opacity: .55; cursor: default; }
.tk-verktoy { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.tk-mellom { justify-content: space-between; margin-bottom: 4px; }
.tk-brytar { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--ink-2); cursor: pointer; }

/* Hero */
.tk-helt { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 28px; align-items: stretch; }
.tk-inn { display: grid; gap: 16px; align-content: start; }
.tk-inn h1 { font-size: clamp(2.3rem, 1.6rem + 3vw, 3.6rem); font-weight: 800; line-height: .98; }
.tk-inn h1 span { color: var(--aksent); }
.tk-doeme {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .88rem; color: var(--ink-2);
  border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px;
}
.tk-doeme b { color: var(--ink); }
.tk-avlesing {
  background: var(--kort-bg); color: var(--kort-ink); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 26px 22px; display: grid; gap: 18px; align-content: space-between; min-width: 0;
}
.tk-avlesing .tk-auge { color: var(--kort-dim); }
.tk-stortal { font: 800 clamp(3rem, 2rem + 5vw, 5.4rem)/0.9 var(--f-disp); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.tk-stortal small { font-size: .32em; font-weight: 600; letter-spacing: 0; margin-left: .25em; }
.tk-ymd { font-size: 1.05rem; color: var(--kort-dim); }
.tk-urskive { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tk-urskive div { border-top: 1px solid var(--kort-strek); padding-top: 8px; min-width: 0; }
.tk-urskive b { display: block; font: 500 1.02rem var(--f-tal); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tk-urskive span { font-size: .78rem; color: var(--kort-dim); }
.tk-neste { background: var(--kort-flate); border-radius: 10px; padding: 12px 14px; display: grid; gap: 2px; }
.tk-neste b { font: 700 1.15rem var(--f-disp); }
.tk-neste .tk-liten { color: var(--kort-dim); }

/* Sections */
.tk-blokk { display: grid; gap: 18px; min-width: 0; }
.tk-blokk > header { display: grid; gap: 6px; }
.tk-flate { background: var(--flate); border: 1px solid var(--line); border-radius: 12px; padding: 18px; min-width: 0; }

/* Things and their periods */
.tk-tingliste { display: grid; gap: 12px; }
.tk-ting { display: grid; gap: 12px; }
.tk-ting-hovud { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.tk-prikk { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.tk-periodar { display: grid; gap: 8px; padding-left: 24px; }
.tk-periode { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.tk-periode label { display: grid; gap: 4px; font-size: .78rem; color: var(--ink-2); }
.tk-periode-feil { grid-column: 1 / -1; font-size: .82rem; color: var(--no); }
.tk-ting-fot { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding-left: 24px; }
.tk-ting-sum { font-size: .86rem; color: var(--ink-2); }

/* Legends: a symbol and a short label per item */
.tk-forklaring { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .84rem; color: var(--ink-2); }
.tk-forklaring li { display: inline-flex; align-items: center; gap: 6px; }
.tk-forklaring i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tk-forklaring i.tk-strek { height: 3px; border-radius: 2px; width: 16px; }
.tk-forklaring i.tk-stipla { height: 0; border-top: 2px dashed var(--ink-2); width: 16px; border-radius: 0; }
.tk-forklaring i.tk-ring { border: 2px solid var(--no); }
.tk-forklaring i.tk-open { background: var(--flate); border: 1px solid var(--line); }

/* Charts */
.tk-skroll { overflow-x: auto; }
.tk-graf { width: 100%; height: auto; display: block; }
.tk-graf text { font-family: var(--f-tal); fill: var(--ink-2); font-size: 11px; }
.tk-graf .tk-akse { stroke: var(--line); }
.tk-graf .tk-rute { stroke: var(--line); stroke-dasharray: 2 3; }
.tk-graf .tk-noline { stroke: var(--no); stroke-width: 1.5; }
.tk-graf text.tk-notekst { fill: var(--no); font-weight: 500; }
.tk-graf text.tk-krysstekst { fill: var(--ink); font-weight: 500; }
.tk-monster { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Milestones */
.tk-filter { display: grid; gap: 10px; }
.tk-filterrad { display: grid; grid-template-columns: 3.6em minmax(0, 1fr); gap: 10px; align-items: center; }
.tk-mile-tal { margin-right: auto; }
.tk-brikker { display: flex; flex-wrap: wrap; gap: 6px; }
.tk-brikke { display: inline-flex; gap: 7px; align-items: center; }
.tk-brikke[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tk-brikke i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tk-mile-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.tk-mileliste { list-style: none; margin: 0; padding: 0; display: grid; }
.tk-mileliste li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line); }
.tk-mileliste li:last-child { border-bottom: 0; }
.tk-mileliste .tk-p { width: 10px; height: 10px; border-radius: 50%; align-self: center; }
.tk-mileliste li.tk-stor .tk-tekst { font-weight: 600; }
.tk-mileliste .tk-naar { font: 500 .84rem var(--f-tal); text-align: right; white-space: nowrap; }
.tk-mileliste .tk-dato { grid-column: 2 / 4; font-size: .82rem; color: var(--ink-2); }
.tk-mileliste li.tk-forbi .tk-tekst, .tk-mileliste li.tk-forbi .tk-naar { color: var(--ink-2); }
.tk-mileliste .tk-ingen { grid-template-columns: 1fr; color: var(--ink-2); font-size: .9rem; }
.tk-hale summary {
  display: inline-block; margin-top: 10px; font: 600 .88rem var(--f-tekst); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 13px; cursor: pointer; list-style: none;
}
.tk-hale summary::-webkit-details-marker { display: none; }
.tk-hale[open] summary { margin-bottom: 4px; }
.tk-kal { grid-column: 2 / 4; }
.tk-kal summary { display: inline-block; cursor: pointer; list-style: none; font: 600 .8rem var(--f-tekst); color: var(--aksent); }
.tk-kal summary::-webkit-details-marker { display: none; }
.tk-kal summary::after { content: " ▾"; font-size: .7em; }
.tk-kal[open] summary::after { content: " ▴"; }
.tk-kalval { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tk-kalval a, .tk-kalval button {
  font: 600 .8rem var(--f-tekst); color: var(--ink); text-decoration: none; background: var(--flate);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px;
}
.tk-kalval a:hover { border-color: var(--ink-2); }

/* Share of life */
.tk-delrader { display: grid; gap: 18px; }
.tk-delrad { display: grid; gap: 6px; }
.tk-topplinje { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.tk-pst { font: 700 1.5rem var(--f-disp); font-variant-numeric: tabular-nums; }
.tk-spor { position: relative; height: 18px; background: var(--tom); border-radius: 4px; overflow: hidden; }
.tk-seg { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.tk-halv { position: absolute; top: -3px; bottom: -3px; left: 50%; width: 0; border-left: 1px dashed var(--ink-2); }
.tk-sporakse { display: flex; justify-content: space-between; font: .72rem var(--f-tal); color: var(--ink-2); }

/* Crossover */
.tk-krys { display: grid; gap: 14px; }
.tk-velgjar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.tk-velgjar select { width: auto; max-width: 100%; }
.tk-dom { font: 700 clamp(1.15rem, 1rem + .6vw, 1.45rem)/1.3 var(--f-disp); max-width: 40ch; }

/* Weeks */
.tk-veke-oppsett { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 24px; align-items: start; }
.tk-vekeinfo { display: grid; gap: 14px; min-width: 0; }
.tk-vekestor { font: 700 1.6rem/1.1 var(--f-disp); font-variant-numeric: tabular-nums; }
.tk-vekeinfo .tk-flate { display: grid; gap: 8px; }

/* Units */
.tk-einingar { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tk-eining { background: var(--flate); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 4px; align-content: start; }
.tk-eining b { font: 500 1.35rem var(--f-tal); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tk-eining span { font-size: .86rem; color: var(--ink-2); }
.tk-merke {
  display: inline-block; font: 500 .68rem var(--f-tal); text-transform: uppercase; letter-spacing: .08em;
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; margin-left: 4px; color: var(--ink-2); vertical-align: 1px;
}

/* Quick sums */
.tk-snogg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.tk-snogg .tk-flate { display: grid; gap: 12px; align-content: start; }
.tk-rad2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.tk-svar { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 2px; }
.tk-svar b { font: 700 1.2rem var(--f-disp); }

/* How it is counted */
.tk-om { border-top: 1px solid var(--line); padding-top: 24px; display: grid; gap: 12px; }
.tk-om h2 { font-size: 1.2rem; }
.tk-om ul { margin: 0; padding-left: 1.1em; display: grid; gap: 6px; max-width: 75ch; color: var(--ink-2); }
.tk-fot { max-width: 1040px; margin: 0 auto; padding-block: 0 40px; font-size: .88rem; color: var(--ink-2); }

@media (max-width: 860px) {
  .tk-veke-oppsett, .tk-snogg { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .tk-helt, .tk-mile-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .tk-filterrad { grid-template-columns: 1fr; gap: 6px; }
  .tk-urskive { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tk-periode { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .tk-periode .tk-fjern-periode { grid-column: 1 / -1; justify-self: start; }
  .tk-periodar, .tk-ting-fot { padding-left: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .tk-seg { transition: left .4s ease, width .4s ease; }
}
@media (prefers-reduced-motion: reduce) {
  .tk-seg { transition: none; }
}
