/* ==========================================================================
   Nexus Run — Mobile Landscape Layout
   Transforms the Nexus UI for phone landscape orientation using a
   tactical cockpit layout: battlefield (zones) left, command panel right.

   Targets phones via max-height: 500px — excludes tablets and desktop.
   ========================================================================== */


/* ── New structural elements (all viewports) ─────────────────────────── */

.nexus-battlefield {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.nexus-command {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}


/* ==========================================================================
   LANDSCAPE PHONE — @media (orientation: landscape) and (max-height: 500px)
   ========================================================================== */

@media (orientation: landscape) and (max-height: 500px) {

  /* ── Header: hide when Nexus is active ──────────────────────────
     In landscape, every pixel of height is precious. The topbar and
     panel header are hidden to give the game full viewport. Users
     can rotate to portrait to access navigation.
     ─────────────────────────────────────────────────────────────── */

  body:has(#panel-nexus.panel--active) .topbar {
    display: none;
  }

  #panel-nexus .panel__header {
    display: none;
  }

  body:has(#panel-nexus.panel--active) .main {
    padding: 4px;
    max-width: 100%;
  }


  /* ── Phase container ────────────────────────────────────────────── */

  .nexus-phase {
    max-width: 100%;
    padding: 4px 8px;
    overflow-y: auto;
    max-height: calc(100dvh - 12px);
  }

  .nexus-phase h2 {
    font-size: 1rem;
    margin-bottom: 4px;
  }


  /* ── HUD: ultra-compact ribbon ──────────────────────────────────── */

  .nexus-hud {
    margin-bottom: 4px;
    font-size: 0.65rem;
    border-radius: 5px;
  }

  .nexus-hud__seg {
    padding: 3px 8px;
    min-width: 36px;
  }

  .nexus-hud__label {
    font-size: 0.46rem;
  }

  .nexus-hud__val {
    font-size: 0.82rem;
  }

  .nexus-hud__hp-wrap {
    min-width: 80px;
    padding: 3px 8px;
    gap: 4px;
  }

  .nexus-hud__hp-track {
    width: 40px;
    height: 4px;
  }

  .nexus-hud__hp-num {
    font-size: 0.72rem;
  }

  .nexus-hud__quit {
    padding: 4px 8px;
    font-size: 0.72rem;
  }


  /* ── Combat header ──────────────────────────────────────────────── */

  .nexus-combat-header {
    margin-bottom: 2px;
  }

  .nexus-combat-header__name {
    font-size: 1rem;
  }

  .nexus-combat-header__tier {
    font-size: 0.52rem;
    padding: 2px 5px;
  }

  .nexus-combat-header__round-num {
    font-size: 1.3rem;
  }

  .nexus-combat-header__round-of {
    font-size: 0.72rem;
  }

  .nexus-enemy-desc {
    display: none;
  }

  .nexus-mechanic {
    padding: 3px 8px;
    margin-bottom: 2px;
    font-size: 0.7rem;
  }

  .nexus-mechanic__key {
    font-size: 0.56rem;
    padding: 1px 5px;
  }


  /* ══════════════════════════════════════════════════════════════════
     COMBAT SPLIT-PANEL
     Zones occupy the left ~65%, command sidebar the right ~35%.
     This eliminates vertical scrolling during the core gameplay loop.
     ══════════════════════════════════════════════════════════════════ */

  .nexus-battlefield {
    flex-direction: row;
    gap: 6px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* ── Zones panel (left) ─────────────────────────────────────────── */

  .nexus-battlefield .nexus-zones {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
    gap: 4px;
    align-self: stretch;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nexus-zones {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .nexus-zone {
    border-radius: 6px;
    border-width: 1.5px;
  }

  .nexus-zone:hover {
    transform: none;
  }

  /* Zone header — tight */
  .nexus-zone__header {
    padding: 3px 5px;
    font-size: 0.65rem;
    gap: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nexus-zone__desc {
    display: none;
  }

  /* NPC intent — icon + power + ability tag */
  .nexus-zone__npc-side {
    padding: 2px 4px;
  }

  .nexus-zone__intent-card {
    gap: 3px;
    padding: 2px;
    flex-direction: column;
    align-items: center;
  }

  .nexus-zone__intent-left .nexus-thumb {
    width: 26px;
    height: 26px;
  }

  .nexus-zone__intent-pwr {
    font-size: 0.58rem;
    padding: 0 3px;
  }

  .nexus-zone__intent-info {
    align-items: center;
    text-align: center;
  }

  .nexus-zone__intent-name {
    font-size: 0.58rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .nexus-zone__intent-ab-desc {
    display: none;
  }

  .nexus-zone__intent-ab-name {
    font-size: 0.52rem;
  }

  .nexus-zone__intent-ab .nexus-ab-tag {
    font-size: 0.44rem;
    padding: 0 2px;
  }

  /* Versus bar — thin divider */
  .nexus-zone__versus {
    padding: 2px 3px;
    font-size: 0.65rem;
    gap: 2px;
  }

  .nexus-zone__versus-icon {
    font-size: 0.55rem;
  }

  /* Player stacked cards — pill-sized */
  .nexus-zone__stack {
    padding: 1px 3px;
  }

  .nexus-zone__stacked-card {
    gap: 2px;
    padding: 1px 2px;
    font-size: 0.54rem;
  }

  .nexus-zone__stacked-card .nexus-thumb {
    width: 14px;
    height: 14px;
  }

  .nexus-zone__sc-name {
    font-size: 0.52rem;
  }

  .nexus-zone__sc-pwr {
    font-size: 0.58rem;
    min-width: 14px;
  }

  .nexus-zone__sc-ab,
  .nexus-zone__stacked-card .nexus-ab-tag {
    display: none;
  }

  /* Deploy slot */
  .nexus-zone__slot {
    margin: 2px 3px 3px;
    padding: 4px 2px;
    min-height: 22px;
    border-radius: 5px;
  }

  .nexus-zone__slot-label {
    font-size: 0.48rem;
    letter-spacing: 0.06em;
  }

  .nexus-zone__locked-overlay {
    font-size: 0.52rem;
  }


  /* ── Command panel (right sidebar) ──────────────────────────────── */

  .nexus-command {
    width: 205px;
    flex-shrink: 0;
    gap: 3px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 100%;
  }

  /* Mana — compact strip */
  .nexus-command .nexus-mana {
    padding: 3px 6px;
    margin-bottom: 0;
    font-size: 0.75rem;
    border-radius: 4px;
    gap: 4px;
  }

  .nexus-command .nexus-mana__gem {
    width: 10px;
    height: 10px;
    border-radius: 2px;
  }

  .nexus-command .nexus-mana__count {
    font-size: 0.75rem;
  }

  /* Hand header */
  .nexus-command .nexus-hand-header {
    margin-bottom: 1px;
  }

  .nexus-command .nexus-hand-header__title {
    font-size: 0.55rem;
  }

  .nexus-command .nexus-hand-header__info {
    font-size: 0.55rem;
  }

  /* Hand cards — vertical list in sidebar */
  .nexus-command .nexus-draft-options {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
  }

  .nexus-command .nexus-card-btn--with-thumb {
    min-height: 0;
  }

  .nexus-command .nexus-card-btn__art {
    border-right-width: 1px;
  }

  .nexus-command .nexus-card-btn__art .nexus-thumb--sm {
    width: 34px;
    height: 38px;
  }

  .nexus-command .nexus-card-btn__mana {
    width: 15px;
    height: 15px;
    font-size: 0.56rem;
    bottom: 1px;
    left: 1px;
    border-width: 1px;
  }

  .nexus-command .nexus-card-btn__info {
    padding: 2px 5px;
    gap: 1px;
  }

  .nexus-command .nexus-card-btn__name {
    font-size: 0.68rem;
  }

  .nexus-command .nexus-card-btn__power {
    font-size: 0.82rem;
  }

  .nexus-command .nexus-card-btn__ab-row {
    margin-top: 0;
  }

  .nexus-command .nexus-card-btn__ab-name {
    font-size: 0.58rem;
  }

  .nexus-command .nexus-card-btn__ab-desc {
    display: none;
  }

  .nexus-command .nexus-ab-tag {
    font-size: 0.44rem;
    padding: 0 3px;
  }

  /* Draggable in sidebar */
  .nexus-command .nexus-card-btn--draggable:hover {
    transform: translateY(-2px) scale(1.01);
  }

  .nexus-command .nexus-card-btn--selected {
    transform: translateY(-1px);
  }

  /* Action buttons — stacked in sidebar */
  .nexus-command .nexus-combat__actions {
    flex-direction: column;
    gap: 3px;
    margin-top: 2px;
  }

  .nexus-command .nexus-combat__actions .nexus-btn {
    padding: 5px 6px;
    font-size: 0.64rem;
    min-width: 0;
    width: 100%;
    text-align: center;
  }

  .nexus-command .nexus-btn--advance {
    min-width: 0 !important;
    letter-spacing: 0.04em;
  }

  .nexus-command .nexus-btn--resolve {
    min-width: 0 !important;
    letter-spacing: 0.04em;
  }

  .nexus-command .nexus-btn__round-num {
    font-size: 0.78rem;
  }

  .nexus-command .nexus-btn--retreat {
    font-size: 0.56rem;
    padding: 3px 6px;
  }


  /* ── Map: compact ───────────────────────────────────────────────── */

  .nexus-map {
    padding: 6px 10px 4px;
    margin-bottom: 4px;
    border-radius: 8px;
  }

  .nexus-map__label {
    font-size: 0.52rem;
    margin: 1px 0 2px;
  }

  .nexus-map__path {
    gap: 3px;
    margin: 2px 0;
  }

  .nexus-map__arrow {
    font-size: 0.85rem;
  }

  .nexus-map__boss {
    margin: 4px 0 3px;
    padding: 2px 0;
  }

  .nexus-map__boss::before,
  .nexus-map__boss::after {
    width: 40px;
  }

  .nexus-node {
    width: 48px;
    height: 48px;
    font-size: 0.95rem;
    border-radius: 8px;
    border-width: 1.5px;
  }

  .nexus-node small {
    font-size: 0.46rem;
    margin-top: 1px;
  }

  .nexus-node--boss {
    width: 56px;
    height: 56px;
    font-size: 1.15rem;
  }


  /* ── Hand (non-combat — map/rest views) ─────────────────────────── */

  .nexus-hand {
    padding: 5px 8px;
    margin-bottom: 4px;
    border-radius: 6px;
  }

  .nexus-hand h3 {
    font-size: 0.58rem;
    margin-bottom: 2px;
  }

  .nexus-hand__card {
    padding: 2px 5px;
    font-size: 0.7rem;
    margin-bottom: 1px;
    border-radius: 5px;
  }

  .nexus-hand__card .nexus-thumb {
    width: 16px;
    height: 16px;
  }

  .nexus-card-btn__mana.nexus-card-btn__mana--inline {
    width: 14px;
    height: 14px;
    font-size: 0.52rem;
  }

  .nexus-ability-tag {
    font-size: 0.6rem;
    padding: 0 4px;
  }


  /* ── Events ─────────────────────────────────────────────────────── */

  .nexus-event__narrative {
    padding: 6px 10px;
    font-size: 0.8rem;
    line-height: 1.35;
    margin-bottom: 4px;
    border-radius: 6px;
  }

  .nexus-event__choices {
    gap: 3px;
    margin-bottom: 4px;
  }

  .nexus-event__choice {
    padding: 7px 10px;
    gap: 8px;
    border-radius: 6px;
  }

  .nexus-event__choice-emoji {
    font-size: 1.05rem;
  }

  .nexus-event__choice-body strong {
    font-size: 0.78rem;
  }

  .nexus-event__choice-desc {
    font-size: 0.65rem;
  }

  .nexus-event__changes {
    margin-bottom: 4px;
    gap: 6px;
  }

  .nexus-event__change {
    font-size: 0.72rem;
    padding: 2px 8px;
  }


  /* ── Shop ────────────────────────────────────────────────────────── */

  .nexus-shop .nexus-shop__items {
    gap: 3px;
    margin-bottom: 4px;
  }

  .nexus-shop__item {
    padding: 6px 10px;
    gap: 8px;
    border-radius: 6px;
  }

  .nexus-shop__item-emoji {
    font-size: 1.05rem;
  }

  .nexus-shop__item-body strong {
    font-size: 0.78rem;
  }

  .nexus-shop__item-desc {
    font-size: 0.65rem;
  }

  .nexus-shop__item-cost {
    font-size: 0.88rem;
  }


  /* ── Trivia ─────────────────────────────────────────────────────── */

  .nexus-trivia__question {
    padding: 6px 10px;
    font-size: 0.85rem;
    line-height: 1.35;
    margin-bottom: 4px;
    border-radius: 6px;
  }

  .nexus-trivia__hint {
    font-size: 0.75rem;
    margin-bottom: 3px;
  }

  .nexus-trivia__timer {
    font-size: 0.72rem;
    margin-bottom: 3px;
  }

  .nexus-trivia__timer--urgent {
    font-weight: 700;
  }

  .nexus-trivia__input {
    gap: 4px;
    margin-bottom: 4px;
  }

  .nexus-trivia__input input {
    padding: 5px 8px;
    font-size: 0.85rem;
    border-radius: 5px;
  }


  /* ── Rest: 3-column choices ─────────────────────────────────────── */

  .nexus-rest .nexus-rest__choices {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }

  .nexus-rest .nexus-event__choice {
    flex-direction: column;
    text-align: center;
    padding: 6px 4px;
    gap: 3px;
  }

  .nexus-rest .nexus-event__choice-emoji {
    font-size: 1.2rem;
  }


  /* ── Relic choice ───────────────────────────────────────────────── */

  .nexus-relic-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 4px;
  }

  .nexus-btn--relic {
    padding: 6px 8px;
    margin-bottom: 0;
    font-size: 0.78rem;
  }

  .nexus-btn--relic small {
    font-size: 0.65rem;
  }


  /* ── Card reward ────────────────────────────────────────────────── */

  .nexus-reward-cards {
    gap: 6px;
    margin: 4px 0;
  }

  .nexus-reward-card {
    width: 150px;
    padding: 5px;
    border-radius: 8px;
  }

  .nexus-reward-card__name {
    font-size: 0.78rem;
  }

  .nexus-reward-card__stats {
    font-size: 0.68rem;
    gap: 4px;
    margin-bottom: 2px;
  }

  .nexus-reward-card__power {
    font-size: 0.82rem;
  }

  .nexus-reward-card__img .nexus-thumb--md {
    width: 50px;
    height: 50px;
  }

  .nexus-reward-card__ability {
    gap: 2px;
  }

  .nexus-reward-card__ab-desc {
    font-size: 0.6rem;
  }


  /* ── Summary ────────────────────────────────────────────────────── */

  .nexus-summary__header {
    font-size: 1.3rem;
    letter-spacing: 0.15em;
    margin-bottom: 6px;
  }

  .nexus-summary__grid {
    margin-bottom: 6px;
  }

  .nexus-summary__stat {
    padding: 6px 12px;
    min-width: 55px;
  }

  .nexus-summary__stat-val {
    font-size: 1.15rem;
  }

  .nexus-summary__stat-label {
    font-size: 0.46rem;
  }

  .nexus-summary__rewards {
    padding: 6px 8px;
    margin-bottom: 4px;
    border-radius: 6px;
  }

  .nexus-summary__reward {
    padding: 2px 0;
    font-size: 0.75rem;
  }

  .nexus-zone-results {
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    margin-bottom: 4px;
  }

  .nexus-zr {
    padding: 5px 6px;
    font-size: 0.7rem;
    border-radius: 5px;
  }

  .nexus-zr__zone {
    font-size: 0.78rem;
    margin-bottom: 2px;
  }


  /* ── Mastery ────────────────────────────────────────────────────── */

  .nexus-mastery {
    padding: 3px 6px;
  }

  .nexus-mastery__label {
    font-size: 0.52rem;
  }

  .nexus-mastery__xp {
    font-size: 0.56rem;
  }

  .nexus-summary__mastery {
    margin-bottom: 6px;
  }


  /* ── Relics panel ───────────────────────────────────────────────── */

  .nexus-relics {
    padding: 4px 6px;
    margin-bottom: 4px;
    border-radius: 6px;
  }

  .nexus-relics h3 {
    font-size: 0.56rem;
    margin-bottom: 1px;
  }

  .nexus-relics__item {
    padding: 2px 0;
    font-size: 0.72rem;
  }


  /* ── Lobby ──────────────────────────────────────────────────────── */

  .nexus-lobby {
    max-width: 100%;
  }

  .nexus-lobby__intro {
    padding: 8px 12px 6px;
    margin-bottom: 6px;
    border-radius: 8px;
  }

  .nexus-lobby__title {
    font-size: 1.3rem;
    letter-spacing: 0.15em;
    margin-bottom: 2px;
  }

  .nexus-lobby__tagline {
    font-size: 0.75rem;
    margin-bottom: 4px;
  }

  .nexus-lobby__rules {
    border-radius: 5px;
  }

  .nexus-lobby__rule {
    padding: 4px 8px;
    font-size: 0.7rem;
    gap: 6px;
  }

  .nexus-lobby__rule-key {
    font-size: 0.48rem;
    min-width: 48px;
    padding: 1px 5px;
  }

  .nexus-btn--launch {
    padding: 8px 16px;
    font-size: 0.75rem;
    margin-bottom: 4px;
    border-radius: 5px;
    letter-spacing: 0.08em;
  }

  .nexus-lobby__actions {
    flex-direction: row;
    gap: 4px;
  }


  /* ── Deck selection ─────────────────────────────────────────────── */

  .nexus-deck-phase__header {
    margin-bottom: 6px;
  }

  .nexus-deck-phase__header h2 {
    font-size: 1.05rem;
    margin-bottom: 1px;
  }

  .nexus-deck-phase__header p {
    font-size: 0.72rem;
  }

  .nexus-deck-grid {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 8px;
  }

  .nexus-deck {
    border-radius: 10px;
  }

  .nexus-deck__hero {
    padding: 8px 8px 4px;
    gap: 8px;
  }

  .nexus-deck__hero-art {
    width: 48px;
    height: 56px;
  }

  .nexus-deck__hero-img {
    width: 48px;
    height: 56px;
    border-radius: 5px;
    border-width: 1.5px;
  }

  .nexus-deck__hero-glow {
    inset: -4px;
    border-radius: 10px;
  }

  .nexus-deck__hero-name {
    font-size: 0.85rem;
  }

  .nexus-deck__hero-power {
    font-size: 0.65rem;
  }

  .nexus-deck__hero-ability {
    font-size: 0.62rem;
  }

  .nexus-deck__hero-desc {
    font-size: 0.56rem;
  }

  .nexus-deck__identity {
    padding: 0 8px;
    gap: 5px;
    margin-bottom: 2px;
  }

  .nexus-deck__emoji {
    font-size: 1rem;
  }

  .nexus-deck__name {
    font-size: 0.78rem;
  }

  .nexus-deck__archetype {
    font-size: 0.55rem;
  }

  .nexus-deck__desc {
    font-size: 0.65rem;
    padding: 0 8px;
    margin-bottom: 2px;
  }

  .nexus-deck__strategy {
    font-size: 0.56rem;
    padding: 0 8px;
    margin-bottom: 4px;
  }

  .nexus-deck__support {
    padding: 0 6px;
    margin-bottom: 4px;
  }

  .nexus-deck__sup {
    padding: 2px 3px;
    font-size: 0.65rem;
  }

  .nexus-deck__sup-pwr {
    font-size: 0.6rem;
    min-width: 24px;
  }

  .nexus-deck__action {
    padding: 0 8px 6px;
  }

  .nexus-mastery-badge {
    font-size: 0.65rem;
  }


  /* ── Boss power reveal ──────────────────────────────────────────── */

  .nexus-boss-power__title {
    font-size: 1.1rem;
    margin-bottom: 3px;
  }

  .nexus-boss-power__desc {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }

  .nexus-boss-power__effect {
    padding: 6px 8px;
    margin: 4px auto;
    max-width: 340px;
    border-radius: 6px;
  }

  .nexus-boss-power__reinforcement {
    padding: 4px 8px;
    margin: 3px auto;
    max-width: 340px;
    border-radius: 6px;
  }

  .nexus-boss-power__rounds {
    font-size: 0.75rem;
    margin-top: 4px;
  }


  /* ── Tutorial overlay ───────────────────────────────────────────── */

  .nexus-tutorial {
    padding: 12px 14px;
    max-width: 380px;
  }

  .nexus-tutorial__icon {
    font-size: 1.8rem;
    margin-bottom: 3px;
  }

  .nexus-tutorial__title {
    font-size: 1rem;
    margin-bottom: 3px;
  }

  .nexus-tutorial__body {
    font-size: 0.78rem;
    line-height: 1.35;
    margin-bottom: 6px;
  }

  .nexus-tutorial__progress {
    font-size: 0.65rem;
    margin-bottom: 3px;
  }


  /* ── Tooltips ───────────────────────────────────────────────────── */

  .nexus-tip__inner {
    max-width: 220px;
    min-width: 150px;
    padding: 5px;
    gap: 5px;
    border-radius: 7px;
  }

  .nexus-tip__img {
    width: 44px;
    height: 56px;
    border-radius: 4px;
  }

  .nexus-tip__name {
    font-size: 0.75rem;
    margin-bottom: 2px;
  }

  .nexus-tip__stats {
    font-size: 0.65rem;
    margin-bottom: 3px;
  }

  .nexus-tip__power {
    font-size: 0.78rem;
  }

  .nexus-tip__ab {
    font-size: 0.65rem;
  }

  .nexus-tip__ab-desc {
    font-size: 0.58rem;
  }

  .nexus-tip--relic {
    max-width: 180px;
  }

  .nexus-tip__relic-header {
    font-size: 0.78rem;
  }

  .nexus-tip__relic-desc {
    font-size: 0.68rem;
  }


  /* ── Generic buttons ────────────────────────────────────────────── */

  .nexus-btn {
    padding: 5px 12px;
    font-size: 0.78rem;
    border-radius: 5px;
  }

  .nexus-btn--start {
    padding: 7px 18px;
    font-size: 0.88rem;
  }

  .nexus-btn--ghost {
    padding: 4px 8px;
    font-size: 0.58rem;
  }

  .nexus-btn--abandon {
    margin-top: 4px;
    font-size: 0.65rem;
  }

  .nexus-btn--secondary {
    font-size: 0.7rem;
  }

  .nexus-btn--choice {
    padding: 6px 10px;
    margin-bottom: 3px;
  }


  /* ── History ─────────────────────────────────────────────────────── */

  .nexus-history__run {
    padding: 3px 8px;
    font-size: 0.78rem;
  }

  .nexus-history__run small {
    font-size: 0.65rem;
  }


  /* ── Cooldown ───────────────────────────────────────────────────── */

  .nexus-cooldown {
    padding: 4px;
    font-size: 0.72rem;
  }

  .nexus-cooldown__label {
    font-size: 0.48rem;
  }

  .nexus-encounter-label {
    font-size: 0.5rem;
    margin-bottom: 1px;
  }


  /* ── Relic bar (in HUD) ─────────────────────────────────────────── */

  .nexus-relic-bar__slot {
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    border-radius: 4px;
  }

  .nexus-relic-bar__slot--empty {
    font-size: 0.55rem;
  }


  /* ── Touch ghost (drag) ─────────────────────────────────────────── */

  .nexus-touch-ghost {
    transform: scale(0.7) rotate(-1deg);
    border-radius: 5px;
  }
}
