/* BROKEBOTS — Darklabs test-chamber styling.
   The cabinet is laid out at a fixed logical size (1280 wide) and scaled as one
   unit by game.js, so the HUD, canvas and SVG bots always stay aligned. */

:root {
  --brand: #690000;
  --crimson: #b3141c;
  --crimson-hi: #d8322f;
  --black: #050303;
  --near-black: #0e0908;
  --panel: #140d0c;
  --steel: #2b2826;
  --steel-hi: #4a4540;
  --bronze: #9c7536;
  --bronze-hi: #c49a4c;
  --gold: #e8b04a;
  --offwhite: #f0e8d8;
  --dim: #9a8670;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--black);
  color: var(--offwhite);
  font-family: var(--mono);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------------- viewport + cabinet ---------------- */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;               /* no scroll, zoom or pull-to-refresh from game input */
  background:
    radial-gradient(ellipse at 50% 40%, rgba(105, 0, 0, 0.22), transparent 65%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.015) 0 1px, transparent 1px 64px),
    var(--black);
}

#cabinet {
  position: absolute;
  left: 0;
  top: 0;
  width: 1280px;
  padding: 12px 22px 8px;
  transform-origin: 0 0;
  background: linear-gradient(180deg, #1a1110 0%, #0c0707 100%);
  border: 3px solid #3a2a18;
  outline: 2px solid var(--brand);
  outline-offset: -9px;
  box-shadow: 0 0 0 1px #000, 0 30px 80px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(232, 176, 74, 0.15);
}

/* ---------------- HUD ---------------- */
#hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 104px;
  padding: 0 6px 6px;
}
.hud-side { display: flex; align-items: center; gap: 22px; }
.hud-right { justify-content: flex-end; }

.bot-tag { display: flex; flex-direction: column; line-height: 1.15; }
.hud-right .bot-tag { text-align: right; }
.tag-model { font-size: 13px; letter-spacing: 3px; color: var(--dim); }
.tag-name { font-size: 34px; font-weight: 800; letter-spacing: 5px; }
.bot-tag.old .tag-name { color: var(--gold); }
.bot-tag.new .tag-name { color: var(--offwhite); }
.tag-role {
  font-size: 14px; letter-spacing: 2px; color: var(--offwhite);
  background: var(--brand); padding: 2px 8px; margin-top: 4px; align-self: flex-start;
}
.hud-right .tag-role { align-self: flex-end; }

.score {
  min-width: 110px;
  text-align: center;
  font-size: 76px;
  font-weight: 800;
  line-height: 1;
  padding: 4px 10px 6px;
  background: #080505;
  border: 2px solid #3a2a18;
  box-shadow: inset 0 0 18px rgba(105, 0, 0, 0.55);
  color: var(--offwhite);
  text-shadow: 0 0 14px rgba(232, 176, 74, 0.35);
  font-variant-numeric: tabular-nums;
}
.score.bump { animation: bump 0.45s ease-out; }
@keyframes bump { 0% { transform: scale(1.35); color: var(--gold); } 100% { transform: scale(1); } }

.hud-center { text-align: center; padding: 0 20px; }
.hud-title { font-size: 30px; font-weight: 800; letter-spacing: 12px; color: var(--offwhite); text-shadow: 3px 3px 0 var(--brand); }
.hud-sub { font-size: 12px; letter-spacing: 4px; color: var(--dim); margin-top: 2px; }
.hud-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.hud-btn {
  font: 700 15px var(--mono);
  letter-spacing: 2px;
  color: var(--offwhite);
  background: #1c1312;
  border: 2px solid var(--bronze);
  padding: 5px 14px;
  min-width: 64px;
  cursor: pointer;
}
.hud-btn:hover, .hud-btn:focus-visible { background: var(--brand); outline: none; }
.hud-btn.off { color: var(--dim); border-color: #4a3418; }

/* ---------------- stage frame ---------------- */
#stageFrame {
  position: relative;
  padding: 18px;
  background:
    repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.25) 0 6px, transparent 6px 12px),
    linear-gradient(180deg, #7a5a2a, #3e2b14 55%, #5e4320);
  border: 2px solid #1b120a;
  box-shadow: inset 0 0 0 2px rgba(232, 176, 74, 0.25), inset 0 0 22px rgba(0, 0, 0, 0.7);
}
.rivet {
  position: absolute; width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f0d08a, #6b4c1f 70%);
  box-shadow: 0 1px 1px #000;
}
.r1 { left: 4px; top: 4px; } .r2 { right: 4px; top: 4px; } .r3 { left: 4px; bottom: 4px; } .r4 { right: 4px; bottom: 4px; }

