/* Leave room for the close tab and safe areas before sizing the artwork. */
#panel-overlay:has(#game-window[data-panel="pets"]) {
  padding:calc(var(--ui-safe-top,0px) + 12px) calc(var(--ui-safe-right,0px) + 12px) calc(var(--ui-safe-bottom,0px) + 12px) calc(var(--ui-safe-left,0px) + 12px);
  overflow:hidden;
}
body[data-story-panel=true] #panel-overlay:has(#game-window[data-panel="pets"]) {
  padding-top:calc(var(--ui-safe-top,0px) + var(--ui-story-panel-height,124px) + 24px);
  padding-bottom:calc(var(--ui-safe-bottom,0px) + 12px);
}
body[data-story-panel=true]:has(#game-window[data-panel="pets"]) #story-guide[data-panel=true] {
  z-index:56;
}
#game-window[data-panel="pets"] {
  max-width:100%;
  max-height:100%;
}
#game-window[data-panel="pets"] #panel-close {
  right:8px;
}
#game-window[data-panel="pets"] .window-header h1 {
  max-width:100%;
  white-space:normal;
  overflow-wrap:break-word;
  text-align:center;
  text-wrap:balance;
  line-height:1.2;
}
/* The care card owns its title, backdrop and scrollport at every viewport size. */
#game-window[data-panel="pets"] .pet-layout::before {
  display:none;
}
#game-window[data-panel="pets"] .pet-roster {
  border-radius:18px;
  background:#ffda82;
  padding:0 6px;
  overflow:auto;
  scrollbar-width:thin;
  scrollbar-color:#dc960f transparent;
}
#game-window[data-panel="pets"] .pet-workspace {
  min-width:0;
  min-height:0;
  overflow:hidden;
}
#game-window[data-panel="pets"] :is(.pet-work,.pet-feeding,.pet-collection) {
  min-width:0;
  min-height:0;
  padding:12px;
  border-radius:18px;
  background:#ffda82;
  overflow:hidden;
}
#game-window[data-panel="pets"] .pet-work {
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  gap:6px;
}
#game-window[data-panel="pets"] .pet-section-heading {
  flex:none;
  align-items:flex-start;
  gap:4px 12px;
  padding:0 3px 6px;
  border-bottom:1px solid #fff3bd;
}
#game-window[data-panel="pets"] .pet-section-heading :is(h3,span) {
  min-width:0;
  max-width:100%;
  line-height:1.45;
  white-space:normal;
  overflow-wrap:break-word;
}
#game-window[data-panel="pets"] .pet-work-scroll {
  grid-row:2;
  width:100%;
  height:100%;
  min-height:0;
  padding:4px 10px 12px 3px;
  overflow-x:hidden;
  overflow-y:auto;
  overscroll-behavior:contain;
  touch-action:pan-y;
  scrollbar-gutter:stable;
  scrollbar-width:thin;
  scrollbar-color:#dc960f transparent;
  scroll-padding-block:8px;
}
#game-window[data-panel="pets"] .pet-work-scroll:focus-visible {
  outline:2px solid #b57816;
  outline-offset:-2px;
  border-radius:4px;
}
#game-window[data-panel="pets"] :is(.pet-toggle,.pet-select) {
  gap:10px;
  align-items:center;
}
#game-window[data-panel="pets"] :is(.pet-toggle,.pet-select)>span {
  min-width:0;
  overflow-wrap:break-word;
}
#game-window[data-panel="pets"] .pet-select select {
  width:52%;
  min-width:0;
  max-width:58%;
  flex:0 1 52%;
}
#game-window[data-panel="pets"] .pet-work-facts {
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px 18px;
}
#game-window[data-panel="pets"] .pet-work-facts :is(dt,dd),
#game-window[data-panel="pets"] :is(.pet-catalysis-rule,.pet-catalysis-exclusive) {
  line-height:1.55;
  overflow-wrap:break-word;
}
#game-window[data-panel="pets"] .pet-detail-scroll {
  padding-inline:6px 10px;
  scrollbar-gutter:stable;
  overscroll-behavior:contain;
  touch-action:pan-y;
}
#game-window[data-panel="pets"] .pet-detail-actions {
  flex:none;
}
@media(max-width:1050px),(max-height:700px) {
  #game-window[data-panel="pets"] :is(.pet-work,.pet-feeding,.pet-collection) {
    padding:8px;
    border-radius:12px;
  }
  #game-window[data-panel="pets"] .pet-work {
    gap:4px;
  }
  #game-window[data-panel="pets"] .pet-work-scroll {
    padding:3px 7px 10px 2px;
  }
  #game-window[data-panel="pets"] .pet-roster {
    padding:0 4px;
    border-radius:12px;
  }
  #game-window[data-panel="pets"] .pet-work-facts {
    gap:8px 12px;
  }
}
@media(max-width:700px) and (orientation:portrait) {
  #game-window[data-panel="pets"] .pet-roster {
    padding:0 3px;
  }
  #game-window[data-panel="pets"] .pet-work-facts {
    grid-template-columns:minmax(0,1fr);
  }
  #game-window[data-panel="pets"] .pet-section-heading>span {
    font-size:11px;
  }
}
/* The viewport, not the artwork's original height, owns the available space.
   Lists occupy the remaining track; fixed controls never participate in it. */
