/* 寵物算檔 */

.pets-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "summon forecast sim"
    "summon compare sim";
  gap: 18px;
  align-items: start;
}

.area-summon { grid-area: summon; }
.area-forecast { grid-area: forecast; min-width: 0; }
.area-compare { grid-area: compare; min-width: 0; }

.area-sim {
  grid-area: sim;
}

/* 只有螢幕夠高、整塊設定放得下時才黏著；矮螢幕（筆電）黏著會讓下半部被右下角的懸浮卡蓋住而且捲不出來 */
@media (min-height: 940px) {
  .area-sim {
    position: sticky;
    top: calc(var(--topbar-h) + var(--ad-anchor-top, 0px) + 16px);
  }
}

.area-compare .ad-slot {
  margin-top: 0;
}

.sub-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-2);
  margin-bottom: 8px;
}

.sub-label .hud {
  margin-left: auto;
}

.link-btn {
  border: 0;
  background: none;
  padding: 2px 4px;
  color: var(--aqua);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- 召喚台 ---------- */
.summon {
  display: grid;
  gap: 14px;
}

.combo {
  position: relative;
  margin-top: 2px;
}

.combo__icon {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.combo__input {
  padding-left: 40px;
  min-height: 46px;
  font-size: 1rem;
}

.combo__list {
  position: absolute;
  z-index: 60;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  max-height: min(360px, 55vh);
  overflow-y: auto;
  list-style: none;
  padding: 6px;
  margin: 0;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--panel-solid);
  box-shadow: 0 24px 48px -16px rgba(0, 0, 0, 0.55);
}

.combo__list:empty {
  display: none;
}

.combo__list li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
}

.combo__list li img {
  width: 32px;
  height: 28px;
  object-fit: contain;
  image-rendering: pixelated;
}

.combo__list li:hover,
.combo__list li[aria-selected="true"] {
  background: var(--aqua-soft);
  color: var(--aqua);
}

.manual-hint {
  margin: 2px 0 10px;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.manual-grid .input {
  min-height: 38px;
}

/* 召喚陣 */
.pet-stage {
  --sprite-max-h: 156px; /* 召喚台高度 − 腳下 30px − 上方 14px */
  position: relative;
  height: 200px;
  display: grid;
  place-items: end center;
  perspective: 700px;
  border-radius: 12px;
  background: radial-gradient(120% 90% at 50% 100%, var(--aqua-soft), transparent 70%);
  overflow: hidden;
}

.pet-stage .mc {
  position: absolute;
  left: 50%;
  bottom: -62px;
  width: 260px;
  height: 260px;
  margin-left: -130px;
  transform: rotateX(70deg);
  opacity: 0.95;
}

.petPic {
  position: relative;
  z-index: 2;
  margin-bottom: 30px;
  display: grid;
  place-items: end center;
  min-height: 60px;
}

.petPic img {
  /* 尺寸由 pets-ui.js 依召喚台大小計算；這裡的上限是腳本還沒執行時的保險 */
  width: auto;
  height: auto;
  max-height: var(--sprite-max-h);
  object-fit: contain;
  image-rendering: pixelated;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.35s, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.pet-stage.has-pet .petPic img {
  opacity: 1;
  transform: none;
  animation: float 4s ease-in-out infinite;
}

.petPic::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  width: 70px;
  height: 12px;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.45), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.pet-stage.has-pet .petPic::after {
  opacity: 1;
}

.pet-stage__empty {
  position: absolute;
  inset: 0 16px 76px;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-3);
}

.pet-stage.has-pet .pet-stage__empty {
  display: none;
}

.pet-id {
  text-align: center;
}

.pet-id__no {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.pet-id__no::before {
  content: "No.";
}

.pet-id__name {
  font-size: 1.5rem;
  margin: 2px 0 10px;
}

.pet-id__tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.pet-id__tags b {
  color: var(--text);
}

.chip--total b {
  color: var(--aqua);
}

/* 成長檔 */
.growth-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 30px 78px;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.growth-row__label {
  font-size: 0.84rem;
  color: var(--text-2);
}

.growth-row__bar {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
}

.growth-row__bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 45%, transparent), var(--c));
  box-shadow: 0 0 10px -2px var(--c);
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.growth-row__val {
  text-align: right;
  font-weight: 600;
}

.growth-row__stars {
  font-size: 0.66rem;
  white-space: nowrap;
  overflow: hidden;
  color: #ffac00;
}

