:root {
  --bg-blueprint: #061325;
  --bg-panel: rgba(10, 29, 56, 0.88);
  --grid-line: rgba(79, 172, 254, 0.12);
  --line-cyan: #00f2fe;
  --line-bright: #64d2ff;
  --text-white: #e8f4fc;
  --text-dim: #7da5c9;
  --accent-warn: #ffb703;
  --accent-alert: #ff4757;
  --accent-success: #00e676;
  --border-cyan: rgba(0, 242, 254, 0.4);
  --font-mono: 'Share Tech Mono', monospace;
  --font-display: 'Rajdhani', sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-blueprint);
  font-family: var(--font-mono);
  color: var(--text-white);
}

#app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-blueprint);
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  z-index: 1;
}

/* UNIFIED COMPACT TOP TELEMETRY & DIRECTIVES HEADER */
#hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 175px; /* Clear margin for right-top buttons */
  z-index: 10;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
  padding: 6px 14px;
  background: linear-gradient(180deg, rgba(6, 19, 37, 0.88) 0%, rgba(6, 19, 37, 0.35) 80%, transparent 100%);
  border-bottom: 1px solid rgba(0, 242, 254, 0.15);
  pointer-events: none;
}

#hud-top > * {
  pointer-events: auto;
}

.hud-left-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.hud-block {
  display: flex;
  flex-direction: column;
}

.title-block {
  min-width: 155px;
}

.hud-label {
  font-size: 8px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.hud-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-white);
  letter-spacing: 0.5px;
}

.hud-val.highlight {
  color: var(--line-cyan);
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 1px;
}

.telemetry-cell {
  border-left: 1px solid rgba(0, 242, 254, 0.2);
  padding-left: 12px;
}

/* BORDERLESS CLEAN TEXT DIRECTIVES IN HEADER (User Marked Position) */
.hud-directives-strip {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border-left: 1px solid rgba(0, 242, 254, 0.25);
  padding-left: 14px;
  overflow: hidden;
  flex-grow: 1;
}

.directive-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.directive-label {
  font-size: 7.5px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  flex-shrink: 0;
}

.directive-val {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-line .directive-val {
  color: var(--line-cyan);
}

.guidance-line .directive-val {
  color: var(--accent-warn);
  font-weight: 500;
}

/* TOP-RIGHT BUTTONS DOCK (No lower boxes - 100% open field) */
#hud-right-panel {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 160px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

#hud-right-panel > * {
  pointer-events: auto;
}

.action-btn-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(6, 19, 37, 0.85);
  border: 1px solid rgba(0, 242, 254, 0.25);
  border-radius: 3px;
  padding: 5px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.action-btn-group .blueprint-btn {
  width: 100%;
  padding: 6px 8px;
  font-size: 10px;
  justify-content: center;
}

.blink {
  animation: cadPulse 2s infinite ease-in-out;
}

