
/*
 * Taiyue XXL Game v1.8.2-rc.6
 * Full-page responsive audit and adaptation pass.
 *
 * Target surfaces:
 * - Battle board
 * - Story card / formal art panel
 * - Skill buttons / item buttons / objective pills
 * - Result dialog
 * - Shop
 * - Codex / gallery
 * - Weekly goals and rankings
 * - iPhone width, Android mid width, iPad portrait, PC narrow window
 */

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.screen.active {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ===== rc3 chapter card fix retained as part of rc4 baseline ===== */
:root {
  --xxl-card-side-art: clamp(82px, 24%, 140px);
}

.chapter-screen {
  overflow-x: hidden;
}

.chapter-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)) !important;
  align-items: stretch !important;
  gap: clamp(12px, 1.4vw, 18px) !important;
}

.chapter-card {
  position: relative !important;
  isolation: isolate;
  display: block !important;
  min-height: 268px !important;
  height: auto !important;
  padding: 0 !important;
  overflow: hidden !important;
}

.chapter-card::before {
  z-index: 0;
}

.chapter-card-content {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  min-height: 268px;
  height: 100%;
  padding: 18px;
  padding-right: calc(var(--xxl-card-side-art) + 14px);
}

.chapter-card .chapter-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start !important;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.chapter-card .chapter-meta span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chapter-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin: 10px 0 8px;
  min-width: 0;
}

.chapter-card .formal-tag,
.chapter-card .best-badge,
.chapter-card .chapter-stars {
  position: static !important;
  inset: auto !important;
  display: inline-flex !important;
  align-items: center;
  width: auto !important;
  max-width: 100% !important;
  margin: 0 !important;
  line-height: 1.25 !important;
  white-space: normal !important;
  overflow-wrap: anywhere;
}

.chapter-card .chapter-stars {
  letter-spacing: 1px !important;
  color: #fde68a;
  text-shadow: 0 1px 4px rgba(0,0,0,.55);
}

.chapter-card h2 {
  max-width: 100% !important;
  margin: 4px 0 7px !important;
  font-size: clamp(18px, 2vw, 22px) !important;
  line-height: 1.24 !important;
  letter-spacing: 0 !important;
  word-break: break-word;
}

.chapter-card p {
  max-width: 100% !important;
  color: #dbeafe;
  line-height: 1.55 !important;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.chapter-card button {
  position: static !important;
  z-index: 4 !important;
  width: 100%;
  min-height: 44px;
  margin-top: auto !important;
  flex-shrink: 0;
}

.chapter-card .chapter-portrait {
  position: absolute !important;
  z-index: 1 !important;
  right: 4px !important;
  bottom: 54px !important;
  width: var(--xxl-card-side-art) !important;
  max-height: 148px !important;
  object-fit: contain !important;
  object-position: bottom right !important;
  opacity: .26 !important;
  pointer-events: none;
  filter: drop-shadow(0 22px 34px rgba(0,0,0,.52));
}

/* ===== full-page responsive audit fixes ===== */
.hero,
.topbar,
.battle-layout,
.scan-panel,
.footer-note {
  width: min(1480px, 100%);
}

.hero,
.topbar,
.story-card,
.board-card,
.codex-card,
.shop-card,
.result-card {
  min-width: 0;
}

.battle-layout {
  align-items: start;
}

.story-card,
.board-card,
.codex-card {
  overflow: hidden;
}

.board-card {
  position: relative;
}

.board-zone {
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.board {
  --xxl-board-gap: clamp(4px, 1.15vw, 8px);
  --xxl-board-pad: clamp(8px, 1.8vw, 14px);
  --cell: clamp(38px, 13.4vw, 72px);
  gap: var(--xxl-board-gap) !important;
  padding: var(--xxl-board-pad) !important;
  max-width: 100%;
  margin-inline: auto;
}

.tile {
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
}

.badge {
  max-width: calc(100% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud {
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)) !important;
}

.hud div {
  min-width: 0;
}

.hud strong {
  overflow-wrap: anywhere;
}

.objective-list,
.skill-bar,
.item-bar,
.control-row {
  width: 100%;
  min-width: 0;
}

.objective-pill,
.skill-btn,
.item-btn {
  min-width: 0 !important;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.skill-btn {
  flex: 1 1 136px;
  justify-content: flex-start;
}

.skill-btn img {
  flex: 0 0 auto;
}

.control-row button {
  min-height: 42px;
}

.portrait-row {
  min-width: 0;
}

.portrait-row > div {
  min-width: 0;
}

.portrait-row p,
.hint-box p,
.codex-card p,
.codex-card li,
#taiyue-xxl-game-intent-copy {
  overflow-wrap: anywhere;
}

.formal-art-panel {
  min-height: clamp(150px, 26vh, 220px) !important;
}

.formal-art-panel img {
  height: clamp(190px, 34vh, 320px) !important;
}

.result-mask {
  padding: 12px;
  overflow: auto;
}

.result-card {
  width: min(430px, 100%) !important;
  max-height: min(88dvh, 620px);
  overflow: auto;
}

.result-card h2 {
  font-size: clamp(22px, 6vw, 28px) !important;
}

.result-card .buttons {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
}

.cutin {
  max-width: calc(100% - 24px);
  text-align: center;
  font-size: clamp(20px, 6vw, 28px) !important;
  white-space: normal;
}

.coach {
  max-width: min(560px, calc(100vw - 24px)) !important;
}

/* ===== modal surfaces: shop / codex / ranking ===== */
.shop-mask {
  place-items: start center !important;
  overflow: auto !important;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)) !important;
}