/* 屬性條：舊程式每 1 點輸出一個圖示，這裡把每個圖示畫成一格，湊成魔力寶貝的十格屬性條 */
.el-gauge__bar {
  display: flex;
  gap: 3px;
  height: 14px;
  padding: 2px;
  border-radius: 6px;
  background: var(--panel-3);
}

.el-gauge__bar .arrcolor {
  display: contents;
}

.el-gauge__bar i {
  display: block;
  flex: 0 0 calc((100% - 27px) / 10);
  height: 100%;
  border-radius: 3px;
  font-size: 0 !important;
  line-height: 0 !important;
  background: var(--seg, var(--text-3));
  box-shadow: 0 0 8px -2px var(--seg, transparent);
}

.el-gauge__bar i::before {
  content: none !important;
}

.el-gauge__bar .fa-leaf { --seg: var(--earth); }
.el-gauge__bar .fa-tint { --seg: var(--water); }
.el-gauge__bar .fa-gripfire { --seg: var(--fire); }
.el-gauge__bar .fa-cloud { --seg: var(--wind); }

.el-gauge__legend {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  list-style: none;
  padding: 0;
  margin-top: 8px;
}

.el-gauge__legend li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 3px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 0.82rem;
}

.el-gauge__legend b {
  color: var(--c);
}

.el-gauge__legend li.is-zero {
  opacity: 0.45;
}

.pet-trait {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--field);
  font-size: 0.86rem;
}

.pet-trait__label {
  flex-shrink: 0;
  color: var(--text-3);
}

.petProbability:empty::before {
  content: "—";
  color: var(--text-3);
}

/* ---------- 能力預測 ---------- */
.level {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--field);
  margin-bottom: 14px;
}

.level__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.level__readout {
  display: flex;
  align-items: center;
  gap: 6px;
}

.level__readout .input {
  width: 68px;
  min-height: 38px;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--aqua);
}

.level__quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.level__quick .chip {
  min-height: 28px;
  font-family: var(--font-hud);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.forecast-table th[scope="row"] {
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
}

.forecast-table th[scope="row"] .hud {
  margin-left: 4px;
  font-size: 0.66rem;
}

.forecast-table .num-col {
  text-align: right;
  font-family: var(--font-hud);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  width: 28%;
}

.forecast-table td.is-target {
  color: var(--text);
  font-weight: 600;
  font-size: 1.1rem;
  background: color-mix(in srgb, var(--aqua) 7%, transparent);
}

.forecast-table thead th.is-target {
  color: var(--aqua);
}

.forecast-table tbody tr:last-child > * {
  border-bottom: 0;
}

.forecast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 12px;
  align-items: start;
}

.area-forecast {
  container-type: inline-size;
}

/* 中間欄窄的時候拿掉英文小標，兩張表才放得下並排 */
@container (max-width: 500px) {
  .forecast-table th[scope="row"] .hud {
    display: none;
  }
}

.forecast-hint {
  margin-top: 10px;
}

/* 中間欄切換按鈕只在桌機工作台出現 */
.mid-switch {
  display: none;
}

.mid-switch.is-bumped {
  animation: bump 0.6s ease-out;
}

@keyframes bump {
  30% {
    transform: scale(1.06);
    box-shadow: var(--glow);
  }
}

.forecast-table .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 2px;
  background: var(--c);
  transform: rotate(45deg) translateY(-1px);
}

.forecast-table td.flash {
  animation: cell-flash 0.7s ease-out;
}

@keyframes cell-flash {
  from {
    box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--aqua) 22%, transparent);
  }
}

.pred-note {
  margin-top: 12px;
}

.pred-note:has(.predPS:empty) {
  display: none;
}

/* ---------- 比較清單 ---------- */
.compare .panel__head h2 {
  gap: 8px;
}

.compare__clear {
  margin-left: auto;
}

.compare__body {
  display: grid;
  /* 欄寬固定在面板內；不然寬表格會把 grid 撐開，手機整頁變寬被縮小顯示 */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-content: start;
}

.compare__empty {
  color: var(--text-3);
  font-size: 0.86rem;
}

.seg--cmp {
  flex-wrap: nowrap;
}

