/* Timer visual (scripts/features/utilities/timer.js). A cena do macaco segue o projeto original. */

/* Cartões da página de ajustes (servem também para os próximos utilitários). */
.utility-card {
  display: grid;
  gap: 6px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid #dce9f2;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 6px 0 #e3eef6, 0 16px 34px rgba(32, 71, 98, 0.08);
}

.utility-card h3 {
  margin: 0;
  color: #172033;
  font-size: 1.25rem;
  font-weight: 900;
}

.utility-hint {
  margin: 0;
  color: #64748b;
  font-size: 0.92rem;
  font-weight: 700;
}

.timer-settings-page {
  display: grid;
  gap: clamp(14px, 2.4vh, 22px);
}

/* iPad deitado: Tempo e Bananas lado a lado, para o "Começar" caber na tela sem rolar. */
@media (min-width: 900px) and (orientation: landscape) {
  .timer-settings-page {
    grid-template-columns: 1.25fr 1fr;
    align-items: start;
  }

  .timer-start-row,
  .timer-settings-head {
    grid-column: 1 / -1;
  }

  /* Timers sem bananas: só o cartão do tempo. */
  .timer-settings-page.is-single {
    grid-template-columns: minmax(0, 1fr);
  }

  .timer-pill {
    min-width: 66px;
    min-height: 50px;
    padding: 0 13px;
  }
}

.timer-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.timer-pill {
  min-width: 74px;
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  border: 2px solid #dce9f2;
  border-radius: 999px;
  background: #f6fbff;
  color: #1f2f44;
  font: inherit;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
}

