:root {
  color-scheme: light;
  --mist: #dde4e5;
  --cool-blue: #91a9b2;
  --charcoal: #263139;
  --off-white: #f5f7f6;
  --shy-pink: #f45b7e;
  --line: rgba(38, 49, 57, 0.14);
  --toolbar-height: 78px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--mist);
  color: var(--charcoal);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  isolation: isolate;
  overflow: hidden;
  background: var(--mist);
}

.room-layer {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-color: var(--mist);
  background-image: url("./assets/room-day.png");
  background-size: cover;
  background-position: center bottom;
  image-rendering: pixelated;
  transform: scale(1.01);
  transition: filter 420ms var(--ease), opacity 320ms var(--ease);
}

.app-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(245, 247, 246, 0.1), transparent 38%, rgba(38, 49, 57, 0.08));
}

.theme-night .room-layer {
  filter: brightness(0.43) saturate(0.72) hue-rotate(8deg);
}

.theme-night::after {
  background: linear-gradient(180deg, rgba(34, 47, 63, 0.35), rgba(18, 28, 40, 0.48));
}

.theme-night { color: var(--off-white); }

.theme-solid .room-layer {
  opacity: 0;
}

.theme-solid {
  background:
    linear-gradient(180deg, #dfe7e8 0 58%, #9bafb7 58% 59%, #a9bbc1 59% 100%);
}

.pet-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: pixelated;
}

.status-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: calc(env(safe-area-inset-top) + 16px) 18px 0;
  pointer-events: none;
}

.status-copy {
  display: grid;
  gap: 3px;
  text-shadow: 0 1px 0 rgba(245, 247, 246, 0.65);
}

.theme-night .status-copy { text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }

.status-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
}

#petStatus {
  font-size: 19px;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.quiet-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(38, 49, 57, 0.2);
  border-radius: 12px;
  background: rgba(245, 247, 246, 0.78);
  color: var(--charcoal);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(38, 49, 57, 0.08);
  pointer-events: auto;
}

.quiet-button:active, .tool-button:active, .preset-grid button:active, .reset-button:active, .close-button:active {
  transform: translateY(1px) scale(0.985);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--toolbar-height) + env(safe-area-inset-bottom) + 18px);
  max-width: min(80vw, 330px);
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(38, 49, 57, 0.9);
  color: var(--off-white);
  font-size: 13px;
  line-height: 1.35;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.tool-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  height: var(--toolbar-height);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  padding: 6px;
  border: 1px solid rgba(245, 247, 246, 0.5);
  border-radius: 18px;
  background: rgba(245, 247, 246, 0.86);
  box-shadow: 0 16px 40px rgba(38, 49, 57, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.tool-button {
  min-width: 0;
  min-height: 44px;
  display: grid;
  place-content: center;
  gap: 3px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--charcoal);
  transition: background 160ms ease, transform 120ms ease;
}

.tool-button:focus-visible, .quiet-button:focus-visible, .close-button:focus-visible,
.preset-grid button:focus-visible, .reset-button:focus-visible, .size-range:focus-visible {
  outline: 3px solid var(--shy-pink);
  outline-offset: 2px;
}

.tool-button:hover { background: rgba(145, 169, 178, 0.13); }
.tool-button[aria-pressed="true"] { background: rgba(244, 91, 126, 0.12); }
.tool-button strong { font-size: 14px; line-height: 1; }
.tool-button span { overflow: hidden; font-size: 10px; color: rgba(38, 49, 57, 0.66); text-overflow: ellipsis; white-space: nowrap; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(38, 49, 57, 0.3);
}

.sheet-backdrop[hidden] { display: none; }

.bottom-sheet {
  width: min(100%, 560px);
  padding: 9px 20px calc(22px + env(safe-area-inset-bottom));
  border: 1px solid rgba(38, 49, 57, 0.1);
  border-radius: 24px 24px 0 0;
  background: var(--off-white);
  color: var(--charcoal);
  box-shadow: 0 -20px 60px rgba(38, 49, 57, 0.18);
  animation: sheet-in 260ms var(--ease) both;
}

@keyframes sheet-in { from { transform: translateY(26px); opacity: 0; } }

.sheet-handle {
  width: 36px;
  height: 4px;
  margin: 0 auto 15px;
  border-radius: 2px;
  background: rgba(38, 49, 57, 0.2);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.sheet-header span { font-size: 12px; color: rgba(38, 49, 57, 0.62); }
.sheet-header h2 { margin: 3px 0 0; font-size: 28px; line-height: 1; letter-spacing: -0.04em; }
.sheet-header output { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

.close-button {
  min-width: 68px;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--charcoal);
  color: var(--off-white);
  font-weight: 750;
}

.size-range {
  width: 100%;
  height: 38px;
  margin: 2px 0 0;
  accent-color: var(--shy-pink);
  touch-action: pan-x;
}

.range-labels { display: flex; justify-content: space-between; margin-top: -3px; color: rgba(38, 49, 57, 0.56); font-family: ui-monospace, monospace; font-size: 11px; }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 20px;
}

.preset-grid button, .reset-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #e8edef;
  color: var(--charcoal);
  font-size: 13px;
  font-weight: 700;
}

.preset-grid button.is-selected { border-color: var(--shy-pink); background: rgba(244, 91, 126, 0.1); }

.reset-button { width: 100%; margin-top: 10px; background: transparent; }
.sheet-note, .offline-status { margin: 14px 2px 0; color: rgba(38, 49, 57, 0.62); font-size: 12px; line-height: 1.45; }

.install-steps { display: grid; gap: 16px; margin: 0; padding: 0; list-style: none; counter-reset: install; }
.install-steps li { position: relative; display: grid; gap: 3px; min-height: 44px; padding-left: 46px; counter-increment: install; }
.install-steps li::before { content: counter(install); position: absolute; left: 0; top: 0; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--cool-blue); color: var(--charcoal); font-family: ui-monospace, monospace; font-weight: 800; }
.install-steps strong { font-size: 14px; }
.install-steps span { color: rgba(38, 49, 57, 0.64); font-size: 12px; line-height: 1.4; }
.offline-status { padding: 12px; border-radius: 10px; background: #e8edef; }

noscript { position: fixed; inset: 20px; z-index: 50; padding: 20px; background: var(--off-white); color: var(--charcoal); }

@media (orientation: landscape) {
  :root { --toolbar-height: 66px; }
  .tool-bar { left: auto; width: min(440px, 62vw); }
  .status-bar { right: auto; width: 46vw; }
  .bottom-sheet { border-radius: 24px 24px 0 0; }
}

@media (max-height: 600px) {
  .status-label { display: none; }
  #petStatus { font-size: 16px; }
  .status-bar { padding-top: calc(env(safe-area-inset-top) + 9px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
