/* Phone-first match shell. The existing battlefield and game controls stay intact. */
#play .mx-mobile-header,
#play .mx-mobile-nav,
#play .mx-mobile-panel-head,
#play .mx-mobile-preferences,
#play .mx-mobile-field-status,
#play .mx-mobile-field-tip,
#play .mx-mobile-command-note {
  display: none;
}

@media (min-width: 0px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  body > .site-header,
  main#top > :not(#play) {
    display: none !important;
  }

  main#top {
    display: block !important;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  #play {
    --mx-phone-ink: #111b1b;
    --mx-phone-panel: #1d2b2a;
    --mx-phone-line: #50605a;
    --mx-phone-cream: #f4ead8;
    --mx-phone-gold: #d7ad72;
    --mx-phone-muted: #b8c7bd;
    --mx-phone-head: calc(54px + env(safe-area-inset-top));
    --mx-phone-hud: 48px;
    --mx-phone-nav: calc(62px + env(safe-area-inset-bottom));
    --mx-phone-content: calc(var(--mx-phone-head) + var(--mx-phone-hud));
    --mx-phone-field-dock: 72px;
    --mx-phone-map-dock: 124px;
    --mx-phone-dock: var(--mx-phone-field-dock);
    --mx-phone-left: max(8px, env(safe-area-inset-left));
    --mx-phone-right: max(8px, env(safe-area-inset-right));
    position: fixed !important;
    inset: 0;
    z-index: 10;
    display: block !important;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    isolation: isolate;
    color: var(--mx-phone-cream);
    background: var(--mx-phone-ink);
    color-scheme: dark;
  }

  #play > .section-lead,
  #play .campaign-track,
  #play .install-note,
  #play .stage-bottom {
    display: none !important;
  }

  #play .match-layout,
  #play .game-column {
    display: block !important;
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
  }

  #play .mx-mobile-header {
    position: fixed;
    inset: 0 0 auto;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    height: var(--mx-phone-head);
    padding: env(safe-area-inset-top) var(--mx-phone-right) 0 var(--mx-phone-left);
    border-bottom: 1px solid rgba(215, 173, 114, .35);
    background: linear-gradient(110deg, #1f302d, #101b1b 70%);
    box-shadow: 0 5px 18px rgba(6, 13, 12, .35);
  }

  #play .mx-mobile-identity {
    display: grid;
    gap: 2px;
    flex: 0 0 auto;
    line-height: 1.1;
  }

  #play .mx-mobile-identity strong {
    color: var(--mx-phone-gold);
    font-size: .63rem;
    font-weight: 900;
    letter-spacing: .14em;
    text-transform: uppercase;
  }

  #play .mx-mobile-identity span {
    color: var(--mx-phone-cream);
    font-family: Georgia, serif;
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
  }

  #play .mx-mobile-header-actions {
    display: flex;
    gap: 4px;
    flex: none;
  }

  #play .mx-mobile-header button {
    min-width: 48px;
    min-height: 44px;
    padding: 4px 7px;
    border: 1px solid var(--mx-phone-line);
    border-radius: 9px;
    color: var(--mx-phone-cream);
    background: #273734;
    font: inherit;
    font-size: .75rem;
    font-weight: 800;
    cursor: pointer;
  }

  #play .mx-mobile-header button:disabled {
    opacity: .5;
  }

  #play .mx-mobile-header .mx-mobile-playback {
    min-width: 62px;
  }

  #play .mx-mobile-header .mx-mobile-playback:not(:disabled) {
    color: var(--mx-phone-ink);
    background: var(--mx-phone-gold);
  }

  #play .match-hud {
    position: fixed !important;
    top: var(--mx-phone-head);
    right: 0;
    left: 0;
    z-index: 69;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    width: 100%;
    max-width: none;
    height: var(--mx-phone-hud);
    margin: 0;
    padding: 3px var(--mx-phone-right) 3px var(--mx-phone-left);
    border: 0;
    border-bottom: 1px solid rgba(215, 173, 114, .32);
    border-radius: 0;
    background: rgba(17, 27, 27, .97);
    box-shadow: none;
  }

  #play .hud-stat {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    margin: 0;
    padding: 0 4px;
    border: 0;
    border-right: 1px solid rgba(184, 199, 189, .2);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    text-align: center;
  }

  #play .hud-stat:last-child {
    border-right: 0;
  }

  #play .hud-stat small {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--mx-phone-muted);
    font-size: .57rem;
    font-weight: 800;
    letter-spacing: .12em;
  }

  #play .hud-stat small .mx-ic {
    width: 12px;
    height: 12px;
  }

  #play .hud-stat strong {
    color: var(--mx-phone-cream);
    font-size: 1.06rem;
    line-height: 1;
    white-space: nowrap;
  }

  #play .hud-stat.is-build strong {
    color: var(--mx-phone-gold);
  }

  #play .hud-stat[data-state="warn"] strong { color: #f1cc89; }
  #play .hud-stat[data-state="danger"] strong { color: #ffaba3; }

  #play .hud-stat .meter {
    display: none !important;
  }

  #play[data-mobile-view="map"] {
    --mx-phone-dock: var(--mx-phone-map-dock);
  }

  #play .stage-frame {
    position: fixed !important;
    inset: var(--mx-phone-content) 0 calc(var(--mx-phone-nav) + var(--mx-phone-dock)) !important;
    z-index: 1;
    display: grid !important;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100vw !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left) !important;
    overflow: hidden;
    border: 0 !important;
    border-radius: 0 !important;
    background: radial-gradient(ellipse at 50% 45%, #314c41, #122521 80%);
  }

  #play[data-mobile-view]:not([data-mobile-view="field"]):not([data-mobile-view="map"]) .stage-frame {
    display: none !important;
  }

  #play #battlefield {
    position: static;
    display: block;
    justify-self: center;
    width: 100% !important;
    min-width: 0;
    max-width: 100% !important;
    height: 100% !important;
    aspect-ratio: auto;
    min-height: 0;
    max-height: none !important;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    touch-action: none;
  }

  #play .stage-top {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 8px;
    width: 100%;
    margin: 0;
    padding: 4px 10px 5px;
    border: 0;
    border-bottom: 1px solid rgba(215, 173, 114, .24);
    color: var(--mx-phone-cream);
    background: #192925;
    font-size: .72rem;
    letter-spacing: 0;
  }

  #play[data-mobile-view] .stage-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  #play .mx-mobile-field-status {
    display: block;
    color: var(--mx-phone-cream);
    font-weight: 800;
  }

  #play[data-mobile-phase="assault"] .mx-mobile-field-status { color: #ffbdb1; }
  #play[data-mobile-phase="prepare"] .mx-mobile-field-status { color: #f4ce94; }

  #play .mx-mobile-field-tip {
    display: block;
    grid-column: 1 / -1;
    margin: 0;
    color: var(--mx-phone-muted);
    font-size: .71rem;
    font-weight: 500;
    line-height: 1.2;
  }

  #play .stage-clock {
    color: var(--mx-phone-muted);
    font-variant-numeric: tabular-nums;
  }

  #play .stage-top .pan-hint,
  #play .stage-clock-label {
    display: none !important;
  }

  #play .mx-mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    height: var(--mx-phone-nav);
    padding: 3px var(--mx-phone-right) env(safe-area-inset-bottom) var(--mx-phone-left);
    border-top: 1px solid rgba(215, 173, 114, .4);
    background: linear-gradient(180deg, #263632, #152321);
    box-shadow: 0 -8px 24px rgba(6, 13, 12, .4);
  }

  #play .mx-mobile-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    min-height: 44px;
    padding: 3px 1px;
    border: 0;
    border-radius: 9px;
    color: var(--mx-phone-muted);
    background: transparent;
    font: inherit;
    font-size: .64rem;
    font-weight: 800;
    letter-spacing: .02em;
    cursor: pointer;
  }

  #play .mx-mobile-nav button[aria-current="page"] {
    color: var(--mx-phone-ink);
    background: var(--mx-phone-gold);
  }

  #play .mx-mobile-nav svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  #play .command-strip {
    position: fixed !important;
    top: auto;
    right: 0;
    bottom: var(--mx-phone-nav);
    left: 0;
    z-index: 35;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: auto;
    max-width: none;
    margin: 0;
    padding: 6px var(--mx-phone-right) 6px var(--mx-phone-left);
    border: 0;
    border-top: 1px solid rgba(215, 173, 114, .38);
    border-radius: 0;
    background: var(--mx-phone-ink);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  #play[data-mobile-view="field"] .command-strip {
    height: var(--mx-phone-field-dock);
  }

  #play .command-strip button.mx-cmd {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    margin: 0;
    padding: 3px;
    border: 1px solid rgba(215, 173, 114, .25);
    border-radius: 9px;
    color: var(--mx-phone-cream);
    background: #273b34;
    text-align: center;
  }

  #play .command-strip button.mx-cmd:disabled {
    opacity: 1;
    color: #d1ded4;
    border-color: #42544e;
    background: #1d2b29;
  }

  #play .command-strip .mx-cmd > .mx-ic {
    width: 17px;
    height: 17px;
    flex: none;
    color: var(--mx-phone-gold);
  }

  #play .command-strip .mx-cmd strong {
    font-size: .72rem;
    line-height: 1.13;
  }

  #play .command-strip .mx-cmd small {
    color: var(--mx-phone-muted);
    font-size: .66rem;
    line-height: 1.15;
    justify-content: center;
    flex-wrap: wrap;
  }

  #play .command-strip .mx-cmd small .mx-ic {
    width: 11px;
    height: 11px;
  }

  #play .command-strip .mx-cmd .command-num,
  #play .command-strip .mx-mobile-panel-head {
    display: none;
  }

  #play[data-mobile-view="field"] .command-strip .mx-cmd:not(#deploy):not(#deploy-archer):not(#next-wave),
  #play:not([data-mobile-view="field"]):not([data-mobile-view="orders"]) .command-strip {
    display: none !important;
  }

  #play[data-mobile-view="field"] .command-strip button.mx-cmd:disabled small {
    display: none;
  }

  #play[data-mobile-view="field"] .command-strip button.mx-cmd:disabled .mx-mobile-command-note,
  #play[data-mobile-view="orders"] .mx-mobile-command-note {
    display: block;
    color: var(--mx-phone-muted);
    font-size: .66rem;
    line-height: 1.15;
  }

  #play[data-mobile-view="orders"] .command-strip {
    top: var(--mx-phone-content);
    right: 0;
    bottom: var(--mx-phone-nav);
    left: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 10px;
    padding: 14px max(14px, var(--mx-phone-right)) 18px max(14px, var(--mx-phone-left));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
    background: linear-gradient(150deg, #263832, var(--mx-phone-ink) 62%);
    box-shadow: none;
    backdrop-filter: none;
  }

  #play[data-mobile-view="orders"] .command-strip .mx-mobile-panel-head {
    display: block;
    grid-column: 1 / -1;
  }

  #play[data-mobile-view="orders"] .command-strip button.mx-cmd {
    min-height: 96px;
    padding: 8px 6px;
    gap: 5px;
  }

  #play[data-mobile-view="orders"] .command-strip .mx-cmd strong {
    font-size: .81rem;
  }

  #play[data-mobile-view="orders"] .mx-mobile-order-brief {
    margin-top: 8px;
    padding: 8px 10px;
    border-left: 2px solid var(--mx-phone-gold);
    background: #1d2b2a;
    color: var(--mx-phone-cream);
  }

  #play .world-controls,
  #play .command-desk,
  #play .match-actions {
    position: fixed !important;
    top: var(--mx-phone-content);
    right: 0;
    bottom: var(--mx-phone-nav);
    left: 0;
    z-index: 35;
    display: none !important;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    margin: 0;
    padding: 18px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
    color: var(--mx-phone-cream);
    background: linear-gradient(150deg, #263832, var(--mx-phone-ink) 62%);
    box-shadow: none;
    -webkit-overflow-scrolling: touch;
  }

  #play[data-mobile-view="log"] .command-desk {
    display: block !important;
  }

  #play[data-mobile-view="map"] .world-controls {
    display: grid !important;
    top: auto;
    height: var(--mx-phone-map-dock);
    align-content: start;
    gap: 3px;
    padding: 6px var(--mx-phone-right) 5px var(--mx-phone-left);
    border-top: 1px solid var(--mx-phone-line);
  }

  #play[data-mobile-view="menu"] .match-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 10px;
  }

  #play .mx-mobile-panel-head {
    margin: 0 0 16px;
    color: var(--mx-phone-cream);
  }

  #play .match-actions .mx-mobile-panel-head {
    display: block;
    grid-column: 1 / -1;
    margin-bottom: 4px;
  }

  #play .mx-mobile-panel-head small {
    display: block;
    margin-bottom: 6px;
    color: var(--mx-phone-gold);
    font-size: .62rem;
    font-weight: 900;
    letter-spacing: .18em;
  }

  #play .mx-mobile-panel-head h2 {
    margin: 0 0 5px;
    color: var(--mx-phone-cream);
    font-family: Georgia, serif;
    font-size: clamp(1.45rem, 6vw, 2rem);
    line-height: 1.1;
  }

  #play .mx-mobile-panel-head p {
    margin: 0;
    color: var(--mx-phone-muted);
    font-size: .82rem;
    line-height: 1.45;
  }

  #play .world-controls .road-range,
  #play .world-controls .map-presets,
  #play .world-controls .control-head {
    width: 100%;
    max-width: none;
    margin: 0;
  }

  #play .world-controls .control-head { min-height: 18px; }
  #play .world-controls .road-range { padding-block: 0; }
  #play .world-controls #travel { min-height: 44px; margin-block: 0; }

  #play .world-controls .map-presets {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  #play .world-controls .map-presets button {
    min-height: 44px;
    padding: 4px;
    font-size: .75rem;
  }

  #play .command-desk .feed {
    max-height: none;
    overflow: visible;
  }

  #play .command-desk .desk-title h3 {
    font-family: Georgia, serif;
  }

  #play .match-actions > button {
    min-width: 0;
    min-height: 54px;
    width: 100%;
    margin: 0;
    padding: 8px;
    border: 1px solid var(--mx-phone-line);
    border-radius: 10px;
    color: var(--mx-phone-cream);
    background: #293a35;
    font-size: .79rem;
    font-weight: 800;
  }

  #play .match-actions > #start {
    color: var(--mx-phone-ink);
    background: var(--mx-phone-gold);
  }

  #play .mx-mobile-preferences {
    display: grid;
    grid-column: 1 / -1;
    gap: 10px;
    margin-top: 14px;
  }

  #play .mx-mobile-preferences h3 {
    margin: 0;
    color: var(--mx-phone-gold);
    font-size: .69rem;
    font-weight: 900;
    letter-spacing: .14em;
    text-transform: uppercase;
  }

  #play .mx-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 60px;
    padding: 10px 12px;
    border: 1px solid var(--mx-phone-line);
    border-radius: 10px;
    background: #22332f;
  }

  #play .mx-mobile-toggle span {
    display: grid;
    gap: 3px;
    font-size: .82rem;
    font-weight: 800;
  }

  #play .mx-mobile-toggle small,
  #play .mx-mobile-save-note {
    color: var(--mx-phone-muted);
    font-size: .7rem;
    font-weight: 500;
    line-height: 1.35;
  }

  #play .mx-mobile-toggle input {
    flex: none;
    width: 20px;
    height: 20px;
    accent-color: var(--mx-phone-gold);
  }

  #play .mx-mobile-save-note {
    margin: 8px 0 0;
  }

  #play :is(.mx-mobile-header button, .mx-mobile-nav button, .mx-cmd, .mx-mobile-toggle input, .world-controls button, #travel, #battlefield):focus-visible {
    outline: 3px solid var(--mx-phone-gold);
    outline-offset: 2px;
  }

  #play[data-mobile-text="large"] .mx-mobile-nav button,
  #play[data-mobile-text="large"] .command-strip .mx-cmd strong,
  #play[data-mobile-text="large"] .mx-mobile-field-tip,
  #play[data-mobile-text="large"] .mx-mobile-panel-head p,
  #play[data-mobile-text="large"] .mx-mobile-toggle span {
    font-size: .91rem;
  }

  #play[data-mobile-text="large"] { --mx-phone-field-dock: 80px; }

  #play[data-mobile-motion="reduced"] *,
  #play[data-mobile-motion="reduced"] *::before,
  #play[data-mobile-motion="reduced"] *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 720px) and (max-height: 580px) {
  #play {
    --mx-phone-head: calc(48px + env(safe-area-inset-top));
    --mx-phone-hud: 39px;
    --mx-phone-nav: calc(53px + env(safe-area-inset-bottom));
    --mx-phone-field-dock: 66px;
  }
}
