/* =========================================================
   Rutinas Visuales CAA — estilos
   Mobile-first, táctil, minimalista, colores pastel
   ========================================================= */

:root {
  /* Paleta pastel suave */
  --bg: #FDF6EC;
  --bg-soft: #F4EFE4;
  --card-bg: #FFFFFF;
  --primary: #8FD3C7;
  --primary-dark: #5FB8A8;
  --accent: #FFC98B;
  --accent-2: #FFB3B3;
  --accent-3: #C6B8F0;
  --text: #3A3A3A;
  --text-soft: #6B6B6B;
  --success: #A9D8B8;
  --success-dark: #4CAF7D;
  --danger: #E88C8C;
  --danger-dark: #C85C5C;
  --shadow: 0 4px 14px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 22px;
  --radius-sm: 14px;
  --font: 'Nunito', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button, input {
  font-family: var(--font);
}

.hidden { display: none !important; }

/* ===================== PANTALLA BASE ===================== */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
}

/* ===================== PANTALLA HOME ===================== */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 20px 8px 20px;
}

.app-title {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 800;
  margin: 0;
  color: var(--text);
}

.btn-icon-corner {
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--bg-soft);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.6;
  transition: transform .15s ease, opacity .15s ease;
  touch-action: none;
  -webkit-touch-callout: none;
}
.btn-icon-corner:active {
  transform: scale(0.9);
  opacity: 1;
}
.btn-icon-corner.holding {
  transition: transform .9s ease, opacity .9s ease, background .9s ease;
  transform: scale(1.15);
  opacity: 1;
  background: var(--primary);
}

.routine-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  padding: 20px;
  align-content: start;
}

.routine-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: none;
  padding: 28px 20px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  color: var(--text);
}
.routine-card:active {
  transform: scale(0.96);
  box-shadow: var(--shadow-lg);
}
.routine-card .routine-icon {
  font-size: 4rem;
  line-height: 1;
}
.routine-card .routine-name {
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
}
.routine-card .routine-progress {
  font-size: 0.95rem;
  color: var(--text-soft);
  font-weight: 600;
}

