/* Layout: en smal läsyta på kall kortkatalogspapper; klassnumren sätts som katalogsignum i mono. */
:root {
  --paper: #eef0ec;
  --paper-2: #e0e4dd;
  --card: #fafbf8;
  --ink: #1b2130;
  --ink-2: #4c5466;
  --ink-3: #7d8494;
  --rule: #d3d8d0;
  --accent: #23489a;
  --accent-ink: #fafbf8;
  --on-c: #ffffff;
  --scan-bg: #ffffff;
  --ok: #2c7d4b;
  --bad: #b23a3a;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 22px -12px rgba(20, 30, 50, .22);

  --c1: #4a5fb5; --c2: #1f7f74; --c3: #567f27; --c4: #a8741a;
  --c5: #bf5a25; --c6: #b23b50; --c7: #844597; --c8: #c0477f;

  --serif: "Libre Caslon Text", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12151b; --paper-2: #1d222b; --card: #1a1e26; --ink: #e6e9ef; --ink-2: #b2b9c6; --ink-3: #7d8494;
    --rule: #2e343f; --accent: #8fb0f2; --accent-ink: #12151b; --on-c: #12151b; --scan-bg: #e6e9ef;
    --ok: #6cc28a; --bad: #ef7d72;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px -12px rgba(0, 0, 0, .6);
    --c1: #8d9cf0; --c2: #52c2b2; --c3: #9cc75f; --c4: #e3b14b;
    --c5: #f0905a; --c6: #ef7488; --c7: #c58ad6; --c8: #f287b6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12151b; --paper-2: #1d222b; --card: #1a1e26; --ink: #e6e9ef; --ink-2: #b2b9c6; --ink-3: #7d8494;
  --rule: #2e343f; --accent: #8fb0f2; --accent-ink: #12151b; --on-c: #12151b; --scan-bg: #e6e9ef;
  --ok: #6cc28a; --bad: #ef7d72;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px -12px rgba(0, 0, 0, .6);
  --c1: #8d9cf0; --c2: #52c2b2; --c3: #9cc75f; --c4: #e3b14b;
  --c5: #f0905a; --c6: #ef7488; --c7: #c58ad6; --c8: #f287b6;
  color-scheme: dark;
}

.t1 { --c: var(--c1); } .t2 { --c: var(--c2); } .t3 { --c: var(--c3); } .t4 { --c: var(--c4); }
.t5 { --c: var(--c5); } .t6 { --c: var(--c6); } .t7 { --c: var(--c7); } .t8 { --c: var(--c8); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.55 var(--sans);
  min-height: 100vh; display: flex; flex-direction: column;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--paper); }