@media(max-width:1050px),(max-height:700px) {
  #game-window[data-panel="pets"] .pet-feeding {
    display:grid;
    grid-template-rows:auto minmax(0,1fr) auto;
    gap:4px;
  }
  #game-window[data-panel="pets"] .pet-collection {
    display:grid;
    grid-template-rows:auto minmax(0,1fr);
    gap:4px;
  }
  #game-window[data-panel="pets"] :is(.pet-food-list,.pet-effect-list) {
    min-height:0;
    height:100%;
    max-height:none;
    align-content:start;
    overflow-x:hidden;
    overflow-y:auto;
    overscroll-behavior:contain;
    touch-action:pan-y;
    scroll-padding-block:4px;
  }
  #game-window[data-panel="pets"] .pet-detail-scroll {
    min-height:0;
    overflow-x:hidden;
    overflow-y:auto;
    scroll-padding-block:8px;
  }
  #game-window[data-panel="pets"] .pet-feed-footer {
    display:grid;
    grid-template-columns:auto 56px minmax(0,1fr);
    min-width:0;
    margin:0;
    padding:4px 0 0;
    gap:6px;
  }
  #game-window[data-panel="pets"] .pet-feed-footer input {
    width:100%;
    min-width:0;
  }
  #game-window[data-panel="pets"] .pet-feed-footer .pet-primary {
    justify-self:end;
    margin:0;
    max-width:100%;
    white-space:normal;
    overflow-wrap:break-word;
    line-height:1.2;
  }
  #game-window[data-panel="pets"] .pet-upgrade strong {
    display:flex;
    flex-wrap:nowrap;
    max-width:100%;
    gap:3px;
    white-space:nowrap;
    overflow-wrap:normal;
    font-variant-numeric:tabular-nums;
  }
  #game-window[data-panel="pets"] .pet-upgrade strong>span {
    min-width:0;
    overflow-wrap:normal;
    white-space:nowrap;
  }
  #game-window[data-panel="pets"] .pet-detail-actions :is(.pet-upgrade,.pet-carry) {
    min-width:0;
    overflow-wrap:break-word;
    line-height:1.2;
  }
  #game-window[data-panel="pets"] .pet-vitals {
    display:flow-root;
  }
}
/* Keep the desktop's two columns, but put the portrait beside its caption so
   hunger, mutation and buff descriptions retain a usable scroll window. */