.shop-card {
  width: min(680px, 100%) !important;
  max-height: calc(100dvh - 20px) !important;
  overflow: auto !important;
  -webkit-overflow-scrolling: touch;
}

.shop-card header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: linear-gradient(180deg,#fff7ed,#fde68a);
  padding-bottom: 8px;
}

.shop-card h2 {
  font-size: clamp(20px, 5.4vw, 24px) !important;
}

.shop-crystal {
  overflow-wrap: anywhere;
}

.shop-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)) !important;
}

.shop-item {
  min-width: 0;
}

.shop-row {
  flex-wrap: wrap;
}

.shop-row .primary-btn,
.shop-row .ghost-btn,
.shop-item .buy,
.shop-item .upg {
  min-height: 38px;
}

.codex-grid {
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)) !important;
}

.codex-cell {
  min-width: 0;
}

.codex-cell img,
.codex-cell.locked .lock {
  width: clamp(48px, 14vw, 56px) !important;
  height: clamp(48px, 14vw, 56px) !important;
}

.codex-cell figcaption {
  overflow-wrap: anywhere;
}

.codex-levels {
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)) !important;
}

.goal-top,
.reward-box,
.name-row {
  flex-wrap: wrap;
  min-width: 0;
}

.rank-list li {
  min-width: 0;
  flex-wrap: wrap;
}

.rank-list .rk {
  flex: 0 0 34px;
}

.rank-list .rd {
  min-width: 0;
  flex: 1 1 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list .rs {
  flex: 0 0 auto;
}

/* ===== tablet and PC narrow: board first, story below ===== */
@media (max-width: 1180px) {
  .battle-layout {
    grid-template-columns: 1fr !important;
  }

  .board-card {
    order: 1;
  }

  .story-card {
    order: 2;
  }

  .codex-card {
    order: 3;
  }

  .board {
    --cell: clamp(48px, 9.1vw, 72px);
  }

  .story-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 340px);
    gap: 12px;
    align-items: start;
  }

  .story-card .portrait-row,
  .story-card .hint-box,
  .story-card .choice-box,
  .story-card #taiyue-xxl-game-dialogue-next {
    grid-column: 1;
  }

  .story-card .formal-art-panel {
    grid-column: 2;
    grid-row: 1 / span 4;
    margin-top: 0;
  }

  .codex-card {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
  }
}

