html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

#build-sha {
  position: fixed;
  top: 4px;
  right: 6px;
  font-family: monospace;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
  z-index: 9999;
  user-select: none;
}

body {
  font-family: 'Roboto', Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #f5f5f5;
  overflow: hidden;
  overscroll-behavior: none;
  height: 100vh; /* clipping container for the scaled wrapper */
  /* flex layout lives on #page-scale-wrapper */
}

#page-scale-wrapper {
  display: flex;
  flex-direction: row; /* Horizontal layout for padding panels */
  transform-origin: top left;
  overflow: hidden;
  /* width, height, transform set by applyPageZoom() in JS */
}

/* Main content wrapper - contains header and container */
.main-content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Allow shrinking */
  overflow: hidden;
}

header {
  background: #1976d2;
  color: white;
  padding: 16px 24px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 500;
}

.container {
  display: flex;
  flex: 1;
  /* overflow: clip (not hidden) so focus outlines aren't clipped at the edges */
  overflow: clip;
}

.blockly-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  border-right: 1px solid #ddd;
  position: relative;
}

#blocklyDiv {
  flex: 1;
  min-height: 0;
}

#blocklyDiv.hidden {
  display: none;
}

/* Floating button group over the blockly workspace */
.workspace-btns {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 50;
  display: flex;
  gap: 6px;
}

.clear-workspace-btn {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  background: #757575;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: all 0.2s;
}

.clear-workspace-btn:hover {
  background: #616161;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.clear-workspace-btn:active {
  background: #424242;
  transform: translateY(1px);
}

/* Hide buttons when blockly is hidden (immediate mode) */
#blocklyDiv.hidden ~ .workspace-btns {
  display: none;
}


/* Make editable fields (dropdowns, inputs) visually distinct from block background */
.blocklyFieldRect {
  fill: rgba(0, 0, 0, 0.15) !important;
  stroke: rgba(0, 0, 0, 0.35) !important;
  stroke-width: 1.5px !important;
}

/* Hover lightens slightly to indicate interactivity */
.blocklyField:hover > .blocklyFieldRect {
  fill: rgba(0, 0, 0, 0.08) !important;
  stroke: rgba(0, 0, 0, 0.5) !important;
  stroke-width: 2px !important;
}

/* Keyboard focus styling for fields - active focus (solid border) */
.blocklyActiveFocus.blocklyField > .blocklyFieldRect {
  stroke: var(--blockly-active-node-color) !important;
  stroke-width: var(--blockly-selection-width) !important;
}

/* Keyboard focus styling for fields - passive focus (dashed border) */
.blocklyPassiveFocus.blocklyField > .blocklyFieldRect {
  stroke: var(--blockly-active-node-color) !important;
  stroke-width: var(--blockly-selection-width) !important;
  stroke-dasharray: 5px 3px !important;
}

.game-controls {
  position: relative;
  z-index: 10;
  padding: 16px 0;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

#capacityBubble {
  padding: 8px 16px;
  background: #e8f5e9;
  border: 2px solid #4caf50;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  color: #2e7d32;
  transition: all 0.3s;
  width: 100%;
  text-align: center;
  margin-top: 8px;
}

#capacityBubble.warning {
  background: #fff3e0;
  border-color: #ff9800;
  color: #e65100;
}

#capacityBubble.error {
  background: #ffebee;
  border-color: #f44336;
  color: #c62828;
}

#capacityBubble.hidden {
  display: none;
}

/* Hint dialog styles */
#hintDialog {
  display: none;
  position: fixed;
  z-index: 1000;
  background: white;
  border: 2px solid #1976d2;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  padding: 16px 20px;
  max-width: 300px;
  font-size: 14px;
  line-height: 1.5;
  color: #333;
}

#hintDialog::before {
  content: '💡';
  font-size: 20px;
  margin-right: 8px;
  vertical-align: middle;
}

#hintDialog.visible {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

#hintDialog .close-btn {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
  padding: 0 4px;
}

#hintDialog .close-btn:hover {
  color: #333;
}