#stage {
  position: relative;
  width: 1200px;
  height: 675px;
  overflow: hidden;
  background: #070505;
  box-shadow: 0 0 0 3px #000, 0 0 0 5px var(--brand);
}
#stage.jolt { animation: jolt 0.28s linear; }
@keyframes jolt {
  0% { transform: translate(0, 0); } 20% { transform: translate(-4px, 2px); }
  40% { transform: translate(3px, -2px); } 60% { transform: translate(-2px, 1px); }
  80% { transform: translate(1px, 0); } 100% { transform: translate(0, 0); }
}

#arena { position: absolute; left: 0; top: 0; width: 1200px; height: 675px; display: block; }

/* ---------------- bots (DOM/SVG) ---------------- */
#botLayer { position: absolute; inset: 0; pointer-events: none; }
.bot { position: absolute; left: 0; top: 0; width: 145.6px; height: 182px; }
.bot-anim { width: 100%; height: 100%; transform-origin: 50% 90%; }
.bot svg { display: block; overflow: visible; }

.bot-old .bot-anim { filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.45)); }
.bot-new .bot-anim { filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.45)); }

.bot-anim.hurt { animation: hurt 0.45s ease-out; }
@keyframes hurt { 0% { transform: translateX(0); } 25% { transform: translateX(-5px) rotate(-3deg); } 50% { transform: translateX(4px) rotate(2deg); } 100% { transform: none; } }
.bot-anim.win { animation: win 0.55s ease-in-out infinite; }
@keyframes win { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px) rotate(2deg); } }
.bot-old .bot-anim.lose { animation: slumpOld 1.2s ease-out forwards; }
@keyframes slumpOld { 0% { transform: none; } 40% { transform: rotate(-12deg) translateY(4px); } 60% { transform: rotate(-7deg) translateY(2px); } 100% { transform: rotate(-10deg) translateY(6px); opacity: 0.8; } }
.bot-new .bot-anim.lose { animation: flickerOff 1.4s steps(1) forwards; }
@keyframes flickerOff { 0% { opacity: 1; } 15% { opacity: 0.3; } 25% { opacity: 1; } 40% { opacity: 0.4; } 55% { opacity: 0.9; } 70% { opacity: 0.5; } 100% { opacity: 0.62; transform: translateY(5px); } }

.p-smoke { opacity: 0; transform-box: fill-box; transform-origin: 50% 100%; }
.p-smoke.puff { animation: puff 1.3s ease-out forwards; }
.p-smoke.puff.loop { animation: puff 1.6s ease-out infinite; }
@keyframes puff { 0% { opacity: 0.7; transform: translateY(6px) scale(0.6); } 100% { opacity: 0; transform: translateY(-16px) scale(1.5); } }

.p-led { fill: #2a1010; }
.p-led.on { fill: #ff4a3a; }
.p-led.dead { fill: #0d0d0d; }

/* ---------------- CRT overlays (CSS only) ---------------- */
.crt { position: absolute; inset: 0; pointer-events: none; }
.crt-scan {
  background: repeating-linear-gradient(180deg, rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, 0.16) 2px 3px);
}
.crt-vignette {
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.5) 100%);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6), inset 0 0 3px rgba(232, 176, 74, 0.3);
}
.crt-flicker { background: rgba(255, 210, 160, 0.018); animation: flicker 5s steps(1) infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 31% { opacity: 0.4; } 32% { opacity: 1; } 67% { opacity: 0.7; } 68% { opacity: 1; } }

