/* «Гараж» — build bay + race HUD. Every selector is scoped to #garage. */

#garage {
  background:
    radial-gradient(ellipse at 70% 0%, rgba(242,194,48,.06), transparent 55%),
    repeating-linear-gradient(-45deg, transparent 0 60px, rgba(255,255,255,.012) 60px 61px),
    linear-gradient(180deg, #1a1916, #151412 40%);
  overflow-x: clip;
}
#garage [hidden] { display: none !important; } /* .tape / .plate set display and would beat the attribute */
#garage .g-wrap { display: grid; grid-template-columns: minmax(290px, 360px) minmax(0, 1fr); gap: 20px; align-items: stretch; }

/* ---------- shelf */
#garage .g-shelf { padding: 18px 16px 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#garage .g-shelf-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 6px; }
#garage .g-shelf h3 { margin: 0; font-size: 26px; color: var(--paper); }
#garage .g-total { font-size: 14px; }
#garage .g-parts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#garage .g-part {
  position: relative; display: grid; grid-template-columns: 50px minmax(0, 1fr); grid-template-rows: auto 1fr; column-gap: 8px;
  align-items: start; text-align: left; padding: 6px 8px 7px 6px; cursor: pointer; min-width: 0;
  background: linear-gradient(180deg, #312f2a, #24231f); border: 1px solid #0c0b0a; border-radius: 3px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 2px 0 #0c0b0a;
  transition: transform .1s ease, box-shadow .1s ease, border-color .15s, background .15s;
}
#garage .g-part:hover { transform: translateY(-2px); border-color: #5b5549; box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 4px 0 #0c0b0a; }
#garage .g-part:active { transform: translateY(1px); box-shadow: inset 0 2px 5px rgba(0,0,0,.6); }
#garage .g-part[aria-pressed="true"] { border-color: var(--hazard); background: linear-gradient(180deg, #3d3726, #29251b); box-shadow: inset 0 0 0 1px var(--hazard), 0 2px 0 #0c0b0a; }
#garage .g-part[aria-pressed="true"]::after {
  content: 'в руках'; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%) rotate(-2deg);
  font: 600 10px/1 var(--font-body); letter-spacing: .12em; text-transform: uppercase; color: #151412; background: var(--hazard); padding: 2px 6px;
}
#garage .g-part[aria-disabled="true"] { cursor: default; }
#garage .g-part[aria-disabled="true"]:hover { transform: none; }
#garage .g-part.full:not([aria-pressed="true"]) { opacity: .5; }
#garage .g-thumb {
  grid-row: 1 / 3; width: 50px; height: 50px; border-radius: 3px; overflow: hidden; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 60%, #4a453c, #1c1b18 70%);
}
#garage .g-thumb img { width: 118%; height: 118%; max-width: none; object-fit: contain; transition: transform .3s cubic-bezier(.3,1.6,.5,1); }
#garage .g-part:hover .g-thumb img { transform: rotate(-9deg) scale(1.1); }
#garage .g-thumb.loading { background: linear-gradient(100deg, #2a2824 30%, #3a3731 50%, #2a2824 70%) 0 0 / 300% 100%; animation: g-shimmer 1.2s linear infinite; }
#garage .g-thumb.loading img { visibility: hidden; }
@keyframes g-shimmer { to { background-position: -300% 0; } }
#garage .g-name { font: 600 15px/1.1 var(--font-body); text-transform: uppercase; letter-spacing: .04em; color: var(--paper); padding-right: 22px; }
#garage .g-joke { font-size: 12px; line-height: 1.2; color: var(--paper-dim); }
#garage .g-count { position: absolute; top: 5px; right: 6px; font: 600 12px/1 var(--font-body); color: var(--hazard); }
#garage .g-count[data-n="0"] { color: #6b655a; }
#garage .g-count.bump { animation: g-bump .35s ease-out; }
@keyframes g-bump { 40% { transform: scale(1.6); } }
#garage .g-hint { align-self: flex-start; margin: 4px 0 0; font-size: 14px; line-height: 1.25; }

