:root {
  --ink: #2c2233;
  --ink-soft: #6d6275;
  --card: rgba(255, 255, 255, 0.82);
  --line: rgba(44, 34, 51, 0.1);
  --accent: #ff8a5c;
  --accent-dark: #e8663a;
  --good: #7ccf8a;
  --warn: #ffc15e;
  --bad: #ff6b6b;
  --radius: 18px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe3f2; }
body { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.topbar { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.pet-card { pointer-events: auto; border: 0; text-align: left; background: var(--card); backdrop-filter: blur(10px); border-radius: var(--radius); padding: 10px 16px; display: grid; gap: 1px; box-shadow: 0 6px 20px rgba(44, 34, 51, 0.08); }
.pet-card strong { font-size: 20px; letter-spacing: -0.01em; }
.pet-card > span { font-size: 13px; color: var(--ink-soft); }
.pet-card .pet-mood { font-weight: 700; color: var(--accent-dark); }
.icon-button { pointer-events: auto; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card); backdrop-filter: blur(10px); font-size: 22px; line-height: 1; box-shadow: 0 6px 20px rgba(44, 34, 51, 0.08); }

.hud-left { display: grid; gap: 10px; justify-items: start; }
.stats { pointer-events: auto; width: 206px; display: grid; gap: 6px; background: var(--card); backdrop-filter: blur(10px); padding: 12px 14px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(44, 34, 51, 0.08); }
.stat { display: grid; grid-template-columns: 20px 58px 1fr; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.stat-icon { font-size: 14px; text-align: center; }
.bar { height: 9px; border-radius: 9px; background: rgba(44, 34, 51, 0.09); overflow: hidden; }
.bar i { display: block; height: 100%; width: 50%; border-radius: inherit; background: var(--good); transition: width 0.5s ease, background-color 0.5s ease; }
.stat.is-low .bar i { background: var(--warn); }
.stat.is-critical .bar i { background: var(--bad); }
.stat.is-critical .stat-icon { animation: nudge 1.2s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.3); } }

.actions { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 8px; padding: 8px; background: var(--card); backdrop-filter: blur(10px); border-radius: 24px; box-shadow: 0 10px 30px rgba(44, 34, 51, 0.12); }
.action { position: relative; display: grid; justify-items: center; gap: 2px; min-width: 70px; padding: 9px 10px 8px; border: 0; border-radius: 16px; background: transparent; font-size: 13px; font-weight: 700; transition: background-color 0.15s, transform 0.15s; }
.action > span { font-size: 24px; line-height: 1.1; }
.action b { font-weight: inherit; }
.action kbd { position: absolute; top: 4px; right: 6px; font: 600 10px/1 ui-monospace, monospace; color: var(--ink-soft); opacity: 0.6; }
.action:hover:not(:disabled) { background: rgba(255, 138, 92, 0.14); }
.action:active:not(:disabled) { transform: scale(0.95); }
.action:disabled { opacity: 0.38; }
.action[hidden] { display: none; }
.action[aria-expanded="true"] { background: rgba(255, 138, 92, 0.2); }
.actions[hidden] { display: none; }

