/* Designtokens, typografi och schema-CSS är lyfta ur sites/immutable.mine.nu/index.html
   — ett schema härifrån ska vara omöjligt att skilja från det handritade originalet. */

:root {
  --bg:        #EEF0F6;
  --surface:   #FFFFFF;
  --surface-2: #E3E7F1;
  --ink:       #171A22;
  --ink-2:     #4E5468;
  --line:      #C6CCDC;
  --line-soft: #D9DEEA;
  --power:     #B26A12;
  --data:      #5B4BD6;
  --video:     #0E7A90;
  --usb:       #B23A66;
  --therm:     #6F7688;
  --sel:       #0E7A90;

  --cond: "IBM Plex Sans Condensed", "Helvetica Neue", Arial, sans-serif;
  --body: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0E1017;
    --surface:   #171A24;
    --surface-2: #1F2330;
    --ink:       #E9EBF2;
    --ink-2:     #98A0B5;
    --line:      #333A4B;
    --line-soft: #262C3A;
    --power:     #F0A53A;
    --data:      #A396FF;
    --video:     #4CC6DE;
    --usb:       #FF7FA6;
    --therm:     #838BA0;
    --sel:       #4CC6DE;
  }
}

:root[data-theme="dark"] {
  --bg:        #0E1017;
  --surface:   #171A24;
  --surface-2: #1F2330;
  --ink:       #E9EBF2;
  --ink-2:     #98A0B5;
  --line:      #333A4B;
  --line-soft: #262C3A;
  --power:     #F0A53A;
  --data:      #A396FF;
  --video:     #4CC6DE;
  --usb:       #FF7FA6;
  --therm:     #838BA0;
  --sel:       #4CC6DE;
}

* { box-sizing: border-box; }

/* Klassregler som sätter display slår ut webbläsarens egen [hidden]-regel,
   eftersom författarstilar vinner över UA-stilar oavsett specificitet. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(32px, 6vw, 72px) clamp(18px, 4vw, 40px) 96px;
  display: flex;
  flex-direction: column;
  gap: clamp(28px, 4vw, 48px);
}

/* ---------- header ---------- */
header { display: flex; flex-direction: column; gap: 18px; }

.eyebrow {
  font-family: var(--cond);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin: 0;
}

h1 {
  font-family: var(--cond);
  font-weight: 700;
  font-size: clamp(48px, 11vw, 96px);
  line-height: .92;
  letter-spacing: -.015em;
  margin: 0;
  text-wrap: balance;
}

.deck {
  max-width: 62ch;
  color: var(--ink-2);
  margin: 0;
  font-size: 17px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  padding: 0;
  list-style: none;
}
.chips li {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink-2);
}
.chips b { color: var(--ink); font-weight: 500; }

/* ---------- diagram ---------- */
figure { margin: 0; display: flex; flex-direction: column; gap: 18px; }

.canvas {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  overflow: auto;
  overscroll-behavior: contain;
}
.canvas svg {
  display: block;
  width: calc(100% * var(--zoom, 1));
  min-width: calc(680px * var(--zoom, 1));
  height: auto;
  touch-action: pan-x pan-y;
}

figcaption {
  color: var(--ink-2);
  font-size: 14.5px;
  max-width: 68ch;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 26px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}
.swatch { width: 26px; height: 0; border-top: 3px solid currentColor; border-radius: 2px; }
.sw-power { color: var(--power); }
.sw-data  { color: var(--data); }
.sw-video { color: var(--video); }
.sw-usb   { color: var(--usb); }
.sw-rf    { color: var(--usb); border-top-style: dashed; border-top-width: 2px; }
.sw-air   { color: var(--therm); border-top-style: dashed; border-top-width: 2px; }

/* ---------- svg internals ---------- */
.case-outline {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.25;
  stroke-dasharray: 7 7;
}
.box {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1.25;
}
.box-hub { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.25; }