.gutter, .topbar, main, .foot {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; line-height: 1.15; margin: 0 0 .3em; text-wrap: balance; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.3rem; }
p { margin: 0 0 .8em; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
.center { text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; }
.eyebrow { font-family: var(--mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; margin: 0; }
.lede { font-size: 1.12rem; color: var(--ink-2); max-width: 40em; }

/* ---------- Ram ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding-block: .7rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px), calc((100vw - 1120px) / 2));
  padding-right: max(16px, env(safe-area-inset-right, 0px), calc((100vw - 1120px) / 2));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; font-family: var(--serif); font-size: 1.25rem; font-weight: 500; }
.brand .mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 1.1rem; }
.topnav { display: flex; gap: .25rem; }
.topnav a { text-decoration: none; padding: .35rem .8rem; border-radius: 99px; color: var(--ink-2); font-weight: 500; font-size: .95rem; }
.topnav a.on { background: var(--ink); color: var(--paper); }

main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding-block: 1.5rem 3rem; }
.foot { border-top: 1px solid var(--rule); color: var(--ink-3); font-size: .8rem; padding-block: 1.2rem 2rem; text-align: center; }
.foot p { max-width: 60em; margin: 0 auto; }

.loading { display: flex; gap: .7rem; align-items: center; justify-content: center; padding: 6rem 0; color: var(--ink-2); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--rule); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border: 1px solid var(--rule); border-radius: 14px; padding: 1.2rem 1.3rem; box-shadow: var(--shadow); }
a.card { text-decoration: none; display: block; transition: transform .15s, border-color .15s; }
a.card:hover { transform: translateY(-2px); border-color: var(--ink-3); color: inherit; }

/* ---------- Knappar och chips ---------- */
.chip {
  display: inline-block; padding: .12rem .55rem; margin: .16rem .12rem; border-radius: 99px;
  background: var(--paper-2); color: var(--ink-2); text-decoration: none; font-size: .93rem;
  border: 1px solid transparent; transition: background .12s, color .12s;
}
.chip.common { color: var(--ink); font-weight: 500; }
.chip:hover { background: var(--c, var(--accent)); color: var(--on-c); }
.chip.mark { background: var(--c, var(--accent)); color: var(--on-c); font-weight: 600; }
.pill, .ghost, .primary {
  display: inline-flex; align-items: center; gap: .3rem; padding: .4rem .9rem; border-radius: 99px;
  border: 1px solid var(--rule); background: var(--card); text-decoration: none; font-size: .92rem;
}
.ghost { background: transparent; }
.ghost:hover, .pill:hover { border-color: var(--ink-3); }
.ghost:disabled { opacity: .4; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; padding: .55rem 1.2rem; }
.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.pill.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.toggle { display: inline-flex; gap: .4rem; align-items: center; font-size: .9rem; color: var(--ink-2); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Sök ---------- */
.search { position: relative; display: flex; align-items: center; max-width: 560px; }
.search .icon { position: absolute; left: .9rem; color: var(--ink-3); font-size: 1.2rem; pointer-events: none; }
.search input {
  width: 100%; padding: .65rem 1rem .65rem 2.4rem; border-radius: 99px;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink); font: inherit; font-size: 1rem;
  box-shadow: var(--shadow);
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.search.big { max-width: 620px; }
.search.big input { padding: .95rem 1.2rem .95rem 2.8rem; font-size: 1.15rem; }
.search.big .icon { left: 1.1rem; font-size: 1.4rem; }
.sugg {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; list-style: none; margin: 0; padding: .3rem;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); display: none;
}
.sugg.open { display: block; }
.sugg li { display: flex; justify-content: space-between; gap: 1rem; padding: .45rem .8rem; border-radius: 9px; cursor: pointer; }
.sugg li small { color: var(--ink-3); }
.sugg li.active, .sugg li:hover { background: var(--paper-2); }
.toolbar { margin-bottom: 1rem; }

/* ---------- Startsida ---------- */
.hero { padding: 2.5rem 0 2rem; }
.hero h1 { font-size: clamp(2.4rem, 7vw, 4.4rem); margin: .2em 0 .35em; letter-spacing: -.01em; }
.hero h1 em { color: var(--accent); font-weight: 400; }
.samples { margin-top: 1rem; display: flex; flex-wrap: wrap; align-items: center; gap: .1rem; }
.homegrid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 1rem; margin: 1rem 0 1.5rem; }
.wod { display: flex !important; flex-direction: column; gap: .2rem; background: linear-gradient(135deg, var(--card), color-mix(in srgb, var(--accent) 7%, var(--card))); }
.wodword { font-family: var(--serif); font-size: 2.6rem; line-height: 1.1; color: var(--accent); }
.wod .syns { margin-top: .4rem; font-family: var(--serif); font-size: 1.1rem; font-style: italic; color: var(--ink-2); }
.about { max-width: 52em; }
.about p { margin: 0; }

/* ---------- Ordsida ---------- */
.trail { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: -.2rem 0 1rem; font-size: .92rem; }
.trail .sep { color: var(--ink-3); }
.wordhead { margin-bottom: .5rem; }
.wordhead h1 { font-size: clamp(2.4rem, 6vw, 3.6rem); }
.graphwrap { margin: .5rem auto 0; max-width: 1000px; }
.wordgraph { width: 100%; height: auto; display: block; overflow: visible; font-family: var(--sans); }
.wordgraph .link { fill: none; stroke: var(--c); stroke-opacity: .55; stroke-width: 2; transition: stroke-opacity .2s; }
.wordgraph .link.leaf { stroke-opacity: .22; stroke-width: 1.2; }
.wordgraph .center rect { fill: var(--ink); }
.wordgraph .center text { fill: var(--paper); font-family: var(--serif); font-size: 30px; font-weight: 500; }
.wordgraph .classnode { cursor: pointer; animation: pop .45s backwards; animation-delay: calc(var(--i) * 35ms); transform-box: fill-box; transform-origin: center; }
.wordgraph .classnode circle { fill: var(--c); stroke: var(--paper); stroke-width: 3; transition: r .15s; }
.wordgraph .classnode .num { fill: var(--on-c); font-family: var(--mono); font-size: 14px; font-weight: 600; pointer-events: none; }
.wordgraph .classnode .cname { fill: var(--c); font-family: var(--serif); font-size: 17px; font-style: italic; paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round; }
.wordgraph .leafnode { cursor: pointer; animation: fade .5s backwards; animation-delay: calc(150ms + var(--i) * 12ms); }
.wordgraph .leafnode circle { fill: var(--c); }
.wordgraph .leafnode text { fill: var(--ink-2); font-size: 16px; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.wordgraph .leafnode text.common { fill: var(--ink); font-weight: 500; }
.wordgraph .leafnode:hover text, .wordgraph .leafnode:focus text { fill: var(--c); font-weight: 600; }
.wordgraph .leafnode:hover circle { r: 7; }
.wordgraph.dim .link, .wordgraph.dim .leafnode, .wordgraph.dim .classnode { opacity: .18; }
.wordgraph.dim .hl { opacity: 1; }
.wordgraph.dim .link.hl { stroke-opacity: .8; }
@keyframes pop { from { opacity: 0; transform: scale(.4); } }
@keyframes fade { from { opacity: 0; } }
.hint { text-align: center; margin: .2rem 0 1.5rem; }

.senses { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 1rem; }
.sense { border-top: 4px solid var(--c); display: flex; flex-direction: column; gap: .6rem; }
.sense header { display: flex; gap: .9rem; align-items: flex-start; }
.sense .num {
  flex: none; min-width: 3rem; height: 3rem; padding: 0 .4rem; border-radius: 10px; display: grid; place-items: center;
  background: var(--c); color: var(--on-c); font-family: var(--mono); font-size: 1.05rem; font-weight: 500; text-decoration: none;
}
.sense h3 { margin: 0; }
.sense h3 a { text-decoration: none; }
.crumbs { margin: .1rem 0 0; font-size: .8rem; color: var(--ink-3); }
.crumbs a { color: var(--c, inherit); text-decoration: none; }
.stycke { display: flex; flex-wrap: wrap; align-items: baseline; margin: 0; }
.stycke .tag { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--c, var(--ink-3)); font-weight: 600; margin-right: .4rem; }
.sense footer { display: flex; flex-wrap: wrap; gap: .3rem 1rem; justify-content: space-between; margin-top: auto; padding-top: .5rem; border-top: 1px dashed var(--rule); font-size: .88rem; }
.sense footer a { text-decoration: none; color: var(--ink-2); }
.sense footer a:hover { color: var(--c); }
.notfound { max-width: 720px; }

/* ---------- Klassida ---------- */
.classpage { max-width: 900px; }
.pager { display: flex; justify-content: space-between; gap: 1rem; font-size: .88rem; margin-bottom: 1.2rem; }
.pager a { text-decoration: none; color: var(--ink-2); }
.classpage > header { display: flex; gap: 1.2rem; align-items: center; margin-bottom: 1rem; }
.bignum {
  flex: none; font-family: var(--serif); font-size: clamp(2.6rem, 8vw, 4.2rem); line-height: 1; color: var(--c);
  padding-right: 1.2rem; border-right: 3px solid var(--c);
}
.classpage h1 { margin: 0; }
.pill.opp { border-color: var(--c); color: var(--c); }
.possec { margin-top: 1.8rem; }
.possec h2 { font-size: 1.25rem; color: var(--c); border-bottom: 1px solid var(--rule); padding-bottom: .3rem; margin-bottom: .6rem; }
.possec .stycke { padding: .35rem 0 .45rem; border-bottom: 1px dotted var(--rule); }
.original { margin-top: 2rem; display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; }
.scan { flex-basis: 100%; display: none; }
.scan.open { display: block; }
.scan img { max-width: 100%; border: 1px solid var(--rule); border-radius: 8px; background: var(--scan-bg); }

/* ---------- Utforska ---------- */
.page-head { margin-bottom: 1.2rem; }
.explore { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.sunwrap { position: relative; }
.sunburst { width: 100%; height: auto; display: block; }
.seg { fill: var(--c); stroke: var(--paper); stroke-width: 1; cursor: pointer; transition: opacity .2s, fill-opacity .2s; }
.seg.l0 { fill-opacity: 1; }
.seg.l1 { fill-opacity: .78; }
.seg.l2 { fill-opacity: .55; }
.seg.l2.merged { fill-opacity: .45; }
.seg.l3 { fill-opacity: .38; stroke-width: .35; }
.seg:hover { fill-opacity: 1; }
.seg.faded { opacity: .18; }
.seg.sel { stroke: var(--ink); stroke-width: 2; }
.seglabel { fill: var(--on-c); font-family: var(--serif); font-size: 18px; pointer-events: none; }
.hub { fill: var(--ink-3); font-family: var(--serif); font-size: 26px; }
.tooltip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 5;
  background: var(--ink); color: var(--paper); padding: .3rem .6rem; border-radius: 7px; font-size: .85rem; white-space: nowrap;
}
.tooltip.on { opacity: 1; }
.panel { border-top: 4px solid var(--c); max-height: 640px; overflow: auto; position: sticky; top: 76px; }
.classlist { list-style: none; padding: 0; margin: .5rem 0 0; columns: 2 12rem; column-gap: 1.2rem; }
.classlist li { break-inside: avoid; padding: .15rem 0; font-size: .93rem; }
.classlist a { text-decoration: none; }
.classlist .n { color: var(--c); font-family: var(--mono); font-size: .85rem; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; margin-top: 1.2rem; font-size: .88rem; }
.legend .lg { display: inline-flex; gap: .4rem; align-items: center; text-decoration: none; color: var(--ink-2); }
.legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }

