/* ============================================================
   AI Pet — application shell
   Layout: top bar (status), pet stage, chat panel.
   Palette: warm cream + soft lavender, peach pet.
   ============================================================ */

:root {
  --bg: #f7f1ea;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 253, 251, 0.86);
  --surface-solid: #fffdfb;
  --ink: #3d3238;
  --ink-soft: #6d5f66;
  --ink-faint: #9b8d94;
  --accent: #8f7ae0;
  --accent-strong: #6f57c9;
  --accent-soft: #ece6ff;
  --peach: #ffb98f;
  --pink: #ff9aa2;
  --ok: #4fbf8b;
  --warn: #e0a44c;
  --danger: #e2686f;
  --radius-lg: 30px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-soft: 0 22px 48px -30px rgba(74, 52, 58, 0.5);
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1100px 620px at 10% -12%, #efe3ff 0%, rgba(239, 227, 255, 0) 62%),
    radial-gradient(900px 520px at 94% -4%, #ffe7d6 0%, rgba(255, 231, 214, 0) 58%),
    radial-gradient(900px 700px at 50% 118%, #e4f3ea 0%, rgba(228, 243, 234, 0) 60%),
    var(--bg);
  background-attachment: fixed;
}

body.is-pairing {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: 100;
  padding: 10px 20px;
  border-radius: 999px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 16px 30px -18px rgba(52, 40, 58, 0.6);
  translate: -50% -160%;
  transition: translate 0.18s ease;
}

.skip-link:focus {
  translate: -50% 0;
}

.chat-log:focus {
  outline: none;
}

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(12px, 1.8vw, 20px);
  width: 100%;
  max-width: 1200px;
  min-height: 100dvh;
  margin-inline: auto;
  padding: clamp(12px, 2.2vw, 30px);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr);
  gap: clamp(12px, 1.8vw, 22px);
  min-height: 0;
}

.layout > * {
  min-width: 0;
  min-height: 0;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.015em;
}

.brand::before {
  content: "";
  width: 30px;
  height: 30px;
  border-radius: 12px 12px 14px 14px;
  background: radial-gradient(circle at 34% 26%, #fff2e6, #ffd0ae 58%, #ef9f75);
  box-shadow:
    inset 0 -2px 0 rgba(150, 90, 60, 0.14),
    0 8px 16px -10px rgba(239, 154, 114, 0.95);
}

.brand small {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(140, 120, 160, 0.16);
}

.statusbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 26px -22px rgba(74, 52, 58, 0.65);
  backdrop-filter: blur(10px);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.status-live {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.lease-chip {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a6b2f;
  background: #fff4dd;
  border: 1px solid rgba(224, 164, 76, 0.38);
  padding: 2px 8px;
  border-radius: 999px;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--ink);
}

.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
  box-shadow: 0 0 0 3px rgba(155, 141, 148, 0.16);
  transition:
    background-color 0.3s ease,
    box-shadow 0.3s ease;
}

.conn-dot[data-conn="online"] {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(79, 191, 139, 0.18);
}

.conn-dot[data-conn="connecting"],
.conn-dot[data-conn="reconnecting"] {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(224, 164, 76, 0.2);
  animation: conn-pulse 1.4s ease-in-out infinite;
}

.conn-dot[data-conn="offline"] {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(226, 104, 111, 0.18);
}

@keyframes conn-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.status-divider {
  width: 1px;
  height: 14px;
  background: rgba(140, 120, 160, 0.24);
}

.sv {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sv b {
  font-weight: 700;
  color: var(--ink);
}

/* ------------------------------------------------------------------- stage */

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: min(56vh, 560px);
  padding: clamp(16px, 3vw, 34px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  isolation: isolate;
  box-shadow: var(--shadow-soft);
}

.stage-scene {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(120% 92% at 50% -4%, #fff8f0 0%, #ffeadf 36%, #f7e8f8 70%, #ece6fa 100%);
}

.scene-cloud {
  position: absolute;
  width: 34%;
  aspect-ratio: 2.3;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  filter: blur(16px);
  animation: cloud-drift 26s ease-in-out infinite alternate;
}

.scene-cloud--one {
  top: 14%;
  left: 5%;
}

.scene-cloud--two {
  top: 32%;
  right: 3%;
  width: 26%;
  animation-duration: 34s;
  animation-delay: -9s;
}

@keyframes cloud-drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(16px, -8px, 0) scale(1.06);
  }
}

.scene-ground {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 4%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 72%);
}

.scene-glow {
  position: absolute;
  left: 50%;
  bottom: 8%;
  width: 62%;
  height: 30%;
  translate: -50% 0;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 224, 196, 0.85), rgba(255, 224, 196, 0) 70%);
  filter: blur(6px);
}

.pet-slot {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding-bottom: 4vh;
}

/* The call control sits under the pet, next to the hint. */
.stage-actions {
  display: flex;
  justify-content: center;
}

