/* ═══════════════════════════════════════════════════════════════
   VÍAS EN LA NIEBLA — UI Moderna Profesional
   Inspirado en: Mini Metro, Into the Breach, Unrailed!
   ═══════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────
   VARIABLES & RESET
   ─────────────────────────────────────────────────────────────── */
:root {
  /* Paleta principal */
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --bg-elevated: #263347;
  
  /* Acentos */
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-green: #22c55e;
  --accent-yellow: #eab308;
  --accent-orange: #f97316;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  
  /* Texto */
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  /* Estados */
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  
  /* Bordes y sombras */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-blue: 0 0 20px rgba(59, 130, 246, 0.3);
  --shadow-glow-green: 0 0 20px rgba(34, 197, 94, 0.3);
  
  /* Tipografía */
  --font-pixel: 'Press Start 2P', cursive;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  
  /* Espaciado */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  
  /* Radios */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: linear-gradient(135deg, var(--bg-primary) 0%, #0f1729 50%, var(--bg-primary) 100%);
  background-attachment: fixed;
  font-family: var(--font-ui);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ───────────────────────────────────────────────────────────────
   LAYOUT PRINCIPAL
   ─────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh; /* mobile: viewport dinámico */
  padding: var(--spacing-md);
  gap: var(--spacing-md);
  overflow: hidden;
}

/* ───────────────────────────────────────────────────────────────
   HEADER / HUD
   ─────────────────────────────────────────────────────────────── */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1200px;
  padding: var(--spacing-sm) var(--spacing-lg);
  background: linear-gradient(180deg, rgba(31, 41, 55, 0.95), rgba(17, 24, 39, 0.95));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.hud-left {
  display: flex;
  align-items: center;
}

.game-logo {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.logo-icon {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 6px rgba(231, 76, 60, 0.4));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.logo-text {
  font-family: var(--font-pixel);
  font-size: 0.85rem;
  color: var(--text-primary);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
  letter-spacing: 1px;
  white-space: nowrap;
}

.logo-accent {
  color: var(--accent-yellow);
  margin-left: var(--spacing-xs);
}

.hud-stats {
  display: flex;
  gap: var(--spacing-md);
  align-items: center;
}

.stat {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) var(--spacing-md);
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  font-size: 1.2rem;
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-pixel);
  font-size: 0.85rem;
  font-weight: 700;
}

.stat-money .stat-value { color: var(--success); }
.stat-time .stat-value { color: var(--warning); }
.stat-score .stat-value { color: var(--accent-blue); }
.stat-record .stat-value { color: var(--accent-purple); }

.stat-time.low .stat-value {
  color: var(--danger);
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.hud-right {
  display: flex;
  align-items: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-tertiary));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
}

.icon-btn:hover {
  background: var(--accent-blue);
  color: white;
  transform: scale(1.05);
  box-shadow: var(--shadow-glow-blue);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ───────────────────────────────────────────────────────────────
   GAME CONTAINER
   ─────────────────────────────────────────────────────────────── */
#game-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

#canvas-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 
    var(--shadow-lg),
    0 0 0 2px rgba(59, 130, 246, 0.1),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  background: #080a0f;
  /* width: min(85vw, calc(100vh - 220px), 720px);
  height: min(85vw, calc(100vh - 220px), 720px); */
  transition: transform 0.3s ease;
}

/* Overlay de estado (victoria/derrota temporal) */
#game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#game-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-content {
  text-align: center;
  animation: popIn 0.3s ease;
}

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#overlay-title {
  font-family: var(--font-pixel);
  font-size: 2rem;
  margin-bottom: var(--spacing-md);
}

#overlay-text {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* Feedback toast */
#feedback {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: var(--spacing-sm) var(--spacing-lg);
  background: linear-gradient(180deg, rgba(31, 41, 55, 0.98), rgba(17, 24, 39, 0.98));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

#feedback.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#feedback.success { border-color: var(--success); color: var(--success); }
#feedback.error { border-color: var(--danger); color: var(--danger); }
#feedback.warning { border-color: var(--warning); color: var(--warning); }
#feedback.info { border-color: var(--info); color: var(--info); }

/* ───────────────────────────────────────────────────────────────
   DIFF
   ─────────────────────────────────────────────────────────────── */

.diff-select {
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-tertiary));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 8px;
  cursor: pointer;
  outline: none;
}
.diff-select:hover { border-color: var(--accent-blue); }

.start-logo { font-size: 4rem; margin-bottom: 8px; animation: bounce 0.6s ease; }
.start-title {
  font-family: var(--font-pixel);
  font-size: 1.3rem;
  color: var(--accent-yellow);
  text-shadow: 2px 2px 0 rgba(0,0,0,.6);
  margin-bottom: 6px;
}
.start-sub { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 18px; }

