*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brass-bright: #eec779;
  --brass-mid: #b4853b;
  --amber-glow: #ffb83f;
  --led-red: #ff5b36;
  --led-amber: #ffbe42;
  --cream: #f8e7c2;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0604;
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

.mobile-only {
  display: none;
}

.mobile-controls-hint {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(10, 5, 2, 0.62);
  border: 1px solid rgba(204, 152, 74, 0.34);
  font-size: 12.5px;
  line-height: 1.4;
  color: rgba(248, 231, 194, 0.88);
}

#scene-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  z-index: 0;
  touch-action: none;
}

/* --- Compact Top Floating Scoreboard Pill --- */
.hud-top-bar {
  position: fixed;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(12, 6, 3, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(206, 154, 76, 0.38);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 228, 174, 0.12);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}

.hud-lbl {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: rgba(236, 198, 134, 0.66);
}

.hud-val {
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--led-red);
  text-shadow: 0 0 8px rgba(255, 90, 48, 0.68);
  font-variant-numeric: tabular-nums;
}

.hud-val small {
  font-size: 0.7em;
  opacity: 0.65;
}

.hud-amber {
  color: var(--led-amber);
  text-shadow: 0 0 8px rgba(255, 190, 66, 0.68);
}

.hud-balls {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 17px;
}

.steel-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #ffffff 0%, #c8cfd6 38%, #5b554e 78%, #1e1812 100%);
  box-shadow: 0 0 5px rgba(255, 224, 165, 0.42);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.steel-pip.is-spent {
  opacity: 0.16;
  transform: scale(0.75);
  box-shadow: none;
}

/* --- Translucent Title / Game Over / Victory Overlay --- */
.cabinet-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  z-index: 6;
  background: radial-gradient(circle at 50% 50%, rgba(16, 8, 4, 0.14), rgba(8, 4, 2, 0.58));
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.cabinet-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  width: 100%;
  max-width: 375px;
  padding: 22px 20px 18px;
  text-align: center;
  border-radius: 14px;
  background: linear-gradient(165deg, rgba(46, 23, 11, 0.9) 0%, rgba(18, 8, 4, 0.94) 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid rgba(226, 174, 88, 0.65);
  box-shadow:
    0 24px 54px rgba(0, 0, 0, 0.85),
    0 0 42px rgba(255, 168, 48, 0.16),
    inset 0 1px 0 rgba(255, 232, 178, 0.24);
}

.overlay-kicker {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.24em;
  color: var(--amber-glow);
}

.overlay-title {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(24px, 3.2vw, 31px);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff3d2;
  text-shadow: 0 0 16px rgba(255, 180, 56, 0.55), 0 2px 4px rgba(0, 0, 0, 0.85);
}

.overlay-message {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.48;
  color: rgba(248, 231, 194, 0.88);
}

.overlay-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.control-badge {
  padding: 8px 6px;
  border-radius: 8px;
  background: rgba(10, 5, 2, 0.65);
  border: 1px solid rgba(204, 152, 74, 0.36);
}

.control-side {
  display: block;
  margin-bottom: 5px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--brass-bright);
}

.key-pair {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 10.5px;
  color: rgba(248, 231, 194, 0.82);
}

.preset-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.preset-pill {
  padding: 6px 4px;
  border-radius: 6px;
  border: 1px solid rgba(204, 152, 74, 0.36);
  background: rgba(12, 6, 3, 0.62);
  color: rgba(242, 214, 162, 0.74);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.14s ease, color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
}

.preset-pill:hover {
  border-color: rgba(235, 182, 88, 0.72);
  color: #fff3d2;
}

.preset-pill.is-selected {
  background: linear-gradient(180deg, rgba(233, 163, 54, 0.3) 0%, rgba(154, 86, 16, 0.34) 100%);
  border-color: #ffcf6d;
  color: #fff5d6;
  box-shadow: 0 0 10px rgba(255, 184, 63, 0.28);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
  color: #241004;
  background: linear-gradient(180deg, #fae3b0 0%, #d4a353 100%);
  border: 1px solid #fff2cc;
  box-shadow: 0 2px 0 #5b3810, 0 3px 6px rgba(0, 0, 0, 0.45);
}

.coin-start-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  padding: 10px 16px;
  border: 1.5px solid #ffe4a1;
  border-radius: 8px;
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #231003;
  background: linear-gradient(180deg, #ffd87a 0%, #e49724 55%, #b8670e 100%);
  box-shadow:
    0 0 22px rgba(255, 174, 48, 0.48),
    0 4px 0 #5e3104,
    0 8px 20px rgba(0, 0, 0, 0.6);
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-sub-hint {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(35, 16, 3, 0.78);
}

.coin-start-btn:hover {
  filter: brightness(1.08);
}

.coin-start-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 14px rgba(255, 174, 48, 0.45), 0 2px 0 #5e3104;
}

.overlay-hint {
  margin: 11px 0 0;
  font-size: 11px;
  color: rgba(242, 214, 162, 0.72);
}

.overlay-hint kbd {
  min-width: 18px;
  height: 18px;
  font-size: 10px;
}

/* --- Sleek Ultra-Compact Floating Brass Control Dock at Bottom --- */
.hud-bottom-dock {
  position: fixed;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 12px);
  padding: 5px 10px;
  border-radius: 11px;
  background: rgba(12, 6, 3, 0.74);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(206, 154, 76, 0.4);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.78), inset 0 1px 0 rgba(255, 228, 174, 0.12);
}

.dock-levers {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
}