/* ---------------- banner ---------------- */
#banner {
  position: absolute; left: 0; right: 0; top: 34%;
  text-align: center; pointer-events: none;
  font-size: 34px; font-weight: 800; letter-spacing: 8px;
  color: var(--offwhite);
  text-shadow: 3px 3px 0 var(--brand), 0 0 18px rgba(232, 176, 74, 0.35);
  opacity: 0;
}
#banner.show { animation: bannerIn 1.1s ease-out forwards; }
@keyframes bannerIn { 0% { opacity: 0; transform: scaleY(0.2); } 12% { opacity: 1; transform: scaleY(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------- screens / panels ---------------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(5, 3, 3, 0.45);
}
.screen[data-active="1"] { display: flex; animation: screenIn 0.25s ease-out; }
@keyframes screenIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }

.panel {
  position: relative;
  background: rgba(14, 9, 8, 0.93);
  border: 2px solid var(--bronze);
  padding: 26px 44px 22px;
  text-align: center;
  clip-path: polygon(18px 0, calc(100% - 18px) 0, 100% 18px, 100% calc(100% - 18px), calc(100% - 18px) 100%, 18px 100%, 0 calc(100% - 18px), 0 18px);
  box-shadow: inset 0 0 0 5px rgba(105, 0, 0, 0.55), inset 0 0 40px rgba(0, 0, 0, 0.8);
}
.panel::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 8px;
  background: repeating-linear-gradient(135deg, var(--brand) 0 10px, #1a0505 10px 20px);
}
.panel.menu { width: 860px; padding-top: 30px; }
.panel.small { min-width: 520px; padding: 34px 60px 30px; }
.panel.controls { width: 900px; }

.brand-mark { font-size: 14px; letter-spacing: 10px; color: var(--bronze-hi); margin-bottom: 2px; }
.title {
  margin: 0;
  font-size: 88px; line-height: 1; font-weight: 900; letter-spacing: 10px;
  color: var(--offwhite);
  text-shadow: 4px 4px 0 var(--brand), 8px 8px 0 #1a0505;
}
.title span { color: var(--crimson-hi); text-shadow: 4px 4px 0 #2a0000, 8px 8px 0 #0d0202; }
.subtitle { margin: 10px 0 14px; font-size: 16px; letter-spacing: 5px; color: var(--gold); }
.hint { margin: 14px 0 0; font-size: 15px; letter-spacing: 3px; color: var(--dim); }
.panel-title { margin: 6px 0 10px; font-size: 48px; letter-spacing: 8px; color: var(--offwhite); text-shadow: 3px 3px 0 var(--brand); }
.blink-slow { animation: blinkSlow 1.4s steps(1) infinite; }
@keyframes blinkSlow { 50% { opacity: 0.45; } }

.boot-log { text-align: left; display: inline-block; font-size: 16px; line-height: 1.7; color: #c9b48c; margin: 8px 0 20px; }
.boot-log div:nth-child(3) { color: var(--crimson-hi); }

/* menu rows */
.menu-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.row {
  display: grid; grid-template-columns: 190px 1fr; align-items: center;
  padding: 6px 12px 6px 30px; position: relative;
  border: 1px solid transparent;
}
.row::before { content: ""; position: absolute; left: 8px; top: 50%; margin-top: -8px; border: 8px solid transparent; border-left-color: var(--gold); opacity: 0; }
.row.focus { background: rgba(105, 0, 0, 0.22); border-color: rgba(196, 154, 76, 0.35); }
.row.focus::before { opacity: 1; }
.row.disabled { opacity: 0.28; }
.row-label { text-align: left; font-size: 19px; letter-spacing: 3px; color: var(--dim); }
.opts { display: flex; gap: 10px; }
.opt {
  flex: 1;
  font: 700 21px var(--mono); letter-spacing: 2px;
  color: #bfae94; background: #1a1110;
  border: 2px solid #4a3418;
  padding: 9px 10px;
  cursor: pointer;
}
.opt:hover { border-color: var(--bronze-hi); color: var(--offwhite); }
.opt.sel { background: var(--brand); color: #fff1dc; border-color: var(--bronze-hi); box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35); }
.row.disabled .opt { cursor: default; }
.row-actions { grid-template-columns: 1fr 1.4fr; gap: 14px; padding-top: 12px; }
.row-actions::before { display: none; }
.row-actions.focus { background: none; border-color: transparent; }

.btn {
  font: 800 24px var(--mono); letter-spacing: 5px;
  color: var(--offwhite); background: #1a1110;
  border: 2px solid var(--bronze-hi);
  padding: 13px 28px;
  cursor: pointer;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.btn.primary { background: var(--brand); }
.btn.big { font-size: 30px; padding: 16px 54px; }
.btn:hover, .btn:focus-visible, .btn.focus { outline: none; background: #8a0a0a; color: #fff; box-shadow: inset 0 0 0 3px var(--gold); }
.btn:not(.primary):hover, .btn:not(.primary).focus, .btn:not(.primary):focus-visible { background: #3a1a12; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

.final-score { font-size: 72px; font-weight: 900; color: var(--gold); letter-spacing: 6px; }
.over-note { font-size: 15px; letter-spacing: 2px; color: var(--dim); max-width: 520px; margin: 8px auto 0; line-height: 1.5; }

/* controls */
.ctrl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin: 16px 0; text-align: left; }
.ctrl-col { background: #0b0707; border: 1px solid #3a2a18; padding: 14px 16px; }
.ctrl-head { font-size: 17px; letter-spacing: 3px; color: var(--dim); margin-bottom: 10px; border-bottom: 1px solid #3a2a18; padding-bottom: 6px; }
.ctrl-head.old { color: var(--gold); }
.ctrl-head.new { color: var(--offwhite); }
.keys { font-size: 18px; letter-spacing: 2px; margin: 8px 0; color: #d8cbb4; }
kbd {
  display: inline-block; min-width: 44px; text-align: center;
  font: 800 17px var(--mono);
  padding: 4px 8px; margin-right: 8px;
  color: var(--offwhite); background: #231816;
  border: 2px solid var(--bronze); border-bottom-width: 4px;
}
.ctrl-note { font-size: 15px; letter-spacing: 1.5px; color: var(--dim); line-height: 1.6; margin: 6px 0 16px; }

/* ---------------- diagnostics footer ---------------- */
#diag {
  display: grid;
  grid-template-columns: 18px 1fr auto 1fr 18px;
  align-items: center; gap: 12px;
  height: 44px; margin-top: 8px; padding: 0 12px;
  font-size: 14px; letter-spacing: 1px;
  background: #080505;
  border: 1px solid #3a2a18;
  color: #b89a6a;
  white-space: nowrap; overflow: hidden;
}
.diag-text { overflow: hidden; text-overflow: ellipsis; }
.diag-text.right { text-align: right; }
.diag-mid { color: var(--offwhite); padding: 2px 12px; border-left: 1px solid #3a2a18; border-right: 1px solid #3a2a18; }
.lamp { width: 14px; height: 14px; border-radius: 50%; background: #2a3a1a; box-shadow: inset 0 0 3px #000, 0 0 6px rgba(120, 180, 60, 0.35); }
.lamp.warn { background: var(--crimson-hi); box-shadow: inset 0 0 3px #000, 0 0 10px rgba(216, 50, 47, 0.8); animation: blinkSlow 0.5s steps(1) infinite; }
.maker { text-align: right; font-size: 12px; letter-spacing: 4px; color: #6b4c3a; padding: 5px 4px 0; }

/* ---------------- mobile helpers ---------------- */
#rotateHint {
  display: none;
  position: fixed; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom));
  text-align: center; font-size: 12px; letter-spacing: 2px; color: var(--dim);
  pointer-events: none; padding: 0 16px;
}
@media (pointer: coarse) {
  body.portrait #rotateHint { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .crt-flicker, #stage.jolt, .bot-anim.win, .lamp.warn, .blink-slow { animation: none !important; }
}
