: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: #f59e0b;
  --accent-hover: #d97706;
  --moon-accent: #60a5fa;
  --success: #10b981;
  --danger: #ef4444;
  --radius-lg: 16px;

  --cell-bg: #172136;
  --cell-fixed-bg: #1f2b44;
  --cell-border: #2a3956;
  --badge-bg: #0f172a;
  --badge-border: #3b4f73;
  --badge-text: #f8fafc;
}

[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: #d97706;
  --accent-hover: #b45309;
  --moon-accent: #2563eb;

  --cell-bg: #ffffff;
  --cell-fixed-bg: #e2e8f0;
  --cell-border: #cbd5e1;
  --badge-bg: #ffffff;
  --badge-border: #64748b;
  --badge-text: #0f172a;
}

*, *::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%;
}

.sl-badge-daily {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

[data-theme="light"] .sl-badge-daily { color: #b45309; }

.sl-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;
}

.sl-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(245, 158, 11, 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;
}

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

.sl-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"] .sl-card {
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

.sl-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;
}

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

.sl-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"] .sl-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");
}

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

.sl-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);
}

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

.sl-counter-val { font-family: var(--font-mono); font-weight: 700; color: var(--text-main); }
.sl-rules-hint { font-size: 0.83rem; color: var(--text-muted); }

/* Tablero con conectores superpuestos */
.sl-board-wrap {
  display: flex;
  justify-content: center;
  margin: 0.5rem auto 1.25rem;
  width: 100%;
}

.sl-board-stage {
  position: relative;
  width: min(100%, 440px);
  aspect-ratio: 1 / 1;
  border: 2.5px solid var(--cell-border);
  border-radius: 14px;
  overflow: visible;
  background: var(--cell-bg);
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.sl-grid {
  display: grid;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
}

.sl-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--cell-border);
  background: var(--cell-bg);
  cursor: pointer;
  padding: 0;
  transition: background-color 0.14s ease, transform 0.1s ease;
  outline: none;
}

.sl-cell:hover:not(.is-fixed) { filter: brightness(1.1); }
[data-theme="light"] .sl-cell:hover:not(.is-fixed) { background: #f1f5f9; }

.sl-cell.is-fixed {
  background: var(--cell-fixed-bg);
  cursor: default;
}

.sl-cell.is-fixed::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.55;
}

.sl-cell.is-conflict {
  box-shadow: inset 0 0 0 2.5px #ef4444;
  background: rgba(239, 68, 68, 0.15) !important;
}

.sl-symbol-svg {
  width: 56%;
  height: 56%;
  pointer-events: none;
  animation: symPop 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes symPop {
  0% { transform: scale(0.55); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

.sl-edges-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.sl-edge-badge {
  position: absolute;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: var(--badge-bg);
  border: 2px solid var(--badge-border);
  color: var(--badge-text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.sl-edge-badge.is-eq { color: #38bdf8; }
[data-theme="light"] .sl-edge-badge.is-eq { color: #0284c7; }
.sl-edge-badge.is-x { color: #fb7185; }
[data-theme="light"] .sl-edge-badge.is-x { color: #e11d48; }

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

.sl-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;
}

.sl-action-btn:hover:not(:disabled) { border-color: var(--accent-primary); color: var(--accent-primary); }
.sl-action-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.sl-action-btn.primary { background: var(--accent-primary); color: #0f172a; border-color: var(--accent-primary); font-weight: 700; }
.sl-action-btn.primary:hover:not(:disabled) { background: var(--accent-hover); color: #ffffff; }

.sl-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);
}

.sl-feedback-banner.visible { display: flex; }
.sl-feedback-banner.error { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.12); }
.sl-feedback-banner.hint { border-color: rgba(59, 130, 246, 0.5); background: rgba(59, 130, 246, 0.12); }
.sl-feedback-banner.success { border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.12); }

/* Modales */
.sl-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;
}

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

.sl-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);
}

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

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

.sl-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;
}

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

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

.sl-stat-val { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 800; color: var(--accent-primary); }
.sl-stat-lbl { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

.sl-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;
}

.sl-modal-actions { display: flex; gap: 0.65rem; flex-wrap: wrap; }
.sl-modal-actions .sl-action-btn { flex: 1 1 140px; }

.sl-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);
}

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

.sl-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;
  opacity: 0;
  pointer-events: none;
  z-index: 1500;
  transition: all 0.2s ease;
}

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

.sl-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);
}
.sl-help-list strong { color: var(--text-main); }

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