/* ---------- Ordbryggan ---------- */
.bridgehead { margin: .2rem 0 1rem; }
.bridgehead h1 { font-size: clamp(2rem, 7vw, 2.8rem); margin: 0; }
.bridgehead p { margin: .2rem 0 0; }
.bridgewrap, .bridgehead, .install { max-width: 720px; margin-inline: auto; }
.bridge-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem 1rem; margin-bottom: .9rem; }
.levels { display: flex; gap: .4rem; }
.levels .pill { flex-direction: column; gap: 0; line-height: 1.2; padding: .4rem .95rem; min-height: 44px; justify-content: center; }
.levels .hops { font-family: var(--mono); font-size: .68rem; opacity: .75; }
.stats { display: flex; gap: .9rem; margin: 0; font-size: .82rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.stats b { font-family: var(--mono); color: var(--ink); font-weight: 500; }

.bridge .ends { display: flex; align-items: center; gap: .7rem; margin-bottom: .9rem; }
.bridge .end { font-family: var(--serif); font-size: 1.6rem; padding: .25rem .85rem; border-radius: 12px; background: var(--paper-2); min-width: 0; overflow-wrap: anywhere; }
.bridge .end.to { background: var(--accent); color: var(--accent-ink); }
.bridge .span { flex: 1; min-width: 2.5rem; text-align: center; font-family: var(--mono); font-size: .72rem; color: var(--ink-3); border-bottom: 2px dashed var(--rule); line-height: 0; }
.bridge .span span { background: var(--card); padding: 0 .4rem; }
.path { list-style: none; padding: 0; margin: 0 0 .4rem; display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; font-family: var(--serif); font-size: 1.15rem; color: var(--ink-2); }
.path li { display: flex; align-items: center; gap: .25rem; animation: fade .3s backwards; }
.path .arrow { color: var(--ink-3); }
.path li.goal .pw { background: var(--ok); color: var(--on-c); padding: 0 .5rem; border-radius: 8px; }
.path.won li { animation: hop .45s backwards; animation-delay: calc(var(--i) * 90ms); }
@keyframes hop { 40% { transform: translateY(-8px); } }

.current { display: flex; flex-direction: column; align-items: center; gap: .1rem; margin: 1rem 0 .6rem; padding: .8rem 0; border-block: 1px solid var(--rule); text-align: center; }
.current .cw { font-family: var(--serif); font-size: clamp(2.2rem, 9vw, 3rem); line-height: 1.15; color: var(--accent); overflow-wrap: anywhere; }
.options { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.option {
  min-height: 44px; padding: .4rem 1rem; border-radius: 99px; border: 1.5px solid var(--rule); background: var(--paper);
  font-family: var(--serif); font-size: 1.15rem; transition: transform .1s, border-color .1s, background .1s;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.option:hover { border-color: var(--accent); }
.option:active { transform: scale(.96); }
.option.dim { opacity: .45; }
.option.goalopt { border-color: var(--accent); color: var(--accent); }
.option.hinted { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); animation: pulse 1.2s ease-in-out 2; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.actions { display: flex; justify-content: center; flex-wrap: wrap; gap: .5rem; margin-top: 1.2rem; }
.actions .ghost { min-height: 44px; }

.feedback { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--rule); }
.feedback .yay { color: var(--ok); font-weight: 600; font-size: 1.15rem; }
.feedback .nay { color: var(--ink); font-weight: 600; }
.primary.wide { width: 100%; justify-content: center; min-height: 48px; margin-top: 1rem; font-size: 1rem; }
.explain-steps { list-style: none; padding: 0; margin: .3rem 0 .8rem; display: grid; gap: .45rem; }
.explain-steps li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .2rem .8rem; padding: .5rem .7rem; border-radius: 10px; background: var(--paper); }
.explain-steps .pair { font-family: var(--serif); font-size: 1.12rem; display: flex; gap: .35rem; align-items: baseline; }
.explain-steps .pw { text-decoration: none; }
.explain-steps .arrow { color: var(--ink-3); }
.explain-steps .via { font-size: .85rem; color: var(--c); text-decoration: none; }
.explain-steps .via .n { font-family: var(--mono); margin-right: .35rem; }

.install { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem; padding: .8rem 1rem; margin-bottom: 1rem; border: 1px solid var(--accent); border-radius: 12px; background: color-mix(in srgb, var(--accent) 8%, var(--card)); font-size: .92rem; }
.install p { margin: 0; flex: 1 1 16rem; }

/* ---------- Mobil ---------- */
@media (max-width: 820px) {
  .homegrid { grid-template-columns: 1fr; }
  .explore { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .brand span:last-child { display: none; }
  .hero { padding-top: 1rem; }
  .bridge .end { font-size: 1.3rem; }
  .bridge.card { padding: 1rem; }
  .stats { gap: .7rem; }
  .pager { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Mobil: större text i ordnätet */
.wordgraph.compact .leafnode text { font-size: 19px; }
.wordgraph.compact .classnode .cname { font-size: 18px; }
.wordgraph.compact .center text { font-size: 28px; }
.classlist li { display: grid; grid-template-columns: 2.8rem 1fr; }
.seg.faded { opacity: .28; }