.stage-actions .btn[disabled] {
  opacity: 0.5;
}

.stage-hint {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(93, 76, 84, 0.62);
  text-align: center;
  user-select: none;
}

.stage-hint kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(140, 120, 160, 0.22);
  box-shadow: 0 1px 0 rgba(140, 120, 160, 0.18);
}

/* -------------------------------------------------------------------- chat */

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(140, 120, 160, 0.12);
}

.chat-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chat-status {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(140, 120, 160, 0.14);
  transition: color 0.25s ease;
}

.chat-status[data-streaming="true"] {
  color: var(--accent-strong);
}

.chat-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 120, 160, 0.35) transparent;
}

.chat-log::-webkit-scrollbar {
  width: 8px;
}

.chat-log::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
  background-color: rgba(140, 120, 160, 0.3);
}

.chat-empty {
  margin: auto;
  max-width: 28ch;
  padding: 18px;
  text-align: center;
  color: var(--ink-soft);
}

.chat-empty__title {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.chat-empty__body {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-faint);
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 86%;
  animation: message-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message--user {
  align-self: flex-end;
  align-items: flex-end;
}

.message--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message--notice {
  align-self: center;
  align-items: center;
  max-width: 94%;
}

.message__bubble {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message--user .message__bubble {
  border-bottom-right-radius: 7px;
  color: #fff;
  background: linear-gradient(135deg, #a892f2, #8269dd);
  box-shadow: 0 10px 20px -14px rgba(111, 87, 201, 0.95);
}

.message--assistant .message__bubble {
  border-bottom-left-radius: 7px;
  background: #fff;
  border: 1px solid rgba(140, 120, 160, 0.14);
  box-shadow: 0 6px 14px -12px rgba(74, 52, 58, 0.5);
}

.message--notice .message__bubble {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-faint);
  background: transparent;
  border: 1px dashed rgba(140, 120, 160, 0.32);
  box-shadow: none;
}

.message__bubble--streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 2px;
  vertical-align: -0.12em;
  background: var(--accent);
  animation: caret-blink 1s steps(2, start) infinite;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.message__note {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-left: 4px;
}

.message--typing {
  max-width: 62%;
}

.message__bubble--typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: typing-pulse 1.15s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.chat-form {
  display: grid;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(140, 120, 160, 0.12);
  background: rgba(255, 255, 255, 0.55);
}

.chat-input {
  width: 100%;
  min-height: 46px;
  max-height: 132px;
  padding: 12px 14px;
  resize: none;
  border-radius: var(--radius-md);
  border: 1px solid rgba(140, 120, 160, 0.22);
  background: #fff;
  color: var(--ink);
  font-size: 0.94rem;
  line-height: 1.45;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.chat-input::placeholder {
  color: var(--ink-faint);
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(143, 122, 224, 0.14);
}

.chat-input:disabled {
  background: rgba(250, 246, 243, 0.8);
  color: var(--ink-faint);
  cursor: not-allowed;
}

.chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease,
    opacity 0.18s ease;
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn--primary {
  color: #fff;
  background: linear-gradient(135deg, #9e89f2, #7a60d7);
  box-shadow: 0 12px 22px -14px rgba(111, 87, 201, 0.95);
}

.btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 26px -14px rgba(111, 87, 201, 0.95);
}

.btn--ghost {
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.75);
  border-color: rgba(140, 120, 160, 0.24);
}

.btn--ghost:hover:not(:disabled) {
  background: #fff;
  border-color: rgba(140, 120, 160, 0.4);
}

.btn--tiny {
  padding: 6px 12px;
  font-size: 0.76rem;
  border-radius: 999px;
}

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom, 18px));
  z-index: 80;
  display: grid;
  gap: 8px;
  justify-items: center;
  width: min(92vw, 440px);
  translate: -50% 0;
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(140, 120, 160, 0.18);
  box-shadow: 0 16px 32px -20px rgba(52, 40, 58, 0.6);
  pointer-events: auto;
  animation: toast-in 260ms cubic-bezier(0.2, 0.9, 0.3, 1);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.toast--info {
  border-color: rgba(143, 122, 224, 0.35);
}

.toast--warn {
  background: #fffaf0;
  border-color: rgba(224, 164, 76, 0.45);
}

.toast--error {
  color: #8e3b42;
  background: #fff5f5;
  border-color: rgba(226, 104, 111, 0.45);
}

