* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #07071a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #fff;
  user-select: none;
}

/* ── Game container (wraps HUD + canvas + bonus bar for unified scaling) ─── */
#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Touch layout: fixed fullscreen, container scaled + centered via JS */
body.touch-layout {
  overflow: hidden;
  position: fixed;
  width: 100vw;
  height: 100dvh;
}
body.touch-layout #game-container {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
}

/* ── HUD ─────────────────────────────────────────────────────────────────── */
#hud {
  display: flex;
  gap: 32px;
  margin-bottom: 10px;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #556;
}

#hud span {
  color: #9bf;
  font-weight: bold;
  letter-spacing: 2px;
}

/* ── Canvas wrapper ──────────────────────────────────────────────────────── */
#canvas-wrapper {
  position: relative;
  display: inline-block;
  line-height: 0;
}

#canvas {
  border: 2px solid #1e2040;
  border-radius: 4px;
  cursor: none;   /* hidden during play; pointer lock also suppresses the OS cursor */
  display: block;
}

/* ── Mobile menu button (touch only, shown during play) ─────────────────── */
#btn-mobile-menu {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  background: rgba(20, 30, 70, 0.78);
  border: 1px solid #334470;
  border-radius: 6px;
  color: #9bf;
  font-size: 15px;
  padding: 6px 13px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 1px;
}

/* ── Active bonuses bar ──────────────────────────────────────────────────── */
#active-bonuses {
  display: flex;
  gap: 8px;
  margin-top: 9px;
  min-height: 26px;
  flex-wrap: wrap;
  justify-content: center;
}

.bonus-tag {
  background: rgba(80, 160, 255, 0.15);
  border: 1px solid #338;
  border-radius: 10px;
  padding: 2px 10px;
  font-size: 12px;
  color: #9bf;
  transition: border-color 0.3s, color 0.3s;
}

/* ── Overlay panels ──────────────────────────────────────────────────────── */
.overlay-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;          /* shown via JS: el.style.display = 'flex' */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: rgba(4, 4, 18, 0.87);
  backdrop-filter: blur(3px);
  padding: 24px 20px;
  z-index: 10;
  overflow-y: auto;
}

.ov-title {
  font-size: 44px;
  font-weight: 900;
  color: #aaccff;
  text-shadow: 0 0 28px #446, 0 0 8px #fff2;
  text-align: center;
  line-height: 1.1;
  letter-spacing: 2px;
}

.ov-sub {
  color: #7a9bbb;
  font-size: 14px;
  text-align: center;
}

.ov-sep {
  color: #2a3050;
  font-size: 11px;
  letter-spacing: 2px;
  margin: 2px 0;
  text-transform: uppercase;
}

/* ── Overlay buttons ─────────────────────────────────────────────────────── */
.ov-btn {
  background: rgba(30, 45, 90, 0.7);
  border: 1px solid #334470;
  border-radius: 6px;
  color: #9bf;
  font-size: 14px;
  padding: 8px 22px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-width: 150px;
  font-family: inherit;
  letter-spacing: 1px;
}

.ov-btn:hover {
  background: rgba(50, 70, 140, 0.85);
  border-color: #5566cc;
}

.ov-btn.primary {
  background: rgba(30, 60, 180, 0.65);
  border-color: #4466dd;
  font-weight: bold;
  font-size: 15px;
  color: #ccdeff;
}

.ov-btn.primary:hover {
  background: rgba(50, 90, 220, 0.8);
}

.ov-btn.danger {
  background: rgba(80, 20, 20, 0.55);
  border-color: #602020;
  color: #e99;
}

.ov-btn.danger:hover {
  background: rgba(110, 30, 30, 0.7);
  border-color: #993333;
}

/* ── Save slots ──────────────────────────────────────────────────────────── */
#roomlist-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 300px;
  max-height: 200px;
  overflow-y: auto;
  margin: 4px 0 8px;
}
.roomlist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  padding: 6px 12px;
}
.roomlist-code {
  font-family: 'Courier New', monospace;
  font-size: 15px;
  letter-spacing: 3px;
  color: #88ddff;
  font-weight: bold;
}
.roomlist-status {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ffcc44;
  border: 1px solid rgba(255,204,68,0.3);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: auto;
}

.ready-row {
  display: flex;
  gap: 28px;
  justify-content: center;
  margin: 4px 0 10px;
}

