/* Live Load. Its own look: an engineering drawing title block on site-sign colours.
   Every text pairing here is AA or better on the surface it sits on (checked in tools/contrast.mjs). */
:root {
  --paper: #f4f1e8;
  --card: #fbfaf5;
  --hover: #e9e3d3;
  --ink: #1b2228;
  --ink-2: #4a5560;
  --hivis: #ffc72c;
  --hivis-hover: #ffd75e;
  --blue: #1d4f91;
  --red: #a8231b;
  --green: #22663a;
  --wirxl: #b84518;
  --font: "Bahnschrift", "DIN Alternate", "DIN Next", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --bar-h: auto;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.35 var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
button, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ---------- title block ---------- */
.titleblock {
  display: flex;
  align-items: stretch;
  border-bottom: 2px solid var(--ink);
  background: var(--card);
  min-width: 0;
}
.tb-cell {
  display: flex; flex-direction: column; justify-content: center;
  padding: 6px 14px;
  border-right: 2px solid var(--ink);
  min-width: 0;
}
.tb-name { flex-direction: row; align-items: baseline; gap: 12px; }
h1 {
  margin: 0;
  font-size: 22px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  white-space: nowrap;
}
.wirxl-badge { font-size: 12px; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.wirxl-badge:hover { text-decoration: underline; }
.wirxl-mark { color: var(--wirxl); font-weight: 700; letter-spacing: 0.04em; }
.tb-label { font-size: 11px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-2); white-space: nowrap; }
.tb-value { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tb-level { flex: 1 1 auto; }
.tb-of { color: var(--ink-2); font-weight: 400; }
.tb-over { height: 16px; line-height: 16px; font-size: 12px; color: var(--red); font-weight: 700; white-space: nowrap; }
.tb-money.is-over #cost { color: var(--red); }
.tb-actions { display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin-left: auto; }

/* ---------- buttons ---------- */
button {
  min-height: 44px;
  padding: 6px 14px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
  touch-action: manipulation;
}
button:hover { background: var(--hover); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
button:disabled { color: var(--ink-2); border-color: var(--ink-2); cursor: default; background: var(--card); }
button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.go {
  background: var(--hivis);
  font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  border-width: 3px;
}
.go:hover { background: var(--hivis-hover); }

/* ---------- stage ---------- */
#stage { position: relative; min-height: 0; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#view.is-pan { cursor: grab; }
#view.is-erase { cursor: not-allowed; }
#view.is-move { cursor: grab; }
#view.is-moving { cursor: grabbing; }
.overlay-top { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; pointer-events: none; }
.note, .hint, .hud {
  margin: 0;
  padding: 5px 10px;
  background: var(--card);
  border: 2px solid var(--ink);
  font-size: 14px;
  max-width: 46rem;
}
.hint { border-style: dashed; }
.hud { font-variant-numeric: tabular-nums; font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; font-size: 12px; color: var(--ink-2); }
.legend-bar { width: 90px; height: 10px; border: 1px solid var(--ink); background: linear-gradient(90deg, rgb(47,158,68), rgb(242,183,5) 50%, rgb(232,89,12) 80%, rgb(201,42,42)); }
.tip {
  position: absolute; z-index: 3;
  padding: 4px 8px;
  background: var(--ink); color: var(--paper);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  pointer-events: none; white-space: nowrap;
}
.rotate { position: absolute; bottom: 10px; left: 12px; right: 12px; margin: 0; padding: 6px 10px; background: var(--card); border: 2px solid var(--ink); font-size: 14px; }

/* ---------- result ---------- */
.result {
  position: absolute; z-index: 2;
  top: 10px; left: 50%; transform: translateX(-50%);
  width: min(32rem, calc(100% - 24px));
  background: var(--card);
  border: 2px solid var(--ink);
  padding: 0 16px 14px;
}
.result::before {
  content: ""; display: block; height: 10px; margin: 0 -16px 10px;
  border-bottom: 2px solid var(--ink);
  background: repeating-linear-gradient(-45deg, var(--hivis) 0 12px, var(--ink) 12px 24px);
}
.result.is-pass::before { background: var(--blue); }
.result h2 { margin: 0 0 6px; font-size: 21px; }
.result ul { margin: 0 0 12px; padding-left: 18px; }
.result li { margin: 2px 0; }
.res-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.result.is-compact ul { display: none; }

/* ---------- materials panel ---------- */
.specs {
  position: absolute; z-index: 2; top: 10px; right: 12px;
  width: min(27rem, calc(100% - 24px)); max-height: calc(100% - 20px); overflow-y: auto;
  background: var(--card); border: 2px solid var(--ink); padding: 10px 14px 12px;
}
.specs h2 { margin: 0 0 6px; font-size: 17px; }
.specs-scroll { overflow-x: auto; }
.specs table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
.specs th { text-align: right; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); font-weight: 600; padding: 2px 6px; border-bottom: 2px solid var(--ink); }
.specs td { text-align: right; padding: 4px 6px; border-bottom: 1px solid #d6d0c2; white-space: nowrap; }
.specs td:first-child, .specs th:first-child { text-align: left; }
.specs td:first-child { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.specs td .sw { width: 16px; height: 16px; }
.specs ul { margin: 8px 0 10px; padding-left: 18px; font-size: 13px; }
.specs li { margin: 2px 0; }
.specs-toggle { padding: 4px 12px; }

/* ---------- bars ---------- */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-top: 2px solid var(--ink);
  background: var(--card);
  min-width: 0;
  overflow-x: auto;
}
.tools { display: flex; gap: 6px; }
.tool { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; padding: 4px 10px; }
.tool .sw { grid-row: 1 / span 2; }
.tool-name { font-weight: 700; }
.tool-meta { font-size: 11px; font-weight: 400; color: var(--ink-2); white-space: nowrap; }
.tool[aria-pressed="true"] .tool-meta { color: var(--paper); }
.sw { width: 22px; height: 22px; border: 2px solid var(--ink); display: block; }
.sw-road { background: linear-gradient(var(--card) 0 30%, #3b3b3b 30% 70%, var(--card) 70%); }
.sw-wood { background: linear-gradient(135deg, var(--card) 0 38%, #b07a3e 38% 62%, var(--card) 62%); }
.sw-steel { background: linear-gradient(135deg, var(--card) 0 40%, #7d8c99 40% 60%, var(--card) 60%); }
.sw-cable { background: linear-gradient(135deg, var(--card) 0 46%, #2a2a2a 46% 54%, var(--card) 54%); }
.sw-move { background: radial-gradient(circle, var(--ink) 0 18%, var(--card) 20% 42%, var(--blue) 44% 56%, var(--card) 58%); }
.sw-erase { background: linear-gradient(45deg, var(--card) 0 44%, var(--red) 44% 56%, var(--card) 56%), linear-gradient(-45deg, transparent 0 44%, var(--red) 44% 56%, transparent 56%); background-blend-mode: multiply; }
.tool[aria-pressed="true"] .sw { border-color: var(--paper); }
.edits { display: flex; gap: 6px; margin-left: auto; }
#btn-go { min-width: 96px; font-size: 18px; }
#testbar { justify-content: flex-start; }

/* ---------- dialogs ---------- */
dialog {
  border: 2px solid var(--ink); border-radius: 0;
  background: var(--card); color: var(--ink);
  padding: 16px 20px;
  width: min(30rem, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(27, 34, 40, 0.45); }
dialog h2 { margin: 0 0 10px; font-size: 20px; }
#level-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
#level-list button { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 12px; }
#level-list .lv-state { font-weight: 400; color: var(--ink-2); white-space: nowrap; }
#level-list button[aria-current="true"] { border-width: 3px; }
#level-list .is-cleared .lv-state { color: var(--green); font-weight: 700; }
#share-url { width: 100%; padding: 8px; border: 2px solid var(--ink); background: #fff; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.share-status { min-height: 1.4em; margin: 6px 0; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
dialog form { margin: 0; }

/* ---------- narrow and short screens ---------- */
/* the Specs panel carries cost and length, so the labels under each material go first when space runs out */
@media (max-width: 1400px) {
  .tool-meta { display: none; }
  .tool { padding: 4px 12px; }
}
@media (max-width: 900px) {
  .tool-meta { display: none; }
  .tb-cell { padding: 4px 10px; }
  .tb-name { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; }
  .wirxl-badge { font-size: 11px; }
}
@media (max-width: 640px) {
  .titleblock { flex-wrap: wrap; }
  .tb-name { order: 1; flex: 1 1 auto; border-right: 0; }
  .tb-actions { order: 2; padding: 4px 8px; }
  .tb-level { order: 3; flex: 1 1 55%; border-top: 2px solid var(--ink); }
  .tb-money { order: 4; flex: 1 1 auto; border-top: 2px solid var(--ink); border-right: 0; }
  .bar { flex-wrap: wrap; overflow-x: visible; }
  .tools { flex: 1 1 100%; }
  .tools .specs-toggle { flex: 1 1 0; min-width: 0; padding: 4px 2px; }
  .specs { padding: 8px 10px 10px; }
  .specs table { font-size: 13px; }
  .specs td, .specs th { padding: 3px 4px; }
  .specs td { white-space: normal; }
  .tools .tool { flex: 1 1 0; justify-content: center; text-align: center; grid-template-columns: auto; min-width: 0; padding: 4px 2px; }
  .edits { flex: 1 1 auto; margin-left: 0; }
  .edits button { flex: 1 1 0; padding: 4px 6px; min-width: 0; }
  #btn-go { flex: 0 0 auto; min-width: 84px; }
  #testbar button { flex: 1 1 auto; }
  .tb-name h1 { font-size: 17px; }
  .tb-level .tb-value { font-size: 15px; }
  .tb-actions button { padding: 4px 10px; }
  .tool { padding: 4px 8px; }
  .tool .sw { display: none; }
  .tools, .edits { gap: 4px; }
  .bar { gap: 6px; padding: 6px; }
}
/* phones held sideways: the tools move to a column on the right so the bridge gets the height */
@media (max-height: 520px) and (orientation: landscape) {
  body { grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) auto; }
  .titleblock { grid-column: 1; grid-row: 1; }
  #stage { grid-column: 1; grid-row: 2; }
  .bar { grid-column: 2; grid-row: 1 / span 2; flex-direction: column; align-items: stretch; border-top: 0; border-left: 2px solid var(--ink); overflow-y: auto; overflow-x: hidden; padding: 6px; gap: 6px; width: 148px; }
  .tools, .edits { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 0; }
  .tool { grid-template-columns: auto; justify-content: center; text-align: center; }
  .tool .sw { display: none; }
  .bar button { font-size: 14px; }
  .tool { padding: 2px 8px; min-height: 40px; }
  .bar button { min-height: 40px; padding: 2px 6px; }
  #btn-go { min-width: 0; }
  .tool-meta { display: none; }
  .tb-cell { padding: 2px 10px; }
  h1 { font-size: 16px; }
  .tb-value { font-size: 14px; }
  .tb-actions button { min-height: 36px; }
  .note, .hint, .hud { font-size: 13px; padding: 3px 8px; }
  .result { top: auto; bottom: 8px; padding: 0 12px 10px; }
  .result h2 { font-size: 17px; margin-bottom: 4px; }
  .result ul { margin-bottom: 8px; font-size: 13px; }
  .result::before { margin-bottom: 6px; height: 8px; }
  .res-actions button { min-height: 38px; padding: 2px 10px; }
}