button {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

button:active {
  transform: translateY(0);
}

/* Consistent focus indicator: gap + colored outer ring.
   Uses --element-color if set (auto-matches button color), else --focus-accent, else white.
   Set --element-color on colored elements, or --focus-accent to override just the focus ring. */
:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--focus-accent, var(--element-color, white));
  outline-offset: 2px;
}

#runButton {
  --element-color: #4caf50;
  background: var(--element-color);
  color: white;
}

#runButton.hidden {
  display: none;
}

#runButton:hover {
  background: #45a049;
}

#ghostRunButton {
  --element-color: #7c4dff;
  background: var(--element-color);
  color: white;
}

#ghostRunButton.hidden {
  display: none;
}

#ghostRunButton:hover {
  background: #6c3de0;
}

#resetButton {
  --element-color: #ff9800;
  background: var(--element-color);
  color: white;
}

#resetButton:hover {
  background: #e68900;
}

.game-container {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  background: white;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.level-selector {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
  padding: 12px;
  background: #e8f5e9;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.level-selector button {
  padding: 6px 12px;
  font-size: 14px;
  background: #4caf50;
  color: white;
  min-width: 40px;
  z-index: 10;
}

.level-selector button:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.level-selector span {
  font-weight: 500;
  color: #2e7d32;
  flex: 1;
  text-align: center;
  transition: opacity 0.3s ease;
}

/* Compact mode: hide label and overlay buttons on canvas */
.game-container.compact .level-selector {
  position: absolute;
  top: 24px;
  left: 24px;
  right: 24px;
  margin: 0;
  padding: 0;
  background: transparent;
  z-index: 20;
  pointer-events: none;
}

.game-container.compact .level-selector button {
  pointer-events: auto;
  position: absolute;
  background: rgba(76, 175, 80, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.game-container.compact .level-selector #prevLevel {
  left: 16px;
  top: 50px;
}

.game-container.compact .level-selector #nextLevel {
  right: 16px;
  top: 50px;
}

.game-container.compact .level-selector span {
  opacity: 0;
  pointer-events: none;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 150px;
  min-height: 0;
  flex: 1;
  align-self: stretch;
  overflow: hidden;
}

#mazeCanvas {
  display: block;
  margin: 0;
  box-shadow: 0 0 0 1px #ccc;
}

/* Centered mode toggle in header */
.header-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-selectors {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.selector-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.selector-group select {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: #1976d2;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231976d2' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 32px;
}

.selector-group select:hover {
  background: white;
  border-color: rgba(255, 255, 255, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.selector-group select option {
  background: white;
  color: #1976d2;
  padding: 8px;
  font-weight: 500;
}

.selector-group select option:checked {
  background: #1976d2;
  color: white;
}

/* Mode toggle button styles */
.mode-toggle {
  padding: 8px 14px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #1976d2;
  font-weight: 500;
}

.mode-toggle:hover {
  background: white;
  border-color: rgba(255, 255, 255, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.mode-toggle .mode-icon {
  display: none;
  font-size: 16px;
}

.mode-toggle.practice .practice-icon {
  display: inline;
}

.mode-toggle.coding .coding-icon {
  display: inline;
}

.mode-action {
  white-space: nowrap;
}

.mode-label {
  color: white;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
}

/* Pegman button and menu styles */
#pegmanButton {
  padding: 0;
  position: relative;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  width: 49px;
  height: 51px;
  transform: scale(0.73); /* 37px target / 51px native */
  transform-origin: right center;
}
#pegmanButton:hover {
  background: white;
  border-color: rgba(255, 255, 255, 0.8);
  transform: scale(0.73) translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}
#pegmanButton.buttonHover {
  background: white;
  border-color: #ffeb3b;
}
#pegmanButton>img {
  height: 51px;
  width: 1029px;
  display: block;
  position: absolute;
  left: -980px;
  top: 0;
}
#pegmanButton>span {
  position: absolute;
  top: 0.8ex;
  right: 5px;
  color: #1976d2;
  font-weight: bold;
  z-index: 1;
}
#pegmanMenu {
  border: 2px solid #1976d2;
  border-radius: 6px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  display: none;
  position: absolute;
  background: white;
  z-index: 1000;
  transform: scale(0.73);
  transform-origin: top left;
}
#pegmanMenu>div {
  background-color: #fff;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.2s;
  position: relative;
  width: 49px;
  height: 51px;
  overflow: hidden;
}
#pegmanMenu>div:hover {
  background-color: #e3f2fd;
}
#pegmanMenu>div>img {
  height: 51px;
  width: 1029px;
  display: block;
  position: absolute;
  left: -980px;
  top: 0;
}