/* ---------- bay */
#garage .g-bay { position: relative; min-width: 0; }
#garage .g-stage {
  position: relative; height: 700px; border-radius: 4px; overflow: hidden; background: #2a2723;
  border: 2px solid #0c0b0a; box-shadow: var(--shadow-hard); touch-action: pan-y; scroll-margin-top: 70px;
}
#garage .g-canvas { width: 100%; height: 100%; cursor: grab; }
#garage .g-stage.dragging .g-canvas { cursor: grabbing; }
#garage .g-stage.placing .g-canvas { cursor: crosshair; }
#garage .g-stage.can-unbolt .g-canvas { cursor: pointer; }
#garage .g-tip { position: absolute; z-index: 3; pointer-events: none; transform: translate(16px, 14px) rotate(-1.6deg); font-size: 13px; white-space: nowrap; }
#garage .g-empty { position: absolute; left: 18px; top: 50%; z-index: 2; pointer-events: none; font-size: 15px; animation: g-nudge 1.6s ease-in-out infinite; }
@keyframes g-nudge { 50% { transform: translateX(-6px) rotate(1.8deg); } }
#garage .g-note {
  position: absolute; left: 50%; bottom: 136px; z-index: 3; pointer-events: none; max-width: min(90%, 460px); text-align: center;
  transform: translateX(-50%); background: rgba(21,20,18,.86); border-left: 4px solid var(--hazard); padding: 8px 14px;
  font: 600 16px/1.3 var(--font-body); color: var(--paper);
}
#garage .g-note.on { animation: g-note-in .3s cubic-bezier(.2,1.4,.5,1); }
@keyframes g-note-in { from { opacity: 0; transform: translate(-50%, 10px); } }
#garage .g-loading { position: absolute; inset: 0; z-index: 7; display: grid; place-content: center; justify-items: center; gap: 16px; background: #1b1a17; color: var(--paper-dim); font-size: 16px; transition: opacity .6s ease, visibility .6s; }
#garage .g-loading.gone { opacity: 0; visibility: hidden; }
#garage .g-spin {
  width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle, #8f8474 0 7px, #151412 8px 17px, transparent 18px), repeating-conic-gradient(#151412 0 12deg, #2e2c28 12deg 24deg);
  box-shadow: 0 0 0 5px #0c0b0a, inset 0 0 0 7px #0c0b0a; animation: g-spin 1.1s linear infinite;
}
@keyframes g-spin { to { transform: rotate(360deg); } }

/* build overlay: corners of the bay */
#garage .g-ui { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
#garage .g-ui > * { position: absolute; pointer-events: auto; }
#garage .g-passport { top: 14px; left: 14px; width: 262px; padding: 14px 16px 12px; transform: rotate(-1.4deg); font-size: 14px; line-height: 1.3; }
#garage .g-pp-title { font: 400 22px/1 var(--font-title); text-transform: uppercase; margin-bottom: 6px; color: #1d1b18; }
#garage .g-passport ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#garage .g-passport li { position: relative; padding-left: 22px; }
#garage .g-passport li::before {
  content: ''; position: absolute; left: 0; top: .2em; width: 13px; height: 13px; border: 2px solid #2a2622; border-radius: 2px;
  background: linear-gradient(45deg, transparent 44%, #3a7a2a 44% 56%, transparent 56%);
}
#garage .g-passport li.bad::before { border-color: var(--alarm); background: linear-gradient(45deg, transparent 43%, var(--alarm) 43% 57%, transparent 57%), linear-gradient(-45deg, transparent 43%, var(--alarm) 43% 57%, transparent 57%); }
#garage .g-passport li.bad { color: #8e2019; }
#garage .g-passport li.warn::before { border-color: var(--orange); }
#garage .g-passport li.flash { animation: g-flash .8s ease-out; }
@keyframes g-flash { from { background: rgba(242,194,48,.55); } }
#garage .g-pp-count { margin-top: 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: #5a534a; }
#garage .g-presets { top: 14px; right: 14px; display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
#garage .g-presets-title { font: 600 12px/1 var(--font-body); letter-spacing: .2em; text-transform: uppercase; color: var(--paper); text-shadow: 0 1px 2px #000; }
#garage .g-preset { border: 0; cursor: pointer; font-size: 14px; transition: transform .12s ease, filter .15s; }
#garage .g-preset:nth-child(odd) { transform: rotate(1.6deg); }
#garage .g-preset:hover { transform: translateX(-4px) rotate(-2.5deg); filter: brightness(1.08); }
#garage .g-preset:active { transform: translateX(-2px) scale(.96); }
#garage .g-preset.on { background: linear-gradient(180deg, #ffd54a, #e0ab12); }
#garage .g-clear { margin-top: 4px; background: linear-gradient(180deg, #c9b9a4, #a9977f); }
#garage .g-tools { left: 14px; bottom: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: calc(100% - 300px); }
#garage .g-tool .keycap { font-size: 12px; min-width: 1.7em; height: 1.7em; }
#garage .g-tool:disabled { opacity: .45; cursor: default; filter: none; transform: none; }
#garage .g-help { flex-basis: 100%; margin: 0; font-size: 13px; color: var(--paper); text-shadow: 0 1px 3px #000, 0 0 8px rgba(0,0,0,.6); }
#garage .g-go-wrap { right: 18px; bottom: 18px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#garage .g-go { font: 400 clamp(26px, 2.4vw, 36px)/1 var(--font-title); padding: .5em 1em .45em; letter-spacing: .02em; }
#garage .g-go:not(:disabled):hover { animation: g-rattle .25s linear infinite; }
#garage .g-go:disabled { opacity: .5; cursor: progress; }
@keyframes g-rattle { 25% { transform: translate(1px, -1px) rotate(.4deg); } 75% { transform: translate(-1px, 1px) rotate(-.4deg); } }
#garage .g-go-note { font-size: 13px; color: var(--paper); text-shadow: 0 1px 3px #000; }

