/* ===== CSS CUSTOM PROPERTIES ===== */
:root {
  --navy:  #0B214A;
  --turq:  #00E6BC;
  --lime:  #04FFB4;
  --mint:  #C5FFDF;
  --lemon: #FFFFAB;
  --rojo:  #E74C3C;
  --white: #FFFFFF;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Baloo 2', cursive;
  background: var(--navy);
  color: var(--white);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html.results { overflow-y: auto; }
html.results body { overflow-y: auto; height: auto; min-height: 100%; }

/* ===== WRAPPER ===== */
body {
  max-width: 430px;
  margin: 0 auto;
  position: relative;
}

/* ===== SCREENS ===== */
.screen { display: none; width: 100%; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ===== INTRO ===== */
#intro {
  align-items: center;
  justify-content: center;
  padding: 20px 20px;
  padding-top: calc(max(var(--safe-top), 16px) + 8px);
  background: var(--navy);
  background-image: url('assets/bg_cocina.jpg');
  background-size: cover;
  background-position: center top;
}

#intro::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(11,33,74,0.72);
  z-index: 0;
}

#intro .intro-wrap { position: relative; z-index: 1; }

.intro-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 340px;
}

.intro-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--white);
  text-align: center;
  line-height: 1.1;
}

.intro-subtitle {
  font-size: 16px;
  font-weight: 600;
  color: var(--turq);
  text-align: center;
}

.intro-avatar {
  width: 180px;
  height: auto;
  max-height: 230px;
  object-fit: contain;
}

/* ===== SPEECH BUBBLE ===== */
.speech-bubble {
  background: #1F3A5C;
  border-radius: 12px;
  border-bottom-right-radius: 4px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.5;
  width: 100%;
  max-width: 320px;
  text-align: left;
}

/* ===== HOWTO ===== */
#howto {
  align-items: center;
  justify-content: center;
  padding: 20px 20px;
  padding-top: calc(max(var(--safe-top), 16px) + 8px);
}

.howto-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 340px;
}

.howto-avatar {
  width: 180px;
  height: auto;
  max-height: 230px;
  object-fit: contain;
}

.howto-slides { width: 100%; }

.howto-slide { display: none; }
.howto-slide.active { display: block; animation: popIn 0.25s ease-out; }

.howto-num-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--turq);
  opacity: 0.8;
  margin-bottom: 6px;
}

.howto-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--turq);
  margin-bottom: 8px;
}

.howto-text {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.9;
}

.howto-text strong { color: var(--turq); }

.howto-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: background 0.2s;
  cursor: pointer;
}

.dot.active { background: var(--turq); }

/* ===== CTA BUTTON ===== */
.cta {
  display: block;
  width: 100%;
  max-width: 300px;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  background: var(--turq);
  color: var(--navy);
  font-family: 'Baloo 2', cursive;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  text-align: center;
}

.cta:active { transform: scale(0.96); opacity: 0.9; }
.cta-sm { font-size: 15px; padding: 10px 20px; }

/* ===== HUD ===== */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  padding-top: calc(max(var(--safe-top), 16px) + 8px);
  padding-right: 66px;
  height: calc(48px + max(var(--safe-top), 16px));
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
  position: relative;
  flex-shrink: 0;
}

.hud-lives {
  display: flex;
  gap: 4px;
  align-items: center;
}

.life-icon {
  width: 22px; height: 22px;
  fill: var(--rojo);
  transition: opacity 0.3s;
}

.life-icon.lost { opacity: 0.25; }

.hud-round {
  font-size: 13px;
  font-weight: 700;
  color: var(--lemon);
}

.hud-hint {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--turq);
  background: transparent;
  color: var(--turq);
  font-family: 'Baloo 2', cursive;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* ===== MACA HEADER (fase material) ===== */
.maca-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 16px 4px;
  flex-shrink: 0;
  z-index: 5;
  animation: slideDown 0.3s ease-out;
}

.maca-header.hidden { display: none; }

.maca-header-avatar {
  width: 90px;
  height: auto;
  max-height: 120px;
  object-fit: contain;
  flex-shrink: 0;
}