.diff-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.diff-chip {
  padding: 8px 16px;
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-tertiary));
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.diff-chip:hover { border-color: var(--border-hi); color: var(--text-primary); }
.diff-chip.selected {
  background: linear-gradient(180deg, #1a2f52, #0f1d38);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  box-shadow: var(--shadow-glow-blue);
}

/* ───────────────────────────────────────────────────────────────
   TOOLBAR
   ─────────────────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: stretch;
  gap: var(--spacing-md);
  width: 100%;
  max-width: 1200px;
  padding: var(--spacing-md);
  background: linear-gradient(180deg, rgba(31, 41, 55, 0.95), rgba(17, 24, 39, 0.95));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm);
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.group-label {
  font-size: 0.55rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
  padding: var(--spacing-xs) 0;
  border-radius: var(--radius-sm);
}

.group-tracks .group-label {
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
}

.group-works .group-label {
  color: var(--accent-orange);
  background: rgba(249, 115, 22, 0.1);
}

.group-recon .group-label {
  color: var(--accent-green);
  background: rgba(34, 197, 94, 0.1);
}

.group-buttons {
  display: flex;
  gap: var(--spacing-xs);
}

.toolbar-divider {
  width: 2px;
  background: linear-gradient(180deg, transparent, var(--border-medium), transparent);
  margin: 0 var(--spacing-xs);
}

/* Botones de herramientas */
.tool-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  width: 80px;
  height: 90px;
  padding: var(--spacing-sm);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-tertiary));
  border: 2px solid var(--border-medium);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-primary);
  font-family: var(--font-ui);
}

.tool-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-blue);
}

.tool-btn:active:not(:disabled) {
  transform: translateY(-1px);
}

.tool-btn.selected {
  background: linear-gradient(180deg, #1e3a5f, #0f2440);
  border-color: var(--accent-blue);
  box-shadow: var(--shadow-glow-blue), inset 0 0 12px rgba(59, 130, 246, 0.15);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-icon-wrap {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-icon {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.tool-name {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.tool-cost {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--success);
}

.hotkey-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* Variantes especiales */
.tool-explorer {
  background: linear-gradient(180deg, #1a3a2a, #0d2418);
  border-color: rgba(34, 197, 94, 0.4);
}

.tool-explorer:hover:not(:disabled) {
  border-color: var(--accent-green);
  box-shadow: var(--shadow-glow-green);
}

.tool-explorer.armed {
  background: linear-gradient(180deg, #1e4a32, #152a1e);
  border-color: var(--accent-green);
  animation: pulse-green 1.2s infinite;
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 8px rgba(34, 197, 94, 0.3); }
  50% { box-shadow: 0 0 20px rgba(34, 197, 94, 0.6); }
}

.tool-restart {
  background: linear-gradient(180deg, #3a2020, #241212);
  border-color: rgba(239, 68, 68, 0.4);
}

.tool-restart:hover:not(:disabled) {
  border-color: var(--accent-red);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.4);
}

/* ───────────────────────────────────────────────────────────────
   MODALES
   ─────────────────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-lg);
}

.modal.open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  background: linear-gradient(180deg, var(--bg-secondary), var(--bg-primary));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(59, 130, 246, 0.1);
  animation: modalSlideIn 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-small {
  max-width: 420px;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-family: var(--font-pixel);
  font-size: 1.1rem;
  color: var(--accent-blue);
  text-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.modal-body {
  padding: var(--spacing-lg);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: var(--spacing-lg);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: center;
  gap: var(--spacing-md);
}

.modal-footer-split {
  justify-content: space-between;
}

/* Contenido de ayuda */
.help-section {
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.help-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.help-section h3 {
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-yellow);
  margin-bottom: var(--spacing-sm);
}

.help-section p,
.help-section li {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.help-warning {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
}

.help-warning h3 {
  color: var(--danger);
}

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-sm);
}

.shortcut {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
}

.shortcut kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: 4px;
  font-family: var(--font-pixel);
  font-size: 0.6rem;
  color: var(--accent-cyan);
}

.shortcut span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.tool-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.tool-list li {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-sm);
}

.tool-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.cost-10 { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.cost-15 { background: rgba(249, 115, 22, 0.2); color: var(--accent-orange); }
.cost-30 { background: rgba(6, 182, 212, 0.2); color: var(--accent-cyan); }
.cost-40 { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.cost-free { background: rgba(139, 92, 246, 0.2); color: var(--accent-purple); }

/* Fin de partida */
.end-content {
  padding: var(--spacing-xl);
}

.end-icon {
  font-size: 4rem;
  margin-bottom: var(--spacing-md);
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

.end-title {
  font-family: var(--font-pixel);
  font-size: 1.8rem;
  margin-bottom: var(--spacing-lg);
}

.end-title.won {
  color: var(--success);
  text-shadow: 0 0 20px rgba(34, 197, 94, 0.5);
}

.end-title.lost {
  color: var(--danger);
  text-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
}

.end-stats {
  display: flex;
  justify-content: center;
  gap: var(--spacing-xl);
  margin-bottom: var(--spacing-lg);
}

.end-stat {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.end-stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.end-stat-value {
  font-family: var(--font-pixel);
  font-size: 1.5rem;
  color: var(--accent-blue);
}

.new-record-badge {
  display: inline-block;
  padding: var(--spacing-sm) var(--spacing-lg);
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.2), rgba(234, 179, 8, 0.2));
  border: 1px solid var(--success);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--success);
  animation: glow-pulse 1.5s infinite;
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(34, 197, 94, 0.3); }
  50% { box-shadow: 0 0 25px rgba(34, 197, 94, 0.6); }
}

/* ───────────────────────────────────────────────────────────────
   BOTONES
   ─────────────────────────────────────────────────────────────── */
.btn {
  padding: var(--spacing-md) var(--spacing-xl);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-blue), #2563eb);
  color: white;
  box-shadow: var(--shadow-glow-blue);
}

.btn-primary:hover {
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
}

.btn-secondary {
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-tertiary));
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}