.ov-slots {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  max-width: 330px;
}

.slot-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 30, 70, 0.55);
  border: 1px solid #222d55;
  border-radius: 6px;
  padding: 6px 12px;
}

.slot-row.has-save {
  border-color: #334488;
}

.slot-row.auto-slot {
  border-color: #1d3a3a;
  background: rgba(10, 30, 40, 0.6);
}

.slot-row.auto-slot.has-save {
  border-color: #2a5555;
}

.slot-row.auto-slot .slot-label {
  color: #3a8888;
}

.slot-label {
  font-size: 12px;
  font-weight: bold;
  color: #667;
  min-width: 42px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.slot-info {
  flex: 1;
  font-size: 11px;
  color: #7a9bbb;
  text-align: left;
}

.slot-btn {
  min-width: unset;
  padding: 4px 12px;
  font-size: 11px;
}

/* ── Code jump input ─────────────────────────────────────────────────────── */
.ov-codebox {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ov-input {
  background: rgba(10, 15, 40, 0.9);
  border: 1px solid #334470;
  border-radius: 5px;
  color: #ffe;
  font-size: 20px;
  font-family: 'Courier New', monospace;
  letter-spacing: 5px;
  padding: 5px 10px;
  width: 88px;
  text-align: center;
  text-transform: uppercase;
  transition: border-color 0.2s;
}

.ov-input:focus {
  outline: none;
  border-color: #5577ff;
}

.ov-input.invalid {
  border-color: #ff4444;
  color: #ff6666;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}

/* ── Horizontal button row (difficulty / penalty selectors) ─────────────── */
.ov-btnrow {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Selected state for toggle-button groups */
.ov-btn.selected {
  background: rgba(50, 90, 220, 0.75);
  border-color: #6688ff;
  color: #fff;
}

/* ── Level code badge ────────────────────────────────────────────────────── */
.code-badge {
  display: inline-block;
  background: rgba(30, 30, 80, 0.6);
  border: 1px solid #445;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  letter-spacing: 4px;
  padding: 1px 9px;
  color: #ddf;
  font-size: 18px;
}

/* ── Build info label ────────────────────────────────────────────────────── */
#build-info {
  position: fixed;
  bottom: 10px;
  left: 12px;
  z-index: 9000;
  font-size: 10px;
  color: #445566;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
  pointer-events: none;
  user-select: none;
}

/* ── Dev Console ─────────────────────────────────────────────────────────── */
#devconsole-btn {
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 9999;
  background: rgba(20, 25, 60, 0.85);
  border: 1px solid #334470;
  border-radius: 8px;
  color: #9bf;
  font-size: 18px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
}

#devconsole-btn:hover {
  background: rgba(40, 55, 130, 0.9);
  border-color: #5566cc;
}

#devconsole-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #cc2222;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border-radius: 8px;
  padding: 1px 4px;
  min-width: 16px;
  text-align: center;
  line-height: 14px;
  display: none;
}

#devconsole-panel {
  position: fixed;
  bottom: 60px;
  right: 14px;
  z-index: 9998;
  width: 480px;
  max-width: calc(100vw - 28px);
  height: 300px;
  background: rgba(6, 7, 22, 0.96);
  border: 1px solid #2a3060;
  border-radius: 8px;
  display: none;
  flex-direction: column;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  overflow: hidden;
}

#devconsole-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  background: rgba(20, 25, 65, 0.9);
  border-bottom: 1px solid #2a3060;
  font-size: 12px;
  color: #667;
  letter-spacing: 1px;
  text-transform: uppercase;
  flex-shrink: 0;
}

#devconsole-header div {
  display: flex;
  gap: 6px;
}

#devconsole-clear,
#devconsole-close {
  background: transparent;
  border: 1px solid #334470;
  border-radius: 4px;
  color: #668;
  font-size: 11px;
  padding: 2px 7px;
  cursor: pointer;
  font-family: inherit;
}

#devconsole-clear:hover,
#devconsole-close:hover {
  background: rgba(50, 70, 140, 0.6);
  color: #9bf;
}

#devconsole-log {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.5;
}

.dc-entry {
  padding: 1px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.dc-log   { color: #7a9bbb; }
.dc-info  { color: #66bbdd; }
.dc-warn  { color: #ddaa44; background: rgba(80,60,0,0.15); }
.dc-error { color: #ff6666; background: rgba(80,10,10,0.2); }