.picker { position: absolute; bottom: calc(100% + 10px); left: 8px; display: flex; gap: 8px; padding: 8px; background: var(--card); backdrop-filter: blur(10px); border-radius: 18px; box-shadow: 0 10px 30px rgba(44, 34, 51, 0.12); }
.picker--play { left: 70px; }
.picker[hidden] { display: none; }
.picker button { display: grid; justify-items: center; gap: 1px; min-width: 92px; padding: 8px 10px; border: 0; border-radius: 14px; background: rgba(255, 255, 255, 0.7); font-size: 13px; font-weight: 700; }
.picker button span { font-size: 26px; }
.picker button small { font-size: 10px; font-weight: 600; color: var(--ink-soft); }
.picker button:hover { background: #fff; }

.alerts { position: absolute; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 92px); transform: translateX(-50%); display: flex; gap: 10px; }
.alert-button { display: flex; align-items: center; gap: 8px; padding: 10px 18px; border: 0; border-radius: 999px; background: #fff; font-size: 15px; font-weight: 800; box-shadow: 0 8px 24px rgba(44, 34, 51, 0.18); animation: nudge 1.4s ease-in-out infinite; }
.alert-button b { font-weight: inherit; }
.alert-button span { font-size: 22px; }
.alert-button--bad { background: #ffe1e1; color: #a0262e; }
.alert-button[hidden] { display: none; }

.egg-hint, .paused-badge { position: absolute; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0; padding: 10px 18px; border-radius: 999px; background: var(--card); backdrop-filter: blur(10px); font-size: 14px; font-weight: 700; box-shadow: 0 8px 24px rgba(44, 34, 51, 0.12); text-align: center; max-width: calc(100% - 32px); }
.egg-hint[hidden], .paused-badge[hidden] { display: none; }

.guess { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(380px, calc(100% - 24px)); padding: 16px 18px 14px; border-radius: 24px; background: rgba(255, 255, 255, 0.94); box-shadow: 0 16px 40px rgba(44, 34, 51, 0.18); text-align: center; }
.guess[hidden] { display: none; }
.guess h2 { margin: 0 0 12px; font-size: 18px; }
.guess-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.guess-buttons .primary:disabled { opacity: 0.5; }
.guess-score { margin: 10px 0 0; font-size: 18px; letter-spacing: 0.2em; }

.bubble { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); padding: 8px 12px; border-radius: 16px; background: #fff; font-size: 22px; line-height: 1; box-shadow: 0 6px 18px rgba(44, 34, 51, 0.14); pointer-events: none; will-change: transform; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; width: 12px; height: 12px; background: #fff; transform: translateX(-50%) rotate(45deg); }
.bubble[hidden] { display: none; }

.toast { position: absolute; left: 50%; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 150px); transform: translate(-50%, 12px); max-width: min(360px, calc(100% - 32px)); padding: 10px 16px; border-radius: 14px; background: rgba(44, 34, 51, 0.88); color: #fff; font-size: 14px; font-weight: 600; text-align: center; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(400px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; padding: 26px 24px 22px; border-radius: 26px; background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(14px); box-shadow: 0 20px 60px rgba(44, 34, 51, 0.2); }
.panel[hidden] { display: none; }
.panel--small { width: min(340px, calc(100% - 32px)); }
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-dark); }
.panel h1 { margin: 0 0 10px; font-size: 36px; line-height: 1.02; letter-spacing: -0.02em; }
.panel h1 em { font-style: normal; color: var(--accent-dark); }
.panel h2 { margin: 0 0 14px; font-size: 24px; }
.panel-copy { margin: 0 0 18px; color: var(--ink-soft); font-size: 15px; line-height: 1.45; }
.field { display: grid; gap: 6px; margin-bottom: 14px; font-size: 13px; font-weight: 700; }
.field input { width: 100%; padding: 11px 14px; border: 2px solid var(--line); border-radius: 12px; font: inherit; font-size: 16px; font-weight: 600; color: var(--ink); background: #fff; user-select: text; -webkit-user-select: text; }
.swatches { display: flex; gap: 10px; }
.swatches button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8); }
.swatches button[aria-checked="true"] { border-color: var(--ink); }
.primary { width: 100%; padding: 13px 18px; border: 0; border-radius: 14px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 800; box-shadow: 0 6px 0 var(--accent-dark); transition: transform 0.1s, box-shadow 0.1s; }
.primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 3px 0 var(--accent-dark); }
.primary:disabled { opacity: 0.6; }
.ghost { width: 100%; padding: 10px; border: 0; background: none; color: var(--bad); font-size: 14px; font-weight: 700; }
.panel-actions { display: grid; gap: 10px; margin-top: 6px; }
.save-note { margin: -4px 0 14px; font-size: 12px; color: var(--ink-soft); line-height: 1.4; }
.panel-copy--small { font-size: 13px; margin: -4px 0 14px; }
.panel-copy--small:empty { display: none; }
.status-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 14px; font-size: 14px; }
.status-grid dt { color: var(--ink-soft); font-weight: 600; }
.status-grid dd { margin: 0; font-weight: 700; text-align: right; }
.toggle { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; font-size: 14px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.toggle span { display: grid; gap: 1px; }
.toggle small { color: var(--ink-soft); font-size: 12px; line-height: 1.35; }
.panel--dark { background: rgba(33, 28, 58, 0.94); color: #fff; }
.panel--dark .panel-copy { color: rgba(255, 255, 255, 0.75); }
.panel--dark .eyebrow { color: #ffcf7a; }

.hint { position: absolute; right: 16px; bottom: max(22px, env(safe-area-inset-bottom)); margin: 0; font-size: 12px; font-weight: 600; color: rgba(44, 34, 51, 0.55); pointer-events: none; }
body.is-night .hint { color: rgba(255, 255, 255, 0.55); }

@media (max-width: 1200px) {
  .hint { display: none; }
}

@media (max-width: 720px) {
  .hint { display: none; }
  .stats { position: fixed; top: auto; left: 12px; right: 12px; width: auto; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 84px); grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 8px 10px; }
  .stat { grid-template-columns: 1fr; justify-items: center; gap: 3px; }
  .stat-label { display: none; }
  .bar { width: 100%; height: 7px; }
  .toast { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 200px); }
  .alerts { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 142px); }
  .picker--play { left: auto; right: 8px; }
  .picker button { min-width: 0; flex: 1; }
  .picker { left: 8px; right: 8px; }
  .actions { left: 12px; right: 12px; transform: none; justify-content: space-between; gap: 2px; }
  .action { min-width: 0; flex: 1; padding: 8px 4px 6px; font-size: 12px; }
  .action kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stat.is-critical .stat-icon, .alert-button { animation: none; }
}