.seg--cmp span {
  min-height: 32px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.cmp-status {
  font-size: 0.8rem;
  color: var(--ok);
}

/* 即時比較表：每筆一列、數字對齊；窄的時候左右捲動，第一欄固定 */
.cmp-wrap {
  /* position: relative 讓表格裡絕對定位的隱藏文字以這裡為基準，才會被一起裁切；
     否則它會跑到表格右端、撐寬整頁，手機就被縮小顯示 */
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  scrollbar-width: thin;
}

.cmp-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.86rem;
}

.cmp-table th,
.cmp-table td {
  padding: 7px 7px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--panel-solid);
}

.cmp-table tbody tr:last-child > * {
  border-bottom: 0;
}

.cmp-table thead th {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-3);
  background: var(--panel-2);
}

.cmp-table th[scope="row"],
.cmp-table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 128px;
  text-align: left;
  font-weight: 500;
  border-right: 1px solid var(--line);
}

.cmp-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text);
}

.cmp-table th[scope="row"] small {
  display: block;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-3);
}

.cmp-tag,
.cmp-warn {
  padding: 0 6px;
  border-radius: 5px;
  font-size: 0.66rem;
  line-height: 1.6;
  border: 1px solid currentColor;
}

.cmp-tag {
  color: var(--aqua);
}

.cmp-warn {
  color: var(--fire);
}

.cmp-current > * {
  background: color-mix(in srgb, var(--aqua) 8%, var(--panel-solid));
}

.cmp-table td.num-col {
  text-align: right;
  font-family: var(--font-hud);
  font-variant-numeric: tabular-nums;
}

.cmp-table td b {
  font-weight: 600;
}

.cmp-table td small {
  display: block;
  font-size: 0.68rem;
  line-height: 1.1;
}

.cmp-table td.is-up {
  color: var(--ok);
}

.cmp-table td.is-down {
  color: var(--danger);
}

.cmp-act {
  width: 1%;
  padding-left: 4px;
  text-align: right;
}

.cmp-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text-3);
  font-weight: 700;
}

.cmp-btn .i {
  width: 16px;
  height: 16px;
}

.cmp-add {
  border-color: color-mix(in srgb, var(--gold) 60%, transparent);
  background: var(--gold-soft);
  color: var(--gold);
}

.cmp-add:hover:not(:disabled) {
  border-color: var(--gold);
  box-shadow: 0 0 14px -4px color-mix(in srgb, var(--gold) 70%, transparent);
}

.cmp-add:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cmp-del:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------- 模擬設定 ---------- */
.sim {
  display: grid;
  gap: 18px;
}

.drop-total {
  margin-left: auto;
  font-weight: 500;
  color: var(--text-3);
}

.drop-total b {
  color: var(--text);
}

.drop-total.is-dropped b {
  color: var(--fire);
}

.grade-panel {
  display: grid;
  gap: 6px;
}

.grade-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.grade-row__label {
  font-weight: 700;
  text-align: center;
  color: var(--c);
}

.seg--grade {
  flex-wrap: nowrap;
  gap: 4px;
}

.seg--grade span {
  min-height: 32px;
  padding: 0 4px;
  font-size: 0.8rem;
}

.seg--grade label:nth-child(2) { --c: var(--wind); }
.seg--grade label:nth-child(3) { --c: var(--st-str); }
.seg--grade label:nth-child(4) { --c: var(--fire); }
.seg--grade label:nth-child(5) { --c: var(--danger); }

.seg--strategy {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.points-left {
  margin-left: auto;
  font-weight: 500;
  color: var(--text-3);
}

.points-left .points {
  width: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--aqua);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
}

.mix-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.mix-item {
  display: grid;
  gap: 4px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--c);
}

.mix-item .input {
  min-height: 38px;
  padding: 4px 2px;
}

.mix-item .input[readonly] {
  border-color: color-mix(in srgb, var(--c) 60%, transparent);
  color: var(--c);
}

.sim-equip > summary .i {
  color: var(--aqua);
}

.sim-equip > summary .hud {
  margin-left: 4px;
}

.equip-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.equip-grid .input {
  min-height: 38px;
}

/* ---------- 手機版：固定結果摘要 ---------- */
.mini-result {
  display: none;
}

/* ---------- RWD ---------- */
@media (max-width: 1240px) {
  .pets-layout {
    grid-template-columns: 330px minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "summon forecast"
      "sim compare";
  }

  .area-sim {
    position: static;
  }
}

