/* Responsive layout shared by campaign, fitting room and forest duels. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
html { -webkit-text-size-adjust: 100%; }
body:has(dialog[open]), body:has(#game:not([hidden])), body:has(#forestFight:not([hidden])) {
  overflow: hidden;
  overscroll-behavior: none;
}
button, a, select { touch-action: manipulation; }
#game, #forestFight { height: 100dvh; bottom: auto; }
dialog { overscroll-behavior: contain; scroll-padding-block: 60px 24px; }
#closeDialog {
  position: sticky; top: 0; float: right; z-index: 10;
  width: 44px; height: 44px; margin: -18px -8px 0 8px;
  border: 1px solid #5a718477; border-radius: 50%;
  background: #142130f5; color: #e1edf5; line-height: 1;
}
#dialogBody { min-width: 0; }
.profile-layout > *, .upgrade-detail, .fighter-hud { min-width: 0; }
.forest-panel { overscroll-behavior: contain; }
.forest-panel-card { margin: auto; }
.forest-actions span { max-width: 100%; overflow-wrap: anywhere; }
.forest-pause { width: 44px; height: 44px; top: calc(var(--safe-top) + 8px); right: calc(var(--safe-right) + 10px); z-index: 2; }
.forest-hud { top: calc(var(--safe-top) + 28px); }
.forest-input { bottom: calc(var(--safe-bottom) + 54px); left: max(5%, calc(var(--safe-left) + 12px)); right: max(5%, calc(var(--safe-right) + 12px)); }
.forest-keyboard { bottom: calc(var(--safe-bottom) + 17px); }
.forest-panel { padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px); }
.touch .forest-keyboard { display: none; }
.touch .forest-input { bottom: calc(var(--safe-bottom) + 18px); }
.touch .forest-actions kbd { display: none; }
.touch button { -webkit-user-select: none; user-select: none; }
.touch .icon-btn, .touch .text-btn, .touch .fitting-tools button, .touch .compare-gear { min-height: 44px; min-width: 44px; }
.touch .fitting-zoom { min-height: 36px; }
.touch .fitting-zoom input { height: 32px; }
.touch .game-bottom { bottom: calc(var(--safe-bottom) + 22px); left: calc(var(--safe-left) + 16px); }
.touch #joystick { right: calc(var(--safe-right) + 24px); bottom: calc(var(--safe-bottom) + 34px); }
.touch .battle-wallet { left: calc(var(--safe-left) + 16px); }
.touch .ability { min-width: 0; }
.game-top { left: calc(var(--safe-left) + 20px); right: calc(var(--safe-right) + 20px); top: calc(var(--safe-top) + 16px); }
#buff { top: calc(var(--safe-top) + 118px); }
#tutorial { top: calc(var(--safe-top) + 142px); }
#joystickHint { right: calc(var(--safe-right) + 38px); bottom: calc(var(--safe-bottom) + 184px); }
@media (max-width: 900px) {
  .profile-layout { grid-template-columns: minmax(0, 1fr); }
  .fitting-stage { position: relative; max-width: 100%; }
  .fitting-stage canvas { height: 320px; }
  .profile-wallet { max-width: none; }
  .profile-heading { flex-wrap: wrap; }
}
@media (max-width: 650px) {
  .topbar {
    height: auto; min-height: 112px; display: grid; grid-template-columns: minmax(0, 1fr) 44px auto;
    padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 16px) 10px calc(var(--safe-left) + 16px); gap: 6px 8px;
  }
  .top-actions { display: contents; }
  .brand { grid-row: 1; grid-column: 1 / 3; font-size: 11px; gap: 8px; }
  .brand small { font-size: 8px; letter-spacing: 2px; }
  .cross-mark { font-size: 31px; }
  .modes-button { grid-row: 1; grid-column: 3; min-height: 44px; padding: 10px; font-size: 11px; }
  .modes-button span { margin-left: 3px; }
  .wallet { grid-row: 2; grid-column: 1; justify-self: start; max-width: 100%; min-height: 44px; gap: 8px; font-size: 12px; padding: 8px 10px; }
  .top-actions .sound { grid-row: 2; grid-column: 2; }
  .top-actions #help { grid-row: 2; grid-column: 3; justify-self: end; }
  .top-actions .icon-btn { width: 44px; height: 44px; }
  .adventure-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 10px calc(var(--safe-right) + 12px) 10px calc(var(--safe-left) + 12px); gap: 6px; }
  .adventure-nav button { min-height: 48px; padding: 8px 4px; font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
  .adventure-nav #profile { grid-column: auto; }
  .hero-section { min-height: 0; }
  .hero-copy { padding: 28px calc(var(--safe-right) + 20px) 28px calc(var(--safe-left) + 20px); width: 100%; }
  h1 { font-size: clamp(43px, 11.8vw, 68px); margin: 19px 0 15px; }
  .hero-art { background-position: 63% 28%; }
  .hero-shade { background: linear-gradient(90deg,#080e16e8,#080e1655),linear-gradient(0deg,#080e16,transparent 80%); }
  .intro { font-size: 13px; line-height: 1.8; }
  .selected-hero { margin: 18px 0; width: 100%; max-width: 380px; gap: 12px; }
  .selected-hero small { letter-spacing: 1px; }
  .selected-hero #heroLevel { margin-left: 5px; }
  .selected-hero .text-btn { min-height: 44px; padding: 8px 0 8px 8px; }
  .menu-xp { width: 100%; max-width: 380px; }
  .hero-copy .primary, .upgrade-menu-btn { width: 100%; max-width: 380px; min-width: 0; min-height: 48px; }
  .hero-copy .primary { padding: 16px 20px; }
  .save-note { line-height: 1.6; font-size: 10px; }
  .campaign { padding: 12px calc(var(--safe-right) + 16px) 24px calc(var(--safe-left) + 16px); }
  .section-heading { align-items: start; gap: 12px; }
  .section-heading h2 { font-size: 18px; }
  .section-heading > span { text-align: right; line-height: 1.6; flex-shrink: 0; }
  .mission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mission-card { padding: 14px 12px; }
  .mission-card h3 { overflow-wrap: anywhere; }
  .mission-reward { line-height: 1.7; font-size: 10px; }
  footer { padding-bottom: calc(var(--safe-bottom) + 16px); }
  footer button { min-height: 44px; }
  dialog, #dialog[data-kind="profile"] {
    width: calc(100% - var(--safe-left) - var(--safe-right) - 16px);
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 16px);
    padding: 20px 16px; border-radius: 14px;
  }
  #closeDialog { margin: -10px -6px 0 6px; }
  .modal-title { font-size: 28px; line-height: 1.25; overflow-wrap: anywhere; }
  .modal-text { font-size: 13px; }
  .modal-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .primary, .secondary { min-width: 0; max-width: 100%; min-height: 46px; }
  .modal-actions button { width: 100%; }
  .hero-grid, .mode-grid { grid-template-columns: minmax(0, 1fr); }
  .hero-option { grid-template-columns: 88px minmax(0, 1fr); }
  .difficulty-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .difficulty-picker button { padding: 12px 4px; font-size: 11px; }
  .difficulty-picker small { font-size: 10px; }
  .upgrade-heading { flex-wrap: wrap; padding-right: 0; gap: 8px; }
  .upgrade-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .upgrade-tabs button { min-width: 0; overflow-wrap: anywhere; min-height: 56px; }
  .upgrade-detail { min-width: 0; flex-basis: calc(100% - 36px); }
  .upgrade-purchase { min-width: 0; flex-wrap: wrap; }
  .upgrade-purchase button { min-height: 46px; min-width: 0; flex: 1; }
  .upgrade-purchase small { flex-basis: 100%; text-align: left; }
  .growth-top { flex-wrap: wrap; }
  .growth-stats, .result-stats, .reward-totals { flex-wrap: wrap; gap: 16px; }
  .reward-heading { flex-wrap: wrap; }
  .reward-heading > span { text-align: left; max-width: 100%; }
  .exchange-panel button { min-height: 44px; }
  .daily-task, .shop-test, .resume-run { padding: 14px; }
  .login-days { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .profile-heading { padding-right: 0; }
  .profile-heroes { scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
  .profile-heroes button { min-height: 48px; scroll-snap-align: start; }
  .profile-layout { display: flex; gap: 16px; }
  .fitting-stage { position: sticky; top: 0; padding: 8px 10px; }
  .fitting-stage canvas { height: clamp(160px, 26dvh, 230px); }
  .fitting-tools button { min-height: 44px; }
  .fitting-zoom { margin: 4px 0; }
  .fitting-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .equipment-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .equipment-item strong { font-size: 11px; overflow-wrap: anywhere; }
  .equipment-item img { height: 76px; }
  .forest-select select { font-size: 16px; padding: 12px 6px; }
  .forest-preview { height: 140px; padding: 18px; }
  .forest-preview strong { font-size: 32px; }
  .forest-setup-controls { font-size: 12px; }
  .game-top { top: calc(var(--safe-top) + 10px); left: calc(var(--safe-left) + 12px); right: calc(var(--safe-right) + 12px); gap: 8px; flex-wrap: wrap; }
  .game-top #pause { width: 44px; height: 44px; }
  .mission-hud { order: 3; width: 100%; min-width: 0; padding: 8px 12px; }
  .mission-hud small { letter-spacing: 1px; }
  .mission-hud strong { font-size: 11px; }
  #tutorial { left: calc(var(--safe-left) + 12px); top: calc(var(--safe-top) + 170px); width: min(270px, calc(100% - 24px - var(--safe-left) - var(--safe-right))); padding: 12px 14px; }
  #tutorial h2 { font-size: 16px; }
  #tutorial p { font-size: 12px; line-height: 1.6; }
  #buff { top: calc(var(--safe-top) + 150px); left: calc(var(--safe-left) + 14px); }
  #toast { top: calc(var(--safe-top) + 300px); width: min(85%, 360px); padding: 9px 12px; }
  .touch .abilities { display: grid; grid-template-columns: repeat(2, 60px); gap: 8px; max-width: none; }
  .touch .ability, .touch #attack { width: 60px; height: 62px; flex-direction: column; }
  .touch .ability b { font-size: 10px; }
  .touch #attack > span { margin: 0; }
  .touch #joystick { width: 116px; height: 116px; right: calc(var(--safe-right) + 20px); }
  #stick { left: calc(50% - 27.5px); top: calc(50% - 27.5px); }
  #joystick > span { top: calc(100% + 10px); }
  .battle-wallet { bottom: calc(var(--safe-bottom) + 166px); }
  #joystickHint { bottom: calc(var(--safe-bottom) + 160px); }
  .forest-hud { top: calc(var(--safe-top) + 54px); left: calc(var(--safe-left) + 14px); right: calc(var(--safe-right) + 14px); grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr); gap: 10px; }
  .fighter-name strong { font-size: 18px; height: auto; min-height: 40px; overflow-wrap: anywhere; }
  .forest-location { top: calc(var(--safe-top) + 188px); }
  .forest-location small { display: none; }
  .forest-input, .touch .forest-input { display: flex; align-items: end; bottom: calc(var(--safe-bottom) + 18px); left: calc(var(--safe-left) + 14px); right: calc(var(--safe-right) + 14px); gap: 12px; }
  .forest-movement { display: grid; grid-template-columns: repeat(2, 48px); gap: 8px; }
  .forest-movement button { min-width: 0; width: 48px; height: 56px; min-height: 0; }
  .forest-movement [data-fight="jump"] { grid-column: 1 / 3; grid-row: 1; width: 100%; height: 48px; font-size: 21px; }
  .forest-movement small { display: inline; margin-left: 8px; }
  .forest-actions { display: grid; grid-template-columns: repeat(2, 60px); gap: 8px; }
  .forest-actions button { width: 60px; height: 62px; }
  .forest-actions span { font-size: 10px; line-height: 1.15; }
  .forest-banner { top: 35%; font-size: 28px; }
  .forest-panel-card { padding: 22px 18px; }
}
@media (max-width: 360px) {
  .brand { font-size: 10px; letter-spacing: .4px; }
  .brand small { letter-spacing: 1px; }
  .adventure-nav button { font-size: 10px; }
  .equipment-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .forest-input { gap: 8px; }
  .touch .abilities { grid-template-columns: repeat(2, 56px); }
  .touch .ability, .touch #attack { width: 56px; }
  .touch #joystick { width: 106px; height: 106px; right: calc(var(--safe-right) + 16px); }
  .hero-number { font-size: 25px; padding-left: 10px; }
  .hero-copy { padding-left: 16px; padding-right: 16px; }
}
/* A pinned preview must never consume the entire scrollable sheet. */
@media (max-height: 740px) and (max-width: 900px) {
  .fitting-stage { position: relative; }
  .fitting-stage canvas { height: 220px; }
}
@media (max-height: 540px) and (orientation: landscape) {
  dialog, #dialog[data-kind="profile"] { max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 12px); padding: 20px; }
  .game-top { top: calc(var(--safe-top) + 8px); left: calc(var(--safe-left) + 12px); right: calc(var(--safe-right) + 12px); flex-wrap: nowrap; gap: 12px; }
  .player-card { min-width: 150px; padding: 6px 9px; }
  .player-card strong { font-size: 11px; }
  .health-track { width: 100px; margin-top: 5px; }
  .mission-hud { order: 0; width: auto; min-width: 0; max-width: 45%; padding: 6px 12px; }
  .mission-hud small { margin-bottom: 3px; font-size: 8px; }
  .mission-hud strong { font-size: 10px; }
  .objective-track { margin-top: 5px; }
  #tutorial { top: calc(var(--safe-top) + 83px); left: calc(var(--safe-left) + 12px); width: 205px; padding: 8px 10px; }
  #tutorial h2 { font-size: 13px; margin: 5px 0; }
  #tutorial p { font-size: 10px; line-height: 1.4; }
  #buff { top: calc(var(--safe-top) + 73px); left: 45%; font-size: 10px; }
  #toast { top: calc(var(--safe-top) + 88px); left: 60%; width: 240px; }
  .touch .game-bottom { bottom: calc(var(--safe-bottom) + 12px); left: calc(var(--safe-left) + 12px); }
  .touch .abilities { display: flex; flex-wrap: nowrap; gap: 7px; max-width: none; }
  .touch .ability, .touch #attack { width: 56px; height: 56px; }
  .touch .ability > span { font-size: 21px; }
  .touch #joystick { width: 104px; height: 104px; right: calc(var(--safe-right) + 20px); bottom: calc(var(--safe-bottom) + 16px); }
  #joystick > span { display: none; }
  #stick { left: calc(50% - 27.5px); top: calc(50% - 27.5px); }
  #joystickHint { bottom: calc(var(--safe-bottom) + 124px); font-size: 11px; }
  #joystickHint b { font-size: 25px; }
  .battle-wallet { bottom: calc(var(--safe-bottom) + 78px); left: calc(var(--safe-left) + 12px); font-size: 10px; padding: 5px 8px; }
  .forest-hud { top: calc(var(--safe-top) + 12px); left: calc(var(--safe-left) + 18px); right: calc(var(--safe-right) + 66px); grid-template-columns: minmax(0, 1fr) 64px minmax(0, 1fr); gap: 16px; }
  .fighter-name { display: flex; margin-bottom: 4px; gap: 8px; }
  .fighter-name strong { font-size: 18px; min-height: 0; height: auto; }
  .fighter-name > span { font-size: 9px; margin: 0; }
  .fighter-meta { font-size: 10px; }
  .forest-guard { margin: 5px 3px; }
  .duel-clock > strong { font-size: 33px; }
  .duel-clock > span, .duel-clock small { font-size: 8px; }
  .forest-location { top: calc(var(--safe-top) + 93px); }
  .forest-location > span { font-size: 9px; letter-spacing: 2px; }
  .forest-location small { display: none; }
  .forest-input, .touch .forest-input { display: flex; bottom: calc(var(--safe-bottom) + 12px); left: calc(var(--safe-left) + 14px); right: calc(var(--safe-right) + 14px); }
  .forest-movement, .forest-actions { display: flex; gap: 7px; }
  .forest-movement button, .forest-movement [data-fight="jump"] { width: 48px; height: 50px; min-width: 48px; min-height: 50px; font-size: 22px; }
  .forest-movement small { display: block; font-size: 9px; margin: 0; }
  .forest-actions button { width: 54px; height: 54px; }
  .forest-actions span { font-size: 9px; }
  .forest-banner { top: 32%; font-size: 28px; }
  .forest-panel-card { padding: 16px 24px; }
  .forest-panel-card h2 { font-size: 28px; margin: 6px 0; }
  .forest-panel-card p { font-size: 12px; margin: 8px 0; }
  .forest-panel-card button { min-height: 44px; padding: 10px; margin-top: 8px; }
  .forest-keyboard { display: none; }
}
@media (max-width: 650px) and (max-height: 680px) and (orientation: portrait) {
  .player-card { padding: 6px 9px; }
  .mission-hud { padding: 6px 10px; }
  .mission-hud small { margin-bottom: 3px; }
  .objective-track { margin-top: 6px; }
  #tutorial { top: calc(var(--safe-top) + 145px); padding: 8px 12px; }
  #tutorial > span { font-size: 8px; }
  #tutorial h2 { font-size: 14px; margin: 5px 0; }
  #tutorial p { font-size: 11px; line-height: 1.4; }
  #buff { top: calc(var(--safe-top) + 128px); }
  #toast { top: calc(var(--safe-top) + 246px); }
}
/* Portrait screens wait here; both combat simulations freeze behind this sheet. */
#rotateDevice {
  position: fixed; inset: 0; z-index: 90; height: 100dvh; overflow: auto;
  display: grid; place-items: center; overscroll-behavior: contain;
  padding: calc(var(--safe-top) + 24px) calc(var(--safe-right) + 20px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 20px);
  background: radial-gradient(ellipse at 50% 25%, #20354d, #080e16 75%);
}
.rotate-card { max-width: 380px; margin: auto; text-align: center; }
.rotate-card h2 { font: 500 clamp(30px, 8vw, 42px) Oswald, sans-serif; margin: 16px 0; }
.rotate-card p { color: #b6c6d8; font-size: 14px; line-height: 1.75; }
.rotate-card .rotate-note { color: #839bb5; font-size: 12px; margin: 22px 0; }
.rotate-card button { min-height: 48px; width: 100%; }
.rotate-phone { width: 104px; height: 60px; border: 3px solid #8dd9ff; border-radius: 12px; margin: 12px auto 38px; box-shadow: 0 0 36px #63b8ec25; display: grid; place-items: center; }
.rotate-phone span { color: #a8e5ff; font-size: 40px; line-height: 1; }
