:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-body: #0b0f17;
  --bg-card: #131b2e;
  --bg-elevated: #1c2539;
  --bg-input: #0f1626;
  --text-main: #f8fafc;
  --text-primary: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --accent-warm: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --radius-lg: 16px;

  --cell-bg: #172136;
  --cell-visited-bg: rgba(59, 130, 246, 0.14);
  --cell-border: #25334d;
  --wall-color: #f8fafc;
  --path-stroke: #3b82f6;
  --path-stroke-solved: #10b981;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #f1f5f9;
  --bg-input: #f8fafc;
  --text-main: #0f172a;
  --text-primary: #0f172a;
  --text-muted: #475569;
  --border-color: #e2e8f0;
  --accent-primary: #2563eb;
  --accent-hover: #1d4ed8;

  --cell-bg: #f8fafc;
  --cell-visited-bg: rgba(37, 99, 235, 0.1);
  --cell-border: #cbd5e1;
  --wall-color: #0f172a;
  --path-stroke: #2563eb;
  --path-stroke-solved: #059669;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-main);
  line-height: 1.5;
}

.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Quick bar */
.zip-badge-daily {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.14);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

[data-theme="light"] .zip-badge-daily {
  color: #1d4ed8;
}

.zip-timer-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.zip-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-pill {
  min-height: 40px;
  padding: 0 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-pill:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-pill.active {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-icon-sq {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-icon-sq:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Tarjeta principal */
.zip-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

[data-theme="light"] .zip-card {
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

.zip-practice-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.zip-practice-bar.visible {
  display: flex;
}

.zip-select {
  min-height: 40px;
  max-width: 100%;
  padding: 0 38px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.86rem;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px 15px;
  cursor: pointer;
}

[data-theme="light"] .zip-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.zip-select option {
  background: var(--bg-card);
  color: var(--text-main);
}

.zip-status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.zip-counters {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.zip-counter-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
}

.zip-rules-hint {
  font-size: 0.83rem;
  color: var(--text-muted);
}

/* Tablero contenedor con SVG superpuesto */
.zip-board-wrap {
  display: flex;
  justify-content: center;
  margin: 0.5rem auto 1.25rem;
  width: 100%;
}

.zip-board-stage {
  position: relative;
  width: min(100%, 440px);
  aspect-ratio: 1 / 1;
  border: 3px solid var(--wall-color);
  border-radius: 12px;
  overflow: hidden;
  background: var(--cell-bg);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

.zip-grid {
  display: grid;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

.zip-svg-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.zip-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--cell-border);
  cursor: pointer;
  background: transparent;
  transition: background-color 0.12s ease;
}

.zip-cell.is-visited {
  background: var(--cell-visited-bg);
}

.zip-cell.is-head {
  background: rgba(59, 130, 246, 0.26);
}

/* Muros entre casillas */
.zip-cell.wall-top { border-top: 4px solid var(--wall-color); }
.zip-cell.wall-right { border-right: 4px solid var(--wall-color); }
.zip-cell.wall-bottom { border-bottom: 4px solid var(--wall-color); }
.zip-cell.wall-left { border-left: 4px solid var(--wall-color); }

.zip-node {
  position: relative;
  z-index: 4;
  width: 58%;
  height: 58%;
  border-radius: 999px;
  background: #0f172a;
  color: #f8fafc;
  border: 2.5px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: clamp(0.85rem, 2.5vw, 1.15rem);
  font-weight: 800;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

[data-theme="light"] .zip-node {
  background: #0f172a;
  color: #ffffff;
  border-color: #ffffff;
}

.zip-node.is-reached {
  background: var(--path-stroke);
  border-color: #ffffff;
  transform: scale(1.06);
}

.zip-node.is-next {
  border-color: var(--accent-warm);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.32);
}

.zip-board-stage.is-solved .zip-node.is-reached {
  background: var(--path-stroke-solved);
}

.zip-bottom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.zip-action-btn {
  min-height: 42px;
  padding: 0 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.15s ease;
}

.zip-action-btn:hover:not(:disabled) {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.zip-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zip-action-btn.primary {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.zip-action-btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: #ffffff;
}

.zip-feedback-banner {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.88rem;
  display: none;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.zip-feedback-banner.visible { display: flex; }
.zip-feedback-banner.warn {
  border-color: rgba(245, 158, 11, 0.5);
  background: rgba(245, 158, 11, 0.12);
}
.zip-feedback-banner.hint {
  border-color: rgba(59, 130, 246, 0.5);
  background: rgba(59, 130, 246, 0.12);
}
.zip-feedback-banner.success {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.12);
}

/* Modales y toast */
.zip-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.zip-modal-backdrop.open { display: flex; }

.zip-modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  color: var(--text-main);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.zip-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.zip-modal-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
}

.zip-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-main);
  cursor: pointer;
}

.zip-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
  margin: 1rem 0 1.25rem;
}

.zip-stat-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.75rem 0.5rem;
  text-align: center;
}

.zip-stat-val {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent-primary);
}

.zip-stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.zip-share-preview {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: pre;
  overflow-x: auto;
  text-align: center;
  margin-bottom: 1rem;
}

.zip-modal-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.zip-modal-actions .zip-action-btn {
  flex: 1 1 140px;
}

.zip-countdown-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.zip-countdown-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-main);
}

.zip-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--accent-primary);
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  z-index: 1500;
  transition: all 0.2s ease;
}

.zip-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.zip-help-list {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.zip-help-list strong { color: var(--text-main); }

@media (max-width: 768px) {
  .zip-card { padding: 1rem; }
  .zip-quick-actions { width: 100%; justify-content: space-between; }
  .zip-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .zip-action-btn { flex: 1 1 calc(50% - 0.35rem); }
  .zip-practice-bar .zip-select,
  .zip-practice-bar .zip-action-btn { width: 100%; }
}
