/*
 * Garden Bot phone gameplay — preview route ONLY.
 *
 * Uses the live React battle DOM and existing on-chain card click handlers.
 * Nothing here is loaded by /battle, /battle/pvp or /battle/trials.
 * Layout is active only while a match is actually running.
 */
@media screen and (max-width: 640px) {
  .gb-battle-page.gb-battle-page-active:has(.gb-battle-hud .gb-battle-options) {
    height: 100vh;
    height: 100dvh;
    min-height: 0 !important;
    max-height: 100dvh;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
  }

  /* Keep wallet and menu available, but remove page-level advertisements,
     badges and help sections during play. */
  .gb-battle-page-active .gb-player-status-strip,
  .gb-battle-page-active .gb-dedicated-mode-heading,
  .gb-battle-page-active .gb-tree-benefits-trigger,
  .gb-battle-page-active .gb-quick-start-tools,
  .gb-battle-page-active .gb-active-reference-tools,
  .gb-battle-page-active .gb-ecosystem-status-card,
  .gb-battle-page-active footer {
    display: none !important;
  }
  .gb-battle-page-active .gb-app-header {
    flex: 0 0 auto;
    min-height: 41px;
    max-height: 56px;
    padding: 4px 8px !important;
    gap: 4px;
    flex-wrap: nowrap;
    z-index: 15;
  }
  .gb-battle-page-active .gb-header-brand,
  .gb-battle-page-active .gb-header-game-logo {
    max-height: 34px !important;
    max-width: 66px !important;
    width: 66px !important;
    object-fit: contain;
  }
  .gb-battle-page-active .gb-header-actions {
    flex-wrap: nowrap;
    min-width: 0;
    gap: 5px;
  }
  .gb-battle-page-active .gb-mobile-menu-toggle { min-width: 38px; min-height: 38px; padding: 0 7px; }
  .gb-battle-page-active .gb-mobile-nav-panel[data-open="true"] {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 60;
    max-height: 75dvh;
    overflow-y: auto;
  }

  /* Build one constrained play surface, with the battlefield fixed in its top
     region and only secondary actions/logs scrolling below the move tray. */
  .gb-battle-page-active .gb-battle-main {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    padding: 3px 5px max(4px, env(safe-area-inset-bottom, 0px)) !important;
    margin: 0;
    display: flex;
    overflow: hidden;
  }
  .gb-battle-page-active .gb-battle-main > :not(.gb-battle-hud) { display: none !important; }
  .gb-battle-page-active .gb-battle-hud {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 0;
    margin: 0;
  }
  .gb-battle-page-active .gb-battle-hud-center {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: 100%;
    width: 100%;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 4px;
    overflow: hidden;
  }
  .gb-battle-page-active .gb-match-status-bar {
    margin: 0 !important;
    padding: 4px 7px !important;
    min-height: 35px;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    max-width: none;
    border-radius: 8px;
  }
  .gb-battle-page-active .gb-match-status-summary { gap: 0; }
  .gb-battle-page-active .gb-match-status-summary span { font-size: 8px; }
  .gb-battle-page-active .gb-match-status-summary strong { font-size: 10px; white-space: nowrap; }
  .gb-battle-page-active .gb-match-status-live {
    min-height: 28px;
    font-size: 10px;
    padding: 4px 7px;
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .gb-battle-page-active .gb-match-terms-details { display: none; }

  /* Compact but recognizable battle trees; growth meters always on screen.
     React uses inline sizes, so the intentional overrides need !important. */
  .gb-battle-page-active .gb-battle-arena {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none;
    min-height: 0;
    overflow: hidden;
    border-radius: 9px;
  }
  .gb-battle-page-active .gb-battle-arena .battle-grid {
    display: grid;
    grid-template-columns: minmax(0,1fr) 24px minmax(0,1fr);
    align-items: center;
    justify-items: center;
    gap: 3px !important;
    margin: 0 !important;
    padding: 4px !important;
  }
  .gb-battle-page-active .gb-battle-arena .player-card,
  .gb-battle-page-active .gb-battle-arena .opponent-card {
    box-sizing: border-box;
    max-width: none !important;
    min-width: 0;
    min-height: 0;
    width: 100% !important;
    padding: 3px 5px !important;
    gap: 1px;
  }
  .gb-battle-page-active .gb-battle-slot-label {
    margin: 0 0 1px !important;
    padding: 2px 4px !important;
    font-size: 9px !important;
    line-height: 1.25;
    white-space: nowrap;
  }
  .gb-battle-page-active .gb-battle-arena .gb-battle-tree-portrait {
    width: 100% !important;
    max-width: min(120px, 32vw) !important;
    height: clamp(64px, 11dvh, 96px) !important;
    max-height: 96px !important;
    aspect-ratio: auto !important;
    margin: 1px auto !important;
    border-radius: 8px !important;
  }
  .gb-battle-page-active .gb-battle-arena .growth-stage-art {
    width: 90% !important;
    height: 90% !important;
    object-fit: contain !important;
  }
  .gb-battle-page-active .gb-battle-arena .player-card > p,
  .gb-battle-page-active .gb-battle-arena .opponent-card > p {
    font-size: 10px !important;
    line-height: 1.18;
    margin: 1px 0 !important;
  }
  .gb-battle-page-active .gb-battle-arena .player-card > div:has(> [data-testid="health-bar-player"]),
  .gb-battle-page-active .gb-battle-arena .opponent-card > div:has(> [data-testid="health-bar-opponent"]) {
    width: 100% !important;
    max-width: none !important;
    height: 8px !important;
    padding: 1px !important;
    margin: 1px 0 !important;
  }
  .gb-battle-page-active [data-testid="health-bar-player"],
  .gb-battle-page-active [data-testid="health-bar-opponent"] { height: 6px !important; }
  .gb-battle-page-active .gb-battle-arena .vs-element {
    min-width: 22px !important;
    min-height: 27px !important;
    font-size: 16px !important;
    line-height: 1;
    padding: 2px !important;
    border-radius: 7px;
  }

  .gb-battle-page-active .gb-battle-options {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    max-width: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    margin: 0 !important;
    padding: 1px 1px 8px;
    gap: 4px;
    scrollbar-width: thin;
  }
  /* Core actions first; optional rerolls and history remain accessible by
     scrolling ONLY this controls pane — never the battlefield. */
  .gb-battle-page-active .gb-battle-options > .gb-turn-command {
    order: -6 !important;
    flex: 0 0 auto;
    margin: 0 !important;
    padding: 5px 7px !important;
    min-height: 32px;
    gap: 3px;
  }
  .gb-battle-page-active .gb-bonus-step-help { gap: 4px; padding: 0; }
  .gb-battle-page-active .gb-bonus-step-help p { font-size: 10px; line-height: 1.25; }
  .gb-battle-page-active .gb-bonus-step-help button { min-height: 44px; padding: 5px; font-size: 10px; }
  .gb-battle-page-active .gb-battle-options > .gb-fifth-picker { order: -5 !important; flex: 0 0 auto; }
  .gb-battle-page-active .gb-battle-options:has(> .gb-move-card-grid) > .gb-fifth-picker { display: none !important; }
  .gb-battle-page-active .gb-battle-options > .gb-last-opponent-move {
    order: -4 !important;
    flex: 0 0 auto;
    padding: 5px;
    margin: 0 !important;
  }
  .gb-battle-page-active .gb-battle-options > .gb-hand-toolbar {
    order: -3 !important;
    flex: 0 0 auto;
    margin: 0 !important;
    padding: 4px 7px;
    min-height: 27px;
  }
  .gb-battle-page-active .gb-battle-options > .gb-move-card-grid {
    order: -2 !important;
    flex: 0 0 auto;
  }
  .gb-battle-page-active .gb-battle-options > .gb-move-card-grid,
  .gb-battle-page-active .gb-battle-options .gb-fifth-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 5px !important;
    align-items: stretch;
  }
  .gb-battle-page-active .gb-battle-options .gb-fifth-picker {
    padding: 6px !important;
    margin: 0 !important;
  }
  .gb-battle-page-active .gb-fifth-picker-title { font-size: 11px; }
  .gb-battle-page-active .gb-fifth-picker > p {
    font-size: 10px;
    line-height: 1.3;
    margin: 3px 0 5px;
  }
  .gb-battle-page-active .gb-battle-options button.gb-battle-move-card,
  .gb-battle-page-active .gb-battle-options button.gb-fifth-picker-card {
    box-sizing: border-box;
    min-width: 0;
    min-height: 62px !important;
    max-height: 100px;
    padding: 5px !important;
    border-radius: 7px !important;
    margin: 0 !important;
    text-align: left;
    touch-action: manipulation;
    cursor: pointer;
  }
  .gb-battle-page-active .gb-battle-options button.gb-battle-move-card:focus-visible,
  .gb-battle-page-active .gb-battle-options button.gb-fifth-picker-card:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
  }
  .gb-battle-page-active .gb-battle-options .gb-battle-move-card-fifth {
    grid-column: 1 / -1 !important;
    justify-self: stretch !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
  .gb-battle-page-active .gb-battle-options .gb-fifth-picker-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  .gb-battle-page-active .gb-fifth-move-card-ribbon { display: none !important; }
  .gb-battle-page-active .gb-battle-move-card-fifth:before {
    animation: none !important;
    inset: -2px !important;
    border-radius: 8px !important;
    box-shadow: 0 0 6px #f5c54288 !important;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face,
  .gb-battle-page-active .gb-battle-options .gb-move-face-compact,
  .gb-battle-page-active .gb-battle-options .gb-battle-move-card-fifth .gb-move-face,
  .gb-battle-page-active .gb-battle-options .gb-fifth-picker-card .gb-move-face {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 5px !important;
    min-height: 0 !important;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-visual {
    box-sizing: border-box;
    height: 42px !important;
    width: 40px !important;
    min-height: 42px !important;
    max-height: 42px !important;
    border-radius: 6px;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-icon {
    height: 38px !important;
    width: 38px !important;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-rings {
    height: 28px !important;
    width: 28px !important;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-copy {
    min-width: 0;
    justify-content: center;
    gap: 2px;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-copy strong {
    display: -webkit-box !important;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    margin: 0 !important;
    font-size: clamp(10px, 2.7vw, 12px) !important;
    line-height: 1.17 !important;
    overflow-wrap: anywhere;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-copy small {
    display: -webkit-box !important;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2;
    overflow: hidden !important;
    margin: 0 !important;
    color: #e8f8ee !important;
    font-size: 9px !important;
    line-height: 1.2 !important;
    font-weight: 600;
  }
  .gb-battle-page-active .gb-battle-options .gb-move-face-badges > span {
    font-size: 7px !important;
    padding: 1px 3px !important;
    line-height: 1.05 !important;
  }
  .gb-battle-page-active .gb-battle-options > .gb-free-bot-reroll,
  .gb-battle-page-active .gb-battle-options > .gb-battle-log-panel,
  .gb-battle-page-active .gb-battle-options > .gb-battle-secondary-controls {
    flex: 0 0 auto;
  }
  .gb-battle-page-active .gb-battle-options > .gb-battle-log-panel { order: 12; }

  /* Compact recent-bot-action summary and keep the Card Guide in one row.
     The normal mobile CSS stacks the toolbar at <=380px, using ~86px. */
  .gb-battle-page-active .gb-battle-options > .gb-hand-toolbar {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    min-height: 32px !important;
    max-height: 38px !important;
    padding: 3px 6px !important;
    gap: 6px;
  }
  .gb-battle-page-active .gb-hand-toolbar > span { flex: 1 1 auto; min-width: 0; }
  .gb-battle-page-active .gb-hand-toolbar > span strong {
    font-size: 9px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .gb-battle-page-active .gb-hand-toolbar > button {
    flex: 0 0 auto;
    width: auto !important;
    min-width: 74px;
    max-width: 92px;
    min-height: 32px !important;
    padding: 4px 5px !important;
    font-size: 8px !important;
  }
  .gb-battle-page-active .gb-battle-options > .gb-last-opponent-move {
    display: grid !important;
    grid-template-columns: 36px minmax(0,1fr) !important;
    align-items: center !important;
    min-height: 44px !important;
    max-height: 58px !important;
    overflow: hidden !important;
    padding: 4px !important;
    gap: 4px !important;
  }
  .gb-battle-page-active .gb-last-opponent-move > img {
    width: 34px !important;
    height: 34px !important;
  }
  .gb-battle-page-active .gb-last-opponent-move-copy {
    min-width: 0;
    display: flex !important;
    flex-direction: column;
    gap: 1px;
  }
  .gb-battle-page-active .gb-last-opponent-move-copy strong {
    font-size: 10px !important;
    line-height: 1.2 !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .gb-battle-page-active .gb-last-opponent-move-copy > span {
    font-size: 9px !important;
    line-height: 1.16 !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .gb-battle-page-active .gb-last-opponent-move-result,
  .gb-battle-page-active .gb-last-opponent-move > button { display: none !important; }

  /* On short phones prefer stable 44px actions over decorative height. */
  @media (max-height: 630px) {
    .gb-battle-page-active .gb-app-header { min-height: 39px; padding: 3px 6px !important; }
    .gb-battle-page-active .gb-battle-arena .gb-battle-tree-portrait { height: 62px !important; }
    .gb-battle-page-active .gb-battle-options button.gb-battle-move-card,
    .gb-battle-page-active .gb-battle-options button.gb-fifth-picker-card { min-height: 57px !important; padding: 4px !important; }
    .gb-battle-page-active .gb-battle-options .gb-move-face-visual { height: 38px !important; min-height: 38px !important; }
  }
}

/* Keep the bot's last move visible as a single-line result strip rather than
   letting it occupy several card heights on narrow phone screens. */
@media screen and (max-width: 640px) {
  .gb-battle-page-active .gb-battle-options > .gb-last-opponent-move {
    display: flex !important;
    flex-flow: row nowrap !important;
    align-items: center;
    max-height: 43px;
    min-height: 36px;
    padding: 4px 6px !important;
    overflow: hidden;
    gap: 6px;
  }
  .gb-battle-page-active .gb-last-opponent-move > img {
    flex: 0 0 auto;
    width: 29px !important;
    height: 29px !important;
  }
  .gb-battle-page-active .gb-last-opponent-move-copy {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    gap: 0;
  }
  .gb-battle-page-active .gb-last-opponent-move-copy small,
  .gb-battle-page-active .gb-last-opponent-move-copy > span,
  .gb-battle-page-active .gb-last-opponent-move > button {
    display: none !important;
  }
  .gb-battle-page-active .gb-last-opponent-move-copy strong {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .gb-battle-page-active .gb-last-opponent-move-result {
    flex: 0 0 auto;
    font-size: 9px;
    white-space: nowrap;
  }

  .gb-battle-page-active .gb-battle-options > .gb-hand-toolbar {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between;
    max-height: 36px;
    min-height: 30px;
    overflow: hidden;
  }
  .gb-battle-page-active .gb-hand-toolbar > span {
    min-width: 0;
    overflow: hidden;
  }
  .gb-battle-page-active .gb-hand-toolbar strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 9px;
  }
  .gb-battle-page-active .gb-hand-toolbar button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-height: 27px;
    padding: 4px 6px;
    font-size: 8px;
  }
  .gb-battle-page-active .gb-battle-options > .gb-turn-command:not(:has(.gb-bonus-step-help)) {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center;
    gap: 6px;
    max-height: 36px;
    min-height: 30px;
    padding: 4px 5px !important;
  }
  .gb-battle-page-active .gb-turn-command:not(:has(.gb-bonus-step-help)) strong {
    font-size: 10px;
  }
}
