:root {
  --ink: #2a2140;
  --ink-soft: #625a80;
  --glass: rgba(255, 255, 255, 0.55);
  --glass-brd: rgba(255, 255, 255, 0.8);
  --shadow: 0 10px 30px rgba(40, 30, 80, 0.16), 0 2px 6px rgba(40, 30, 80, 0.08);
  --ok: #3fbf86;
  --mid: #ffad33;
  --low: #ff5468;
  --track: rgba(110, 100, 150, 0.16);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.night {
  --ink: #f3efff;
  --ink-soft: #b9b2da;
  --glass: rgba(26, 22, 58, 0.48);
  --glass-brd: rgba(255, 255, 255, 0.14);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --track: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: linear-gradient(#9fd0ff, #e6f3ff); color: var(--ink); overscroll-behavior: none; }
button { font: inherit; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#scene:active { cursor: grabbing; }

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.7);
  backdrop-filter: blur(18px) saturate(1.7);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--shadow);
  transition: background 1.2s, border-color 1.2s, color 1.2s;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Name card */
.top {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; z-index: 3;
}
.top > * { pointer-events: auto; }
.card.id { border-radius: 24px; padding: 12px 18px 11px; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
h1 { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip {
  flex: none; font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em;
  padding: 4px 9px; border-radius: 999px; background: linear-gradient(135deg, #ffd9b0, #ffa3c4); color: #6a2d45;
}
.meta { margin: 5px 0 0; font-size: 0.84rem; font-weight: 600; color: var(--ink-soft); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.45; }
.status { color: var(--ok); }
.status.warn { color: var(--mid); }
.status.bad { color: var(--low); }
.round { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); cursor: pointer; padding: 0; }
.round:hover { transform: rotate(-30deg); }
.round { transition: transform 0.3s, background 1.2s; }

/* Need gauges */
.needs {
  position: fixed; right: max(16px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px; padding: 12px 8px; border-radius: 30px; z-index: 2;
}
.gauge { width: 60px; display: grid; justify-items: center; gap: 2px; color: var(--ink); --v: 1; --gc: var(--ok); }
.gauge .ring { position: relative; width: 50px; height: 50px; display: grid; place-items: center; }
.gauge svg.r { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge .track { fill: none; stroke: var(--track); stroke-width: 4.5; }
.gauge .fill {
  fill: none; stroke: var(--gc); stroke-width: 4.5; stroke-linecap: round;
  stroke-dasharray: 125.66; stroke-dashoffset: calc(125.66 * (1 - var(--v)));
  transition: stroke-dashoffset 0.7s cubic-bezier(0.3, 1.2, 0.5, 1), stroke 0.4s;
  filter: drop-shadow(0 0 3px color-mix(in srgb, var(--gc) 50%, transparent));
}
.gauge .ring > svg.lucide { width: 20px; height: 20px; stroke-width: 2.4; }
.gauge[data-level="mid"] { --gc: var(--mid); }
.gauge[data-level="low"] { --gc: var(--low); }
.gauge[data-level="low"] .ring { animation: pulse 1.1s ease-in-out infinite; }
.gauge[data-level="low"] .ring > svg.lucide { color: var(--low); }
.gauge .lbl { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.02em; color: var(--ink-soft); }
@keyframes pulse { 50% { transform: scale(1.1); } }

/* Speech bubble that follows the pet's head */
.bubble { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 4; will-change: transform; }
.bubble .b {
  position: relative; transform-origin: 50% 100%; translate: -50% -100%;
  background: #fff; color: #2a2140; font-weight: 750; font-size: 0.98rem; line-height: 1.25;
  padding: 9px 15px; border-radius: 18px; box-shadow: 0 8px 24px rgba(40, 30, 80, 0.22);
  width: max-content; max-width: 230px; text-align: center;
  opacity: 0; scale: 0.5; transition: opacity 0.2s, scale 0.38s cubic-bezier(0.3, 1.7, 0.5, 1);
}
.bubble .b::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; width: 14px; height: 14px; background: #fff;
  transform: translateX(-50%) rotate(45deg); border-radius: 3px;
}
.bubble.show .b { opacity: 1; scale: 1; }

/* Action dock */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; gap: 4px; padding: 8px; border-radius: 30px; z-index: 3;
}
.dock button {
  appearance: none; border: 0; background: none; cursor: pointer; color: var(--ink);
  width: 76px; display: grid; justify-items: center; gap: 6px; padding: 6px 2px 4px; border-radius: 22px;
  font-size: 0.78rem; font-weight: 800; transition: transform 0.18s cubic-bezier(0.3, 1.6, 0.5, 1), opacity 0.3s, filter 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.dock .ico {
  width: 50px; height: 50px; border-radius: 17px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(150deg, var(--c1), var(--c2));
  box-shadow: 0 6px 14px color-mix(in srgb, var(--c2) 45%, transparent), inset 0 1.5px 0 rgba(255, 255, 255, 0.55), inset 0 -2px 0 rgba(0, 0, 0, 0.08);
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.dock .ico svg { width: 24px; height: 24px; stroke-width: 2.4; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15)); }
.dock button:hover:not(:disabled) .ico { transform: translateY(-3px) rotate(-4deg); }
.dock button:active:not(:disabled) { transform: scale(0.9); }
.dock button:focus-visible { outline: 3px solid var(--c2); outline-offset: 2px; }
.dock button:disabled { opacity: 0.35; filter: grayscale(0.7); cursor: default; }
.lights .ico-wake { display: none; }
.lights.on .ico-sleep { display: none; }
.lights.on .ico-wake { display: block; }

.restart {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(max(16px, env(safe-area-inset-bottom)) + 104px); z-index: 3;
  display: inline-flex; align-items: center; gap: 8px; padding: 13px 22px; border: 0; border-radius: 999px; cursor: pointer;
  background: linear-gradient(135deg, #ffd29a, #ff8fb8); color: #5a2440; font-weight: 800; font-size: 1rem;
  box-shadow: 0 10px 24px rgba(255, 120, 160, 0.4);
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translate(-50%, -4px); } }

.dev { position: fixed; left: 16px; bottom: 24px; z-index: 3; display: flex; gap: 6px; align-items: center; padding: 6px 8px; border-radius: 16px; font-size: 0.75rem; font-weight: 800; color: var(--ink-soft); }
.dev button { border: 0; border-radius: 10px; padding: 5px 9px; background: rgba(255, 255, 255, 0.6); color: #2a2140; font-weight: 800; cursor: pointer; }

.nogl { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); padding: 18px 22px; border-radius: 20px; max-width: 320px; text-align: center; font-weight: 700; z-index: 2; }

/* Hatch dialog */
dialog { border-radius: 30px; padding: 26px 24px 22px; width: min(340px, 90vw); color: var(--ink); }
dialog::backdrop { background: rgba(30, 20, 60, 0.25); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
dialog[open] { animation: rise 0.45s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(20px) scale(0.92); } }
dialog form { display: grid; gap: 12px; justify-items: center; text-align: center; }
dialog h2 { margin: 0; font-size: 1.5rem; font-weight: 800; }
dialog p { margin: 0; color: var(--ink-soft); font-weight: 600; }
.egg-badge { width: 72px; height: 72px; border-radius: 26px; display: grid; place-items: center; background: linear-gradient(150deg, #ffe0b8, #ff9ec4); color: #fff; box-shadow: 0 10px 22px rgba(255, 140, 170, 0.45); }
.egg-badge svg { width: 36px; height: 36px; stroke-width: 2.2; }
dialog input {
  width: 100%; font: inherit; font-size: 1.1rem; font-weight: 700; text-align: center; padding: 12px 14px; border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.9); background: rgba(255, 255, 255, 0.75); color: #2a2140; outline: none;
}
dialog input:focus { border-color: #ff9ec4; }
dialog button {
  width: 100%; border: 0; border-radius: 16px; padding: 13px; cursor: pointer; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, #ffbe8f, #ff6f9b); color: #fff; box-shadow: 0 8px 20px rgba(255, 110, 150, 0.4);
}

/* Phones: gauges become a row under the name card, the dock fills the width. */
@media (max-width: 640px) {
  .card.id { padding: 10px 14px 9px; border-radius: 20px; }
  h1 { font-size: 1.25rem; }
  .meta { font-size: 0.76rem; gap: 6px; }
  .round { width: 44px; height: 44px; }
  .needs {
    top: calc(max(14px, env(safe-area-inset-top)) + 84px); right: auto; left: 50%; transform: translateX(-50%);
    flex-direction: row; gap: 2px; padding: 7px 8px; border-radius: 24px;
  }
  .gauge { width: 54px; }
  .gauge .ring { width: 42px; height: 42px; }
  .gauge .ring > svg.lucide { width: 17px; height: 17px; }
  .gauge .lbl { font-size: 0.6rem; }
  .dock { left: 10px; right: 10px; transform: none; justify-content: space-between; padding: 7px 6px; gap: 0; border-radius: 26px; }
  .dock button { width: auto; flex: 1; font-size: 0.68rem; gap: 4px; }
  .dock .ico { width: 44px; height: 44px; border-radius: 15px; }
  .dock .ico svg { width: 21px; height: 21px; }
  .restart { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 92px); }
  .dev { left: 10px; bottom: auto; top: calc(max(14px, env(safe-area-inset-top)) + 160px); }
}
@media (prefers-reduced-motion: reduce) {
  .gauge[data-level="low"] .ring, .restart { animation: none; }
}