.maca-header-bubble {
  flex: 1;
  background: #1F3A5C;
  border-radius: 12px;
  border-top-left-radius: 4px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  align-self: center;
}

/* ===== CONTEXT CARD (legacy, kept for safety) ===== */
.context-card {
  margin: 0 16px 8px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  border-left: 3px solid var(--turq);
  font-size: 13px;
  line-height: 1.4;
  flex-shrink: 0;
  animation: slideDown 0.3s ease-out;
  z-index: 5;
}

.context-card.hidden { display: none; }

/* ===== GAMEPLAY BACKGROUND ===== */
#play {
  background: var(--navy);
  background-image: url('assets/bg_cocina.jpg');
  background-size: cover;
  background-position: center top;
  position: relative;
}

#play::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(11,33,74,0.78);
  z-index: 0;
  pointer-events: none;
}

#play > * { position: relative; z-index: 1; }

/* ===== PLAY AREA ===== */
.play-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  z-index: 10;
  padding: 0 16px;
}

/* ===== INSTRUCTION BANNER ===== */
.instruction-banner {
  text-align: center;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--lemon);
  background: rgba(11,33,74,0.8);
  flex-shrink: 0;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  width: 100%;
  box-sizing: border-box;
}

.instruction-banner:empty { display: none; }

/* ===== MATERIAL TRAY ===== */
.material-tray {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 12px;
  padding-bottom: 80px; /* clear live-bar */
  flex-shrink: 0;
  z-index: 10;
}

.material-tray.hidden { display: none; }

.material-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(255,255,255,0.07);
  color: var(--white);
  font-family: 'Baloo 2', cursive;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  width: 100%;
}

.material-btn:active { background: rgba(255,255,255,0.15); }

.material-btn.wrong {
  border-color: var(--rojo);
  border-width: 1px;
  background: rgba(231,76,60,0.15);
  animation: shake 0.3s ease;
}

.material-img {
  flex: 1;
  height: 32px;
  object-fit: contain;
  min-width: 0;
}

.material-label {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  width: 80px;
  text-align: right;
}

/* ===== CONFIRM BUTTON ===== */
.btn-confirm {
  display: block;
  width: calc(100% - 32px);
  max-width: 300px;
  margin: 8px auto;
  margin-bottom: 80px;
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  background: var(--turq);
  color: var(--navy);
  font-family: 'Baloo 2', cursive;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  flex-shrink: 0;
  z-index: 40;
}

.btn-confirm.disabled {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.3);
  cursor: not-allowed;
}

.btn-confirm:not(.disabled):active { transform: scale(0.96); }

.btn-confirm.hidden { display: none; }

/* ===== PIPE / ACCESSORY (built via JS) ===== */
.pipe-img {
  position: absolute;
  touch-action: none;
  cursor: grab;
  z-index: 20;
  transition: none;
}

.pipe-img.snapping {
  transition: left 0.2s ease-out, top 0.2s ease-out;
}

.pipe-img.dragging { z-index: 500; cursor: grabbing; }

.accessory-img {
  position: absolute;
  z-index: 10;
}

/* ===== BUBBLE LEVEL ===== */
.bubble-level {
  position: absolute;
  z-index: 30;
  pointer-events: none;
}

/* ===== CHARACTER AREA ===== */
.char-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  flex-shrink: 0;
  position: relative;
  z-index: 50;
  min-height: 60px;
}

.char-area.hidden { display: none; }

.char-avatar {
  width: clamp(70px, 18vw, 100px);
  height: auto;
  max-height: 130px;
  object-fit: contain;
  flex-shrink: 0;
  transition: transform 0.3s;
}

.char-avatar.prominent {
  transform: scale(1.05);
}

.char-bubble {
  flex: 1;
  background: #1F3A5C;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.2s;
  margin-bottom: 8px;
}

.char-bubble.visible { opacity: 1; }

/* ===== EMOJI RAIN ===== */
.emoji-rain {
  position: fixed;
  left: 16px;
  bottom: 96px; /* same baseline as live-comments */
  width: 160px;
  height: 200px;
  pointer-events: none;
  z-index: 160;
  overflow: hidden;
}