/* ===== mobile and phone widths ===== */
@media (max-width: 720px) {
  .screen {
    padding-left: max(10px, env(safe-area-inset-left)) !important;
    padding-right: max(10px, env(safe-area-inset-right)) !important;
  }

  .hero,
  .topbar {
    align-items: stretch !important;
    flex-direction: column !important;
    border-radius: 22px !important;
  }

  .topbar > button,
  .hero-actions,
  .hero-actions label,
  .hero-actions button,
  .topbar .ghost-btn {
    width: 100%;
  }

  .title-group h1 {
    font-size: clamp(20px, 6vw, 23px) !important;
  }

  .title-group p {
    font-size: 13px;
  }

  .chapter-grid {
    grid-template-columns: 1fr !important;
  }

  .chapter-card {
    min-height: 0 !important;
    border-radius: 22px !important;
  }

  .chapter-card-content {
    min-height: 224px !important;
    padding: 16px !important;
    padding-right: 16px !important;
  }

  .chapter-card .chapter-portrait {
    display: none !important;
  }

  .battle-layout {
    gap: 10px !important;
  }

  .board-card,
  .story-card,
  .codex-card {
    border-radius: 22px !important;
    padding: 12px !important;
  }

  .story-card {
    display: block;
  }

  .story-card .formal-art-panel {
    margin-top: 12px;
  }

  .formal-art-panel {
    min-height: 138px !important;
  }

  .formal-art-panel img {
    height: 190px !important;
  }

  .portrait-row {
    min-height: 0 !important;
  }

  .portrait-row img,
  .hint-box img {
    width: 52px !important;
    height: 52px !important;
    border-radius: 15px !important;
  }

  .board {
    --cell: clamp(38px, 13.35vw, 56px);
    border-radius: 20px !important;
  }

  .tile {
    border-radius: 13px !important;
  }

  .badge {
    min-width: 18px !important;
    height: 18px !important;
    font-size: 10px !important;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .objective-list {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
  }

  .skill-bar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .skill-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 8px 9px !important;
  }

  .skill-btn img {
    width: 26px !important;
    height: 26px !important;
  }

  .item-bar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-btn {
    width: 100%;
  }

  .control-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
  }

  .control-row button:first-child {
    grid-column: 1 / -1;
  }

  .codex-card {
    display: block;
  }

  .shop-card {
    border-radius: 20px !important;
    padding: 14px !important;
  }

  .rank-list li {
    padding: 8px 10px !important;
  }

  .coach {
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    top: max(10px, env(safe-area-inset-top)) !important;
    transform: none !important;
    max-width: none !important;
  }
}

@media (max-width: 420px) {
  .hero h1 {
    font-size: clamp(23px, 8vw, 28px) !important;
    letter-spacing: .08em !important;
  }

  .eyebrow {
    font-size: 11px;
    letter-spacing: .08em;
  }

  .board-card,
  .story-card,
  .codex-card {
    padding: 10px !important;
  }

  .board {
    --cell: clamp(37px, 13.1vw, 52px);
    --xxl-board-gap: 5px;
    --xxl-board-pad: 8px;
  }

  .skill-bar,
  .item-bar,
  .control-row {
    grid-template-columns: 1fr !important;
  }

  .skill-btn,
  .item-btn,
  .control-row button {
    width: 100%;
    min-height: 42px;
  }

  .shop-grid,
  .codex-levels {
    grid-template-columns: 1fr !important;
  }

  .rank-list .rk {
    flex-basis: 28px;
  }

  .rank-list .rd {
    flex-basis: calc(100% - 84px);
  }
}


/*
 * v1.8.2-rc.6 interaction recovery guard.
 * These rules keep overlays from stealing taps when hidden and make the board/tile layer explicit.
 */
.board-zone {
  pointer-events: auto;
}

.board,
.tile,
.skill-btn,
.item-btn,
.control-row button,
#taiyue-xxl-game-hint-btn {
  pointer-events: auto;
  touch-action: manipulation;
}

.result-mask.hidden,
.shop-mask.hidden,
.coach.hidden,
.cutin.hidden,
.combo-banner.hidden {
  pointer-events: none !important;
}