/* ---------- race layout */
#garage.racing .g-shelf, #garage.racing .g-ui, #garage.racing .section-head { display: none; }
#garage.racing .g-wrap { grid-template-columns: minmax(0, 1fr); }
#garage.racing .g-stage { height: min(calc(100vh - 100px), 860px); touch-action: none; }
#garage.racing.g-full .g-stage { position: fixed; inset: 0; height: auto; z-index: 9100; border: 0; border-radius: 0; }

/* ---------- HUD */
#garage .g-hud { position: absolute; inset: 0; z-index: 4; pointer-events: none; user-select: none; transition: opacity .4s; }
#garage .g-hud.dim { opacity: .25; }
#garage .g-hud.dim button { pointer-events: none; }
#garage .g-hud > * { position: absolute; }
#garage .g-hud button { pointer-events: auto; }
#garage .g-dist { top: 12px; left: 50%; transform: translateX(-50%); padding: 9px 30px 7px; text-align: center; min-width: 160px; }
#garage .g-dist small { display: block; font: 600 11px/1 var(--font-body); letter-spacing: .24em; color: var(--paper-dim); }
#garage .g-dist b { display: block; font: 700 34px/1.05 var(--font-body); font-variant-numeric: tabular-nums; }
#garage .g-board { top: 12px; right: 12px; width: 224px; padding: 12px 16px 12px; }
#garage .g-board h4 { margin: 0 0 6px; font: 400 20px/1 var(--font-title); color: var(--hazard); text-align: center; }
#garage .g-board ol { list-style: none; margin: 0; padding: 0; }
#garage .g-board li { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 8px; padding: 3px 6px; font: 600 14px/1.25 var(--font-body); }
#garage .g-board li i { font-style: normal; color: var(--hazard); }
#garage .g-board li b { font-weight: 600; font-variant-numeric: tabular-nums; }
#garage .g-board li.me { background: rgba(242,194,48,.22); box-shadow: inset 0 0 0 1px rgba(242,194,48,.55); }
#garage .g-gauge { left: 14px; bottom: 14px; width: 150px; height: 150px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
#garage .g-needle { transform-box: view-box; transform-origin: 70px 70px; transform: rotate(-120deg); transition: transform .12s linear; }
#garage .g-fuel { left: 178px; bottom: 22px; width: 210px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 4px 8px; align-items: center; }
#garage .g-fuel span { font: 600 12px/1 var(--font-body); letter-spacing: .18em; color: var(--paper); text-shadow: 0 1px 2px #000; }
#garage .g-fuel em { grid-column: 2; justify-self: end; font: 600 12px/1 var(--font-body); font-style: normal; color: var(--paper); text-shadow: 0 1px 2px #000; }
#garage .g-fuel i { grid-column: 1 / -1; grid-row: 2; height: 14px; background: #151412; border: 2px solid #0c0b0a; box-shadow: 0 2px 0 rgba(0,0,0,.5); }
#garage .g-fuel b { display: block; height: 100%; width: 100%; background: repeating-linear-gradient(-45deg, var(--orange) 0 8px, #c4480c 8px 16px); transition: width .1s linear; }
#garage .g-fuel.empty em { color: var(--alarm); }
#garage .g-feed { right: 14px; top: 50%; transform: translateY(-50%); width: min(320px, 40%); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#garage .g-line { background: rgba(21,20,18,.82); border-left: 4px solid var(--paper-dim); padding: 6px 12px; font: 600 15px/1.25 var(--font-body); animation: g-feed-in .3s cubic-bezier(.2,1.4,.5,1); transition: opacity .5s, transform .5s; }
#garage .g-line.hit { border-color: var(--alarm); }
#garage .g-line.warn { border-color: var(--hazard); }
#garage .g-line.dim { color: var(--paper-dim); }
#garage .g-line.out { opacity: 0; transform: translateX(24px); }
@keyframes g-feed-in { from { opacity: 0; transform: translateX(30px); } }
#garage .g-stamp { left: 50%; top: 40%; transform: translate(-50%, -50%) rotate(-7deg); font: 400 clamp(52px, 8vw, 118px)/1 var(--font-title); color: var(--hazard); text-shadow: 0 5px 0 #151412, 0 0 40px rgba(0,0,0,.4); opacity: 0; white-space: nowrap; }
#garage .g-stamp.on { animation: g-stamp 1.6s ease-out forwards; }
#garage .g-stamp.bad { color: var(--alarm); }
@keyframes g-stamp { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-7deg) scale(2.2); } 12% { opacity: 1; transform: translate(-50%, -50%) rotate(-7deg) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -54%) rotate(-7deg) scale(1); } }
#garage .g-still { left: 50%; top: 60%; transform: translateX(-50%); font: 700 30px/1 var(--font-body); letter-spacing: .06em; color: var(--alarm); text-shadow: 0 2px 0 #000, 0 0 16px rgba(0,0,0,.6); }
#garage .g-keys { left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; white-space: nowrap; background: rgba(21,20,18,.72); padding: 6px 12px; font-size: 13px; color: var(--paper-dim); }
#garage .g-keys .keycap { font-size: 11px; height: 1.8em; }
#garage .g-exit { top: 12px; left: 12px; }
#garage .g-view { top: 12px; left: 150px; display: none; }
#garage .g-touch { display: none; }