/* Mute button styles */
.mute-button {
  --element-color: rgba(255, 255, 255, 0.95);
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 37px;
}

.mute-button:hover {
  background: white;
  border-color: rgba(255, 255, 255, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.mute-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Mute icon visibility - show sound-on by default, hide sound-off */
.mute-button .mute-icon {
  display: none;
}

.mute-button .mute-icon.sound-on {
  display: inline;
}

.mute-button .mute-icon.sound-off {
  display: none;
}

/* When muted, show sound-off icon and hide sound-on */
.mute-button.muted .mute-icon.sound-on {
  display: none;
}

.mute-button.muted .mute-icon.sound-off {
  display: inline;
}

/* Muted state visual feedback */
.mute-button.muted {
  background: rgba(200, 200, 200, 0.95);
  border-color: rgba(150, 150, 150, 0.5);
}

.mute-button.muted:hover {
  background: rgba(220, 220, 220, 0.95);
}

/* Icon buttons used in header (zoom controls, etc.) */
.icon-button {
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  font-size: 16px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 37px;
}

.icon-button:hover {
  background: white;
  border-color: rgba(255, 255, 255, 0.8);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.icon-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Zoom controls group in header */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-label {
  font-size: 0.85em;
  min-width: 3em;
  text-align: center;
  user-select: none;
  color: white;
}

/* Christmas Snow Effect - only shown with Rudolph skin */
#snowContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
  display: none;
}

#snowContainer.active {
  display: block;
}

.snowflake {
  position: absolute;
  top: -20px;
  color: white;
  font-size: 1em;
  text-shadow: 0 0 3px rgba(200, 220, 255, 0.8);
  animation: snowfall linear infinite;
  opacity: 0.9;
}

@keyframes snowfall {
  0% {
    transform: translateY(-20px) rotate(0deg) translateX(0);
  }
  25% {
    transform: translateY(25vh) rotate(90deg) translateX(10px);
  }
  50% {
    transform: translateY(50vh) rotate(180deg) translateX(-10px);
  }
  75% {
    transform: translateY(75vh) rotate(270deg) translateX(10px);
  }
  100% {
    transform: translateY(110vh) rotate(360deg) translateX(0);
  }
}

/* Goal sparkle effect */
.sparkle-container {
  position: absolute;
  pointer-events: none;
  z-index: 50;
}

.sparkle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: radial-gradient(circle, #fff 0%, #ffd700 40%, transparent 70%);
  border-radius: 50%;
  animation: sparkle 1.5s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 0.3; transform: scale(0.5); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Christmas header theme when Rudolph is active */
header.christmas {
  background: linear-gradient(135deg, #1a472a 0%, #2d5a3f 50%, #1a472a 100%);
}

header.christmas h1::before {
  content: '🎄 ';
}

header.christmas h1::after {
  content: ' 🦌';
}

/* Instruction bar styles */
#instructionBar {
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border-bottom: 2px solid #1976d2;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: all 0.3s ease;
}

#instructionBar.hidden {
  display: none;
}

#instructionBar .instruction-content {
  flex: 1;
}

/* Stage selector in instruction bar */
#instructionBar .stage-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#instructionBar .stage-selector label {
  font-size: 14px;
  font-weight: 500;
  color: #1565c0;
}

#instructionBar .stage-selector select {
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  border: 2px solid #1976d2;
  border-radius: 6px;
  background: white;
  color: #1565c0;
  cursor: pointer;
  min-width: 180px;
}

#instructionBar .stage-selector select:hover {
  border-color: #1565c0;
  background: #e3f2fd;
}

#instructionBar .stage-selector select:focus {
  outline: none;
  border-color: #0d47a1;
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.2);
}

/* Hide stage selector in practice/grid modes */
#instructionBar .stage-selector.hidden {
  display: none;
}

