:root {
  --bg-start: #bae6fd;
  --bg-end: #e0f2fe;
  --card-bg: #ffffff;
  --primary: #0284c7;
  --primary-light: #38bdf8;
  --accent: #f59e0b;
  --green: #16a34a;
  --green-light: #22c55e;
  --red: #ef4444;
  --text: #0f172a;
  --muted: #64748b;
  --border-color: #cbd5e1;
}

* {
  box-sizing: border-box;
  font-family: 'Fredoka', cursive, sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 12px;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(circle at top, var(--bg-start), var(--bg-end));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  overflow-x: hidden;
  position: relative;
}

/* BOTÓN SECRETO DESLIZANTE DEL CANDADO */
.secret-lock-btn {
  position: fixed;
  top: 16px;
  right: -70px;
  width: 48px;
  height: 48px;
  background: #0f172a;
  color: #facc15;
  border: 2px solid #e2e8f0;
  border-radius: 50%;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  opacity: 0;
  z-index: 90;
}

.secret-lock-btn.visible {
  transform: translateX(-86px);
  opacity: 1;
}

.container {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  border-radius: 24px;
  padding: 22px 18px;
  box-shadow: 0 10px 25px rgba(2, 132, 199, 0.12), 0 4px 0 #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

/* Cabecera */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Logo secreto (5 toques en 3s) */
.title {
  font-size: clamp(1.2rem, 5vw, 1.45rem);
  margin: 0;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.score-badge {
  background: #fef08a;
  border: 2px solid #facc15;
  color: #854d0e;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

/* Selector de dificultad dinámico */
.mode-selector {
  display: flex;
  gap: 6px;
  background: #f1f5f9;
  padding: 6px;
  border-radius: 16px;
  width: 100%;
}

.mode-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 4px;
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.2s ease;
  line-height: 1.1;
}

.mode-btn .sub-text {
  font-size: 0.72rem;
  opacity: 0.85;
}

.mode-btn .mult-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: #e2e8f0;
  padding: 1px 6px;
  border-radius: 6px;
  margin-top: 2px;
}

.mode-btn.active {
  background: var(--primary-light);
  color: white;
  box-shadow: 0 3px 0 var(--primary);
  transform: translateY(-1px);
}

.mode-btn.active .mult-badge {
  background: rgba(255, 255, 255, 0.28);
  color: white;
}

/* Temporizador */
.timer-container {
  width: 100%;
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.timer-bar {
  width: 100%;
  height: 100%;
  background: var(--green-light);
  border-radius: 999px;
  transition: width 0.1s linear, background-color 0.3s;
}

.timer-info {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 22px;
  text-align: center;
}

.bonus-tag {
  background: #fef3c7;
  color: #b45309;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.75rem;
  border: 1px solid #fcd34d;
}

/* Operación */
.math-card {
  background: #f8fafc;
  border: 3px dashed var(--border-color);
  border-radius: 20px;
  padding: 18px 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: clamp(2rem, 8vw, 2.7rem);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

/* Formulario */
.answer-form {
  display: flex;
  gap: 8px;
  width: 100%;
}

.answer-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  font-size: 1.5rem;
  text-align: center;
  border: 3px solid var(--border-color);
  border-radius: 16px;
  padding: 10px 8px;
  font-weight: 700;
  outline: none;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s;
}

.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.answer-input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.answer-input:focus {
  border-color: var(--primary-light);
}

.submit-btn {
  background: var(--green-light);
  color: white;
  border: none;
  border-radius: 16px;
  padding: 0 20px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--green);
  transition: transform 0.1s, box-shadow 0.1s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.submit-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--green);
}

/* Retroalimentación */
.feedback {
  min-height: 32px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
}

.feedback.success { color: var(--green); }
.feedback.warning { color: var(--accent); }
.feedback.error   { color: var(--red); }

/* MODALES BASE */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: 24px;
  width: 100%;
  max-width: 410px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 20px;
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.25);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popIn 0.2s ease-out;
}

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

.modal-title {
  font-size: 1.3rem;
  margin: 0;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.modal-subtitle {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}

.pin-input {
  font-size: 1.8rem;
  letter-spacing: 0.35em;
  text-align: center;
  border: 3px solid var(--border-color);
  border-radius: 14px;
  padding: 8px 12px;
  font-weight: 700;
  outline: none;
  width: 100%;
}

.pin-input:focus {
  border-color: var(--primary-light);
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.modal-btn {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.modal-btn:active {
  transform: scale(0.98);
}

.modal-btn.primary {
  background: var(--primary);
  color: white;
}

.modal-btn.secondary {
  background: #e2e8f0;
  color: var(--muted);
}

.modal-btn.danger {
  background: var(--red);
  color: white;
}

/* Modal de diálogo / confirmación sobrepuesto */
#dialogModal {
  z-index: 120;
}

/* Tarjetas de Ajustes por Modo */
.mode-settings-card {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.mode-settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.mode-settings-header input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.mode-settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.85rem;
}

.mode-settings-row label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--muted);
  font-weight: 600;
}

.setting-input, .setting-select {
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  outline: none;
  background: white;
}

.danger-action {
  background: #fee2e2;
  border: 2px solid #fecaca;
  color: #b91c1c;
  padding: 10px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  transition: background 0.15s;
}

.danger-action:hover {
  background: #fecaca;
}

.change-pin-box {
  border-top: 1px dashed var(--border-color);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.shake {
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}