/* ---------- result */
#garage .g-result { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 16px; overflow-y: auto; background: rgba(21,20,18,.58); opacity: 0; transition: opacity .35s ease; }
#garage .g-result.on { opacity: 1; }
#garage .g-res-card { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, .9fr); gap: 18px; width: 100%; max-width: 880px; align-items: start; }
#garage .g-result.on .g-res-note { animation: g-drop .45s cubic-bezier(.2,1.3,.5,1); }
@keyframes g-drop { from { transform: translateY(-40px) rotate(-4deg); opacity: 0; } }
#garage .g-res-note { transform: rotate(-1deg); padding: 22px 24px 20px; }
#garage .g-res-kicker { font: 600 12px/1 var(--font-body); letter-spacing: .22em; color: #8a4b2a; margin-bottom: 8px; }
#garage .g-res-note h3 { color: #1d1b18; font-size: clamp(26px, 2.6vw, 38px); margin-bottom: .3em; }
#garage .g-res-line { font: 600 19px/1.3 var(--font-body); margin-bottom: .6em; }
#garage .g-res-stats { margin: 0 0 14px; padding: 0; list-style: none; font-size: 14px; color: #4a453d; display: flex; flex-wrap: wrap; gap: 2px 16px; }
#garage .g-awards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
#garage .g-award { opacity: .5; filter: grayscale(.8); }
#garage .g-award.ok { opacity: 1; filter: none; }
#garage .g-award b { font-size: 14px; }
#garage .g-award.ok b { background: linear-gradient(180deg, #ffd54a, #e0ab12); }
#garage .g-award small { display: block; margin-top: 5px; font-size: 12px; line-height: 1.25; color: #4a453d; }
#garage .g-best { padding: 18px 18px 16px; }
#garage .g-best h4 { margin: 0 0 8px; font: 400 22px/1 var(--font-title); color: var(--hazard); text-align: center; }
#garage .g-best ol { margin: 0; padding: 0; list-style: none; counter-reset: b; }
#garage .g-best li { counter-increment: b; display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; padding: 4px 8px; font: 600 16px/1.3 var(--font-body); border-bottom: 1px dashed rgba(255,255,255,.08); }
#garage .g-best li::before { content: counter(b); color: var(--hazard); }
#garage .g-best li b { font-weight: 600; font-variant-numeric: tabular-nums; }
#garage .g-best li.me { background: rgba(242,194,48,.2); color: var(--hazard); }
#garage .g-res-btns { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
#garage .g-toast { grid-column: 1 / -1; justify-self: center; max-width: 640px; text-align: center; background: rgba(21,20,18,.9); border-left: 4px solid var(--toxic); padding: 6px 14px; font-size: 14px; opacity: 0; transition: opacity .3s; }
#garage .g-toast.on { opacity: 1; }
#garage .g-toast:empty { display: none; }

