/* ---------- Colores (claro) y modo oscuro automático ---------- */
:root {
  --bg1: #f3faf1;
  --bg2: #dff0e6;
  --text: #2c4a3b;
  --muted: #6b8678;
  --card: rgba(255, 255, 255, 0.75);
  --accent: #5fb687;
  --accent-2: #8fd3a8;
  --on-accent: #ffffff;
  --water: #8fd3f4;
  --pot: #e9a98b;
  --pot-dark: #d28f70;
  --rim: #f0b79c;
  --soil: #7a5a47;
  --shadow: rgba(60, 90, 75, 0.18);
  --border: rgba(60, 110, 85, 0.15);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg1: #131c17;
    --bg2: #0d1411;
    --text: #dcefe4;
    --muted: #8fb09f;
    --card: rgba(30, 44, 37, 0.8);
    --accent: #58a97d;
    --accent-2: #3f8a63;
    --on-accent: #f4fff8;
    --water: #6cb8dd;
    --pot: #c98467;
    --pot-dark: #b06f53;
    --rim: #d99476;
    --soil: #4d3a2f;
    --shadow: rgba(0, 0, 0, 0.4);
    --border: rgba(160, 220, 190, 0.15);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg1), var(--bg2)) fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------- Layout con safe areas (notch y barra inferior del iPhone) ---------- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 20px)
           calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 20px);
  max-width: 520px;
  margin: 0 auto;
}
.top { display: flex; justify-content: flex-end; height: 44px; }
.icon-btn {
  border: 0; background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px;
  box-shadow: 0 2px 8px var(--shadow); cursor: pointer;
}
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; gap: 10px; }
.plant-wrap { width: min(78vw, 340px); }
.plant-wrap svg { width: 100%; height: auto; overflow: visible; display: block; }
.message {
  min-height: 3.2em; margin: 0; max-width: 20em; text-align: center;
  font-size: 1.15rem; line-height: 1.4; font-weight: 500;
}
.actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.drink-btn {
  width: 100%; max-width: 360px; padding: 20px 24px; border: 0; border-radius: 28px;
  font-size: 1.3rem; font-weight: 700; color: var(--on-accent); font-family: inherit;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 20px var(--shadow); cursor: pointer;
  transition: transform .15s ease;
}
.drink-btn:active { transform: scale(0.96); }
.glasses { margin: 0; font-size: .9rem; color: var(--muted); }

/* ---------- Planta SVG ---------- */
.plant { --leaf: #7cc99a; --leaf-dark: #5fb087; --stem: #5fae82;
         --a: -36deg; --f: 1; --lean: 0deg; --sag: 0px; }
.plant * { transition: transform 1.4s cubic-bezier(.3,.8,.3,1), fill 1.4s ease, stroke 1.4s ease, opacity .6s ease; }

