:root {
  --hud-amber: #d8af72;
  --hud-cyan: #6ec4b8;
  --hud-red: #e05846;
  --hud-bg: rgba(10, 9, 8, 0.48);
  --hud-border: rgba(216, 175, 114, 0.48);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b0a09;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  color: var(--hud-amber);
  touch-action: none;
}

#webgl-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  touch-action: none;
}

#webgl-container::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  backdrop-filter: blur(1.6px);
  -webkit-backdrop-filter: blur(1.6px);
  mask-image: radial-gradient(ellipse at 50% 50%, transparent 64%, rgba(0, 0, 0, 0.85) 96%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 50%, transparent 64%, rgba(0, 0, 0, 0.85) 96%);
}

#webgl-container::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(
    ellipse at 50% 48%,
    rgba(0, 0, 0, 0) 52%,
    rgba(6, 5, 4, 0.36) 82%,
    rgba(4, 3, 3, 0.72) 100%
  );
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

body.hud-hidden #top-bar,
body.hud-hidden #hud-overlay,
body.hud-hidden #compact-telemetry,
body.hud-hidden #intro-prompt,
body.hud-hidden #btn-kb-big,
body.hud-hidden #print-save-panel {
  opacity: 0 !important;
  pointer-events: none !important;
}

#top-bar,
#hud-overlay,
#compact-telemetry,
#btn-kb-big {
  transition: opacity 0.25s ease;
}

#hud-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 3;
  pointer-events: none;
  shape-rendering: geometricPrecision;
}

.hud-box {
  fill: var(--hud-bg);
  stroke: var(--hud-border);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  transition: stroke 0.16s ease, fill 0.16s ease;
}

.hud-box.bell-flash {
  stroke: var(--hud-red);
  stroke-width: 1.8px;
  fill: rgba(82, 20, 14, 0.65);
}

.hud-title {
  fill: rgba(216, 175, 114, 0.75);
  font-size: 8px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
}

.hud-value {
  fill: #f4ece0;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.7px;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
}

.hud-sub {
  fill: var(--hud-cyan);
  font-size: 8.5px;
  letter-spacing: 1.0px;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
}

.leader-line {
  fill: none;
  stroke: rgba(216, 175, 114, 0.21);
  stroke-width: 1px;
  stroke-dasharray: 3 2;
}

.leader-dot {
  fill: #f0d098;
  stroke: #d8af72;
  stroke-width: 1.2px;
}

.corner-tick {
  fill: none;
  stroke: rgba(216, 175, 114, 0.50);
  stroke-width: 1.2px;
}

#compact-telemetry {
  position: fixed;
  bottom: 8px;
  left: 8px;
  right: 8px;
  z-index: 4;
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(10, 9, 8, 0.84);
  border: 1px solid var(--hud-border);
  font-size: 9.5px;
  letter-spacing: 0.5px;
  color: #f4ece0;
  pointer-events: auto;
  white-space: nowrap;
  overflow: hidden;
}

.compact-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.mobile-kb-cta {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 5;
  display: none;
  background: rgba(14, 12, 10, 0.86);
  border: 1px solid rgba(216, 175, 114, 0.65);
  color: #f4e6d0;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 10px;
  letter-spacing: 1.4px;
  padding: 8px 12px;
  cursor: pointer;
  text-transform: uppercase;
  pointer-events: auto;
}

/* PRINT / SAVE Export Modal Panel */
.export-panel {
  position: fixed;
  top: 52px;
  right: 14px;
  width: min(320px, calc(100vw - 24px));
  background: rgba(14, 12, 10, 0.94);
  border: 1px solid rgba(216, 175, 114, 0.68);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.75);
  z-index: 10;
  padding: 12px;
  pointer-events: auto;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.export-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

.export-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10.5px;
  font-weight: bold;
  letter-spacing: 1.6px;
  color: #f4ece0;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(216, 175, 114, 0.28);
}

.export-close-btn {
  background: transparent;
  border: 1px solid rgba(216, 175, 114, 0.4);
  color: #e8d2b0;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.export-panel-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.export-action-btn {
  min-height: 44px;
  width: 100%;
  background: rgba(216, 175, 114, 0.12);
  border: 1px solid rgba(216, 175, 114, 0.55);
  color: #fff6e8;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.export-action-btn:hover,
.export-action-btn:active {
  background: rgba(216, 175, 114, 0.26);
  border-color: #fff6e8;
}

#intro-prompt {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 4;
  pointer-events: none;
  text-align: center;
  transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1), transform 0.55s ease;
}

#intro-prompt.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

.prompt-pill {
  display: inline-block;
  padding: 5px 14px;
  background: rgba(12, 11, 10, 0.84);
  border: 1px solid rgba(216, 175, 114, 0.58);
  color: #f4e6d0;
  font-size: 10px;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  box-shadow: 0 0 14px rgba(216, 175, 114, 0.12);
  animation: pulseGlow 2.4s infinite ease-in-out;
  white-space: nowrap;
}

.prompt-sub {
  margin-top: 3px;
  font-size: 8px;
  letter-spacing: 1.1px;
  color: rgba(216, 175, 114, 0.68);
  white-space: nowrap;
}

@keyframes pulseGlow {
  0%, 100% {
    border-color: rgba(216, 175, 114, 0.36);
    box-shadow: 0 0 8px rgba(216, 175, 114, 0.08);
  }
  50% {
    border-color: rgba(216, 175, 114, 0.85);
    box-shadow: 0 0 18px rgba(216, 175, 114, 0.22);
  }
}