/* ---------- touch */
@media (pointer: coarse) {
  #garage .g-keys { display: none; }
  #garage .g-view { display: inline-flex; left: auto; right: 12px; }
  #garage .g-touch { display: flex; left: 0; right: 0; bottom: 0; justify-content: space-between; align-items: flex-end; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); }
  #garage .g-touch > div { display: flex; gap: 8px; align-items: flex-end; }
  #garage .g-touch button {
    pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; width: 64px; height: 68px; border-radius: 6px;
    font: 600 14px/1 var(--font-body); letter-spacing: .04em; color: var(--paper);
    background: linear-gradient(180deg, #45423b, #2a2824); border: 2px solid #0d0c0b; box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 4px 0 #0d0c0b;
  }
  #garage .g-touch .g-steer button { font-size: 22px; }
  #garage .g-touch .g-gas { height: 104px; background: linear-gradient(180deg, #ff8a3d, #e25408); color: #151412; }
  #garage .g-touch .g-rocket { background: linear-gradient(180deg, #5a3a2a, #3a2418); font-size: 12px; }
  #garage .g-touch button.on { transform: translateY(3px); box-shadow: 0 1px 0 #0d0c0b; filter: brightness(1.25); }
  #garage .g-gauge { left: auto; right: 12px; top: 62px; bottom: auto; width: 96px; height: 96px; }
  #garage .g-fuel { left: 50%; transform: translateX(-50%); top: 84px; bottom: auto; width: 170px; }
  #garage .g-board { display: none; }
}

/* ---------- phones / narrow */
@media (max-width: 820px) {
  #garage .g-wrap { display: flex; flex-direction: column; gap: 12px; }
  #garage .g-bay { display: contents; }
  #garage .g-stage { order: 1; height: min(64vh, 470px); }
  #garage .g-shelf { order: 2; padding: 12px 10px 10px; gap: 10px; }
  #garage .g-ui { order: 3; position: static; display: flex; flex-direction: column; gap: 14px; pointer-events: auto; }
  #garage .g-ui > * { position: static; }
  #garage .g-shelf h3 { font-size: 20px; }
  #garage .g-parts { display: flex; overflow-x: auto; gap: 8px; padding: 2px 2px 12px; scroll-snap-type: x proximity; scrollbar-width: thin; }
  #garage .g-part { flex: 0 0 92px; grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 8px 4px 8px; scroll-snap-align: start; }
  #garage .g-thumb { grid-row: auto; width: 60px; height: 60px; }
  #garage .g-name { padding: 6px 0 0; font-size: 13px; }
  #garage .g-joke { display: none; }
  #garage .g-hint { font-size: 13px; }
  #garage .g-tools { order: 1; max-width: none; }
  #garage .g-help { display: none; }
  #garage .g-presets { order: 2; flex-direction: row; flex-wrap: wrap; align-items: center; }
  #garage .g-preset:hover { transform: none; }
  #garage .g-go-wrap { order: 3; align-items: stretch; }
  #garage .g-go { justify-content: center; font-size: 30px; }
  #garage .g-go-note { text-align: center; }
  #garage .g-passport { order: 4; width: auto; transform: rotate(-.6deg); }
  #garage .g-empty { left: 50%; top: auto; bottom: 12px; transform: translateX(-50%); animation: none; }
  #garage .g-note { top: 12px; bottom: auto; font-size: 14px; }
  #garage .g-dist { padding: 6px 18px 5px; min-width: 120px; }
  #garage .g-dist b { font-size: 26px; }
  #garage .g-feed { top: 150px; transform: none; left: 12px; right: 12px; width: auto; align-items: center; }
  #garage .g-line { font-size: 13px; }
  #garage .g-res-card { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #garage .g-res-note { padding: 16px 16px 14px; }
  #garage .g-res-line { font-size: 17px; }
  #garage .g-awards { gap: 8px 10px; }
  #garage .g-result { place-items: start center; }
  #garage .g-res-btns .btn { flex: 1 1 40%; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  #garage .g-go:not(:disabled):hover, #garage .g-empty { animation: none; }
}