.plant[data-state="happy"]   { --a: -40deg; --f: 1;   --lean: 0deg; }
.plant[data-state="normal"]  { --a: -22deg; --f: .55; --lean: 0deg; }
.plant[data-state="thirsty"] { --a: 10deg;  --f: .0;  --lean: 5deg;  --leaf: #b9c77a; --leaf-dark: #a1b062; --stem: #8fa86a; }
.plant[data-state="wilted"]  { --a: 38deg;  --f: 0;   --lean: 11deg; --leaf: #c3b774; --leaf-dark: #a89a5e; --stem: #9a9060; }
@media (prefers-color-scheme: dark) {
  .plant { --leaf: #58a97d; --leaf-dark: #418a63; --stem: #4a9a70; }
  .plant[data-state="thirsty"] { --leaf: #98a85f; --leaf-dark: #84944f; --stem: #7b9059; }
  .plant[data-state="wilted"]  { --leaf: #a09660; --leaf-dark: #8a804e; --stem: #82784f; }
}

.sway { transform-origin: 100px 152px; animation: sway 5s ease-in-out infinite; }
.plant[data-state="wilted"] .sway { animation-duration: 9s; }
@keyframes sway { 0%,100% { transform: rotate(-1.6deg); } 50% { transform: rotate(1.6deg); } }
.lean { transform-origin: 100px 152px; transform: rotate(var(--lean)); }

.stem { stroke: var(--stem); stroke-width: 7; stroke-linecap: round; fill: none; }
.leaf-shape { fill: var(--leaf); stroke: var(--leaf-dark); stroke-width: 1.5; }
.leaf-vein { stroke: var(--leaf-dark); stroke-width: 1.5; stroke-linecap: round; fill: none; opacity: .6; }
.leaf { transform: rotate(calc(var(--a) + var(--o, 0deg))); transform-origin: 0 0; }
.l2, .r2 { --o: -6deg; }
.flower-in { transform: scale(var(--f)); transform-origin: 0 0; }
.petal { fill: #ff9a3c; stroke: #e57a1f; stroke-width: 1; stroke-linejoin: round; }
.petal.back { fill: #ffb566; }
.spot { fill: #b8470f; opacity: .75; }
.stamen { stroke: #c2571a; stroke-width: 1.2; stroke-linecap: round; fill: none; }
.anther { fill: #7a2e0b; }
.flower-core { fill: #8fbf5a; }
.pot-body { fill: var(--pot); } .pot-shade { fill: var(--pot-dark); opacity: .35; }
.pot-rim { fill: var(--rim); }
.ground { fill: var(--shadow); }
.eye { fill: #4a3328; } .face-line { stroke: #4a3328; stroke-width: 3; stroke-linecap: round; fill: none; }
.cheek { fill: #ff9fb5; opacity: .55; }
.sweat { fill: var(--water); opacity: 0; }

/* Caras: se muestra solo la del estado actual */
.face > g { opacity: 0; }
.plant[data-state="happy"]   .f-happy,
.plant[data-state="normal"]  .f-normal,
.plant[data-state="thirsty"] .f-thirsty,
.plant[data-state="wilted"]  .f-wilted { opacity: 1; }
.plant[data-state="thirsty"] .sweat, .plant[data-state="wilted"] .sweat { opacity: .85; animation: sweat 2.6s ease-in infinite; }
.plant[data-state="wilted"] .cheek { opacity: 0; }
@keyframes sweat { 0% { transform: translateY(-4px); opacity: 0; } 30% { opacity: .85; } 100% { transform: translateY(12px); opacity: 0; } }

/* Latido suave cuando está feliz */
.plant[data-state="happy"] .pot { animation: bob 3.6s ease-in-out infinite; transform-origin: 100px 226px; }
@keyframes bob { 0%,100% { transform: scale(1,1); } 50% { transform: scale(1.015,.99); } }

/* Parpadeo */
.eye { animation: blink 5s infinite; transform-box: fill-box; transform-origin: center; }
@keyframes blink { 0%,94%,100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }

/* ---------- Efectos: gotas y celebración ---------- */
.fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.drop, .spark {
  position: absolute; top: 0; left: 50%; font-size: 24px; opacity: 0;
}
.drop { animation: fall 1.1s ease-in forwards; }
@keyframes fall {
  0% { transform: translate(var(--x), -20px) scale(.8); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(1); opacity: 0; }
}
.spark { animation: pop 1.6s ease-out forwards; }
@keyframes pop {
  0% { transform: translate(0, var(--y0)) scale(.3); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(1.1) rotate(var(--r)); opacity: 0; }
}
.plant-wrap.celebrate { animation: hop .7s ease; }
@keyframes hop { 0%,100% { transform: translateY(0); } 35% { transform: translateY(-14px) scale(1.03); } 70% { transform: translateY(0) scale(.99); } }

/* ---------- Panel de ajustes ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-width: 520px; margin: 0 auto;
  background: var(--bg1); border-radius: 26px 26px 0 0; border: 1px solid var(--border);
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 88dvh; overflow-y: auto;
  transform: translateY(105%); transition: transform .35s cubic-bezier(.3,.8,.3,1);
  box-shadow: 0 -10px 30px var(--shadow);
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.field label { font-size: 1rem; }
.field input[type="time"], .field select {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px;
}
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 16px;
  background: var(--border); position: relative; transition: background .2s; cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px var(--shadow); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.notif-box { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 14px; margin-top: 14px; }
.notif-status { margin: 0 0 6px; font-weight: 600; }
.notif-help { margin: 0 0 10px; color: var(--muted); font-size: .92rem; line-height: 1.45; white-space: pre-line; }
.notif-help:empty { display: none; }
.notif-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.soft-btn { font: inherit; font-weight: 600; color: var(--text); background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.soft-btn.small { padding: 4px 10px; font-size: .8rem; }
.soft-btn[hidden] { display: none; }
.soft-btn:disabled { opacity: .5; }
.version { text-align: center; color: var(--muted); font-size: .8rem; margin: 18px 0 4px; user-select: none; }
.debug { margin-top: 10px; }
.debug[hidden] { display: none; }
.debug-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.debug pre { margin: 0; max-height: 220px; overflow: auto; font-size: 11px; line-height: 1.4; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px; white-space: pre-wrap; word-break: break-all; }

@media (prefers-reduced-motion: reduce) {
  .sway, .pot, .eye, .sweat { animation: none !important; }
}