.timer-pill img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.timer-pill.is-selected {
  border-color: var(--app-blue, #1ca7f2);
  background: var(--app-blue, #1ca7f2);
  color: #ffffff;
  box-shadow: inset 0 -4px 0 var(--app-blue-dark, #0f78b5);
}

.timer-pill.is-banana.is-selected {
  border-color: #f2b705;
  background: #ffd23f;
  color: #4a3500;
  box-shadow: inset 0 -4px 0 #e0a800;
}

.timer-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
}

.timer-custom label {
  display: grid;
  gap: 6px;
  color: #475569;
  font-size: 0.85rem;
  font-weight: 800;
}

.timer-custom input {
  width: 150px;
  min-height: 50px;
  padding: 0 14px;
  border: 2px solid #dce9f2;
  border-radius: 14px;
  background: #ffffff;
  color: #172033;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
}

.timer-start-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.timer-start {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 0 30px;
  border-radius: 18px;
  font-size: 1.2rem;
}

.timer-start svg {
  width: 22px;
  height: 22px;
}

/* Sessão em tela cheia: a cena marrom do macaco por cima de todo o app. */
body.timer-session-open {
  overflow: hidden;
}

.timer-session {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #b49871;
  color: #47392b;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.timer-session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 24px 12px;
}

.timer-clock {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.timer-round-button {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(71, 57, 43, 0.2);
  color: #47392b;
  cursor: pointer;
}

.timer-round-button.is-big {
  width: 72px;
  height: 72px;
}

.timer-round-button svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.timer-round-button:disabled {
  opacity: 0.35;
}

.timer-stage {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 18px 16px 120px;
  overflow: hidden;
}

.timer-banana-grid {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: var(--banana-gap, 10px);
  width: min(94vw, 1080px);
  padding: 18px 20px 18px var(--monkey-space, 125px);
}

.timer-banana-slot {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: end center;
  width: var(--slot-size, 86px);
  height: calc(var(--slot-size, 86px) + 18px);
}

.timer-banana {
  position: relative;
  z-index: 2;
  width: var(--banana-size, 75px);
  height: var(--banana-size, 75px);
  object-fit: contain;
  filter: drop-shadow(0 9px 7px rgba(72, 52, 28, 0.18));
  transition: transform 120ms linear;
}

.timer-banana-slot.is-peel .timer-banana {
  z-index: 1;
  transform: translateY(7px) rotate(-2deg) scale(0.92);
}

.timer-banana-slot.is-eating .timer-banana {
  transform: translate(8px, 2px) scale(1.12);
}

.timer-monkey {
  position: absolute;
  z-index: 5;
  bottom: 0;
  left: 0;
  width: var(--monkey-size, 145px);
  height: var(--monkey-size, 145px);
  object-fit: contain;
  transform: translateX(-78%);
  filter: drop-shadow(0 12px 9px rgba(72, 52, 28, 0.22));
}

.timer-monkey.is-chewing {
  animation: timer-monkey-chew 460ms ease-in-out infinite;
}

.timer-controls {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 8;
  display: flex;
  gap: 14px;
  transform: translateX(-50%);
}

.timer-celebration {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 330px;
}

.timer-celebration-monkey {
  position: relative;
  z-index: 3;
  width: min(48vw, 280px);
  animation: timer-final-pop 900ms cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.timer-celebration-monkey img {
  display: block;
  width: 100%;
}

.timer-crown {
  position: absolute;
  top: -6%;
  left: 53%;
  z-index: 5;
  width: 45%;
  transform: translateX(-50%);
  animation: timer-crown-drop 750ms ease-out both;
}

.timer-firework {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #ffffff;
  animation: timer-firework 1.25s ease-out infinite;
}

.timer-firework:nth-child(1) { left: 27%; top: 29%; }
.timer-firework:nth-child(2) { left: 72%; top: 32%; animation-delay: 280ms; }
.timer-firework:nth-child(3) { left: 50%; top: 17%; animation-delay: 520ms; }

@keyframes timer-monkey-chew {
  0%, 100% { transform: translateX(-78%) translateY(0) scale(1); }
  35% { transform: translateX(-78%) translateY(-2px) scale(1.01, 0.99); }
  70% { transform: translateX(-78%) translateY(1px) scale(0.99, 1.01); }
}

@keyframes timer-final-pop {
  0% { transform: translateY(12px) scale(0.82); opacity: 0; }
  58% { transform: translateY(-8px) scale(1.22); opacity: 1; }
  100% { transform: translateY(0) scale(1.08); opacity: 1; }
}

@keyframes timer-crown-drop {
  0% { transform: translate(-50%, -55px) scale(0.7); opacity: 0; }
  70% { transform: translate(-50%, 2px) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

@keyframes timer-firework {
  0% { opacity: 0; box-shadow: 0 0 #fff4b0, 0 0 #f6c945, 0 0 #fff, 0 0 #ff8fc1; transform: scale(0.2); }
  25% { opacity: 1; }
  100% { opacity: 0; box-shadow: 0 -48px #fff4b0, 42px -22px #f6c945, 36px 34px #fff, -38px 32px #ff8fc1, -42px -22px #fff; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .timer-monkey.is-chewing,
  .timer-firework { animation: none; }
}

/* ---------- Tela inicial: um círculo por timer ---------- */
.timer-chooser {
  display: grid;
  justify-items: center;
  gap: clamp(16px, 3vh, 28px);
  padding: clamp(8px, 3vh, 32px) 0;
}

.timer-chooser h3 {
  margin: 0;
  color: #172033;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 900;
}

.timer-chooser-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(16px, 3vw, 36px);
  width: min(100%, 980px);
}

.timer-choice {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #172033;
  font: inherit;
  cursor: pointer;
}

.timer-choice-circle {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(130px, 18vw, 200px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 6px solid var(--choice-color, #1ca7f2);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--choice-color, #1ca7f2) 35%, #ffffff), 0 18px 34px rgba(32, 71, 98, 0.14);
  transition: transform 140ms ease;
}

.timer-choice:active .timer-choice-circle {
  transform: scale(0.96);
}

.timer-choice-circle img {
  width: 82%;
  height: 82%;
  object-fit: contain;
}

.timer-choice-circle svg {
  width: 70%;
  height: 70%;
}

.timer-choice strong {
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  font-weight: 900;
  text-align: center;
}

.timer-choice.is-last strong::after {
  content: " ✓";
  color: var(--choice-color, #1ca7f2);
}

.timer-settings-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.timer-settings-head .ghost-button {
  min-height: 48px;
  padding: 0 16px;
}

.timer-choice-circle.is-small {
  width: 56px;
  border-width: 3px;
  box-shadow: none;
}

.timer-settings-head strong {
  color: #172033;
  font-size: 1.3rem;
  font-weight: 900;
}

@media (orientation: portrait) {
  .timer-chooser-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(100%, 560px);
  }

  .timer-choice-circle {
    width: clamp(150px, 30vw, 220px);
  }
}

/* ---------- Sessão dos timers desenhados ---------- */
.timer-session.style-ovo { background: linear-gradient(180deg, #fff3e6, #ffe0c2); }
.timer-session.style-relogio { background: linear-gradient(180deg, #e8f7ff, #cdeefe); }
.timer-session.style-ampulheta { background: linear-gradient(180deg, #f2ecff, #ddd2ff); }

.timer-session:not(.style-macaco) .timer-clock {
  color: #1f2a3a;
}

.timer-visual-wrap {
  display: grid;
  justify-items: center;
  gap: 10px;
}

.timer-visual {
  display: block;
  width: auto;
  height: min(62dvh, 560px);
  max-width: 86vw;
  overflow: visible;
}

.timer-visual-done {
  margin: 0;
  color: #1f2a3a;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 900;
  animation: timer-pop 520ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes timer-pop {
  from { opacity: 0; transform: scale(0.6); }
}

/* Ovo: a superfície do líquido balança; perto do fim o ovo treme e cai um pedacinho da casca. */
.egg-wave {
  animation: egg-wave 2.4s linear infinite;
}

.egg-wave.is-back {
  animation-duration: 3.4s;
}

@keyframes egg-wave {
  to { transform: translateX(300px); }
}

.egg-wave.is-back {
  animation-name: egg-wave-back;
}

@keyframes egg-wave-back {
  from { transform: translate(-75px, -6px); }
  to { transform: translate(225px, -6px); }
}

.egg-body {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.egg-visual.is-wobbling .egg-body {
  animation: egg-wobble 1.6s ease-in-out infinite;
}

@keyframes egg-wobble {
  0%, 60%, 100% { transform: rotate(0); }
  68% { transform: rotate(-4deg); }
  76% { transform: rotate(4deg); }
  84% { transform: rotate(-3deg); }
  92% { transform: rotate(2deg); }
}

.egg-chip {
  opacity: 0;
}

.egg-visual.is-chipped .egg-chip {
  animation: egg-chip-fall 1.2s ease-in forwards;
}

@keyframes egg-chip-fall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(40px, 210px) rotate(120deg); }
}

.egg-visual.is-hatched .egg-top-shell {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: egg-top-off 900ms cubic-bezier(0.3, 1.3, 0.5, 1) forwards;
}

@keyframes egg-top-off {
  to { transform: translate(60px, -40px) rotate(30deg) scale(0.75); }
}

.egg-visual.is-hatched .egg-chick {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: egg-chick-up 900ms 250ms cubic-bezier(0.2, 1.5, 0.4, 1) both, egg-chick-hop 1.2s 1.2s ease-in-out infinite;
}

@keyframes egg-chick-up {
  from { transform: translateY(40px) scale(0.7); }
  to { transform: translateY(-96px) scale(1); }
}

@keyframes egg-chick-hop {
  0%, 100% { transform: translateY(-96px); }
  50% { transform: translateY(-114px); }
}

/* Relógio: no fim o despertador toca (balança). */
.clock-visual.is-ringing {
  animation: clock-ring 0.5s ease-in-out 6;
  transform-origin: 50% 60%;
}

@keyframes clock-ring {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}

/* Ampulheta: grãos descendo; no fim, estrelas saem dela. */
.hourglass-stream {
  animation: hourglass-fall 0.5s linear infinite;
}

@keyframes hourglass-fall {
  to { stroke-dashoffset: -11; }
}

.hourglass-finish {
  position: relative;
  display: grid;
  place-items: center;
}

.hourglass-star {
  position: absolute;
  top: 50%;
  left: 50%;
  color: #ffc93c;
  font-size: clamp(2rem, 5vw, 3.4rem);
  text-shadow: 0 2px 0 #d97706;
  opacity: 0;
  animation: hourglass-star 1.6s var(--delay) ease-out forwards;
}

@keyframes hourglass-star {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--angle)) translateY(0) scale(0.4); }
  30% { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(var(--angle)) translateY(-34vmin) rotate(calc(var(--angle) * -1)) scale(1.1); }
}

/* Pausado: as animações param junto com o tempo. */
.timer-visual.is-paused,
.timer-visual.is-paused * {
  animation-play-state: paused !important;
}

@media (prefers-reduced-motion: reduce) {
  .egg-wave, .hourglass-stream, .egg-visual.is-wobbling .egg-body { animation: none; }
}

/* Botões do topo do timer: fechar e minimizar. */
.timer-header-buttons {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Timer minimizado: some a tela e fica o selo no canto (o tempo continua contando). */
.timer-session.is-minimized {
  display: none;
}

.timer-mini {
  position: fixed;
  z-index: 350;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 18px 6px 6px;
  border: 4px solid #fff;
  border-radius: 999px;
  background: var(--mini-color, #f0a20b);
  color: #fff;
  font: inherit;
  font-size: 1.45rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(20, 24, 40, 0.3);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  animation: timerMiniIn 0.3s ease;
}

.timer-mini-thumb {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  overflow: hidden;
  border-radius: 50%;
  background: #fff;
}

.timer-mini-thumb img,
.timer-mini-thumb svg {
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
}

.timer-mini.is-paused {
  filter: saturate(0.4);
}

.timer-mini.is-paused .timer-mini-clock::after {
  content: " ❚❚";
  font-size: 0.7em;
}

/* Últimos 10 segundos: o selo pulsa de leve. */
.timer-mini.is-ending {
  animation: timerMiniPulse 1s ease-in-out infinite;
}

@keyframes timerMiniIn {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

@media (prefers-reduced-motion: reduce) {
  .timer-mini,
  .timer-mini.is-ending { animation: none; }
}

/* Segurou o selo: some dos módulos e só aparece na página inicial. */
.timer-mini {
  -webkit-touch-callout: none;
}

body:not([data-app-view="inicio"]) .timer-mini.is-home-only {
  display: none;
}

.timer-mini.is-hiding {
  animation: timerMiniOut 0.26s ease forwards;
}

@keyframes timerMiniOut {
  to { transform: scale(0.3); opacity: 0; }
}