.s-title  { font-family: var(--cond); font-weight: 700; font-size: 13.5px; fill: var(--ink); }
.s-sub    { font-family: var(--mono); font-size: 10px; fill: var(--ink-2); }
.s-small  { font-family: var(--mono); font-size: 9.5px; fill: var(--ink-2); }
.s-cap    { font-family: var(--mono); font-size: 9.5px; fill: var(--ink); }
.s-title-sm { font-family: var(--cond); font-weight: 700; font-size: 12.5px; fill: var(--ink); }
.s-eyebrow{ font-family: var(--cond); font-weight: 700; font-size: 11px; letter-spacing: .16em; fill: var(--ink-2); }
/* Halo i canvasfärgen så etiketten går att läsa där den korsar en kabel. */
.e-lbl {
  font-family: var(--mono);
  font-size: 10px;
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.t-power { fill: var(--power); }
.t-data  { fill: var(--data); }
.t-video { fill: var(--video); }
.t-usb   { fill: var(--usb); }
.t-rf    { fill: var(--usb); }
.t-air   { fill: var(--therm); }
.t-therm { fill: var(--therm); }

.e { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.p-power { stroke: var(--power); stroke-width: 2.4; }
.p-data  { stroke: var(--data); }
.p-video { stroke: var(--video); }
.p-usb   { stroke: var(--usb); }
.p-rf    { stroke: var(--usb); stroke-width: 1.8; stroke-dasharray: 3 3; }
.p-air   { stroke: var(--therm); stroke-width: 2; stroke-dasharray: 5 4; }

.mk-power { fill: var(--power); }
.mk-data  { fill: var(--data); }
.mk-video { fill: var(--video); }
.mk-usb   { fill: var(--usb); }
.mk-therm { fill: var(--therm); }

/* ---------- svg: redigeringslager ---------- */
/* Dra i en box = flytta den, dra i bakgrunden = panorera. Utan touch-action: none
   på noderna tolkar webbläsaren dragningen som scroll och skickar pointercancel. */
.node, .port, .grip, .edge-hit { touch-action: none; }

.node { cursor: default; }
[data-mode="edit"] .node { cursor: move; }

/* Handtagens geometri skalas om i JS; strecken hålls i skärmpixlar här, så de
   inte blir hårstrån i ett utzoomat schema. */
.sel-ring, .port, .grip, .edge-hit { vector-effect: non-scaling-stroke; }

.sel-ring {
  fill: none;
  stroke: var(--sel);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.port {
  fill: var(--surface);
  stroke: var(--sel);
  stroke-width: 1.5;
  cursor: crosshair;
  opacity: 0;
  transition: opacity .12s;
}
.node:hover .port,
.node.is-sel .port { opacity: 1; }
.port:hover { fill: var(--sel); }

.grip {
  fill: var(--surface);
  stroke: var(--sel);
  stroke-width: 1.5;
  cursor: nwse-resize;
  opacity: 0;
}
.node:hover .grip, .node.is-sel .grip { opacity: 1; }

.edge-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.edge-sel { stroke-dasharray: 5 4; opacity: .9; }
.ghost { fill: none; stroke: var(--sel); stroke-width: 2; stroke-dasharray: 4 4; pointer-events: none; }

.empty-hint { font-family: var(--mono); font-size: 12px; fill: var(--ink-2); }

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

/* ---------- verktygsfält ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.toolbar .spacer { flex: 1 1 auto; }
.group-sep { width: 1px; align-self: stretch; background: var(--line-soft); margin: 0 4px; }

button, select, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.btn {
  font-family: var(--cond);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .04em;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary:hover { opacity: .88; }
.btn-danger:hover { border-color: var(--usb); color: var(--usb); }
.btn-sm { font-size: 12px; padding: 5px 9px; }

/* Kabelväljaren: en rad radioknappar som visar färgen de står för. */
/* min-width: 0 — fieldset vägrar annars krympa under sitt innehåll och trycker
   ut hela sidan i sidled på smala skärmar. */
.kinds { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; border: 0; min-width: 0; }
.kinds legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.kind-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.kind-btn input { position: absolute; opacity: 0; pointer-events: none; }
.kind-btn .swatch { width: 18px; }
.kind-btn:has(input:checked) { border-color: var(--ink-2); color: var(--ink); background: var(--surface-2); }
.kind-btn:has(input:focus-visible) { outline: 2px solid var(--sel); outline-offset: 2px; }

.status {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
  white-space: nowrap;
}
.status[data-state="fel"] { color: var(--usb); }

/* ---------- skal: schema + inspektör ---------- */
.shell { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }

/* Rutnätsceller har min-width: auto och växer annars med schemats bredd i
   stället för att låta .canvas scrolla — då drar hela sidan iväg i sidled. */
.shell > * { min-width: 0; }

.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.inspector h2 {
  font-family: var(--cond);
  font-weight: 700;
  font-size: 18px;
  margin: 0;
}

.insp-close { display: none; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span {
  font-family: var(--cond);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.field input, .field select, .field textarea {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  width: 100%;
  min-width: 0;
}
.field textarea { resize: vertical; min-height: 62px; font-family: var(--mono); font-size: 12px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--sel); outline-offset: -1px; }
/* Ligger under samma .field > span-regel som etiketterna, så versalerna och
   spärrningen måste nollas — annars ser hjälptexten ut som en rubrik. */
.field .hint {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-2);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.row { display: flex; gap: 8px; }
.row > * { flex: 1 1 0; min-width: 0; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: auto; }

/* ---------- komponentlista ---------- */
.specs { display: flex; flex-direction: column; gap: 30px; }
.specs h2 {
  font-family: var(--cond);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -.01em;
  margin: 0;
}
.groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 28px 44px;
}
.group { display: flex; flex-direction: column; gap: 12px; }
.group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.group li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 9px 0;
  border-top: 1px solid var(--line-soft);
}
.group li:last-child { border-bottom: 1px solid var(--line-soft); }
.group li.stack { flex-direction: column; align-items: flex-start; gap: 2px; }
.group li.stack .mo { text-align: left; }
.nm { font-size: 14.5px; }
.mo {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

footer {
  border-top: 1px solid var(--line-soft);
  padding-top: 18px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px 24px;
}
footer a { color: var(--ink-2); }

/* ---------- länkar och dialoger ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  max-width: min(560px, calc(100vw - 32px));
  width: 100%;
}
dialog::backdrop { background: rgba(14, 16, 23, .55); }
.dlg { display: flex; flex-direction: column; gap: 18px; padding: 24px; }
.dlg h2 { font-family: var(--cond); font-weight: 700; font-size: 24px; margin: 0; }
.dlg p { margin: 0; color: var(--ink-2); font-size: 14.5px; }
.dlg .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.linkrow { display: flex; flex-direction: column; gap: 6px; }
.linkrow .lbl {
  font-family: var(--cond);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.linkrow .inputrow { display: flex; gap: 8px; }
.linkrow input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink);
}

.warn {
  border-left: 3px solid var(--power);
  padding: 10px 0 10px 14px;
  font-size: 14px;
  color: var(--ink-2);
}

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--video);
  border-radius: 3px;
  background: var(--surface);
  font-size: 14px;
  color: var(--ink-2);
}

/* ---------- landningssida ---------- */
.start { display: flex; flex-wrap: wrap; gap: 10px; }

.mine { display: flex; flex-direction: column; gap: 12px; }
.mine ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mine li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 0;
  border-top: 1px solid var(--line-soft);
}
.mine li:last-child { border-bottom: 1px solid var(--line-soft); }
.mine .who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.mine .who a { color: var(--ink); font-size: 15px; text-decoration: none; }
.mine .who a:hover { text-decoration: underline; }
.mine .who small { font-family: var(--mono); font-size: 11px; color: var(--ink-2); }

.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px 40px; }
.how h3 { font-family: var(--cond); font-weight: 700; font-size: 17px; margin: 0 0 6px; }
.how p { margin: 0; color: var(--ink-2); font-size: 14.5px; }

.rise { animation: rise .5s cubic-bezier(.2,.7,.3,1) backwards; }
.rise-2 { animation-delay: .09s; }
.rise-3 { animation-delay: .18s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
}

/* ---------- smala skärmar ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  /* Inspektören blir ett ark underifrån — annars hamnar den utanför skärmen
     när man markerar något högt upp i schemat. */
  .inspector {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 20;
    max-height: 62vh;
    border-radius: 4px 4px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, .18);
    transform: translateY(101%);
    transition: transform .18s ease-out;
  }
  body[data-inspector="open"] .inspector { transform: none; }

  /* Arket ligger över canvasens nederkant, alltså över storleksgreppet. Extra
     luft under sidan gör att man kan scrolla upp det man håller på med. */
  body[data-inspector="open"] .wrap { padding-bottom: 66vh; }
  .insp-close { display: inline-flex; }
  .insp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  @media (prefers-reduced-motion: reduce) {
    .inspector { transition: none; }
  }
}

@media (min-width: 901px) {
  .insp-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
}
