/* Тренажери з інформатики · 8 клас
   Layout: майстерня-верстак — ліворуч лоток деталей, у центрі плата, праворуч «паспорт» пристрою. */
:root {
  /* поверхні й текст */
  --bg: #EDF1EE;
  --surface: #FFFFFF;
  --surface-2: #E1E8E3;
  --ink: #13211B;
  --muted: #55665E;
  --line: #C8D3CC;
  /* акцент — колір шовкографії на платі */
  --accent: #0D7A63;
  --accent-ink: #FFFFFF;
  --accent-soft: #D3EEE6;
  /* стани */
  --ok: #15803D; --ok-bg: #DCF3E3;
  --err: #B42318; --err-bg: #FBE3E0;
  --warn: #C98A0B;
  /* плата й деталі */
  --pcb: #18573F; --pcb-2: #1F6B4F; --trace: #2A7D5D; --silk: #EAF3EE;
  --slot: #262C29; --slot-2: #3A423E;
  --metal: #C3CBC8; --metal-2: #A6B0AC; --edge: #3B4440; --ink-on-metal: #26302C;
  --pin: #C9A227; --chip: #20262A;
  --ram: #2F5D8C; --gpu: #2B3033; --fan: #50585C; --ssd: #2D3540; --ssd-label: #9FD9C6;
  --m2: #11161A; --psu: #3B4246; --screen: #4E8FBF;
  --zone: rgba(255, 214, 102, .22); --zone-line: #FFD666;
  /* шрифти */
  --f-display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --f-body: "Onest", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 10px;
  --shadow: 0 1px 2px rgba(19, 33, 27, .06), 0 6px 18px rgba(19, 33, 27, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1411; --surface: #141F1A; --surface-2: #1B2922; --ink: #E2ECE6; --muted: #93A59C; --line: #2A3A33;
    --accent: #3CC6A1; --accent-ink: #052019; --accent-soft: #143A30;
    --ok: #4ADE80; --ok-bg: #11301E; --err: #F87171; --err-bg: #3A1616; --warn: #E5A92A;
    --pcb: #123F2F; --pcb-2: #18523D; --trace: #1F6A4E; --silk: #CFE1D7;
    --slot: #0A0E0C; --slot-2: #222A26;
    --metal: #A9B3AF; --metal-2: #8C9793; --edge: #59645F; --ink-on-metal: #1A221F;
    --zone: rgba(255, 214, 102, .18); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 22px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C1411; --surface: #141F1A; --surface-2: #1B2922; --ink: #E2ECE6; --muted: #93A59C; --line: #2A3A33;
  --accent: #3CC6A1; --accent-ink: #052019; --accent-soft: #143A30;
  --ok: #4ADE80; --ok-bg: #11301E; --err: #F87171; --err-bg: #3A1616; --warn: #E5A92A;
  --pcb: #123F2F; --pcb-2: #18523D; --trace: #1F6A4E; --silk: #CFE1D7;
  --slot: #0A0E0C; --slot-2: #222A26;
  --metal: #A9B3AF; --metal-2: #8C9793; --edge: #59645F; --ink-on-metal: #1A221F;
  --zone: rgba(255, 214, 102, .18); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 22px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--f-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 24px;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
h1, h2, h3 { text-wrap: balance; margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--f-mono); }

/* шапка */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding-block: 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--pcb); display: grid; place-items: center; }
.brand-mark svg { width: 24px; height: 24px; }
.brand small { display: block; color: var(--muted); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.brand b { font-family: var(--f-display); font-weight: 600; font-size: 15px; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); margin-left: auto; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 500; }
.tab[aria-selected="true"] { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); }