.toast--leaving {
  opacity: 0;
  transform: translateY(6px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ----------------------------------------------------------------- pairing */

.pairing {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 30% 16%, rgba(238, 228, 255, 0.92), rgba(52, 39, 60, 0.55));
  backdrop-filter: blur(12px);
}

.pairing-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(94vw, 424px);
  padding: clamp(22px, 4vw, 34px);
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  box-shadow: 0 48px 90px -46px rgba(40, 26, 48, 0.7);
  text-align: center;
  animation: pairing-in 320ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes pairing-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pairing-art {
  position: relative;
  width: 76px;
  height: 72px;
  border-radius: 26px 26px 32px 32px;
  background: radial-gradient(circle at 34% 26%, #fff2e6, #ffd2b1 56%, #f0ab84);
  box-shadow:
    inset 0 -3px 0 rgba(150, 90, 60, 0.12),
    0 18px 30px -20px rgba(240, 171, 132, 0.95);
}

.pairing-art::before,
.pairing-art::after {
  content: "";
  position: absolute;
  top: 36px;
  width: 9px;
  height: 11px;
  border-radius: 50%;
  background: #42323b;
}

.pairing-art::before {
  left: 21px;
}

.pairing-art::after {
  right: 21px;
}

.pairing-title {
  margin: 4px 0 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.pairing-copy {
  margin: 0;
  max-width: 34ch;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.pairing-form {
  display: grid;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.pairing-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid rgba(140, 120, 160, 0.26);
  background: #fff;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.pairing-input::placeholder {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
}

.pairing-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(143, 122, 224, 0.15);
}

.pairing-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: #933f46;
  background: #fff2f3;
  border: 1px solid rgba(226, 104, 111, 0.3);
}

.pairing-submit {
  width: 100%;
  padding-block: 13px;
}

.pairing-hint {
  margin: 2px 0 0;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--ink-faint);
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 940px) {
  .app {
    grid-template-rows: auto auto;
    min-height: 100dvh;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .stage {
    min-height: min(52vh, 440px);
  }

  .chat-panel {
    height: min(58vh, 540px);
  }
}

@media (max-width: 560px) {
  .app {
    gap: 10px;
    padding: 12px;
  }

  .topbar {
    gap: 10px;
  }

  .statusbar {
    width: 100%;
    justify-content: space-between;
    font-size: 0.78rem;
  }

  .stage {
    min-height: 42vh;
    padding: 14px;
    border-radius: 24px;
  }

  .pet-slot {
    padding-bottom: 2vh;
  }

  .chat-panel {
    height: 54vh;
    min-height: 320px;
    border-radius: 24px;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .chat-log {
    padding: 12px;
  }

  .message {
    max-width: 94%;
  }
}

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

  .btn {
    padding: 9px 14px;
    font-size: 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto;
  }

  .scene-cloud,
  .typing-dot,
  .conn-dot,
  .message,
  .toast,
  .pairing-card {
    animation: none !important;
  }

  .message__bubble--streaming::after {
    animation: none;
  }
}

/* ----------------------------------------------------------------- misc */

.noscript {
  margin: 0;
  padding: 16px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* ============================================================
   Phone hardening
   ============================================================ */

/* Keep the shell clear of notches and the home indicator. */
.app {
  padding-top: max(clamp(12px, 2.2vw, 30px), env(safe-area-inset-top, 0px));
  padding-bottom: max(clamp(12px, 2.2vw, 30px), env(safe-area-inset-bottom, 0px));
  padding-left: max(clamp(12px, 2.2vw, 30px), env(safe-area-inset-left, 0px));
  padding-right: max(clamp(12px, 2.2vw, 30px), env(safe-area-inset-right, 0px));
}

/*
 * Controls get a real thumb target on touch devices. 44px is the smallest comfortable
 * target; the desktop sizes stay tighter so the layout does not change there.
 */
@media (pointer: coarse) {
  .btn {
    min-height: 44px;
    padding-inline: 18px;
  }

  .btn--tiny {
    min-height: 38px;
    padding-inline: 12px;
  }

  .chat-input {
    /* 16px prevents iOS from zooming the page when the composer is focused. */
    font-size: 16px;
  }

  /* Hover styling is meaningless on touch and can stick after a tap. */
  .pet:hover {
    transform: translateX(calc((var(--pet-x) - 0.5) * 42px));
  }
}

/*
 * Landscape phones have very little height: side-by-side beats stacked, because a
 * 42vh stage plus a 54vh chat panel cannot both fit.
 */
@media (max-height: 520px) and (orientation: landscape) {
  .app {
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    /* Keep the safe-area floor: a blind padding-block would put the composer under the
     home indicator in landscape. */
  padding-block: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-bottom));
  }

  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 8px;
  }

  .stage {
    min-height: 0;
  }

  .chat-panel {
    height: auto;
    min-height: 0;
  }

  .stage-hint {
    display: none;
  }

  .pet {
    width: clamp(110px, 26vh, 170px);
  }
}

/* Very narrow phones: keep the pet and the composer usable rather than pretty. */
@media (max-width: 400px) {
  .pet {
    width: clamp(150px, 46vw, 200px);
  }

  .stage {
    min-height: 34vh;
    padding: 10px;
  }

  .chat-panel {
    height: 50vh;
    min-height: 260px;
  }

  .statusbar {
    font-size: 0.72rem;
  }
}