@media (max-width: 820px) {
  .pets-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "summon"
      "forecast"
      "sim"
      "compare";
    gap: 14px;
  }

  .pet-stage {
    --sprite-max-h: 126px;
    height: 170px;
  }

  .comparison-table {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .mini-result {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(var(--topbar-h) + var(--ad-anchor-top, 0px));
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px var(--gutter);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    font-size: 0.8rem;
    transform: translateY(-120%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
  }

  .mini-result.is-visible {
    transform: none;
    opacity: 1;
  }

  .mini-result__name {
    font-weight: 700;
    max-width: 30%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mini-result__lv b {
    color: var(--aqua);
  }

  .mini-result__stats {
    margin-left: auto;
    display: flex;
    gap: 8px;
    color: var(--text-3);
  }

  .mini-result__stats b {
    color: var(--text);
  }
}

/* ---------- 桌機工作台 ----------
   三欄剛好填滿一個畫面，各欄自己捲動、整頁不動：調設定的同時一直看得到結果（取代 v2 的中間夾層）。
   比較清單和能力預測共用中間欄，用按鈕切換。 */
@media (min-width: 1100px) and (min-height: 620px) {
  .page-pets .app-container {
    padding-top: 14px;
  }

  .page-pets .page-head {
    display: flex;
    align-items: baseline;
    gap: 16px;
    min-width: 0;
    margin-bottom: 12px;
  }

  .page-pets .page-head .eyebrow {
    display: none;
  }

  .page-pets .page-head h1 {
    font-size: 1.35rem;
    white-space: nowrap;
  }

  .page-pets .page-head .lede {
    min-width: 0;
    max-width: none;
    margin: 0;
    font-size: 0.86rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pets-layout {
    /* 兩側欄隨寬度縮放，把空間優先留給中間的結果 */
    grid-template-columns: clamp(270px, 24vw, 320px) minmax(0, 1fr) clamp(280px, 24vw, 330px);
    grid-template-rows: calc(100vh - var(--topbar-h) - var(--ad-anchor-top, 0px) - var(--ad-anchor-bottom, 0px) - 80px);
    grid-template-rows: calc(100dvh - var(--topbar-h) - var(--ad-anchor-top, 0px) - var(--ad-anchor-bottom, 0px) - 80px);
    grid-template-areas: "summon forecast sim";
    align-items: stretch;
  }

  .area-compare {
    grid-area: forecast;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
  }

  .pets-layout:not([data-mid="compare"]) > .area-compare,
  .pets-layout[data-mid="compare"] > .area-forecast {
    display: none;
  }

  .mid-switch {
    display: inline-flex;
  }

  .area-summon,
  .area-forecast,
  .area-sim,
  .area-compare .compare {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .area-compare .compare {
    flex: 1 1 auto;
  }

  .area-sim {
    position: relative;
    top: auto;
  }

  .pets-layout .panel__head,
  .pets-layout .panel__foot {
    flex: none;
  }

  .pets-layout .panel__body {
    --fade-top: 0px;
    --fade-bottom: 0px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--line-2) transparent;
    /* 欄內還有內容時在上下緣淡出，提示可以捲（pets-ui.js 切換 more-above / more-below） */
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent 100%);
  }

  .pets-layout .panel__body.more-above {
    --fade-top: 22px;
  }

  .pets-layout .panel__body.more-below {
    --fade-bottom: 40px;
  }

  /* 懸浮卡在這頁改放左下角：那裡是召喚台的展示資訊，不會擋到右邊要操作的設定欄。
     召喚台底部多留一段，最後的內容捲得上來 */
  .page-pets .boost-card {
    left: 20px;
    right: auto;
  }

  body:has(.boost-card) .area-summon .panel__body {
    padding-bottom: 96px;
  }

  /* 緊湊排版，讓 768px 高的筆電也放得下 */
  .summon {
    gap: 10px;
  }

  .pet-stage {
    --stage-h: clamp(140px, 21vh, 200px);
    --sprite-max-h: calc(var(--stage-h) - 44px);
    height: var(--stage-h);
  }

  .growth-row {
    padding: 2px 0;
  }

  .sim {
    gap: 14px;
  }

  .level {
    margin-bottom: 10px;
    padding: 10px 12px;
  }

  .forecast-table th,
  .forecast-table td {
    padding: 6px 8px;
  }

  .seg--grade span {
    min-height: 30px;
  }

  .grade-panel {
    gap: 4px;
  }

  .seg--strategy span {
    min-height: 34px;
  }
}