@keyframes cadPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* BLUEPRINT BUTTONS */
.blueprint-btn {
  background: rgba(10, 29, 56, 0.75);
  border: 1px solid var(--border-cyan);
  color: var(--line-bright);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s ease-in-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.blueprint-btn:hover {
  background: rgba(0, 242, 254, 0.2);
  border-color: var(--line-cyan);
  color: #fff;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.3);
}

.blueprint-btn:active {
  transform: scale(0.97);
  background: rgba(0, 242, 254, 0.35);
}

.blueprint-btn.primary {
  background: rgba(0, 242, 254, 0.2);
  border-color: var(--line-cyan);
  color: #fff;
  font-weight: bold;
}

.blueprint-btn.primary:hover {
  background: rgba(0, 242, 254, 0.4);
  box-shadow: 0 0 14px rgba(0, 242, 254, 0.5);
}

.blueprint-btn.icon-btn {
  min-width: 65px;
  padding: 6px 8px;
}

.blueprint-btn.close-x {
  padding: 2px 8px;
  font-size: 16px;
  line-height: 1;
}

/* BLUEPRINT MODALS */
.blueprint-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(4, 11, 22, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.blueprint-modal.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.modal-card {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-cyan);
  box-shadow: 0 0 30px rgba(0, 242, 254, 0.15), inset 0 0 20px rgba(0, 242, 254, 0.05);
  padding: 28px 24px;
  max-width: 440px;
  width: 100%;
  color: var(--text-white);
  border-radius: 4px;
}

.modal-card.wide {
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-card.failure {
  border-color: rgba(255, 71, 87, 0.6);
  box-shadow: 0 0 30px rgba(255, 71, 87, 0.2);
}

/* CAD Corner marks */
.blueprint-corner {
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--line-cyan);
  border-style: solid;
  pointer-events: none;
}

.modal-card.failure .blueprint-corner {
  border-color: var(--accent-alert);
}

.blueprint-corner.tl { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.blueprint-corner.tr { top: -1px; right: -1px; border-width: 2px 2px 0 0; }
.blueprint-corner.bl { bottom: -1px; left: -1px; border-width: 0 0 2px 2px; }
.blueprint-corner.br { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.cad-badge {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 2px;
  padding: 2px 6px;
  background: rgba(0, 242, 254, 0.15);
  color: var(--line-bright);
  border: 1px solid rgba(0, 242, 254, 0.3);
  margin-bottom: 8px;
  border-radius: 2px;
}

.cad-badge.alert {
  background: rgba(255, 71, 87, 0.15);
  color: var(--accent-alert);
  border-color: rgba(255, 71, 87, 0.4);
}

.modal-header {
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(0, 242, 254, 0.2);
  padding-bottom: 10px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.modal-card.wide .modal-header {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 1.5px;
  color: #fff;
  text-transform: uppercase;
}

.modal-body {
  margin-bottom: 24px;
}

.modal-body p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  background: rgba(6, 19, 37, 0.7);
  padding: 12px;
  border: 1px dashed rgba(0, 242, 254, 0.3);
  border-radius: 2px;
}

.grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.grid-item .label {
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.grid-item .val {
  font-size: 14px;
  font-weight: bold;
  color: var(--text-white);
}

.grid-item .val.rating {
  color: var(--accent-warn);
  font-size: 16px;
  letter-spacing: 2px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* LEVELS SELECTION GRID */
.levels-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 6px;
}

.sector-heading {
  grid-column: 1 / -1;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--line-cyan);
  background: rgba(0, 242, 254, 0.08);
  border-left: 3px solid var(--line-cyan);
  padding: 6px 10px;
  margin-top: 8px;
  text-transform: uppercase;
}

.level-chip {
  background: rgba(6, 19, 37, 0.75);
  border: 1px solid rgba(0, 242, 254, 0.25);
  padding: 10px;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.15s ease;
  position: relative;
}

.level-chip:hover {
  background: rgba(0, 242, 254, 0.15);
  border-color: var(--line-cyan);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.25);
}

.level-chip.active {
  border-color: var(--line-cyan);
  background: rgba(0, 242, 254, 0.25);
}

.level-chip.locked {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: rgba(255, 255, 255, 0.1);
}

.level-num {
  font-size: 9px;
  color: var(--line-cyan);
  letter-spacing: 1px;
}

.level-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.sector-heading {
  grid-column: 1 / -1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--line-cyan);
  letter-spacing: 2px;
  padding: 8px 4px 4px 4px;
  border-bottom: 1px solid rgba(0, 242, 254, 0.3);
  margin-top: 10px;
  text-transform: uppercase;
}

.sector-heading.master-sector {
  color: #ffb703;
  border-bottom-color: rgba(255, 183, 3, 0.4);
}

.level-chip.master-chip {
  border-color: rgba(255, 183, 3, 0.4);
}

.level-chip.master-chip:hover:not(.locked) {
  border-color: #ffb703;
  box-shadow: 0 0 14px rgba(255, 183, 3, 0.3);
}

.level-stars {
  font-size: 11px;
  color: var(--accent-warn);
  margin-top: 2px;
}

/* MOBILE & LANDSCAPE RESPONSIVE OPTIMIZATIONS */
@media (max-width: 900px) {
  #hud-top {
    right: 145px;
    padding: 3px 8px;
    gap: 8px;
  }
  .hud-left-group {
    gap: 8px;
  }
  .title-block {
    min-width: 120px;
  }
  .hud-label {
    font-size: 7px;
  }
  .hud-val {
    font-size: 10.5px;
  }
  .hud-val.highlight {
    font-size: 11.5px;
  }
  .telemetry-cell {
    padding-left: 6px;
  }

  .hud-directives-strip {
    padding-left: 8px;
    gap: 1px;
  }
  .directive-label {
    font-size: 6.5px;
  }
  .directive-val {
    font-size: 8.5px;
  }

  #hud-right-panel {
    width: 135px;
    top: 3px;
    right: 5px;
  }
  .action-btn-group {
    padding: 3px;
    gap: 3px;
  }
  .action-btn-group .blueprint-btn {
    padding: 4px 6px;
    font-size: 8.5px;
  }

  .modal-card {
    padding: 14px 12px;
  }
  .modal-header h2 {
    font-size: 17px;
  }
  .telemetry-grid {
    gap: 6px;
    padding: 8px;
  }
  .levels-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-height: 480px) {
  /* Extra compact for ultrawide / 19:9 / 20:9 phone landscape screens */
  #hud-top {
    right: 135px;
    padding: 2px 6px;
    gap: 6px;
  }
  .hud-left-group {
    gap: 6px;
  }
  .title-block {
    min-width: 105px;
  }
  .hud-directives-strip {
    padding-left: 6px;
  }
  .directive-val {
    font-size: 8px;
  }

  #hud-right-panel {
    width: 125px;
    top: 2px;
    right: 4px;
  }
  .action-btn-group {
    padding: 2px;
    gap: 2px;
  }
  .action-btn-group .blueprint-btn {
    padding: 3px 5px;
    font-size: 8px;
  }
}

/* PORTRAIT ROTATE DEVICE MODAL */
.orientation-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(6, 19, 37, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 24px;
}

.orientation-content {
  max-width: 380px;
  text-align: center;
  background: rgba(10, 29, 56, 0.9);
  border: 1px solid var(--line-cyan);
  box-shadow: 0 0 24px rgba(0, 242, 254, 0.25);
  padding: 28px 20px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.rotate-device-icon {
  font-size: 42px;
  animation: rotateDevice 2.4s ease-in-out infinite;
  display: inline-block;
  margin-bottom: 4px;
}

@keyframes rotateDevice {
  0% { transform: rotate(0deg); }
  35% { transform: rotate(-90deg); }
  70% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

.orientation-content h3 {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--line-cyan);
  text-transform: uppercase;
}

.orientation-content p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Auto-show rotate modal on mobile portrait via CSS media query */
@media (orientation: portrait) and (max-width: 900px) {
  #orientation-overlay:not(.dismissed) {
    display: flex !important;
  }
}

@media (orientation: landscape) {
  #orientation-overlay {
    display: none !important;
  }
}