.dock-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.key-cap {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 44px;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid rgba(212, 163, 83, 0.55);
  background: linear-gradient(180deg, #3c2212 0%, #221107 100%);
  color: var(--cream);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease, background 0.08s ease, box-shadow 0.08s ease;
}

.key-cap kbd {
  min-width: 16px;
  height: 16px;
  font-size: 10px;
  box-shadow: 0 1px 0 #5b3810;
}

.key-cap .arrow {
  font-size: 8.5px;
  color: var(--amber-glow);
}

.key-cap.is-active,
.key-cap:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, #6e3d18 0%, #44220a 100%);
  border-color: #ffcf6d;
  box-shadow: 0 0 10px rgba(255, 184, 63, 0.55);
}

.brass-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid rgba(188, 138, 66, 0.5);
  background: linear-gradient(180deg, #2e180c 0%, #190c05 100%);
  color: rgba(242, 214, 162, 0.72);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.07em;
  cursor: pointer;
  white-space: nowrap;
}

.brass-toggle:hover {
  border-color: var(--brass-bright);
  color: #fff3d2;
}

.pilot-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3a2314;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8);
}

.brass-toggle.is-on {
  color: #fff2ce;
  border-color: rgba(235, 182, 88, 0.76);
}

.brass-toggle.is-on .pilot-led {
  background: #ffbf45;
  box-shadow: 0 0 8px #ffb42e, 0 0 2px #fff6d2;
}

.ambience-slider {
  display: inline-flex;
  align-items: center;
}

.ambience-slider input[type="range"] {
  width: 56px;
  accent-color: #e9a336;
  cursor: pointer;
}

.mini-brass-btn {
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid rgba(202, 152, 74, 0.55);
  background: linear-gradient(180deg, #4b2912 0%, #281307 100%);
  color: #f6ddb0;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.07em;
  cursor: pointer;
  white-space: nowrap;
}

.mini-brass-btn:hover {
  filter: brightness(1.16);
  border-color: var(--brass-bright);
}

/* --- Orbit Hint Pill --- */
.orbit-hint {
  position: fixed;
  bottom: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(14, 7, 4, 0.78);
  border: 1px solid rgba(214, 162, 82, 0.45);
  font-size: 11px;
  color: rgba(248, 231, 194, 0.88);
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.orbit-hint.is-hidden {
  opacity: 0;
}

.orbit-hint kbd {
  min-width: 17px;
  height: 17px;
  font-size: 10px;
}

/* --- Native HTML Help Dialog --- */
.pub-dialog {
  padding: 0;
  border: 1.5px solid rgba(226, 174, 88, 0.7);
  border-radius: 12px;
  background: linear-gradient(165deg, #3a1e0e 0%, #1a0c05 100%);
  color: var(--cream);
  max-width: 440px;
  width: calc(100vw - 32px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.9);
}

.pub-dialog::backdrop {
  background: rgba(6, 3, 1, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-inner {
  padding: 18px 20px 20px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(214, 162, 82, 0.28);
}

.dialog-header h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  letter-spacing: 0.1em;
  color: var(--brass-bright);
}

.dialog-close {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(214, 162, 82, 0.4);
  background: rgba(20, 9, 4, 0.6);
  color: var(--cream);
  cursor: pointer;
}

.dialog-body {
  font-size: 13.5px;
  line-height: 1.55;
  color: rgba(248, 231, 194, 0.9);
}

.dialog-body ul {
  padding-left: 18px;
  margin: 10px 0 12px;
}

.dialog-body li {
  margin-bottom: 6px;
}

.tip-box {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 184, 63, 0.1);
  border: 1px solid rgba(255, 184, 63, 0.32);
  font-size: 12.5px;
}

@media (hover: none) and (pointer: coarse), (max-width: 780px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block;
  }

  .hud-top-bar {
    top: max(6px, env(safe-area-inset-top));
  }

  .hud-pill {
    gap: 10px;
    padding: 5px 12px;
  }

  .hud-val {
    font-size: 13px;
  }

  /* Edge-anchored ergonomic thumb-pad dock for mobile play */
  .hud-bottom-dock {
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    justify-content: space-between;
    align-items: flex-end;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
    border-radius: 0;
    background: linear-gradient(180deg, rgba(10, 5, 2, 0) 0%, rgba(10, 5, 2, 0.72) 55%, rgba(10, 5, 2, 0.9) 100%);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    pointer-events: none;
  }

  .dock-levers,
  .dock-center {
    pointer-events: auto;
  }

  .dock-levers {
    gap: 8px;
  }

  .key-cap {
    min-width: 78px;
    height: 58px;
    padding: 0;
    justify-content: center;
    border-radius: 14px;
    border: 1.5px solid rgba(232, 180, 92, 0.72);
    background: linear-gradient(180deg, rgba(72, 38, 18, 0.92) 0%, rgba(30, 14, 6, 0.95) 100%);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 232, 180, 0.22);
  }

  /* Hide keyboard letter badges on mobile — show large clear thumb arrows only */
  .key-cap kbd {
    display: none;
  }

  .key-cap .arrow {
    font-size: 24px;
    line-height: 1;
    color: #ffd37a;
    text-shadow: 0 0 10px rgba(255, 184, 63, 0.45);
  }

  .dock-center {
    padding: 6px 8px;
    margin-bottom: 4px;
    border-radius: 10px;
    background: rgba(14, 7, 4, 0.78);
    border: 1px solid rgba(206, 154, 76, 0.36);
    gap: 6px;
  }

  .brass-toggle,
  .mini-brass-btn {
    padding: 7px 10px;
    font-size: 10.5px;
  }
}
