html {
  min-height: 100%;
}

body {
  min-height: 100%;
}

body:not(.adventure-rpg-page) {
  background:
    linear-gradient(180deg, rgba(236, 248, 255, 0.88), rgba(211, 233, 255, 0.94)),
    #dcefff;
}

body:has(.app-bottom-tabbar) {
  padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  color: #17345f;
}

body:has(.app-bottom-tabbar)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 255, 255, 0.82) 0 7%, transparent 8%),
    radial-gradient(circle at 86% 18%, rgba(255, 255, 255, 0.7) 0 8%, transparent 9%),
    linear-gradient(180deg, rgba(239, 249, 255, 0.82), rgba(214, 235, 255, 0.72));
}

body:has(.app-bottom-tabbar) .flash-phone,
body:has(.app-bottom-tabbar) .pet-app,
body:has(.app-bottom-tabbar) .pet-dex-app,
body:has(.app-bottom-tabbar) .admin-shell {
  border-color: #83aef3;
  box-shadow:
    0 10px 0 rgba(76, 126, 202, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.74) inset;
}

.app-bottom-tabbar {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(860px, calc(100% - 32px));
  min-height: 56px;
  padding: 5px;
  border: 2px solid #83aef3;
  border-radius: 16px;
  background: rgba(247, 252, 255, 0.9);
  box-shadow:
    0 8px 0 rgba(76, 126, 202, 0.16),
    inset 0 0 0 1px rgba(255, 255, 255, 0.86);
  transform: translateX(-50%);
}

.app-nav-bag-modal,
.app-nav-training-modal {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(31, 62, 104, 0.34);
  backdrop-filter: blur(3px);
}

.app-nav-bag-modal.is-open,
.app-nav-training-modal.is-open,
body.app-nav-bag-open .app-nav-bag-modal,
body.app-nav-training-open .app-nav-training-modal {
  display: grid;
}

.app-nav-bag-card,
.app-nav-training-card {
  width: min(720px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 34px));
  overflow: auto;
  border: 2px solid #83aef3;
  border-radius: 18px;
  padding: 14px;
  color: #17345f;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(229, 245, 255, 0.9)),
    #eef9ff;
  box-shadow: 0 14px 0 rgba(62, 111, 184, 0.18);
}

.app-nav-bag-card {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.app-nav-bag-head,
.app-nav-training-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.app-nav-bag-head p,
.app-nav-training-head p {
  margin: 0 0 2px;
  color: #3378d8;
  font-size: 12px;
  font-weight: 900;
}

.app-nav-bag-head h2,
.app-nav-training-head h2 {
  margin: 0;
  font-size: clamp(24px, 5vw, 36px);
  line-height: 1;
}

.app-nav-equipment-slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}

.app-nav-equipment-slot {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  min-height: 74px;
  border: 2px solid rgba(131, 174, 243, 0.72);
  border-radius: 14px;
  padding: 9px 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(232, 246, 255, 0.88));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.92);
}