.routine-card.color-0 { background: #FFF3E0; }
.routine-card.color-1 { background: #E3F4F1; }
.routine-card.color-2 { background: #F1EAFB; }
.routine-card.color-3 { background: #FFE9EC; }
.routine-card.color-4 { background: #EAF6E3; }

/* ===================== TABLERO DE RUTINA ===================== */
.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  gap: 8px;
}

.btn-back, .btn-reset {
  min-height: 60px;
  min-width: 60px;
  border: none;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  transition: transform .15s ease;
}
.btn-reset { padding: 0; width: 60px; font-size: 1.5rem; justify-content: center; }
.btn-back:active, .btn-reset:active { transform: scale(0.94); }

.board-title {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-weight: 800;
  margin: 0;
  text-align: center;
  flex: 1;
}

.task-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 18px;
  padding: 12px 20px 32px 20px;
  align-content: start;
}

.task-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 170px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  border: none;
  perspective: 800px;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, background .3s ease;
}

.task-card:active {
  transform: scale(0.95);
}

.task-card .task-icon {
  font-size: 3.4rem;
  line-height: 1;
  transition: transform .35s ease;
}

.task-card .task-name {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.task-card .task-check {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.6rem;
  opacity: 0;
  transform: scale(0.4);
  transition: all .3s ease;
}

/* Animación de "dar vuelta" al tocar */
.task-card.flipping {
  animation: flipCard .5s ease;
}
@keyframes flipCard {
  0%   { transform: rotateX(0deg) scale(1); }
  40%  { transform: rotateX(90deg) scale(0.9); }
  60%  { transform: rotateX(90deg) scale(0.9); }
  100% { transform: rotateX(0deg) scale(1); }
}

.task-card.done {
  background: linear-gradient(160deg, var(--success) 0%, #C7E8D0 100%);
}
.task-card.done .task-icon {
  transform: scale(1.05);
}
.task-card.done .task-check {
  opacity: 1;
  transform: scale(1);
}
.task-card.done .task-name::after {
  content: " · ¡Listo!";
  color: var(--success-dark);
  font-weight: 800;
}

/* ===================== CELEBRACIÓN ===================== */
.celebration {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.celebration.hidden { display: none; }

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.celebration-message {
  position: relative;
  background: rgba(255,255,255,0.95);
  border-radius: var(--radius);
  padding: 32px 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: popIn .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.celebration-emoji { font-size: 4rem; }
.celebration-text {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin-top: 8px;
}

/* ===================== MODO CONFIGURACIÓN ===================== */
#screen-settings { background: var(--bg); }
.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 40px 20px;
  -webkit-user-select: text;
  user-select: text;
}

.settings-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 14px 0;
}
.settings-panel-header h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.btn-pill {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-pill:active { transform: scale(0.96); }

.btn-back-small {
  min-height: 46px;
  border: none;
  background: transparent;
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
}

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manage-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.manage-item .manage-emoji {
  font-size: 1.8rem;
  min-width: 44px;
  text-align: center;
}

.manage-item .manage-label {
  flex: 1;
  font-weight: 700;
  font-size: 1.05rem;
}

.manage-item .manage-sub {
  font-size: 0.85rem;
  color: var(--text-soft);
  font-weight: 600;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: var(--bg-soft);
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.danger { background: #FBE4E4; color: var(--danger-dark); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  font-weight: 700;
}
.switch-row input[type="checkbox"] {
  width: 44px;
  height: 28px;
}

.edit-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.edit-row label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-soft);
}
.text-input, .emoji-input {
  min-height: 54px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--bg-soft);
  background: var(--card-bg);
  padding: 0 16px;
  font-size: 1.1rem;
  color: var(--text);
}
.emoji-input {
  width: 90px;
  text-align: center;
  font-size: 1.8rem;
}
.text-input:focus, .emoji-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---- Fotos reales (ícono con foto en vez de emoji) ---- */
.routine-icon.photo-visual,
.manage-emoji.photo-visual {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.manage-item .manage-emoji.photo-visual {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  min-width: 44px;
}
.task-icon.photo-visual {
  width: 74px;
  height: 74px;
  object-fit: cover;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.thumb-visual.photo-visual {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 10px;
}

.icon-photo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.danger-pill {
  background: #FBE4E4;
  color: var(--danger-dark);
}

.routine-photo-preview {
  margin-top: 10px;
}
.routine-photo-preview img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.task-manage-item {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.manage-item-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.manage-item-top .text-input {
  flex: 1;
  min-height: 48px;
}
.thumb-btn {
  border: none;
  background: var(--bg-soft);
  border-radius: 12px;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}
.thumb-btn:active { transform: scale(0.92); }

.manage-item-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.toolbar-spacer { flex: 1; }
.icon-btn.small {
  min-width: 40px;
  min-height: 40px;
  width: 40px;
  height: 40px;
  font-size: 0.95rem;
}
.icon-btn.small[data-action="remove-photo"],
.icon-btn.small.danger[aria-label="Quitar foto"] {
  width: auto;
  padding: 0 10px;
}

.edit-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}
.btn-primary, .btn-danger {
  flex: 1;
  min-height: 58px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: #FBE4E4; color: var(--danger-dark); }
.btn-primary:active, .btn-danger:active { transform: scale(0.97); }

/* Selector rápido de emoji */
.emoji-picker {
  position: fixed;
  inset: auto 16px 16px 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  z-index: 998;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}
.emoji-picker button {
  min-height: 48px;
  font-size: 1.6rem;
  border: none;
  background: var(--bg-soft);
  border-radius: 12px;
  cursor: pointer;
}
.emoji-picker button:active { transform: scale(0.9); }

/* ===================== RESPONSIVE: TABLET LANDSCAPE ===================== */
@media (min-width: 700px) {
  .routine-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
  .task-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .settings-body { max-width: 720px; margin: 0 auto; width: 100%; }
}

/* Evitar selección de texto accidental en modo niño, permitir en modo padre */
#screen-home, #screen-board {
  -webkit-user-select: none;
  user-select: none;
}