@media(orientation:landscape) and (max-height:700px),
      (orientation:landscape) and (max-width:1050px) {
  #game-window[data-panel="pets"] .pet-layout {
    --pet-roster-size:40px;
    grid-template-columns:minmax(0,1.6fr) minmax(0,1fr);
    grid-template-rows:72px minmax(0,1fr);
    gap:6px 10px;
    padding:8px;
  }
  #game-window[data-panel="pets"] .pet-roster-item {
    display:grid;
    grid-template-columns:40px minmax(0,1fr);
    grid-template-rows:auto auto auto;
    align-content:center;
    justify-items:center;
    gap:1px 4px;
    padding:4px 2px;
  }
  #game-window[data-panel="pets"] .pet-roster-art {
    grid-column:1;
    grid-row:1 / 4;
    width:40px;
    height:40px;
  }
  #game-window[data-panel="pets"] .pet-roster-item :is(strong,small,.pet-roster-status) {
    grid-column:2;
    width:100%;
    text-align:center;
    white-space:normal;
    overflow-wrap:break-word;
    line-height:1.2;
  }
  #game-window[data-panel="pets"] .pet-roster-item strong { font-size:12px; }
  #game-window[data-panel="pets"] .pet-roster-item small,
  #game-window[data-panel="pets"] .pet-roster-status { font-size:10px; }
  #game-window[data-panel="pets"] .pet-detail {
    display:grid;
    grid-template-columns:minmax(0,1fr);
    grid-template-rows:auto minmax(0,1fr) auto;
    padding:6px;
    gap:5px;
    border-radius:12px;
    background:#ffda82;
    overflow:hidden;
  }
  #game-window[data-panel="pets"] .pet-profile {
    display:grid;
    grid-template-columns:56px minmax(0,1fr);
    grid-template-rows:auto auto;
    align-items:center;
    align-content:center;
    gap:2px 5px;
  }
  #game-window[data-panel="pets"] .pet-preview {
    grid-column:1;
    grid-row:1 / 3;
    width:56px;
    height:52px;
  }
  #game-window[data-panel="pets"] .pet-main-portrait { height:56px;top:-3px; }
  #game-window[data-panel="pets"] .pet-profile h2 {
    grid-column:2;
    width:100%;
    padding:4px 7px;
    font-size:15px;
    line-height:1.2;
    overflow-wrap:break-word;
  }
  #game-window[data-panel="pets"] .pet-form { grid-column:2;font-size:10px; }
  #game-window[data-panel="pets"] .pet-detail-actions {
    display:grid;
    grid-template-columns:minmax(0,1.25fr) minmax(0,1fr);
    gap:5px;
    padding:0;
  }
  #game-window[data-panel="pets"] .pet-detail-actions button {
    min-height:40px;
    padding:4px 5px;
    font-size:12px;
  }
  #game-window[data-panel="pets"] .pet-detail-actions .pet-upgrade {
    flex-direction:column;
    justify-content:center;
    gap:2px;
    padding:4px;
    font-size:11px;
  }
  #game-window[data-panel="pets"] .pet-upgrade strong { font-size:11px; }
  #game-window[data-panel="pets"] :is(.pet-work,.pet-feeding,.pet-collection) { padding:5px; }
  #game-window[data-panel="pets"] .pet-section-heading { gap:2px 6px;padding:0 0 3px; }
  #game-window[data-panel="pets"] .pet-section-heading h3 { font-size:12px; }
  #game-window[data-panel="pets"] .pet-section-heading>span { font-size:10px; }
  #game-window[data-panel="pets"] .pet-feed-footer input,
  #game-window[data-panel="pets"] .pet-feed-footer .pet-primary { height:36px;min-height:36px; }
  #game-window[data-panel="pets"] .pet-empty {
    display:flex;
    align-items:center;
    justify-content:center;
    gap:6px;
    min-height:0;
    padding:4px 2px;
    font-size:12px;
  }
  #game-window[data-panel="pets"] .pet-empty .crop-icon { width:30px;height:30px;margin:0; }
}
@media(orientation:landscape) and (max-height:500px) {
  #game-window[data-panel="pets"] .pet-layout { grid-template-rows:62px minmax(0,1fr);padding:6px; }
  #game-window[data-panel="pets"] .pet-roster-item { grid-template-columns:32px minmax(0,1fr);gap:1px 3px; }
  #game-window[data-panel="pets"] .pet-roster-art { width:32px;height:32px; }
  #game-window[data-panel="pets"] .pet-profile { grid-template-columns:44px minmax(0,1fr); }
  #game-window[data-panel="pets"] .pet-preview { width:44px;height:42px; }
  #game-window[data-panel="pets"] .pet-main-portrait { height:46px; }
  #game-window[data-panel="pets"] .pet-tabs button { height:32px;min-height:32px;font-size:12px; }
  #game-window[data-panel="pets"] .pet-tabs .crop-icon { width:18px;height:18px; }
}
@media(max-width:700px) and (orientation:portrait) {
  #game-window[data-panel="pets"] .pet-layout {
    grid-template-rows:76px minmax(142px,.8fr) minmax(0,1.2fr);
    gap:7px;
  }
  #game-window[data-panel="pets"] .pet-detail {
    grid-template-columns:70px minmax(0,1fr);
    grid-template-rows:minmax(0,1fr) auto;
    gap:6px;
    padding:6px;
    overflow:hidden;
  }
  #game-window[data-panel="pets"] .pet-profile { overflow:hidden; }
  #game-window[data-panel="pets"] .pet-profile h2 { font-size:13px;padding:4px;overflow-wrap:break-word; }
  #game-window[data-panel="pets"] .pet-detail-actions button { min-height:40px; }
  #game-window[data-panel="pets"] .pet-detail-actions .pet-upgrade { flex-direction:column;justify-content:center;gap:2px; }
  #game-window[data-panel="pets"] .pet-roster-item strong { font-size:12px; }
  #game-window[data-panel="pets"] .pet-roster-art { width:36px;height:36px; }
  #game-window[data-panel="pets"] .pet-roster-item small,
  #game-window[data-panel="pets"] .pet-roster-status { font-size:10px;line-height:1.2; }
  #game-window[data-panel="pets"] :is(.pet-work,.pet-feeding,.pet-collection) { padding:5px; }
  #game-window[data-panel="pets"] .pet-section-heading h3 { font-size:12px; }
  #game-window[data-panel="pets"] .pet-section-heading>span { font-size:10px; }
  #game-window[data-panel="pets"] .pet-feed-footer { grid-template-columns:auto 48px minmax(0,1fr); }
  #game-window[data-panel="pets"] .pet-feed-footer :is(input,.pet-primary) { min-height:40px;height:40px; }
}
/* With the tutorial card open on a short phone, use a narrow pet selector
   column. The feeding controls and detail scrollport keep their full height. */
