:root {
  --paper: #e8eef4; --grid: rgba(36, 62, 99, 0.09); --card: #ffffff; --ink: #12274a; --muted: #3f5272; --line: #9db0c8;
  --accent: #ffc72c; --accent-ink: #1a1a1a; --good: #14693a; --bad: #a3231f; --focus: #0b57d0;
  --sky: #cfe6f7; --hill: #bcd6c8; --cloud: #ffffff; --grass: #6aa84f; --soil: #9a7b57; --clay: #bf8a5e; --rockc: #a4afbb;
  --water: #5aa9d6; --voidc: #6f7f94; --leaf: #2f7d4f; --trunk: #6b4a2b; --stone: #8d97a4; --stone-dark: #6c7684;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1b2e; --grid: rgba(150, 180, 220, 0.08); --card: #17263d; --ink: #e6eefb; --muted: #b3c3dc; --line: #3c5273;
    --good: #6fd49b; --bad: #ff8a84; --focus: #8ab4ff;
    --sky: #1b3350; --hill: #2a4a45; --cloud: #3d5a80; --grass: #3d7a3a; --soil: #5e4a35; --clay: #7a5538; --rockc: #4e5a68;
    --water: #2b6c96; --voidc: #05080d; --leaf: #1f5a38; --trunk: #4a3320; --stone: #55606f; --stone-dark: #3d4654;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1b2e; --grid: rgba(150, 180, 220, 0.08); --card: #17263d; --ink: #e6eefb; --muted: #b3c3dc; --line: #3c5273;
  --good: #6fd49b; --bad: #ff8a84; --focus: #8ab4ff;
  --sky: #1b3350; --hill: #2a4a45; --cloud: #3d5a80; --grass: #3d7a3a; --soil: #5e4a35; --clay: #7a5538; --rockc: #4e5a68;
  --water: #2b6c96; --voidc: #05080d; --leaf: #1f5a38; --trunk: #4a3320; --stone: #55606f; --stone-dark: #3d4654;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 100%; }
body {
  margin: 0; font: 1.0625rem/1.5 var(--sans); color: var(--ink); background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px; min-height: 100vh;
}
.wrap { max-width: 80rem; margin: 0 auto; padding: 1rem 1rem 2rem; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; max-width: 80rem; margin: 0 auto; padding: .75rem 1rem 0; }
.topbar__title { font-size: 1.5rem; margin: 0; flex: 1 1 auto; }
.topbar__title a { color: inherit; text-decoration: none; }
.topbar__title a:hover { text-decoration: underline; }
.topbar__tools { display: flex; gap: .5rem; }

h1, h2, h3 { line-height: 1.2; margin: 1rem 0 .5rem; }
h2 { font-size: 1.6rem; margin-top: .5rem; }
h2:focus, h3:focus { outline: none; }
h3 { font-size: 1.15rem; margin-top: .25rem; }
p { margin: .5rem 0; max-width: 70ch; }
.lead { font-size: 1.15rem; }
.hint { color: var(--muted); font-size: .95rem; }
.big { font-size: 1.35rem; font-weight: 700; margin: .1rem 0; }
.good { color: var(--good); font-weight: 700; }
.bad { color: var(--bad); font-weight: 700; }
a { color: var(--ink); }

.btn {
  font: inherit; font-weight: 700; min-height: 44px; padding: .5rem 1.1rem; border-radius: 6px; cursor: pointer;
  background: var(--card); color: var(--ink); border: 2px solid var(--ink);
}
.btn:hover { background: var(--grid); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent-ink); }
.btn--primary:hover { background: #ffd65a; }
.btn--small { min-height: 38px; padding: .25rem .75rem; font-size: .95rem; }
.btn--big { width: 100%; font-size: 1.2rem; min-height: 54px; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--card); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.controls { display: flex; flex-wrap: wrap; gap: .6rem; margin: .75rem 0 0; }

/* level list */
.howto, .panel, .about { background: var(--card); border: 2px solid var(--line); border-radius: 8px; }
.howto { padding: .25rem 1rem .6rem; margin: 1rem 0; }
.howto ol { margin: .25rem 0 0; padding-left: 1.4rem; }
.howto li { margin: .3rem 0; }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; margin: 1rem 0; }
@media (min-width: 36rem) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { font: inherit; color: inherit; text-align: left; padding: 0; background: var(--card); border: 2px solid var(--line); border-radius: 10px; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; }
.tile:hover { border-color: var(--ink); }
.tile__art { display: block; width: 100%; height: 9.5rem; background: var(--sky); }
.tile__body { display: grid; gap: .15rem; padding: .6rem .8rem .8rem; }
.tile__num { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.tile__name { font-weight: 800; font-size: 1.15rem; }
.tile__facts { color: var(--muted); font-size: .95rem; }
.tile__stars { font-size: 1.3rem; letter-spacing: .1em; }

/* build screen */
.buildhead { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.buildhead h2 { margin: 0; }
.goal { margin: .25rem 0 .75rem; }
.labgrid { display: grid; gap: 1rem; }
.stage { border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; background: var(--sky); line-height: 0; touch-action: none; }
.stage__svg { display: block; width: 100%; height: auto; max-height: 70vh; user-select: none; -webkit-user-select: none; cursor: crosshair; }
.stage__svg.is-erase { cursor: not-allowed; }
.stage__svg:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.labpanel { display: grid; gap: .75rem; align-content: start; }
.panel { padding: .5rem .9rem .8rem; }
.panel h3 { margin-top: .2rem; }
summary { cursor: pointer; font-weight: 700; min-height: 32px; }
summary h2 { display: inline; font-size: 1.1rem; margin: 0; }
progress { width: 100%; height: 1rem; accent-color: var(--ink); }
.mats { display: grid; gap: .4rem; }
.mat { display: grid; grid-template-columns: 1.6rem 1fr; grid-template-rows: auto auto; column-gap: .6rem; align-items: center; border: 2px solid var(--line); border-radius: 8px; padding: .35rem .6rem; cursor: pointer; background: var(--card); }
.mat:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--accent); }
.mat:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.mat__swatch { grid-row: 1 / 3; width: 1.6rem; height: .5rem; border-radius: 3px; display: block; }
.mat__swatch--deck { background: #3a3a44; }
.mat__swatch--timber { background: #c68a4a; }
.mat__swatch--steel { background: #7f8fa3; }
.mat__swatch--cable { background: #2b3a55; height: .2rem; }
.mat__name { font-weight: 700; }
.mat__info { color: var(--muted); font-size: .88rem; grid-column: 2; }
.tools { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.views { margin-top: .75rem; display: grid; gap: .4rem; }
.views fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: .2rem; }
.views legend { font-weight: 700; padding: 0; margin-bottom: .2rem; }
.views label, .check { display: flex; align-items: center; gap: .5rem; min-height: 32px; }
.is-testing .buildonly { display: none; }
#build:not(.is-testing) .buildhide { display: none; }
.legend { margin: .4rem 0 0; font-size: .95rem; color: var(--ink); }
#build:not(.is-testing) .legend { visibility: hidden; }
.key { display: inline-block; width: 1.6rem; height: .5rem; border-radius: 3px; vertical-align: middle; margin: 0 .25rem 0 .6rem; }
.key--blue { background: #60a5fa; } .key--amber { background: #fbbf24; } .key--rose { background: #f43f5e; }
.key--cyan { background: #22d3ee; } .key--pink { background: #f472b6; }
.result { border-color: var(--ink); }
.stats { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; margin: .5rem 0; }
.stats div { display: grid; }
.stats b { font-family: var(--mono); font-size: 1.15rem; }
.stats span { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stars { letter-spacing: .15em; }
.beamlist, .loglist { padding-left: 1.2rem; margin: .4rem 0 0; font-size: .95rem; }
.beamlist li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin: .25rem 0; }
.loglist li { margin: .2rem 0; }

@media (min-width: 900px) {
  .labgrid { grid-template-columns: minmax(0, 1fr) 21rem; align-items: start; }
}

/* about, footer pill, dialog */
.about { max-width: 78rem; width: calc(100% - 2rem); margin: 1rem auto 0; padding: .5rem 1rem; }
.about p, .about li { max-width: 68ch; }
.sitefoot { display: flex; justify-content: center; padding: 18px 12px calc(env(safe-area-inset-bottom, 0px) + 18px); }
.madeby {
  display: inline-flex; align-items: center; gap: .35rem; margin: 0; padding: 7px 10px; border-radius: 999px;
  background: rgba(15, 23, 42, .56); border: 1px solid rgba(255, 255, 255, .16); box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, .82); font: 600 11px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: .01em; white-space: nowrap;
}
.madeby a { color: #fff; text-decoration: none; }
.madeby a:hover, .madeby a:focus-visible { text-decoration: underline; }
dialog { background: var(--card); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; max-width: min(34rem, 92vw); padding: 0 1.2rem 1rem; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog__head { display: flex; justify-content: space-between; align-items: center; }
.glossary dt { font-weight: 700; margin-top: .6rem; text-transform: capitalize; }
.glossary dd { margin: 0; }

/* ---------- the blueprint ---------- */
.stage { background: #0b2a4a; border-color: #0b2a4a; }
.bp-bg { fill: #0f3a63; }
.bp-gridline { fill: none; stroke: #ffffff; stroke-opacity: .09; stroke-width: 1; }
.bp-hatchline { stroke: #bfe0ff; stroke-opacity: .32; stroke-width: 1.2; }
.bp-ground { fill: #1b5a8c; }
.bp-ground--soft { fill: #1f5d7d; }
.bp-ground--rock { fill: #1a4f78; }
.bp-outline { fill: none; stroke: #cfe8ff; stroke-width: 2; stroke-linejoin: round; }
.bp-surface { stroke: #cfe8ff; stroke-width: 3; fill: none; }
.bp-water { fill: #3aa0d8; fill-opacity: .16; }
.bp-wave { fill: none; stroke: #7cc8f5; stroke-width: 1.6; stroke-opacity: .7; }
.bp-void { fill: #061a30; }
.bp-quarry { fill: #0c2f52; }
.bp-tower { fill: #25669c; }
.bp-tower-cap { fill: #0f3a63; }
.bp-prop { fill: none; stroke: #9ec9f2; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.bp-prop--hot { stroke: #fb923c; }
.bp-dim { fill: none; stroke: #ffd166; stroke-width: 1.2; stroke-dasharray: 4 3; opacity: .85; }
.bp-dim--line { stroke-dasharray: none; fill: #ffd166; }
.bp-text { fill: #cfe8ff; font: 600 11px var(--mono); letter-spacing: .06em; }
.bp-text--bold { font-weight: 800; fill: #ffffff; }
.bp-titleblock__box { fill: #0b2a4a; stroke: #cfe8ff; stroke-width: 1.5; }
.tile__art { background: #0f3a63; }

.grid__dot { fill: #cfe8ff; opacity: .35; }
.grid.is-hidden { display: none; }
.bar__outline, .bar__body, .bar__detail { stroke-linecap: round; fill: none; }
.bar__outline { stroke: #03152b; }
.beam--deck .bar__body, .simbeam--deck .bar__body { stroke: #aab4c3; }
.beam--timber .bar__body { stroke: #d99a5b; }
.beam--steel .bar__body { stroke: #8fb8e6; }
.beam--cable .bar__body { stroke: #5eead4; }
.bar__detail--deck { stroke: #ffffff; stroke-width: 1.5; stroke-dasharray: 7 7; stroke-linecap: butt; }
.bar__detail--timber { stroke: #8a5a2b; stroke-width: 1.4; stroke-dasharray: 2 5; stroke-linecap: butt; opacity: .8; }
.bar__detail--steel { stroke: #ffffff; stroke-width: 1.4; stroke-opacity: .55; transform: translateY(-1.5px); }
.beam.is-hover .bar__body { stroke: #fb7185; }
.simbeam.is-broken { display: none; }
.simbeam.is-picked .bar__outline { stroke: #ffd166; stroke-width: 14; }
.joint__nut { fill: #ffc72c; stroke: #03152b; stroke-width: 2; }
.joint__hole { fill: #03152b; }
.joint__plate { fill: #fb923c; stroke: #03152b; stroke-width: 2.5; }
.joint__x { stroke: #03152b; stroke-width: 2; stroke-linecap: round; }
.joint.is-start .joint__nut { stroke: #ffffff; stroke-width: 3.5; }
.ring { fill: none; }
.ring--start { stroke: #ffd166; stroke-width: 3.5; }
.ring--hover { stroke: #7cc8f5; stroke-width: 2; stroke-dasharray: 4 4; }
.ring--cursor { stroke: #ffffff; stroke-width: 3; stroke-dasharray: 6 4; }
.ghost { stroke: #7cc8f5; stroke-width: 4; stroke-dasharray: 8 6; stroke-linecap: round; opacity: .9; }
.ghost--bad { stroke: #fb7185; }
.tag__box { fill: #03152b; stroke: #cfe8ff; stroke-width: 1.2; }
.tag--bad .tag__box { fill: #7f1d3a; stroke: #fb7185; }
.tag--strain .tag__box { fill: #1e293b; stroke: #fbbf24; }
.tag--callout .tag__box { fill: #7f1d3a; stroke: #fb7185; stroke-width: 1.8; }
.tag__text { fill: #ffffff; font: 700 13px var(--sans); }
.callout__line { stroke: #fb7185; stroke-width: 2.4; }
.callout__ring { fill: none; stroke: #fb7185; stroke-width: 2.6; stroke-dasharray: 5 4; }
.stamp__box { fill: rgba(3, 21, 43, .72); stroke-width: 4; }
.stamp__text { font: 900 26px var(--sans); letter-spacing: .12em; }
.stamp--ok .stamp__box { stroke: #4ade80; } .stamp--ok .stamp__text { fill: #4ade80; }
.stamp--warn .stamp__box { stroke: #fbbf24; } .stamp--warn .stamp__text { fill: #fbbf24; }
.stamp--bad .stamp__box { stroke: #fb7185; } .stamp--bad .stamp__text { fill: #fb7185; }
.spark { fill: #ffd166; }
.v-skin { fill: #ffffff; } .v-limb { fill: #ffffff; stroke: #03152b; stroke-width: 0.05; stroke-linejoin: round; }
.v-tire { fill: #03152b; stroke: #cfe8ff; stroke-width: 0.05; } .v-hub { fill: #cfe8ff; }
.v-body--car { fill: #5eead4; stroke: #03152b; stroke-width: 0.06; }
.v-body--truck { fill: #fb923c; stroke: #03152b; stroke-width: 0.06; }
.v-body--train { fill: #fbbf24; stroke: #03152b; stroke-width: 0.06; }
.v-glass { fill: #0f3a63; }
.v-box { fill: #cbd5e1; stroke: #03152b; stroke-width: 0.06; }
.v-wagon { fill: #94a3b8; stroke: #03152b; stroke-width: 0.06; } .v-wagon--b { fill: #64748b; }
.v-chassis { fill: #03152b; }

/* ---------- lab panels ---------- */
h4 { font-size: 1rem; margin: .6rem 0 .2rem; }
.panel summary { font-family: var(--mono); font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }
.panel h3 { font-family: var(--mono); font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.costparts { list-style: none; margin: .3rem 0 0; padding: 0; font-size: .9rem; color: var(--muted); }
.costparts li { padding: .1rem 0; }
.checks { list-style: none; margin: .4rem 0 0; padding: 0; display: grid; gap: .35rem; }
.check { display: grid; grid-template-columns: 4.2rem 1fr; gap: .5rem; align-items: start; font-size: .95rem; }
.check b { font: 800 .72rem/1.6 var(--mono); letter-spacing: .06em; text-align: center; border-radius: 4px; padding: 0 .25rem; border: 2px solid var(--line); }
.check--ok b { border-color: var(--good); color: var(--good); }
.check--warn b { border-color: var(--bad); color: var(--bad); }
.check--info b { border-color: var(--muted); color: var(--muted); }
.mat__meter { grid-column: 2; width: 100%; height: .5rem; margin-top: .2rem; }
.strainlist { list-style: none; margin: .2rem 0; padding: 0; display: grid; gap: .3rem; }
.strain { font: inherit; text-align: left; width: 100%; padding: .3rem .6rem; border: 2px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); cursor: pointer; }
.strain:hover, .strain:focus-visible { border-color: var(--ink); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Switch between the two bridge games */
.gameswitch { display: inline-flex; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--card); }
.gameswitch a { display: flex; align-items: center; min-height: 38px; padding: .25rem .95rem; font-weight: 700; font-size: .95rem; text-decoration: none; color: var(--ink); }
.gameswitch a:hover { background: var(--grid); }
.gameswitch a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.gameswitch a:focus-visible { outline-offset: -3px; }
.otheroffer { background: var(--card); border: 2px solid var(--line); border-radius: 8px; padding: .5rem 1rem .9rem; margin: 1rem 0; }
.otheroffer h3 { margin-top: .3rem; }
.otheroffer .btn { display: inline-flex; align-items: center; text-decoration: none; }