.app-nav-equipment-icon {
  width: 50px;
  height: 50px;
  border: 1.5px solid rgba(131, 174, 243, 0.5);
  border-radius: 12px;
  background:
    var(--bag-item-image) center / contain no-repeat,
    linear-gradient(180deg, #ffffff, #e5f3ff);
  image-rendering: pixelated;
}

.app-nav-equipment-icon.is-empty::after {
  content: "?";
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #8aa7ca;
  font-size: 24px;
  font-weight: 900;
}

.app-nav-equipment-slot small,
.app-nav-equipment-slot strong,
.app-nav-equipment-slot em {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-nav-equipment-slot small {
  color: #3378d8;
  font-size: 12px;
  font-weight: 900;
}

.app-nav-equipment-slot strong {
  margin-top: 2px;
  color: #17345f;
  font-size: 16px;
  font-weight: 1000;
}

.app-nav-equipment-slot em {
  margin-top: 2px;
  color: #d38311;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.app-nav-bag-close,
.app-nav-training-close,
.app-nav-bag-use,
.app-nav-bag-cancel {
  min-height: 38px;
  border: 2px solid #83aef3;
  border-radius: 10px;
  padding: 7px 12px;
  color: #17345f;
  font-weight: 900;
  background: linear-gradient(180deg, #ffffff, #e5f3ff);
  cursor: pointer;
}

.app-nav-bag-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.app-nav-bag-filters button {
  min-height: 34px;
  border: 1.5px solid #9ec2ef;
  border-radius: 999px;
  padding: 5px 12px;
  color: #244f98;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.82);
}

.app-nav-bag-filters button.active {
  color: #fff;
  border-color: #4f7edc;
  background: linear-gradient(180deg, #79aaf3, #527ed9);
}

.app-nav-bag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
  min-height: 160px;
  border: 2px solid rgba(131, 174, 243, 0.58);
  border-radius: 14px;
  padding: 10px;
  background: rgba(235, 248, 255, 0.72);
}

.app-nav-bag-box {
  min-height: 0;
  overflow: auto;
}

.app-nav-bag-item {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 108px;
  border: 2px solid #9ec2ef;
  border-radius: 12px;
  padding: 7px;
  color: #17345f;
  background: rgba(255, 255, 255, 0.86);
}

.app-nav-bag-item.selected {
  border-color: #edb34e;
  background: rgba(255, 249, 224, 0.94);
  box-shadow:
    0 0 0 2px rgba(255, 211, 90, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.92);
}

.app-nav-bag-inline-actions {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  margin-top: 3px;
}

.app-nav-bag-inline-actions .app-nav-bag-use,
.app-nav-bag-inline-actions .app-nav-bag-cancel {
  min-height: 26px;
  border-radius: 7px;
  padding: 4px 5px;
  font-size: 11px;
  line-height: 1;
}

.app-nav-bag-inline-actions .app-nav-bag-use {
  color: #744608;
  border-color: #edb34e;
  background: linear-gradient(180deg, #fff5bd, #ffd35a);
}

.app-nav-bag-use.is-disabled,
.app-nav-bag-use:disabled,
.app-nav-bag-inline-actions .app-nav-bag-use.is-disabled {
  color: #8c9aad;
  border-color: #c5d1df;
  background: linear-gradient(180deg, #f3f6fa, #dce4ee);
  box-shadow: none;
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.72;
}

.app-nav-bag-thumb,
.app-nav-bag-detail-icon {
  width: 46px;
  height: 46px;
  background: var(--bag-item-image) center / contain no-repeat;
  image-rendering: pixelated;
}

.app-nav-bag-name {
  color: #d38311;
  font-size: 12px;
  line-height: 1.15;
  text-align: center;
}

.app-nav-bag-count {
  color: #496b9a;
  font-size: 12px;
  font-weight: 900;
}

.app-nav-bag-empty {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
  color: #496b9a;
  font-weight: 900;
}

.app-nav-bag-detail {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  border: 2px solid rgba(237, 179, 78, 0.68);
  border-radius: 14px;
  padding: 10px;
  background: rgba(255, 248, 225, 0.84);
}

.app-nav-bag-detail:not(.has-selection) .app-nav-bag-detail-icon {
  opacity: 0.35;
}

.app-nav-bag-detail[hidden] {
  display: none;
}

.app-nav-bag-detail-text strong {
  display: block;
  color: #d38311;
  font-size: 16px;
}

.app-nav-bag-detail-text p {
  margin: 3px 0 0;
  color: #496b9a;
  font-size: 13px;
  font-weight: 800;
}

.app-nav-bag-detail-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.app-nav-bag-detail-actions .app-nav-bag-use {
  min-width: 84px;
  color: #744608;
  border-color: #edb34e;
  background: linear-gradient(180deg, #fff5bd, #ffd35a);
}

.app-nav-bag-detail-actions .app-nav-bag-cancel {
  min-width: 84px;
}

.app-nav-bag-detail-actions .app-nav-bag-cancel:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.app-nav-training-card {
  position: relative;
  width: min(760px, calc(100vw - 28px));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(231, 246, 255, 0.88)),
    url("assets/ui/cloud-kingdom-game-bg.png") center bottom / cover no-repeat,
    #e9f8ff;
}

.app-nav-training-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.app-nav-training-head {
  padding-right: 84px;
}

.app-nav-training-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.app-nav-training-option {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 132px;
  border: 2px solid rgba(131, 174, 243, 0.72);
  border-radius: 16px;
  padding: 12px;
  color: #17345f;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.86);
}

.app-nav-training-option.sentence {
  border-color: rgba(131, 174, 243, 0.72);
  background: rgba(255, 255, 255, 0.86);
}

.app-nav-training-art {
  display: grid;
  place-items: center;
}

.app-nav-training-art img {
  width: 62px;
  height: 62px;
  object-fit: contain;
  image-rendering: pixelated;
}

.app-nav-training-copy strong {
  display: block;
  font-size: clamp(22px, 4vw, 34px);
  line-height: 1;
}

.app-nav-training-copy span,
.app-nav-training-copy em {
  display: block;
  margin-top: 5px;
  color: #496b9a;
  font-size: 13px;
  font-style: normal;
  font-weight: 850;
}

@media (max-width: 560px) {
  .app-nav-training-options {
    grid-template-columns: 1fr;
  }

  .app-nav-bag-detail {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .app-nav-bag-detail-actions {
    grid-column: 1 / -1;
  }
}

.app-bottom-tabbar a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 44px;
  padding: 4px 8px;
  color: #244f98;
  border: 1px solid transparent;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 900;
  line-height: 1;
}

.app-bottom-tabbar a.active,
.app-bottom-tabbar a.is-active {
  color: #fff;
  border-color: #4f7edc;
  background: linear-gradient(180deg, #79aaf3, #527ed9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.app-bottom-tabbar img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  image-rendering: pixelated;
}

.app-bottom-tabbar strong,
.app-bottom-tabbar span {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.app-bottom-tabbar .nav-text {
  font-weight: 900;
}

.game-page-nav {
  display: none !important;
}

@media (max-width: 520px) {
  body:has(.app-bottom-tabbar) {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  .app-nav-equipment-slots {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .app-nav-equipment-slot {
    min-height: 64px;
    grid-template-columns: 48px minmax(0, 1fr);
    padding: 8px;
  }

  .app-nav-equipment-icon {
    width: 44px;
    height: 44px;
  }

  .app-nav-equipment-slot strong {
    font-size: 15px;
  }

  .app-bottom-tabbar {
    width: calc(100% - 18px);
    min-height: 50px;
    border-radius: 12px;
  }

  .app-bottom-tabbar a {
    flex-direction: column;
    gap: 2px;
    min-height: 40px;
    padding: 3px 2px;
  }

  .app-bottom-tabbar img {
    width: 24px;
    height: 24px;
  }

  .app-bottom-tabbar strong,
  .app-bottom-tabbar span {
    max-width: 100%;
    font-size: 11px;
  }
}

/* Homepage bottom navigation 4-breakpoint lock.
   These rules replace the older accumulated 540/900/1180 overrides for the lobby only. */
body.landing-page:has(.app-bottom-tabbar) {
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important;
}

body.landing-page .app-bottom-tabbar {
  left: 50% !important;
  right: auto !important;
  bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  width: min(860px, calc(100vw - 32px)) !important;
  max-width: min(860px, calc(100vw - 32px)) !important;
  min-width: 0 !important;
  min-height: 64px !important;
  gap: 6px !important;
  padding: 6px !important;
  border-radius: 18px !important;
  transform: translateX(-50%) !important;
}

body.landing-page .app-bottom-tabbar a {
  min-width: 0 !important;
  min-height: 52px !important;
  padding: 5px 8px !important;
  border-radius: 14px !important;
}

body.landing-page .app-bottom-tabbar img {
  width: 28px !important;
  height: 28px !important;
}

body.landing-page .app-bottom-tabbar strong,
body.landing-page .app-bottom-tabbar span {
  max-width: 100% !important;
  overflow: hidden !important;
  font-size: 13px !important;
  line-height: 1.05 !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

/* 1. Phone */
@media (max-width: 540px) {
  body.landing-page:has(.app-bottom-tabbar) {
    padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.landing-page .app-bottom-tabbar {
    bottom: 0 !important;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    min-height: 72px !important;
    gap: 2px !important;
    padding: 6px 6px calc(7px + env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 18px 18px 0 0 !important;
  }

  body.landing-page .app-bottom-tabbar a {
    min-height: 56px !important;
    padding: 4px 1px !important;
    border-radius: 14px !important;
  }

  body.landing-page .app-bottom-tabbar img {
    width: 26px !important;
    height: 26px !important;
  }

  body.landing-page .app-bottom-tabbar strong,
  body.landing-page .app-bottom-tabbar span {
    font-size: 12px !important;
  }
}

/* 2. Tablet portrait */
@media (min-width: 541px) and (max-width: 900px) {
  body.landing-page .app-bottom-tabbar {
    width: min(720px, calc(100vw - 32px)) !important;
    max-width: min(720px, calc(100vw - 32px)) !important;
  }
}

/* 3. Tablet landscape / middle width */
@media (min-width: 901px) and (max-width: 1180px) {
  body.landing-page .app-bottom-tabbar {
    width: min(820px, calc(100vw - 64px)) !important;
    max-width: min(820px, calc(100vw - 64px)) !important;
  }
}

/* 4. Desktop */
@media (min-width: 1181px) {
  body.landing-page .app-bottom-tabbar {
    width: min(860px, calc(100vw - 32px)) !important;
    max-width: min(860px, calc(100vw - 32px)) !important;
  }
}