#instructionBar #levelInstruction {
  font-size: 15px;
  font-weight: 500;
  color: #1565c0;
}

.immediate-marker {
  height: 1.2em;
  vertical-align: middle;
  margin-left: 4px;
}

#instructionBar #contextualHint {
  font-size: 15px;
  font-weight: 500;
  color: #1565c0;
}

#instructionBar #contextualHint:empty {
  display: none;
}

/* Info button in instruction bar */
#instructionBar .info-btn {
  background: #1976d2;
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

#instructionBar .info-btn:hover {
  background: #1565c0;
}

#instructionBar .info-btn:focus {
  outline: 2px solid #90caf9;
  outline-offset: 2px;
}

/* Settings section in shortcuts modal */
.settings-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e0e0e0;
  margin-bottom: 20px;
}

.settings-heading {
  font-size: 1em;
  font-weight: 600;
  color: #555;
  margin: 0 0 10px 0;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1em;
  color: #333;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
  text-align: left;
}

.setting-item:hover {
  background-color: #f5f5f5;
}

.setting-item input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.setting-item span {
  font-size: 1em;
  color: #333;
  user-select: none;
}

/* Shortcuts modal content */
.shortcuts-modal .shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
  text-align: left;
}

.shortcuts-modal .shortcut-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1em;
  color: #333;
}

.shortcuts-modal .shortcut-item kbd {
  display: inline-block;
  padding: 4px 8px;
  font-family: monospace;
  font-size: 0.9em;
  background: #f5f5f5;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 1px 0 #999;
  min-width: 24px;
  text-align: center;
}

.shortcuts-modal .delete-data-btn {
  background: #c62828;
  border-color: #c62828;
  color: #fff;
}

.shortcuts-modal .delete-data-btn:hover {
  background: #b71c1c;
  border-color: #b71c1c;
}

.shortcuts-modal .about-link {
  display: block;
  margin-top: 12px;
  font-size: 0.85em;
  color: #666;
  text-align: center;
  text-decoration: none;
}

.shortcuts-modal .about-link:hover {
  text-decoration: underline;
}

/* Sidebar toggle button */
.sidebar-toggle {
  --element-color: #666;
  position: relative;
  flex-shrink: 0;
  width: 24px;
  background: #e0e0e0;
  border: none;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
  cursor: pointer;
  display: none; /* Hidden - using panel resizer instead */
  align-items: center;
  justify-content: center;
  transition: background 0.2s, width 0.2s;
  z-index: 10;
}

.sidebar-toggle:hover {
  background: #d0d0d0;
}

.sidebar-toggle .toggle-icon {
  font-size: 18px;
  font-weight: bold;
  color: #666;
  transition: transform 0.3s ease;
}

/* Collapsed state */
.container.sidebar-collapsed .sidebar-toggle .toggle-icon {
  transform: rotate(180deg);
}

.container.sidebar-collapsed .game-container {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
}

.game-container {
  transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}

/* Blockly expands when sidebar collapsed */
.container.sidebar-collapsed .blockly-container {
  flex: 1;
}

/* Hide zoom controls when workspace is narrow (but keep trash visible) */
.blockly-container.narrow .blocklyZoom {
  display: none !important;
}


/* Scale Blockly overlay divs to match the page zoom.
   These elements are appended to document.body outside #page-scale-wrapper,
   so they don't inherit the wrapper's CSS transform. We compensate here.
   The --page-zoom variable is set by applyPageZoom() in JS. */
.blocklyDropDownDiv,
.blocklyWidgetDiv {
  transform: scale(var(--page-zoom, 1));
  transform-origin: top left;
}

/* ============================================================
   Immediate Mode Panel Styles
   Used for levels 1-2 before introducing programming concepts
   ============================================================ */

.immediate-mode-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  gap: 24px;
  background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
}

.immediate-mode-panel.hidden {
  display: none;
}

.immediate-hint {
  font-size: 16px;
  color: #495057;
  text-align: center;
  max-width: 320px;
  line-height: 1.5;
}

.command-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  width: 100%;
  max-width: 280px;
}

