/* Reuse the shared UI. Only restore the fourth tab and replace the video surface. */
body.student-active .student-tabs { grid-template-columns: repeat(4,minmax(0,1fr)); }
.pet-board-v5 { box-sizing:border-box; padding-top:0; padding-bottom:clamp(12px,2.4vh,24px); row-gap:clamp(6px,1vh,10px); transform:none; grid-template-rows:auto auto auto auto; align-content:start; height:max-content; }
.pet-board-v5 > [data-pet-agent-host] { min-width:0; min-height:0; align-self:start; }
.pet-agent-page-mount { align-content:start; height:max-content; }
.pet-board-v5 .student-board-head { padding:8px 2px 0; background:transparent; border:0; box-shadow:none; backdrop-filter:none; }
.pet-board-v5 .student-board-head h2 { line-height:1.1; }
.pet-agent-page-mount .pet-agent-stage { height:auto; min-height:0; aspect-ratio:4 / 3; border-radius:18px; overflow:hidden; isolation:isolate; }
.pet-agent-page-mount .pet-agent-stage { border:0 !important; box-shadow:none !important; background:#f7f7f7; }
.pet-local-video { position:absolute; inset:0; width:100%; height:100%; object-fit:contain; object-position:center; }
canvas.pet-local-video { opacity:0; }
.pet-agent-stage.ready canvas.pet-local-video { opacity:1; }
.pet-local-decoders { position:fixed; left:0; bottom:0; width:576px; height:432px; opacity:.001; overflow:hidden; pointer-events:none; z-index:-1; }
.pet-local-decoders video { width:576px; height:432px; position:absolute; }

.pet-board-v5 .student-board-head { align-items:flex-start; }
.pet-local-name-row { display:flex; align-items:center; gap:7px; min-width:0; }
.pet-local-name-row h2 { margin:0; }
.pet-local-level { display:none; align-items:center; min-height:27px; padding:0 9px; border:1px solid #ffe0a6; border-radius:999px; background:#fff6de; color:#b7791f; font-size:12px; font-weight:850; white-space:nowrap; }
.pet-local-rename { min-height:27px; padding:3px 9px; border:1px solid #ded2fb; border-radius:999px; background:#f3edff; color:#6840d8; font:inherit; font-size:11px; font-weight:850; cursor:pointer; white-space:nowrap; }
.pet-local-rename:active { background:#e9ddff; transform:translateY(1px); }
.pet-local-header-right { display:flex; align-items:center; min-height:38px; }
.pet-local-header-right .pet-local-coin-balance { min-height:38px; }
.pet-local-coin-balance-fallback { display:inline-flex; align-items:center; min-height:38px; padding:0 12px; border-radius:999px; background:#f3edff; color:#6840d8; font-size:13px; font-weight:850; white-space:nowrap; }
.pet-local-rename:focus-visible,.pet-rename-submit:focus-visible,.pet-rename-close:focus-visible { outline:3px solid rgba(104,64,216,.32); outline-offset:2px; }

.pet-rename-modal { position:fixed; inset:0; z-index:123; display:grid; place-items:center; padding:20px; }
.pet-rename-modal[hidden] { display:none; }
.pet-rename-backdrop { position:absolute; inset:0; background:rgba(49,32,78,.28); backdrop-filter:blur(5px); }
.pet-rename-dialog { position:relative; width:min(340px,100%); padding:26px 22px 24px; border:1px solid rgba(234,223,248,.95); border-radius:22px; background:#fff; box-shadow:0 20px 54px rgba(48,35,79,.22); text-align:center; }
.pet-rename-kicker { margin:0 0 6px; color:#8b78a2; font-size:12px; font-weight:800; }
.pet-rename-dialog h3 { margin:0; color:#211446; font-size:22px; }
.pet-rename-close { position:absolute; top:8px; right:10px; width:30px; height:30px; border:0; border-radius:50%; background:#f3edff; color:#6840d8; font-size:22px; line-height:1; cursor:pointer; }
.pet-rename-field { display:grid; gap:7px; margin-top:18px; text-align:left; color:#74698b; font-size:12px; font-weight:800; }
.pet-rename-field input { width:100%; box-sizing:border-box; min-height:44px; padding:9px 12px; border:1px solid #ded2fb; border-radius:12px; background:#fff; color:#211446; font:inherit; font-size:15px; outline:none; }
.pet-rename-field input:focus { border-color:#8b68e8; box-shadow:0 0 0 3px rgba(104,64,216,.12); }
.pet-rename-error { min-height:19px; margin:7px 0 0; color:#c04c5c; font-size:12px; }
.pet-rename-submit { width:100%; min-height:44px; margin-top:8px; border:1px solid #ded2fb; border-radius:12px; background:#f3edff; color:#6840d8; font:inherit; font-size:16px; font-weight:850; cursor:pointer; }
.pet-rename-submit:active { background:#e9ddff; transform:translateY(1px); }

.pet-agent-actions button { border:1px solid #ded2fb; border-radius:12px; background:#f3edff; color:#6840d8; font-weight:850; box-shadow:0 6px 14px rgba(86,48,196,.08); }
.pet-agent-actions button:not(:disabled):active { background:#e9ddff; }

.pet-stat-grid-local { grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-top:2px; margin-bottom:6px; }
.pet-stat-grid-local .pet-stat-card { min-height:82px; display:flex; flex-direction:column; align-items:stretch; padding:10px; }
.pet-stat-grid-local .pet-stat-card b { height:1.25em; line-height:1.25; overflow:hidden; font-variant-numeric:tabular-nums; }
.pet-stat-grid-local .pet-stat-number-digits { display:inline-flex; align-items:flex-start; height:1.25em; line-height:1.25; }
.pet-stat-grid-local .pet-stat-digit { display:block; width:.62em; height:1.25em; overflow:hidden; text-align:center; }
.pet-stat-grid-local .pet-stat-digit-reel,
.pet-stat-grid-local .pet-stat-digit-reel > span { display:block; height:1.25em; line-height:1.25; }
.pet-stat-grid-local .pet-stat-card i { overflow:hidden; background:#ece4f8; }
.pet-stat-grid-local .pet-stat-fill { display:block; height:100%; border-radius:inherit; background:var(--primary); transition:width 1.5s cubic-bezier(.22,.7,.2,1); }
@keyframes petStatIncreaseValue {
  0%,100% { color:var(--text-main); }
  30%,75% { color:#1d9b61; }
}
@keyframes petStatDecreaseValue {
  0%,100% { color:var(--text-main); }
  30%,75% { color:#d55656; }
}
@keyframes petStatIncreaseBar {
  0%,100% { background-color:var(--primary); }
  30%,75% { background-color:#27ae70; }
}
@keyframes petStatDecreaseBar {
  0%,100% { background-color:var(--primary); }
  30%,75% { background-color:#d95a5a; }
}
.pet-stat-grid-local .pet-stat-card.pet-stat-increase b { animation:petStatIncreaseValue 1.5s ease; }
.pet-stat-grid-local .pet-stat-card.pet-stat-decrease b { animation:petStatDecreaseValue 1.5s ease; }
.pet-stat-grid-local .pet-stat-card.pet-stat-increase .pet-stat-fill { animation:petStatIncreaseBar 1.5s ease; }
.pet-stat-grid-local .pet-stat-card.pet-stat-decrease .pet-stat-fill { animation:petStatDecreaseBar 1.5s ease; }
@media (prefers-reduced-motion:reduce) {
  .pet-stat-grid-local .pet-stat-card.pet-stat-increase b,
  .pet-stat-grid-local .pet-stat-card.pet-stat-decrease b,
  .pet-stat-grid-local .pet-stat-card.pet-stat-increase .pet-stat-fill,
  .pet-stat-grid-local .pet-stat-card.pet-stat-decrease .pet-stat-fill { animation-duration:.01ms; }
  .pet-stat-grid-local .pet-stat-fill { transition-duration:.01ms; }
}
.pet-wardrobe-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-bottom:4px; }
.pet-wardrobe-action { min-height:54px; border:1px solid #ded2fb; border-radius:14px; background:#f3edff; color:#6840d8; font:inherit; font-size:16px; font-weight:850; cursor:pointer; box-shadow:0 6px 14px rgba(86,48,196,.08); }
.pet-wardrobe-action:active { background:#e9ddff; transform:translateY(1px); }

.pet-wardrobe-modal { position:fixed; inset:0; z-index:120; display:grid; place-items:center; padding:20px; }
.pet-wardrobe-modal[hidden] { display:none; }
.pet-wardrobe-backdrop { position:absolute; inset:0; background:rgba(49,32,78,.28); backdrop-filter:blur(5px); }
.pet-wardrobe-dialog { position:relative; width:min(340px,100%); padding:26px 22px 24px; border:1px solid rgba(234,223,248,.95); border-radius:22px; background:#fff; box-shadow:0 20px 54px rgba(48,35,79,.22); text-align:center; }
.pet-wardrobe-kicker { margin:0 0 6px; color:#8b78a2; font-size:12px; font-weight:800; }
.pet-wardrobe-dialog h3 { margin:0; color:#211446; font-size:22px; }
.pet-wardrobe-empty { margin:14px 0 2px; color:#74698b; font-size:14px; }
.pet-wardrobe-close { position:absolute; top:8px; right:10px; width:30px; height:30px; border:0; border-radius:50%; background:#f3edff; color:#6840d8; font-size:22px; line-height:1; cursor:pointer; }
.pet-wardrobe-close:focus-visible,.pet-wardrobe-action:focus-visible,.pet-agent-actions button:focus-visible { outline:3px solid rgba(104,64,216,.32); outline-offset:2px; }

.pet-feed-modal { position:fixed; inset:0; z-index:121; display:grid; place-items:center; padding:20px; }
.pet-feed-modal[hidden] { display:none; }
.pet-feed-backdrop { position:absolute; inset:0; background:rgba(49,32,78,.28); backdrop-filter:blur(5px); }
.pet-feed-dialog { position:relative; width:min(340px,100%); padding:26px 22px 24px; border:1px solid rgba(234,223,248,.95); border-radius:22px; background:rgba(255,250,255,.68); backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); box-shadow:0 20px 54px rgba(48,35,79,.22); text-align:center; }
.pet-feed-kicker { margin:0 0 6px; color:#8b78a2; font-size:12px; font-weight:800; }
.pet-feed-dialog h3 { margin:0; color:#211446; font-size:22px; }
.pet-feed-close { position:absolute; top:8px; right:10px; width:30px; height:30px; border:0; border-radius:50%; background:#f3edff; color:#6840d8; font-size:22px; line-height:1; cursor:pointer; }
.pet-feed-options { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-top:18px; }
.pet-feed-option { min-height:70px; display:grid; place-items:center; gap:4px; padding:10px 8px; border:1px solid #ded2fb; border-radius:14px; background:#f3edff; color:#6840d8; font:inherit; font-weight:850; cursor:pointer; box-shadow:0 6px 14px rgba(86,48,196,.08); }
.pet-feed-option small { color:#8b78a2; font-size:11px; font-weight:750; }
.pet-feed-option:disabled { cursor:not-allowed; opacity:.42; }
.pet-feed-option:not(:disabled):active { background:#e9ddff; transform:translateY(1px); }
.pet-feed-close:focus-visible,.pet-feed-option:focus-visible { outline:3px solid rgba(104,64,216,.32); outline-offset:2px; }

.pet-play-modal { position:fixed; inset:0; z-index:121; display:grid; place-items:center; padding:20px; }
.pet-play-modal[hidden] { display:none; }
.pet-play-backdrop { position:absolute; inset:0; background:rgba(49,32,78,.28); backdrop-filter:blur(5px); }
.pet-play-dialog { position:relative; width:min(340px,100%); padding:26px 22px 24px; border:1px solid rgba(234,223,248,.95); border-radius:22px; background:rgba(255,250,255,.68); backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); box-shadow:0 20px 54px rgba(48,35,79,.22); text-align:center; }
.pet-play-kicker { margin:0 0 6px; color:#8b78a2; font-size:12px; font-weight:800; }
.pet-play-dialog h3 { margin:0; color:#211446; font-size:22px; }
.pet-play-close { position:absolute; top:8px; right:10px; width:30px; height:30px; border:0; border-radius:50%; background:#f3edff; color:#6840d8; font-size:22px; line-height:1; cursor:pointer; }
.pet-play-options { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-top:18px; }
.pet-play-option { min-height:70px; display:grid; place-items:center; gap:4px; padding:10px 8px; border:1px solid #ded2fb; border-radius:14px; background:#f3edff; color:#6840d8; font:inherit; font-weight:850; cursor:pointer; box-shadow:0 6px 14px rgba(86,48,196,.08); }
.pet-play-option small { color:#8b78a2; font-size:11px; font-weight:750; }
.pet-play-option:disabled { cursor:not-allowed; opacity:.42; }
.pet-play-option:not(:disabled):active { background:#e9ddff; transform:translateY(1px); }
.pet-play-close:focus-visible,.pet-play-option:focus-visible { outline:3px solid rgba(104,64,216,.32); outline-offset:2px; }

@media (max-width:390px) { .pet-stat-grid-local,.pet-wardrobe-actions { gap:8px; } .pet-stat-grid-local .pet-stat-card { min-height:80px; padding:9px; } .pet-wardrobe-action { font-size:16px; } }

/* Portrait WebView: keep every Pet section in normal document flow. The shared
   desktop grid is intentionally two-column, but stretching its tracks on a
   tall phone makes the video and stat cards occupy the same paint area. */
@media (max-width:700px) {
  .pet-board-v5 {
    display:grid !important;
    grid-template-columns:minmax(0,1fr) !important;
    grid-template-rows:auto auto auto auto !important;
    align-content:start !important;
    align-items:start !important;
    height:auto !important;
    min-height:0 !important;
    overflow:visible !important;
  }
  .pet-board-v5 > .student-board-head,
  .pet-board-v5 > [data-pet-agent-host],
  .pet-board-v5 > .pet-stat-grid-local,
  .pet-board-v5 > .pet-wardrobe-actions {
    grid-column:1 !important;
    grid-row:auto !important;
    width:100% !important;
    min-width:0 !important;
  }
  .pet-board-v5 > [data-pet-agent-host] { display:block !important; height:auto !important; }
  .pet-agent-page-mount { display:grid !important; grid-template-columns:minmax(0,1fr) !important; grid-template-rows:auto auto !important; width:100% !important; height:auto !important; align-content:start !important; }
  .pet-agent-stage { position:relative !important; display:block !important; width:100% !important; height:auto !important; min-height:0 !important; aspect-ratio:4 / 3 !important; border:0 !important; box-shadow:none !important; }
  .pet-agent-stage .pet-local-video { position:absolute !important; inset:0 !important; display:block !important; width:100% !important; height:100% !important; }
  .pet-agent-actions { position:relative !important; display:grid !important; grid-template-columns:repeat(2,minmax(0,1fr)) !important; grid-template-rows:auto !important; width:100% !important; height:auto !important; gap:8px !important; }
  .pet-stat-grid-local { align-self:start !important; height:auto !important; }
  .pet-stat-grid-local .pet-stat-card { height:auto !important; align-self:start !important; }
}

/* Keep the production WebView paint geometry identical to the local preview.
   The action spacing is explicit so a late-loaded container rule cannot pull
   the buttons back against the video stage. */
.pet-agent-page-mount {
  gap: 0 !important;
}
.pet-agent-actions {
  margin-top: 10px !important;
  gap: 8px !important;
}
.pet-agent-actions button {
  box-sizing: border-box !important;
  height: 46px !important;
  min-height: 46px !important;
  padding: 0 6px !important;
  font-size: 16px !important;
  line-height: 1.2 !important;
}

.pet-feed-dialog,.pet-play-dialog { box-sizing:border-box; max-height:calc(100dvh - 40px); overflow:auto; }
.pet-feed-option > img, .pet-play-option > img { display:block; width:76px; height:76px; }
.pet-choice-price { display:flex; align-items:center; justify-content:center; gap:6px; }
.pet-choice-price .galaxy-coin { width:20px; height:20px; }
.pet-choice-price .galaxy-coin > span { font-size:12px; }
.pet-owned-section { margin-top:20px; padding-top:14px; border-top:1px solid #d8cceb; text-align:left; }
.pet-owned-section h4 { margin:0 0 10px; color:#554569; font-size:13px; }
.pet-owned-options { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
.pet-owned-options button { display:grid; place-items:center; padding:8px; border:1px solid #ded2fb; border-radius:14px; background:rgba(243,237,255,.7); color:#5932ab; font:inherit; cursor:pointer; }
.pet-owned-options img { width:70px; height:70px; }
.pet-owned-options small { font-size:12px; }
.pet-owned-options button:disabled { opacity:.42; cursor:not-allowed; }
.pet-owned-options button:focus-visible { outline:3px solid #6840d8; outline-offset:2px; }
.pet-owned-empty,.pet-owned-feedback { font-size:12px; color:#554569; margin:0; }
.pet-owned-feedback:not(:empty) { margin-top:10px; }

/* Older WebViews use vh before the dynamic viewport enhancement. */
.pet-feed-dialog,.pet-play-dialog,.pet-rename-dialog,.pet-shop,.pet-shop-detail { max-height:calc(100vh - 40px); max-height:calc(100dvh - 40px); overflow:auto; transform-origin:center; }
.pet-dialog-fallback { display:block; position:fixed; inset:0; margin:auto; height:fit-content; z-index:10000; box-shadow:0 0 0 100vmax rgba(29,19,49,.3); }
.pet-shop-detail.pet-dialog-fallback { z-index:10001; }
.pet-shop.pet-dialog-fallback { overflow:visible; backdrop-filter:none; -webkit-backdrop-filter:none; }

.pet-motion-backdrop { position:fixed; top:0; right:0; bottom:0; left:0; z-index:9999; background:transparent; }
.pet-shop.pet-dialog-fallback,.pet-shop-detail.pet-dialog-fallback { background:rgba(255,250,255,.94); }
.pet-motion-backdrop { background:rgba(33,20,70,.28); }

/* The thought floats inside the existing video; it adds no layout height. */
.pet-thought { position:absolute; top:12px; right:12px; z-index:2; box-sizing:border-box; max-width:46%; padding:9px 12px; border-radius:20px; background:rgba(255,250,255,.92); color:#382257; box-shadow:0 3px 12px rgba(42,25,68,.12); pointer-events:none; text-align:center; }
.pet-thought[hidden] { display:none; }
.pet-thought::before,.pet-thought::after { content:''; position:absolute; border-radius:50%; background:rgba(255,250,255,.92); box-shadow:0 3px 12px rgba(42,25,68,.12); }
.pet-thought::before { width:9px; height:9px; bottom:-10px; left:18px; box-shadow:0 3px 4px rgba(42,25,68,.22); }
.pet-thought::after { width:5px; height:5px; bottom:-17px; left:12px; box-shadow:0 2px 3px rgba(42,25,68,.24); }
.pet-thought strong { display:block; font-size:13px; line-height:1.4; font-weight:700; }
.pet-thought small { display:block; margin-top:2px; font-size:11px; line-height:1.4; color:#684092; }
@media(max-width:360px) { .pet-thought { top:8px; right:8px; padding:7px 9px; } .pet-thought strong { font-size:12px; } }

.pet-thought { opacity:0; visibility:hidden; transition:opacity 220ms ease, visibility 0s linear 220ms; }
.pet-thought.is-visible { opacity:1; visibility:visible; transition:opacity 220ms ease, visibility 0s; }
@media(prefers-reduced-motion:reduce) { .pet-thought,.pet-thought.is-visible { transition-duration:80ms,0s; } }

/* Preserve bubble dimensions as its text crossfades to the completion check. */
.pet-thought,.pet-thought.is-visible { transition:opacity 220ms ease, background-color 320ms ease, visibility 0s linear 220ms; }
.pet-thought.is-visible { transition-delay:0s; }
.pet-thought::before,.pet-thought::after { transition:background-color 320ms ease; }
.pet-thought strong,.pet-thought small { transition:opacity 220ms ease; }
.pet-thought-check { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; color:#fff; opacity:0; transition:opacity 320ms ease; }
.pet-thought-check svg { width:30px; height:30px; }
.pet-thought.is-complete,.pet-thought.is-complete::before,.pet-thought.is-complete::after { background-color:#79bc96; }
.pet-thought.is-complete strong,.pet-thought.is-complete small { opacity:0; }
.pet-thought.is-complete .pet-thought-check { opacity:1; }
@media(prefers-reduced-motion:reduce) { .pet-thought,.pet-thought.is-visible,.pet-thought::before,.pet-thought::after,.pet-thought strong,.pet-thought small,.pet-thought-check { transition-duration:80ms; } }

/* The production page does not load the pet-lab container stylesheet. Keep the
   canvas anchored to its own stage at every width, including tablet landscape. */
.pet-agent-page-mount { display:grid; grid-template-columns:minmax(0,1fr); gap:10px; }
.pet-agent-page-mount .pet-agent-stage { position:relative; display:block; width:100%; padding:0; }
.pet-agent-page-mount .pet-agent-stage::before { content:""; display:block; padding-top:75%; }
.pet-agent-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
.pet-agent-actions button { min-height:44px; font:inherit; font-weight:850; }
.pet-board-v5 .student-board-head > div:first-child { min-width:0; }
.pet-local-name-row h2 { overflow-wrap:anywhere; }
@media (min-width:701px) {
  .student-mode .pet-board-v5 {
    width:100%; max-width:1000px; margin-inline:auto;
    grid-template-columns:minmax(0,1.15fr) minmax(0,1fr);
    grid-template-rows:max-content max-content minmax(max-content,1fr); gap:16px 24px;
    align-items:start; height:auto; min-height:0;
  }
  .pet-board-v5 > .student-board-head { grid-column:1 / -1; grid-row:1; }
  .pet-board-v5 > [data-pet-agent-host] { grid-column:1; grid-row:2 / 4; }
  .pet-board-v5 > .pet-stat-grid-local { grid-column:2; grid-row:2; margin:0; align-self:start; }
  .pet-board-v5 > .pet-wardrobe-actions { grid-column:2; grid-row:3; margin:0; }
}
/* Keep modal controls reachable with a landscape viewport or enlarged text. */
.pet-rename-dialog,.pet-feed-dialog,.pet-play-dialog,.pet-wardrobe-dialog {
  box-sizing:border-box; max-height:calc(100vh - 40px); overflow-y:auto;
  max-height:calc(100dvh - 40px);
}

/* Short screens may scroll the Pet panel; never strand controls behind tabs. */
.student-mode .pet-board-v5 { max-height:100%; overflow-y:auto !important; overflow-x:hidden !important; }
@media (max-width:700px) {
  .pet-agent-page-mount .pet-agent-stage {
    justify-self:center;
    max-width:calc((100vh - 460px) * 1.333333);
    max-width:calc((100dvh - 460px) * 1.333333);
    min-width:min(144px,100%);
  }
}

@media (min-width:701px) {
  .pet-agent-page-mount .pet-agent-stage {
    justify-self:center; max-width:calc((100vh - 250px) * 1.333333);
    max-width:calc((100dvh - 250px) * 1.333333); min-width:144px;
  }
}
@media (max-height:620px) {
  .pet-thought { max-width:calc(100% - 16px); top:8px; right:8px; padding:6px 8px; }
}
