:root {
  --bg: #0e1116;
  --surface: #171c24;
  --surface-2: #1f2630;
  --border: #2a323d;
  --text: #e7edf3;
  --muted: #8b97a6;
  --accent: #4f8cff;
  --green: #2ecc71;
  --red: #ff5c5c;
  --amber: #ffb020;
  --radius: 14px;
  --nav-h: 64px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

a { color: var(--accent); }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

.screen { display: none; padding: 16px; }
.screen.active { display: block; }

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.center { text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---------- Botones ---------- */
button, .btn {
  font: inherit;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: .9rem; border-radius: 10px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }

/* ---------- Fichar ---------- */
.local-foto {
  width: 100%; height: 170px; object-fit: cover;
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2);
}
.hora-grande { font-size: 4rem; font-weight: 700; text-align: center; line-height: 1; margin: 12px 0 4px; letter-spacing: 1px; }
.estado-badge {
  text-align: center; padding: 10px; border-radius: 12px; margin: 8px 0 16px; font-weight: 600;
}
.estado-dentro { background: rgba(46,204,113,.12); color: var(--green); }
.estado-fuera { background: rgba(139,151,166,.12); color: var(--muted); }

.pic-btn {
  width: 100%; padding: 26px; font-size: 1.5rem; font-weight: 700; border-radius: 18px; margin-bottom: 18px;
}
.pic-entrada { background: var(--green); color: #05210f; }
.pic-salida { background: var(--red); color: #2a0606; }

.fichaje-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.fichaje-item:last-child { border-bottom: none; }
.tag { font-size: .8rem; padding: 3px 9px; border-radius: 20px; font-weight: 600; }
.tag-entrada { background: rgba(46,204,113,.15); color: var(--green); }
.tag-salida { background: rgba(255,92,92,.15); color: var(--red); }

/* ---------- Tareas ---------- */
.split { display: flex; flex-direction: column; gap: 0; }
.tareas-hoy { min-height: 40vh; }
.tarea-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.tarea-item:last-child { border-bottom: none; }
.tarea-check {
  width: 26px; height: 26px; min-width: 26px; border-radius: 50%;
  border: 2px solid var(--muted); background: transparent; padding: 0; margin-top: 2px;
}
.tarea-check.done { background: var(--green); border-color: var(--green); }
.tarea-body { flex: 1; }
.tarea-body .t-titulo { font-weight: 600; }
.tarea-body.done .t-titulo { text-decoration: line-through; color: var(--muted); }
.prio { width: 6px; align-self: stretch; border-radius: 4px; }
.prio-1 { background: var(--red); }
.prio-2 { background: var(--amber); }
.prio-3 { background: var(--muted); }
.estado-chip { font-size: .72rem; color: var(--muted); }
.privadas-aviso {
  margin-top: 12px; padding: 9px 12px; border-radius: 10px; font-size: .8rem;
  color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border);
}
.tag-atrasada {
  display: inline-block; margin-left: 8px; font-size: .68rem; font-weight: 600;
  color: var(--red); background: rgba(255,92,92,.13); padding: 1px 7px; border-radius: 20px; vertical-align: middle;
}
.tag-sinfecha {
  display: inline-block; margin-left: 8px; font-size: .68rem; font-weight: 600;
  color: var(--muted); background: rgba(139,151,166,.15); padding: 1px 7px; border-radius: 20px; vertical-align: middle;
}

/* ---------- Calendario ---------- */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .72rem; color: var(--muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: var(--surface-2); position: relative; font-size: .9rem; cursor: pointer;
}
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.today { outline: 2px solid var(--accent); }
.cal-day.selected { background: var(--accent); color: #fff; }
.cal-day .dot { position: absolute; bottom: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); }
.cal-day .dot.done { background: var(--green); }

/* ---------- Stats ---------- */
.stat-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.bars { display: flex; gap: 16px; align-items: flex-end; height: 160px; padding: 10px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 8px 8px 0 0; min-height: 4px; }
.bar-pend { background: var(--amber); }
.bar-prog { background: var(--accent); }
.bar-cump { background: var(--green); }
.bar-label { font-size: .75rem; color: var(--muted); }

/* Segmentado Día/Semana/Mes */
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; background: var(--surface-2); border-radius: 10px; padding: 9px 0; }
.seg button.active { background: var(--accent); color: #fff; }
.hor-turnos { padding: 4px 14px 10px; }
.turno { font-size: .85rem; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.turno:last-child { border-bottom: none; }

.meta { margin-bottom: 14px; }
.meta-top { display: flex; justify-content: space-between; margin-bottom: 6px; }
.progress { height: 12px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 8px; }

/* ---------- Juego match-3 ---------- */
.juego-hud {
  display: flex; justify-content: space-around; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px;
}
.juego-hud div { display: flex; flex-direction: column; gap: 2px; }
.juego-hud b { font-size: 1.3rem; }
.juego-hud .muted { font-size: .7rem; }
.juego-board {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 5px; touch-action: none;
}
.juego-board-wrap { position: relative; }
.celda {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; background: var(--surface-2); border-radius: 6px;
  cursor: pointer; user-select: none;
}
.celda.sel { outline: 3px solid var(--accent); transform: scale(.88); box-shadow: 0 0 10px rgba(79,140,255,.6); }
.celda.pop { animation: pop .22s ease-in forwards; }
.celda.caer { animation: caer .26s cubic-bezier(.34,1.3,.5,1) both; }
.celda.vacia { background: transparent; }
.celda.especial { animation: glow 1.1s ease-in-out infinite; z-index: 1; }
.celda.boom { animation: boom .34s ease-out forwards; z-index: 3; }
@keyframes pop {
  0% { transform: scale(1) rotate(0); }
  45% { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(.1) rotate(-12deg); opacity: 0; }
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 4px 1px rgba(255,210,90,.45); }
  50% { box-shadow: 0 0 13px 4px rgba(255,210,90,.95); }
}
@keyframes boom {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.45); filter: brightness(2.4); box-shadow: 0 0 18px 6px rgba(255,230,120,.9); }
  100% { transform: scale(.1); opacity: 0; filter: brightness(2.4); }
}
@keyframes caer {
  0% { transform: translateY(-46px) scale(.85); opacity: 0; }
  70% { opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Cartel de subida de nivel */
.levelup {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(14,17,22,.78); border-radius: var(--radius); z-index: 5;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.levelup.show { opacity: 1; }
.levelup-card {
  text-align: center; transform: scale(.6); transition: transform .35s cubic-bezier(.34,1.5,.5,1);
}
.levelup.show .levelup-card { transform: scale(1); }
.levelup .lu-emoji { font-size: 3.5rem; }
.levelup #luText { font-size: 1.4rem; font-weight: 700; color: var(--green); margin-top: 6px; }
.juego-msg { text-align: center; font-weight: 600; min-height: 1.4em; margin: 12px 0; color: var(--amber); }
.juego-poderes { display: flex; gap: 8px; margin-top: 10px; }
.juego-poderes button { flex: 1; }
#juegoPoder.armado { background: var(--amber); color: #2a1c00; border-color: var(--amber); font-weight: 700; }
#juegoArco.armado { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.rank-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.rank-row:last-child { border-bottom: none; }

/* ---------- Barra superior + menú ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.topbar-logo { width: 26px; height: 26px; border-radius: 7px; }
.topbar-menu { background: transparent; font-size: 1.4rem; padding: 2px 10px; line-height: 1; color: var(--text); }
.menu-dropdown {
  position: absolute; top: 50px; right: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 210px;
  display: none; flex-direction: column; gap: 2px; z-index: 60; box-shadow: 0 10px 28px rgba(0,0,0,.45);
}
.menu-dropdown.open { display: flex; }
.menu-dropdown button { background: transparent; text-align: left; padding: 12px; border-radius: 8px; font-size: .95rem; }
.menu-dropdown button:active { background: var(--surface); }

/* ---------- Nav inferior ---------- */
.nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; height: var(--nav-h);
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav button {
  flex: 1; background: transparent; border-radius: 0; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; padding: 8px 0;
}
.nav button.active { color: var(--accent); }
.nav .ico { font-size: 1.3rem; }
/* Botón central (Fichar) destacado, elevado en círculo */
.nav .nav-center .ico {
  width: 46px; height: 46px; border-radius: 50%; margin-top: -20px; margin-bottom: 1px;
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
  background: var(--accent); color: #fff; box-shadow: 0 5px 14px rgba(79,140,255,.45);
}
.nav .nav-center.active { color: var(--accent); }

/* ---------- Formularios / modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: 18px 18px 0 0; padding: 20px; max-height: 90vh; overflow-y: auto;
}
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; padding: 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---------- Login ---------- */
.login-wrap { max-width: 380px; margin: 0 auto; padding: 60px 20px; }
.login-logo-img { display: block; width: 96px; height: 96px; margin: 0 auto 12px; border-radius: 22px; }
.login-logo { text-align: center; font-size: 2rem; margin-bottom: 8px; }
.err { color: var(--red); font-size: .9rem; margin-top: 10px; min-height: 1.1em; }

/* ---------- Detalle de tarea ---------- */
.detalle-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.detalle h1 { word-break: break-word; }

.galeria { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.galeria .empty { grid-column: 1 / -1; }
.adj {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.adj img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; }
.adj .doc {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px; text-decoration: none; color: var(--text); font-size: .7rem; padding: 6px; text-align: center;
}
.adj .doc .ico { font-size: 1.6rem; }
.adj-badge {
  position: absolute; bottom: 4px; left: 4px; font-size: .8rem;
  background: rgba(0,0,0,.55); border-radius: 6px; padding: 0 3px; line-height: 1.4;
}
.adj .del {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; padding: 0;
  border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: .9rem; line-height: 1;
}

.nota {
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
}
.nota .nota-head { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-bottom: 4px; }
.nota .nota-del { background: transparent; color: var(--red); padding: 0 4px; font-size: .8rem; }
.nota .nota-texto { white-space: pre-wrap; word-break: break-word; }

/* ---------- Visor de imagen (con zoom y descripción) ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.95); display: none;
  flex-direction: column; z-index: 200;
}
.lightbox.open { display: flex; }
.lb-stage {
  flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center;
  touch-action: none; /* el zoom lo maneja el JS */
}
.lightbox img {
  max-width: 100%; max-height: 100%; border-radius: 6px;
  transform-origin: center center; transition: transform .05s linear; will-change: transform;
  user-select: none; -webkit-user-drag: none;
}
.lb-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.12);
  color: #fff; font-size: 1.1rem; line-height: 1; padding: 0;
}
.lb-caption {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--border);
}
.lb-caption #lbCaptionText { flex: 1; color: var(--text); white-space: pre-wrap; word-break: break-word; font-size: .9rem; }
.lb-caption #lbCaptionText.muted { color: var(--muted); }
.lb-hint { text-align: center; color: var(--muted); font-size: .7rem; padding: 4px 0 0; }

/* ---------- Visor tipo TikTok (swipe vertical entre fotos de una nota) ---------- */
.imgfeed {
  position: fixed; inset: 0; background: #000; display: none; z-index: 210;
}
.imgfeed.open { display: block; }
.imgfeed-scroll {
  height: 100%; overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.imgfeed-scroll::-webkit-scrollbar { display: none; }
.imgfeed-slide {
  height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative;
}
.imgfeed-slide img {
  max-width: 100%; max-height: 100%;
  user-select: none; -webkit-user-drag: none;
}
.imgfeed-slide .imgfeed-nombre {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  color: #fff; font-size: .85rem; text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  word-break: break-word;
}
.imgfeed-counter {
  position: absolute; top: 18px; left: 16px; z-index: 2;
  color: #fff; font-size: .85rem; background: rgba(255,255,255,.15);
  padding: 4px 10px; border-radius: 999px;
}

.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); padding: 12px 18px;
  border-radius: 12px; opacity: 0; transition: opacity .2s; z-index: 100; pointer-events: none;
}
.toast.show { opacity: 1; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