.command-btn {
  /* Toolbox-style button appearance */
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  transition: background 0.15s, box-shadow 0.15s;
  cursor: pointer;
  border: none;

  /* MOVEMENT_HUE = 290 in Blockly (purple/magenta) */
  --element-color: hsl(290, 65%, 54%);
  background: var(--element-color);
  color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.command-btn:hover {
  background: hsl(290, 65%, 60%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}

.command-btn:active {
  background: hsl(290, 65%, 48%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.command-btn.executing {
  background: hsl(290, 65%, 48%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
  opacity: 0.8;
}

.command-btn .cmd-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.command-btn .cmd-label {
  font-size: 14px;
  flex: 1;
}

.immediate-keyboard-hint {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: #6c757d;
  flex-wrap: wrap;
  justify-content: center;
}

.immediate-keyboard-hint kbd {
  display: inline-block;
  padding: 4px 8px;
  font-family: monospace;
  font-size: 12px;
  background: white;
  border: 1px solid #ced4da;
  border-radius: 4px;
  box-shadow: 0 1px 0 #adb5bd;
  margin-right: 4px;
}

/* ============================================================
   Confetti Effect for Level Completion
   ============================================================ */

#confettiContainer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99;
  overflow: hidden;
  border-radius: 4px;
}

.confetti {
  position: absolute;
  width: 6px;
  height: 6px;
  opacity: 0;
  animation: confetti-fall 3s ease-out forwards;
}

.confetti.circle {
  border-radius: 50%;
}

.confetti.square {
  border-radius: 1px;
}

.confetti.ribbon {
  width: 4px;
  height: 12px;
  border-radius: 1px;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg) scale(1);
  }
  10% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(400px) rotate(720deg) scale(0.5);
  }
}

/* Confetti swing animation variants */
.confetti.swing-left {
  animation: confetti-fall-left 3s ease-out forwards;
}

.confetti.swing-right {
  animation: confetti-fall-right 3s ease-out forwards;
}

@keyframes confetti-fall-left {
  0% {
    opacity: 1;
    transform: translateY(0) translateX(0) rotate(0deg) scale(1);
  }
  25% {
    transform: translateY(100px) translateX(-30px) rotate(180deg) scale(0.9);
  }
  50% {
    transform: translateY(200px) translateX(20px) rotate(360deg) scale(0.8);
  }
  75% {
    transform: translateY(300px) translateX(-20px) rotate(540deg) scale(0.6);
  }
  100% {
    opacity: 0;
    transform: translateY(400px) translateX(10px) rotate(720deg) scale(0.4);
  }
}

@keyframes confetti-fall-right {
  0% {
    opacity: 1;
    transform: translateY(0) translateX(0) rotate(0deg) scale(1);
  }
  25% {
    transform: translateY(100px) translateX(30px) rotate(-180deg) scale(0.9);
  }
  50% {
    transform: translateY(200px) translateX(-20px) rotate(-360deg) scale(0.8);
  }
  75% {
    transform: translateY(300px) translateX(20px) rotate(-540deg) scale(0.6);
  }
  100% {
    opacity: 0;
    transform: translateY(400px) translateX(-10px) rotate(-720deg) scale(0.4);
  }
}

/* ============================================================
   Level Banner (positioned over maze)
   ============================================================ */

.level-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: linear-gradient(135deg, #4caf50 0%, #2e7d32 100%);
  color: white;
  padding: 16px 48px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, visibility 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

.level-banner.active {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  visibility: visible;
}

.level-banner .level-number {
  font-size: 32px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  display: block;
  text-align: center;
  white-space: nowrap;
}

/* Fade effect for canvas during transition */
.canvas-wrapper {
  opacity: 1;
  transition: opacity 0.3s ease;
}

.canvas-wrapper.fade-out {
  opacity: 0;
}

.canvas-wrapper.fade-in {
  opacity: 1;
}

/* Fall Overlay (shown when character falls off in practice mode) */
.fall-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

.fall-overlay.active {
  opacity: 1;
  visibility: visible;
}

.fall-overlay-text {
  font-size: 36px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  animation: fall-overlay-bounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fall-overlay-bounce {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================
   Result Modal (replaces alert boxes)
   ============================================ */

/* Native dialog element */
dialog.result-modal {
  border: none;
  background: white;
  border-radius: 12px;
  padding: 24px 32px;
  min-width: 280px;
  max-width: 90%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: modalSlideIn 0.2s ease-out;
}

/* Dialog backdrop (replaces .result-modal-overlay background) */
dialog.result-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease-out;
}

/* Confirmation modal needs to appear above other modals */
#confirmationModal {
  z-index: 1100;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Success variant - green accent */
.result-modal.success {
  border-top: 4px solid #4caf50;
}

.result-modal.success .result-modal-title {
  color: #2e7d32;
}

/* Failure/timeout variant - neutral gray */
.result-modal.failure {
  border-top: 4px solid #9e9e9e;
}

.result-modal.failure .result-modal-title {
  color: #616161;
}

/* Stage intro variant - blue accent for new concepts */
.result-modal.stage-intro {
  border-top: 4px solid #1976d2;
}

.result-modal.stage-intro .result-modal-title {
  color: #1565c0;
}

.stage-intro-name {
  margin: 0 0 12px;
  font-size: 1.3em;
  font-weight: 600;
  color: #1976d2;
}

.result-modal.stage-intro .result-modal-message {
  white-space: pre-line;
}

/* Modal content */
.result-modal-title {
  margin: 0 0 12px;
  font-size: 1.5em;
  font-weight: 600;
}

.result-modal-message {
  margin: 0 0 20px;
  color: #333;
  font-size: 1em;
  line-height: 1.4;
}

.result-modal-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* OK button */
.result-modal-ok {
  position: relative;
  padding: 10px 32px;
  font-size: 1em;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  --element-color: #2196f3;
  background: var(--element-color);
  color: white;
  cursor: pointer;
  transition: background-color 0.15s ease;
  overflow: hidden;
}

.result-modal-ok .ok-text {
  position: relative;
  z-index: 1;
}

/* Progress bar that shrinks from right to left */
.result-modal-ok .ok-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 4px;
  width: 100%;
  background: rgba(255, 255, 255, 0.5);
  transform-origin: left;
}

/* Animation for auto-close countdown */
.result-modal-ok.countdown .ok-progress {
  animation: countdown-progress linear forwards;
}

@keyframes countdown-progress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

.result-modal-ok:hover {
  background: #1976d2;
}

.result-modal-ok:active {
  background: #1565c0;
}

/* Keyboard hint displayed next to button text */
.result-modal-ok .ok-hint,
.result-modal-cancel .cancel-hint {
  font-size: 0.85em;
  opacity: 0.8;
  margin-left: 6px;
}

/* Cancel button (secondary style) */
.result-modal-cancel {
  padding: 10px 20px;
  font-size: 1em;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: #757575;
  color: white;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.result-modal-cancel:hover {
  background: #616161;
}

.result-modal-cancel:active {
  background: #424242;
}

/* Graduation modal buttons */
.graduation-buttons {
  flex-direction: column;
  gap: 8px;
}

.graduation-primary {
  background: #4caf50;
}

.graduation-primary:hover {
  background: #43a047;
}

.graduation-primary:active {
  background: #388e3c;
}

.graduation-secondary {
  background: #757575;
}

.graduation-secondary:hover {
  background: #616161;
}

.graduation-secondary:active {
  background: #424242;
}

/* ============================================================
   Grid Mode Styles
   Used when grid=1 URL parameter is active with practice mode
   For use inside Grid 3 AAC software where all interaction
   comes via keyboard from a gridset.
   ============================================================ */

/* Hide elements in grid mode */
body.grid-mode .mode-label,
body.grid-mode .mode-toggle,
body.grid-mode .blockly-container,
body.grid-mode .sidebar-toggle,
body.grid-mode .level-selector,
body.grid-mode #runButton,
body.grid-mode #ghostRunButton,
body.grid-mode #resetButton,
body.grid-mode .info-btn {
  display: none !important;
}

/* Container layout for grid mode - fill viewport */
body.grid-mode .container {
  flex: 1;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
  height: 100%;
}

body.grid-mode .game-container {
  flex: 1;
  max-width: 100%;
  min-width: auto;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Level label above maze (Grid mode) - kept compact to prioritize maze size */
.grid-mode-level {
  font-size: 18px;
  font-weight: 600;
  color: #2e7d32;
  text-align: center;
  padding: 8px 16px;
  background: #e8f5e9;
  border-radius: 6px;
  margin-bottom: 8px;
}

.grid-mode-level.hidden {
  display: none;
}

/* Instruction count below maze (Grid mode) */
.grid-mode-instruction-count {
  font-size: 18px;
  font-weight: 500;
  color: #1565c0;
  text-align: center;
  padding: 12px 32px;
  background: #e3f2fd;
  border-radius: 8px;
  margin-top: 16px;
}

.grid-mode-instruction-count.hidden {
  display: none;
}

/* Canvas wrapper in grid mode - fill remaining space after labels */
body.grid-mode .canvas-wrapper {
  flex: 1;
  aspect-ratio: 1; /* Keep canvas square when zooming */
  max-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: auto;
  min-height: 0; /* Allow flex shrinking */
  overflow: hidden;
}

/* Hide game controls section in grid mode */
body.grid-mode .game-controls {
  display: none;
}

/* Override sidebar-collapsed styles in grid mode - sidebar is already hidden,
   so game-container should remain visible */
body.grid-mode .container.sidebar-collapsed .game-container {
  width: 100%;
  min-width: auto;
  padding: 0;
  overflow: visible;
  opacity: 1;
}

/* Grid mode body - fit viewport without scrolling */
body.grid-mode {
  height: 100vh;
  overflow: hidden;
  background: white;
}

/* Canvas size is set dynamically by JS (getCanvasSize); no CSS constraints needed. */

/* ============================================================
   Grid Coding Mode Styles
   Used when grid=1 URL parameter is active with coding mode
   Keyboard commands insert blocks AND execute immediately.
   ============================================================ */

/* Hide UI elements in grid coding mode */
body.grid-coding-mode .mode-label,
body.grid-coding-mode .mode-toggle,
body.grid-coding-mode .sidebar-toggle,
body.grid-coding-mode .level-selector,
body.grid-coding-mode #runButton,
body.grid-coding-mode #ghostRunButton,
body.grid-coding-mode #resetButton,
body.grid-coding-mode .info-btn,
body.grid-coding-mode #capacityBubble,
body.grid-coding-mode #immediateModePanel {
  display: none !important;
}

/* Hide the Blockly toolbox and flyout in grid coding mode (Grid3 provides the toolbox) */
body.grid-coding-mode .blocklyToolboxDiv {
  display: none !important;
  width: 0 !important;
}

body.grid-coding-mode .blocklyFlyout {
  display: none !important;
}

/* Grid coding mode body - fit viewport */
body.grid-coding-mode {
  height: 100vh;
  overflow: hidden;
  background: white;
}

/* Container layout for grid coding mode - side by side */
body.grid-coding-mode .container {
  flex-direction: row;
  justify-content: stretch;
  align-items: stretch;
  overflow: hidden;
  padding: 8px;
  height: 100vh;
  gap: 16px;
}

/* Blockly container in grid coding mode - left side */
body.grid-coding-mode .blockly-container {
  order: 0;
  flex: 1;
  min-width: 150px;
  height: 100%;
  border: 3px solid #9c27b0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 2px 0 8px rgba(156, 39, 176, 0.2);
}

body.grid-coding-mode #blocklyDiv {
  height: 100%;
  /* Extend width by the flyout dead-space so the right edge reaches the container edge
     after the leftward transform. --flyout-width is set by JS once the settled
     flyout width is known; the 50px fallback matches the empirically measured value.
     The 8px offset leaves a small gap on the left so blocks aren't flush with the border. */
  width: calc(100% + var(--flyout-width, 50px));
  transform: translateX(calc(-1 * var(--flyout-width, 50px) + 8px));
}

/* Game container in grid coding mode - right side, constrained to square */
body.grid-coding-mode .game-container {
  order: 2;
  flex: 0 0 auto;
  height: 100%;
  width: min(calc(100vh - 16px), 600px);
  max-width: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  gap: 8px;
  overflow: hidden;
  border-left: 4px solid #9c27b0;
  padding-left: 8px;
}

/* Level label for Grid coding mode */
.grid-coding-level {
  font-size: 18px;
  font-weight: 600;
  color: #7b1fa2;
  text-align: center;
  padding: 8px 16px;
  background: #f3e5f5;
  border-radius: 6px;
}

.grid-coding-level.hidden {
  display: none;
}

/* Compact mode - when vertical space is tight */
body.grid-coding-mode .game-container.compact .grid-coding-level {
  display: none;
}

body.grid-coding-mode .game-container.compact {
  gap: 4px;
}

/* Block count display for Grid coding mode */
.grid-coding-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

.grid-coding-controls.hidden {
  display: none;
}

.grid-coding-block-count {
  font-size: 18px;
  font-weight: 500;
  color: #7b1fa2;
  text-align: center;
  padding: 12px 32px;
  background: #f3e5f5;
  border-radius: 8px;
}

/* Canvas wrapper in grid coding mode - height determines width via aspect-ratio */
body.grid-coding-mode .canvas-wrapper {
  flex: 1;
  aspect-ratio: 1;
  max-height: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* Hide regular game controls in grid coding mode */
body.grid-coding-mode .game-controls {
  display: none;
}

/* Override sidebar-collapsed styles in grid coding mode */
body.grid-coding-mode .container.sidebar-collapsed .game-container {
  width: 100%;
  min-width: auto;
  padding: 0;
  overflow: visible;
  opacity: 1;
}

body.grid-coding-mode .container.sidebar-collapsed .blockly-container {
  display: flex !important;
  opacity: 1;
}

/* Canvas size is set dynamically by JS (getCanvasSize); no CSS constraints needed. */

/* ============================================================
   Screen Padding Controls for Eye Gaze Accessibility
   ============================================================ */

/* Screen padding elements - create actual rectangular areas that push content inward */
.screen-padding {
  flex: 0 0 auto;
  width: 0; /* Default, will be set dynamically */
  background: rgba(100, 100, 100, 0.1);
  border: 2px dashed rgba(100, 100, 100, 0.3);
  transition: width 0.3s ease;
  height: 100%; /* Fill the full logical height of the scale wrapper, not just 100vh */
}

.screen-padding.left-padding {
  order: -1; /* Ensure it appears first */
}

.screen-padding.right-padding {
  order: 1; /* Ensure it appears last */
}

/* Control buttons - positioned at page edges */
.padding-control-btn {
  position: fixed;
  bottom: 12px;
  background: rgba(33, 150, 243, 0.85);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  z-index: 1001; /* Above modals */
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.padding-control-btn:hover {
  background: rgba(33, 150, 243, 0.95);
  transform: scale(1.05);
}

.padding-control-btn:active {
  transform: scale(0.95);
}

/* Left side button positioning - both start at edge */
.padding-control-btn.pad-left-dec {
  left: 12px;
}

.padding-control-btn.pad-left-inc {
  left: 12px; /* Starts at edge when alone */
}

/* When decrease is visible, push increase button out */
.padding-control-btn.pad-left-dec.active ~ .padding-control-btn.pad-left-inc {
  left: 60px;
}

/* Right side button positioning - both start at edge */
.padding-control-btn.pad-right-dec {
  right: 12px;
}

.padding-control-btn.pad-right-inc {
  right: 12px; /* Starts at edge when alone */
}

/* When decrease is visible, push increase button out */
.padding-control-btn.pad-right-dec.active ~ .padding-control-btn.pad-right-inc {
  right: 60px;
}

/* Hidden by default, shown when appropriate */
.padding-control-btn.pad-left-dec,
.padding-control-btn.pad-right-dec {
  display: none;
}

/* Show decrease buttons when active */
.padding-control-btn.pad-left-dec.active,
.padding-control-btn.pad-right-dec.active {
  display: block;
}

/* Disable increase buttons at max */
.padding-control-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Hide in grid modes */
body.grid-mode .padding-control-btn,
body.grid-coding-mode .padding-control-btn,
body.grid-mode .screen-padding,
body.grid-coding-mode .screen-padding {
  display: none;
}