.emoji-float {
  position: absolute;
  bottom: 0;
  font-size: 22px;
  animation: floatUp 1.2s ease-in forwards;
}


/* ===== LIVE BAR (barra inferior estilo Instagram Live) ===== */
.live-bar {
  position: fixed;
  bottom: 25px;
  left: 50%; transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 406px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 28px;
  padding: 6px 10px 6px 6px;
  pointer-events: none;
  z-index: 95;
}

.live-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-bar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.live-bar-info {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.live-bar-name {
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.live-bar-badge {
  background: var(--rojo);
  color: #fff;
  font-family: 'Baloo 2', cursive;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.live-bar-viewers {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.live-bar-eye { font-size: 13px; }

/* Comments during gameplay — sits above live-bar, never overlaps it */
.live-comments {
  position: fixed;
  left: 16px;
  bottom: 96px; /* live-bar(25px) + bar-height(46px) + gap(25px) */
  max-width: 220px;
  pointer-events: none;
  z-index: 155;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.live-comment {
  font-family: 'Baloo 2', cursive;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.65);
  border-radius: 8px;
  padding: 3px 10px 3px 12px;
  animation: slideInLeft 0.3s ease-out;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.live-comment strong { color: #fff; font-weight: 800; }

/* ===== DIRECTO PANEL (error overlay — Instagram Live style) ===== */
.directo-panel {
  display: none;
  position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px;
  bottom: 0;
  background: #000;
  z-index: 200;
  flex-direction: column;
  overflow: hidden;
}

.directo-panel.active { display: flex; }

.directo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(max(var(--safe-top), 16px) + 8px);
  background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
}

.directo-badge {
  background: var(--rojo);
  color: #fff;
  font-family: 'Baloo 2', cursive;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.directo-viewers {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.5);
  border-radius: 12px;
  padding: 3px 10px;
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.directo-eye { font-size: 12px; }

.directo-body {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 60px 16px 12px;
  position: relative;
}

.directo-avatar {
  width: 160px;
  height: auto;
  max-height: 210px;
  object-fit: contain;
  flex-shrink: 0;
  animation: popIn 0.3s ease-out;
}

.directo-edu {
  flex: 1;
  background: rgba(255,255,255,0.95);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--navy);
  align-self: center;
  max-height: 280px;
  overflow-y: auto;
}

/* reuse overlay-body label styles inside directo-edu */
.directo-edu .edu-label {
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--rojo);
  margin-top: 8px;
  margin-bottom: 2px;
  display: block;
}
.directo-edu .edu-rule { font-weight: 700; color: var(--navy); }
.directo-edu .edu-action { color: #555; }

/* Floating reactions column (right side) */
.directo-reactions {
  position: absolute;
  right: 12px;
  bottom: 80px;
  width: 44px;
  pointer-events: none;
  z-index: 20;
}

.directo-reaction {
  position: absolute;
  right: 0;
  font-size: 26px;
  animation: reactFloat 1.8s ease-out forwards;
}

@keyframes reactFloat {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  60%  { opacity: 1; transform: translateY(-100px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-180px) scale(0.8); }
}

/* Comments strip */
.directo-comments {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 4px 4px;
  max-height: 60px;
  overflow: hidden;
}

.directo-comment {
  font-family: 'Baloo 2', cursive;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  animation: slideInLeft 0.3s ease-out;
}

.directo-comment strong {
  color: var(--turq);
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Footer */
.directo-footer {
  padding: 8px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.directo-btn {
  max-width: none;
  width: 100%;
  background: var(--turq);
  color: var(--navy);
}

/* Follower drop counter */
.directo-followers {
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  text-align: center;
}
.directo-followers .drop {
  color: var(--rojo);
  font-weight: 700;
}

/* ===== ROUND TRANSITION OVERLAY ===== */
.round-transition {
  display: none;
  position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px;
  bottom: 0;
  background: rgba(11,33,74,0.88);
  z-index: 190;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
}

.round-transition.active { display: flex; }

.rt-avatar {
  width: 180px;
  height: auto;
  max-height: 240px;
  object-fit: contain;
  animation: popIn 0.3s ease-out;
}

.rt-avatar.big {
  width: 240px;
  max-height: 320px;
}

.rt-bubble {
  background: #1F3A5C;
  border-radius: 16px;
  padding: 16px 20px;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
  max-width: 320px;
  color: #fff;
  animation: popIn 0.3s ease-out 0.1s both;
}

/* ===== OVERLAYS (hints, failed — kept for non-edu overlays) ===== */
.overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(11,33,74,0.88);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  max-width: 430px;
  margin: 0 auto;
}

.overlay.active { display: flex; }

.overlay-card {
  background: var(--white);
  border-radius: 16px;
  padding: 24px 20px;
  max-width: 340px;
  width: 100%;
  color: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: popIn 0.25s ease-out;
}

.overlay-avatar {
  width: 80px; height: auto;
  max-height: 105px;
  object-fit: contain;
}

.overlay-body { font-size: 13px; line-height: 1.5; width: 100%; }
.overlay-body .edu-label {
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--rojo);
  margin-top: 8px;
  margin-bottom: 2px;
  display: block;
}
.overlay-body .edu-rule { font-weight: 700; color: var(--navy); }
.overlay-body .edu-action { color: #555; }

/* Hints overlay */
.hints-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--navy);
  text-align: center;
}

.hints-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.hint-item {
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 12px;
  background: rgba(11,33,74,0.06);
  border-radius: 8px;
  border-left: 3px solid var(--turq);
}

/* Failed overlay */
.overlay-failed-msg {
  font-size: 15px;
  text-align: center;
  line-height: 1.5;
  color: var(--navy);
}

/* ===== RESULTS ===== */
#results {
  align-items: center;
  padding: 40px 20px;
  padding-top: calc(40px + max(var(--safe-top), 16px));
  padding-bottom: calc(40px + var(--safe-bottom));
  background: var(--navy);
  background-image: url('assets/bg_cocina_resultado.png');
  background-size: cover;
  background-position: center top;
  position: relative;
}

#results::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(11,33,74,0.80);
  z-index: 0;
}

#results .results-wrap { position: relative; z-index: 1; }

.results-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 340px;
}

.results-avatar {
  width: 180px;
  height: auto;
  max-height: 230px;
  object-fit: contain;
}

.results-avatar.celebrating { animation: celebrate 0.6s ease-in-out 3; }

.results-score {
  font-size: 48px;
  font-weight: 800;
  color: var(--turq);
  line-height: 1;
}

.results-record {
  font-size: 14px;
  opacity: 0.6;
  text-align: center;
}

.results-record.new-record {
  color: var(--lemon);
  opacity: 1;
  animation: pulse 0.6s ease-in-out 3;
}

/* Chunked progress bar */
.results-progress {
  display: flex;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.progress-chunk {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: rgba(231,76,60,0.35);
  max-width: 48px;
  transition: background 0.3s;
}

.progress-chunk.ok { background: var(--turq); }

.results-bubble {
  width: 100%;
  max-width: 320px;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 12px;
}

/* ===== KEYFRAMES ===== */
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

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

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.05); }
}

@keyframes celebrate {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25%       { transform: scale(1.1) rotate(-5deg); }
  75%       { transform: scale(1.1) rotate(5deg); }
}

@keyframes floatUp {
  0%   { transform: translateY(0);    opacity: 1; }
  100% { transform: translateY(-180px); opacity: 0; }
}

@keyframes flashTurq {
  0%, 100% { filter: none; }
  50%       { filter: drop-shadow(0 0 8px var(--turq)); }
}

/* ===== RESPONSIVE ===== */
@media (max-height: 700px) {
  .intro-avatar { width: 130px; }
  .context-card { padding: 8px 12px; font-size: 12px; }
  .material-btn { padding: 8px 12px; font-size: 13px; }
  .char-avatar { max-height: 90px; }
  .char-bubble { font-size: 12px; }
}

@media (max-height: 580px) {
  .intro-avatar { width: 100px; }
  .howto-avatar { width: 70px; }
  .char-area { padding: 4px 12px; }
}