/* панель керування */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding-block: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn[disabled] { opacity: .45; cursor: default; }
.progress { font-family: var(--f-mono); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress b { color: var(--ink); }
.hint-line { color: var(--muted); font-size: 14px; flex: 1 1 260px; min-width: 0; }

/* робоча зона */
.work { display: grid; gap: 16px; grid-template-columns: 210px minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1180px) { .work { grid-template-columns: minmax(0, 1fr) 320px; } .tray { grid-column: 1 / -1; } }
@media (max-width: 780px) { .work { grid-template-columns: minmax(0, 1fr); } }

.tray { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); align-content: start; }
@media (min-width: 1181px) { .tray { grid-template-columns: 1fr; } }
@media (max-width: 780px) {
  .tray { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .part { flex-direction: column; gap: 4px; padding: 8px 4px; text-align: center; }
  .part svg { width: 30px; height: 30px; }
  .part span { font-size: 12px; }
}
.shop-line { font-family: var(--f-mono); font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; line-height: 1.6; }
.linkish { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }
.part {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); cursor: grab; touch-action: none; user-select: none;
  text-align: left; width: 100%;
}
.part svg { width: 40px; height: 40px; flex: none; }
.part span { font-weight: 500; line-height: 1.25; }
.part small { display: block; font-family: var(--f-mono); color: var(--muted); font-size: 11px; }
.part:hover { border-color: var(--accent); }
.part.selected { outline: 3px solid var(--accent); outline-offset: 1px; }
.part.done { opacity: .38; cursor: default; border-style: dashed; }
.shake { animation: shake .38s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; opacity: .92; box-shadow: var(--shadow); width: 170px; }

.stage { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; min-width: 0; }
.stage svg.board { display: block; width: 100%; height: auto; max-height: 78vh; touch-action: manipulation; }
.stage-cap { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); padding: 2px 4px 8px; }