.btn-danger {
  background: linear-gradient(180deg, var(--danger), #dc2626);
  color: white;
}

.btn-large {
  padding: var(--spacing-lg) var(--spacing-xl);
  font-size: 1.1rem;
}

/* ───────────────────────────────────────────────────────────────
   UTILIDADES
   ─────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.text-red {
  color: var(--danger);
}

/* ───────────────────────────────────────────────────────────────
   RESPONSIVE
   ─────────────────────────────────────────────────────────────── */

/* Tablet */
@media (max-width: 1024px) {
  #game {
    width: min(90vw, calc(100vh - 240px), 600px);
    height: min(90vw, calc(100vh - 240px), 600px);
  }
  
  .tool-btn {
    width: 70px;
    height: 80px;
  }
  
  .hud-stats {
    gap: var(--spacing-sm);
  }
  
  .stat {
    padding: var(--spacing-xs) var(--spacing-sm);
  }
  
  .logo-text {
    font-size: 0.7rem;
  }
}

/* Mobile */
@media (max-width: 768px) {
  #app {
    padding: var(--spacing-sm);
    gap: var(--spacing-sm);
  }
  
  #hud {
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
  }
  
  .hud-left {
    order: 1;
  }
  
  .hud-right {
    order: 2;
  }
  
  .hud-stats {
    order: 3;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .logo-text {
    display: none;
  }
  
  .logo-icon {
    font-size: 1.5rem;
  }
  
  .stat-label {
    display: none;
  }
  
  .stat-value {
    font-size: 0.75rem;
  }
  
  #game {
    width: min(95vw, calc(100vh - 280px), 500px);
    height: min(95vw, calc(100vh - 280px), 500px);
  }
  
  #toolbar {
    flex-wrap: wrap;
    justify-content: center;
    padding: var(--spacing-sm);
    gap: var(--spacing-sm);
  }
  
  .tool-group {
    padding: var(--spacing-xs);
  }
  
  .group-label {
    font-size: 0.5rem;
    letter-spacing: 1px;
  }
  
  .tool-btn {
    width: 62px;
    height: 72px;
    padding: var(--spacing-xs);
  }
  
  .tool-icon-wrap {
    width: 28px;
    height: 28px;
  }
  
  .tool-name {
    font-size: 0.5rem;
  }
  
  .tool-cost {
    font-size: 0.55rem;
  }
  
  .hotkey-badge {
    display: none;
  }
  
  .toolbar-divider {
    display: none;
  }
  
  .modal-panel {
    max-height: 90vh;
  }
  
  .shortcut-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  #feedback {
    bottom: 140px;
    font-size: 0.8rem;
    max-width: 90%;
  }
}

/* Mobile pequeño */
@media (max-width: 480px) {
  #game {
    width: min(98vw, calc(100vh - 260px), 400px);
    height: min(98vw, calc(100vh - 260px), 400px);
  }
  
  .tool-btn {
    width: 56px;
    height: 66px;
  }
  
  .tool-icon-wrap {
    width: 24px;
    height: 24px;
  }
  
  .tool-name {
    font-size: 0.45rem;
  }
  
  .stat {
    padding: var(--spacing-xs);
  }
  
  .stat-icon {
    font-size: 1rem;
  }
  
  .stat-value {
    font-size: 0.65rem;
  }
  
  .end-stats {
    flex-direction: column;
    gap: var(--spacing-md);
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #app {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  #hud {
    order: 1;
    width: 100%;
  }
  
  #game-container {
    order: 2;
    flex: 1;
  }
  
  #toolbar {
    order: 3;
    width: 100%;
  }
  
  #game {
    width: min(60vh, 400px);
    height: min(60vh, 400px);
  }
}