#mobile-input {
  position: fixed;
  top: -100px;
  left: -100px;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: none;
  outline: none;
  pointer-events: none;
}

#top-bar {
  position: fixed;
  top: 10px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex-shrink: 1;
}

.brand-name {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 2.2px;
  color: #e8d2b0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-meta {
  font-size: 8.5px;
  letter-spacing: 1.3px;
  color: rgba(216, 175, 114, 0.58);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-controls {
  display: flex;
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 5px;
  pointer-events: auto;
}

.hud-btn {
  background: rgba(12, 11, 10, 0.76);
  border: 1px solid rgba(216, 175, 114, 0.48);
  color: #e8d2b0;
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 9px;
  letter-spacing: 1.0px;
  padding: 5px 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.hud-btn:hover {
  border-color: #e8d2b0;
  background: rgba(216, 175, 114, 0.16);
}

.hud-btn.active {
  border-color: var(--hud-cyan);
  color: var(--hud-cyan);
}

.hud-btn.warn {
  border-color: var(--hud-red);
  color: var(--hud-red);
}

@media (max-width: 820px), (max-height: 560px) {
  #top-bar {
    display: none;
  }
  #hud-cards-group, #hud-leaders {
    display: none;
  }
  #compact-telemetry {
    display: flex;
  }
  .mobile-kb-cta {
    display: inline-block;
  }
  #print-save-panel {
    top: auto;
    bottom: 54px;
    left: 12px;
    right: 12px;
    width: auto;
  }
  #intro-prompt {
    bottom: 48px;
  }
  .prompt-sub {
    display: none;
  }
}


/* Big thumb-sized OPEN KEYBOARD button (owner request): full width, fixed above the bottom bar on touch / small screens */
#btn-kb-big.mobile-kb-cta { display: none; }
@media (max-width: 820px), (pointer: coarse) {
  #btn-kb-big.mobile-kb-cta {
    display: block;
    position: fixed;
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 76px;
    width: auto;
    height: 56px;
    z-index: 40;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.18em;
    color: #1b1610;
    background: #d8af72;
    border: 1px solid #f0cf94;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45);
    pointer-events: auto;
    touch-action: manipulation;
  }
  #btn-kb-big.mobile-kb-cta:active { background: #c29a5e; }
}

/* Quiet mobile chrome: no hint strip, no readout, no big CTA; small icon row only */
@media (max-width: 820px), (pointer: coarse) {
  #btn-kb-big.mobile-kb-cta, #intro-prompt { display: none !important; }
  #compact-col, #compact-line, #compact-key, #compact-bell { display: none; }
  #compact-telemetry {
    left: auto; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 0; background: transparent; border: 0; overflow: visible;
  }
  .compact-actions { gap: 8px; }
  .compact-actions .hud-btn {
    width: 40px; height: 40px; padding: 0; font-size: 18px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 9, 8, 0.45); color: rgba(244, 236, 224, 0.8);
    border: 1px solid rgba(244, 236, 224, 0.25); border-radius: 50%;
  }
  #print-save-panel { bottom: 60px; }
}
body.kb-up #hud-overlay, body.kb-up #compact-telemetry { display: none !important; }

/* Print / Save: centered modal with sheet preview */
#print-save-panel {
  top: 50%; left: 50%; right: auto; bottom: auto;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  z-index: 30;
}
#print-save-panel.hidden { transform: translate(-50%, -46%); }
.export-preview-wrap {
  display: flex; justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px; margin-bottom: 10px;
}
#export-preview {
  display: block;
  max-width: 100%;
  max-height: min(52vh, 520px);
  width: auto; height: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
}
.export-panel-body { flex-direction: row; flex-wrap: wrap; }
.export-panel-body .export-action-btn { flex: 1 1 120px; width: auto; }
@media (max-width: 760px) {
  #print-save-panel { top: 50%; bottom: auto; left: 50%; right: auto; width: calc(100vw - 24px); }
}

/* Print / Save: larger modal with dark overlay, two buttons */
#export-backdrop {
  position: fixed; inset: 0; z-index: 29;
  background: rgba(4, 3, 2, 0.78);
  transition: opacity 0.2s ease;
}
#export-backdrop.hidden { opacity: 0; pointer-events: none; }
#print-save-panel {
  width: min(820px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  z-index: 31;
  padding: 16px;
}
#export-preview { max-height: min(70vh, 820px); }
.export-panel-body .export-action-btn { flex: 1 1 200px; }
@media (max-width: 760px) {
  #print-save-panel { width: calc(100vw - 16px); padding: 12px; }
  #export-preview { max-height: 62vh; }
}
#export-preview { max-height: min(calc(100vh - 230px), 820px); }
@media (max-width: 760px) {
  #export-preview { max-height: min(calc(100vh - 250px), 62vh); }
}

/* Mobile sound toggle, top right */
#btn-mute-m { display: none; }
@media (max-width: 820px), (pointer: coarse) {
  #btn-mute-m {
    position: fixed; top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px; z-index: 6;
    width: 40px; height: 40px; padding: 0; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 9, 8, 0.45); color: rgba(244, 236, 224, 0.8);
    border: 1px solid rgba(244, 236, 224, 0.25); border-radius: 50%;
    pointer-events: auto; touch-action: manipulation;
  }
  #btn-mute-m.muted .snd-waves { display: none; }
  #btn-mute-m.muted .snd-off { display: inline !important; }
}