/* плата */
.board .pcb { fill: var(--pcb); }
.board .trace { stroke: var(--trace); fill: none; stroke-width: 2; }
.board .silk { fill: var(--silk); font-family: var(--f-mono); font-size: 9px; letter-spacing: .04em; }
.board .slot { fill: var(--slot); }
.board .slot-2 { fill: var(--slot-2); }
.board .metal { fill: var(--metal); }
.board .metal2 { fill: var(--metal-2); }
.board .pin { fill: var(--pin); }
.board .chip { fill: var(--chip); }
.zone { fill: transparent; stroke: transparent; stroke-width: 2; cursor: pointer; }
.zone-label { display: none; pointer-events: none; font-family: var(--f-body); font-size: 11px; font-weight: 600; fill: var(--zone-line); paint-order: stroke; stroke: var(--pcb); stroke-width: 3px; }
.board.learn .zone { stroke: var(--zone-line); stroke-dasharray: 5 4; fill: var(--zone); }
.board.learn .zone-label { display: block; }
.board.dragging .zone.hover, .board .zone.hover { fill: rgba(255, 214, 102, .45); stroke: var(--zone-line); stroke-dasharray: none; }
.board .zone.filled { stroke: transparent; fill: transparent; }
.board.learn .zone.filled + .zone-label { display: none; }
.placed { pointer-events: none; }
.pop { animation: pop .35s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes pop { from { transform: scale(.85); opacity: .2; } to { transform: scale(1); opacity: 1; } }

/* паспорт пристрою */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 76px); max-height: calc(100vh - 100px); overflow: auto; min-width: 0; }
.panel h2 { font-family: var(--f-display); font-weight: 600; font-size: 19px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.panel .abbr { font-family: var(--f-mono); font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 6px; letter-spacing: .04em; }
.panel .full { color: var(--muted); font-size: 13px; margin-top: 4px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
.panel ul { margin: 0; padding-left: 18px; display: grid; gap: 5px; }
.panel p { margin: 0; }
.panel-close { display: none; float: right; border: 0; background: var(--surface-2); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 18px; }
.shop { display: flex; flex-wrap: wrap; gap: 4px; }
.shop-row { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: baseline; font-size: 14px; margin-top: 8px; }
.tok { font-family: var(--f-mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; white-space: nowrap; }
.past { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.why { margin-top: 12px; padding-left: 10px; border-left: 3px solid var(--accent); font-size: 14px; }
.panel .empty { color: var(--muted); }
.panel .empty b { color: var(--ink); }
.legend { font-size: 12px; color: var(--muted); margin-top: 14px; }
@media (max-width: 780px) {
  .panel { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 30; max-height: 58vh; border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.25);
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateY(105%); transition: transform .25s; }
  .panel.open { transform: none; }
  .panel-close { display: block; }
}

/* повідомлення */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 60; padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 500; max-width: min(92vw, 520px); box-shadow: var(--shadow); }
.toast.ok { background: var(--ok); color: #fff; }
.toast.err { background: var(--err); color: #fff; }

/* розшифруй оголошення */
.dec { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 900px) { .dec { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0; }
.listing-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.listing-kind { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.listing-title { font-family: var(--f-display); font-weight: 600; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip-t { font-family: var(--f-mono); font-size: 14px; padding: 7px 11px; border-radius: 8px; background: var(--surface-2); border: 1.5px solid var(--line); cursor: grab; touch-action: none; user-select: none; }
.chip-t.plain { cursor: default; background: transparent; border-style: dashed; color: var(--muted); }
.chip-t.selected { border-color: var(--accent); background: var(--accent-soft); }
.chip-t.ok { border-color: var(--ok); background: var(--ok-bg); cursor: default; }
.chip-t.bad { border-color: var(--err); background: var(--err-bg); }
.chip-t.picked { border-color: var(--warn); background: var(--surface); box-shadow: inset 0 0 0 1px var(--warn); }
button.chip-t { cursor: pointer; }
.q { font-weight: 600; font-size: 16px; margin-top: 14px; }
.targets { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.target { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1.5px dashed var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; min-height: 56px; text-align: left; }
.target svg { width: 34px; height: 34px; flex: none; }
.target.hover { border-color: var(--accent); background: var(--accent-soft); border-style: solid; }
.target .cnt { margin-left: auto; font-family: var(--f-mono); font-size: 12px; color: var(--ok); }
.explain { margin-top: 14px; display: grid; gap: 6px; }
.explain div { font-size: 14px; padding: 6px 10px; border-radius: 8px; background: var(--ok-bg); }
.explain .tok { margin-right: 6px; }
.feedback { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.feedback.ok { background: var(--ok-bg); }
.feedback.err { background: var(--err-bg); }
.opts { display: grid; gap: 10px; margin-top: 12px; }
.opt { text-align: left; border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.opt:hover { border-color: var(--accent); }
.opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.opt.bad { border-color: var(--err); background: var(--err-bg); }
.opt b { font-family: var(--f-display); font-weight: 600; font-size: 14px; display: block; margin-bottom: 4px; }
.opt .mono { font-size: 13px; color: var(--muted); }
.side-note { font-size: 14px; color: var(--muted); display: grid; gap: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* результат */
.result { max-width: 560px; margin: 24px auto; text-align: left; }
.result h2 { font-family: var(--f-display); font-weight: 600; font-size: 22px; }
.score { font-family: var(--f-display); font-size: 44px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; margin: 10px 0 4px; }
.result dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0; }
.result dt { color: var(--muted); }
.result dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.result label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
.result input { width: 100%; font: inherit; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); margin-top: 4px; }
.result .stamp { font-family: var(--f-mono); font-size: 12px; color: var(--muted); margin-top: 10px; }

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

/* картка товару «як у магазині» + лінії до пристроїв */
.match { position: relative; display: grid; grid-template-columns: minmax(0, 560px) minmax(56px, 1fr) minmax(190px, 280px); align-items: start; }
.match .pcard { grid-column: 1; }
.match .tcol { grid-column: 3; display: grid; gap: 8px; }
.lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.lines .link { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
.lines .link-dot { fill: var(--accent); }
.tcol .target { min-height: 52px; }
.target.linked { border-style: solid; border-color: var(--accent); }
.pcard { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; min-width: 0; }
.pcard-head { display: flex; gap: 12px; align-items: center; padding: 12px; border-bottom: 1px solid var(--line); }
.pcard-pic { width: 64px; height: 64px; flex: none; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; }
.pcard-pic svg { width: 48px; height: 48px; }
.pcard-name { display: grid; gap: 2px; min-width: 0; }
.pcard-kind { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.pcard-title { font-family: var(--f-display); font-weight: 600; font-size: 16px; line-height: 1.25; }
.pcard-model { font-family: var(--f-body); font-weight: 500; color: var(--muted); font-size: 14px; }
.pcard-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 10px 12px 4px; font-weight: 600; }
.prows { display: grid; gap: 6px; padding: 4px 8px 10px; }
.prow { display: grid; gap: 2px; text-align: left; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface-2); font: inherit; color: inherit; }
.prow-t { font-family: var(--f-mono); font-size: 14px; }
div.prow[data-i], button.prow { cursor: grab; touch-action: none; user-select: none; }
button.prow { cursor: pointer; touch-action: manipulation; }
.prow.static { background: transparent; border-color: transparent; padding: 3px 4px; }
.prow.static .prow-t { font-size: 13px; }
.prow.selected { border-color: var(--accent); background: var(--accent-soft); }
.prow.ok { border-color: var(--ok); background: var(--ok-bg); cursor: default; }
.prow.bad { border-color: var(--err); background: var(--err-bg); }
.prow.picked { border-color: var(--warn); background: var(--surface); box-shadow: inset 0 0 0 1px var(--warn); }
.prow-x { font-size: 12.5px; line-height: 1.35; color: var(--muted); font-family: var(--f-body); }
.ghost-row { width: 220px; font-family: var(--f-mono); }
.one-card { max-width: 560px; }
.cards-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.pick { padding: 0; border: 2px solid transparent; border-radius: 14px; background: none; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.pick:hover .pcard { border-color: var(--accent); }
.pick.ok .pcard { border-color: var(--ok); background: var(--ok-bg); }
.pick.bad .pcard { border-color: var(--err); background: var(--err-bg); }
.pcard.compact .pcard-pic { width: 46px; height: 46px; } .pcard.compact .pcard-pic svg { width: 34px; height: 34px; }
.pcard.compact .pcard-title { font-size: 14px; }
.review-h { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.review { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; }
@media (max-width: 560px) {
  .match { grid-template-columns: minmax(0, 1fr) 30px 92px; }
  .tcol .target { flex-direction: column; gap: 2px; padding: 6px 4px; text-align: center; font-size: 11px; line-height: 1.15; min-height: 60px; justify-content: center; }
  .tcol .target svg { width: 26px; height: 26px; }
  .pcard-pic { width: 46px; height: 46px; } .pcard-pic svg { width: 34px; height: 34px; }
  .prow-t { font-size: 13px; }
}

.prow, .target, .pick, .part { -webkit-tap-highlight-color: transparent; }
@media (max-width: 560px) {
  .seg { flex-wrap: wrap; }
  .seg button { font-size: 13px; padding: 6px 9px; white-space: nowrap; }
}

.stage, .stage svg text, .stage-cap { -webkit-user-select: none; user-select: none; }
.shop-row { grid-template-columns: minmax(0, 46%) minmax(0, 1fr); }
.shop-row .tok { white-space: normal; justify-self: start; }
@media (max-width: 560px) {
  .tabs { margin-left: 0; width: 100%; border-radius: 12px; display: grid; grid-template-columns: 1fr 1fr; }
  .tab { border-radius: 9px; font-size: 13px; padding: 7px 6px; }
}

.type-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.type-opt.ok { border-color: var(--ok); background: var(--ok-bg); }
.type-opt.bad { border-color: var(--err); background: var(--err-bg); }

.theme-btn { order: 3; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 7px 12px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.theme-btn:hover { border-color: var(--accent); }
.theme-btn span { font-size: 15px; }
.top .tabs { order: 2; }
.top .brand + .theme-btn { margin-left: auto; }
@media (max-width: 560px) {
  .theme-btn { order: 1; margin-left: auto; padding: 6px 10px; }
  .top .tabs { order: 2; }
}