@media(orientation:landscape) and (max-height:430px) {
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-layout {
    grid-template-columns:minmax(78px,.42fr) minmax(0,1.2fr) minmax(0,1fr);
    grid-template-rows:minmax(0,1fr);
    grid-template-areas:"roster workspace detail";
    gap:5px;
    padding:5px;
  }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-roster {
    grid-template-columns:minmax(0,1fr);
    grid-template-rows:repeat(3,minmax(44px,1fr));
    padding:0 2px;
    gap:2px;
  }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-roster-item {
    display:grid;
    grid-template-columns:24px minmax(0,1fr);
    grid-template-rows:auto;
    padding:2px 0;
  }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-roster-art { width:24px;height:24px;grid-row:1; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-profile { grid-template-columns:30px minmax(0,1fr);gap:2px; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-preview { width:30px;height:30px; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-main-portrait { height:34px; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-profile h2 { font-size:12px;padding:3px; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-detail-actions button { min-height:36px;font-size:11px; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-tabs button { min-height:32px;height:32px; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-tabs .crop-icon { display:none; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-section-heading { display:none; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-work,
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-collection { grid-template-rows:minmax(0,1fr); }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-work-scroll { grid-row:1; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-feeding { grid-template-rows:minmax(0,1fr) auto; }
  body[data-story-panel=true] #game-window[data-panel="pets"] .pet-feed-footer :is(input,.pet-primary) { min-height:32px;height:32px; }
}
