:root {
  /* Palette KAKURO : bleu/gris puzzle (sobre, lisible) */
  --bg-dark: #0f1419;
  --bg-light: #fafbfc;
  --grid-dark: #1a2332;
  --grid-light: #f0f2f5;
  --cell-dark: #e8ecf1;
  --cell-light: #fafbfc;
  --text-dark: #f0f2f5;
  --text-light: #1a2332;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --success: #059669;
  --error: #dc2626;
  --muted: #6b7280;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--bg-light);
    --grid-bg: var(--grid-light);
    --text: var(--text-light);
    --panel: #ffffff;
    --panel-border: #e5e7eb;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --grid-bg: #1e2938;
    --text: var(--text-dark);
    --panel: #1a2332;
    --panel-border: #2d3e52;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 16px;
}

#wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel);
  color: var(--text);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  z-index: 100;
}

.back-hub {
  font-size: 24px;
  text-decoration: none;
  color: var(--text);
  background: rgba(37,99,235,0.1);
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.back-hub:hover {
  background: rgba(37,99,235,0.2);
}

.brand {
  font-size: 20px;
  font-weight: bold;
  flex: 1;
  text-align: center;
}

.brand b {
  color: var(--accent);
}

.hchips {
  display: flex;
  gap: 12px;
}

.hud {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  font-size: 14px;
  flex-wrap: wrap;
}

.chip {
  background: var(--grid-bg);
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 500;
  color: var(--text);
  border: 1px solid rgba(37,99,235,0.2);
}

.chip b {
  color: var(--accent);
  font-weight: 600;
}

.board-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

#canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

footer {
  padding: 12px 16px;
  background: rgba(0,0,0,0.1);
  font-size: 12px;
  text-align: center;
  border-top: 1px solid rgba(0,0,0,0.2);
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.card {
  background: var(--bg);
  border-radius: 12px;
  padding: 32px 24px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: slideUp 0.3s cubic-bezier(0.23, 1, 0.320, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.logo {
  font-size: 40px;
  font-weight: bold;
  margin-bottom: 8px;
}

.logo b {
  color: #e74c3c;
}

.sub {
  font-size: 14px;
  opacity: 0.7;
  margin-bottom: 24px;
}

.mode-select {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 20px 0;
}

.btn-ghost {
  background: var(--grid-bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.btn-ghost:hover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.05);
  transform: translateY(-1px);
}

.btn-ghost.active {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  margin: 12px 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.big {
  font-size: 48px;
  font-weight: bold;
  color: var(--success);
  margin: 24px 0;
}

#over-time {
  font-size: 14px;
  opacity: 0.7;
  margin-bottom: 20px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
}

.toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
  justify-content: center;
}

.tool-btn {
  background: var(--grid-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 16px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.tool-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(37,99,235,0.05);
  transform: translateY(-1px);
}

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

.tool-btn .ico {
  font-size: 18px;
}

.tool-btn .cost {
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
}

.tool-btn.insufficient {
  border-color: var(--error);
  background: rgba(220,38,38,0.05);
}

@media (max-width: 480px) {
  .card {
    padding: 20px 16px;
    margin: 16px;
  }

  header {
    padding: 10px 12px;
  }

  .hud {
    font-size: 13px;
    gap: 8px;
    padding: 6px 12px;
  }

  .toolbar {
    gap: 6px;
    padding: 6px 12px;
  }

  .tool-btn {
    padding: 6px 12px;
    font-size: 12px;
  }
}
