/* Card art always uses a square atlas cell, including short landscape screens. */
.battle-hand .hand-grid {
  justify-content: flex-start;
  align-items: flex-end;
  min-height: 0;
  padding: .42rem .16rem .1rem;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  scrollbar-width: thin;
  scrollbar-color: #b7a378 #142b31;
}
.battle-hand .card {
  width: clamp(3.25rem, 21svh, 6.8rem);
  flex: 0 0 auto;
}
.battle-hand .card:first-child { margin-inline-start: auto; }
.battle-hand .card:last-child { margin-inline-end: auto; }
.battle-hand .card-art {
  flex: 0 0 auto;
  aspect-ratio: 1;
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
}

.landscape-guide { display: none; }

@media (orientation: landscape) and (max-height: 560px) {
  .view-battle { height: 100svh; height: 100dvh; min-height: 0; }
  .view-battle .duel-screen {
    grid-template-rows: minmax(0, 1fr) clamp(6.5rem, 34svh, 10.5rem) min-content;
    grid-template-rows: minmax(0, 1fr) clamp(6.5rem, 34dvh, 10.5rem) min-content;
  }
  .battle-hand .card { width: clamp(3.25rem, 21dvh, 6.8rem); }
  .battle-hand .card-art { max-height: none; }
  .battle-hand .card-key { font-size: clamp(.65rem, 2.9svh, .86rem); }
  .battle-hand .card-name { font-size: clamp(.59rem, 2.6svh, .72rem); line-height: 1.15; }
  .battle-hand .card-bottom { font-size: clamp(.6rem, 2.7svh, .74rem); }
}

@media (orientation: landscape) and (max-height: 340px) {
  .view-battle .brand { font-size: .75rem; gap: .4rem; }
  .view-battle .brand-destination { font-size: .6rem; margin-top: .14rem; }
  .view-battle .sigil { width: 1.75rem; height: 1.75rem; }
  .view-battle .sigil i { width: 1.12rem; height: 1.12rem; }
  .view-battle .icon-button { min-height: 1.8rem; min-width: 1.8rem; padding-inline: .42rem; }
  .view-battle .utility-label { font-size: .7rem; }
  .view-battle .mode-badge { font-size: .64rem; padding: .2rem .3rem; }
  .view-battle .duel-screen { grid-template-columns: minmax(4rem, 12%) minmax(0, 1fr) minmax(7rem, 18%); }
  .view-battle .leader-medal { width: clamp(2.7rem, 14svh, 3.2rem); }
  .view-battle .leader-name { font-size: .65rem; }
  .view-battle .round-medal { width: 2.4rem; }
  .view-battle .round-medal span { font-size: .58rem; }
  .view-battle .round-medal strong { font-size: 1.05rem; }
  .view-battle .battle-stage { font-size: .6rem; }
}

@media (orientation: portrait) {
  body { overflow: hidden; }
  #game { visibility: hidden; pointer-events: none; }
  .landscape-guide {
    position: fixed;
    z-index: 10000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: max(1.25rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    color: #f8e8c7;
    background: radial-gradient(ellipse at 50% 15%, #31554d, #14242d 58%, #110e17);
  }
  .landscape-guide-panel { width: min(100%, 25rem); text-align: center; }
  .landscape-guide h1 { font: 700 clamp(1.3rem, 5.5vw, 1.8rem)/1.5 var(--serif, serif); margin: .6rem 0; }
  .landscape-guide p { font-size: 1rem; line-height: 1.8; margin: .6rem 0; }
  .landscape-guide .landscape-kicker { color: #dfbf85; font-size: .8rem; letter-spacing: .13em; }
  .landscape-start {
    border: 1px solid #e2c18a;
    padding: .75rem 1.2rem;
    margin-top: .8rem;
    min-height: 3rem;
    color: #173b34;
    background: linear-gradient(135deg, #fff2cf, #b3dbc4);
    font-size: 1rem;
    font-weight: 700;
    touch-action: manipulation;
  }
  .landscape-guide .landscape-hint { color: #cad6cd; font-size: .875rem; margin-top: 1.2rem; }
  .rotate-phone {
    position: relative;
    box-sizing: border-box;
    width: 2.8rem;
    height: 4.5rem;
    margin: 1.4rem auto 1.9rem;
    border: 2px solid #dfbf85;
    border-radius: .4rem;
    box-shadow: 0 0 1.3rem #a8e2c92b;
    animation: rotate-phone 2.8s ease-in-out infinite;
  }
  .rotate-phone::after { content: ''; position: absolute; bottom: .2rem; left: 35%; width: 30%; height: 2px; background: #dfbf85; }
}
@keyframes rotate-phone { 0%, 15% { transform: rotate(0); } 55%, 85%, 100% { transform: rotate(90deg); } }
@media (prefers-reduced-motion: reduce) { .rotate-phone { animation: none; transform: rotate(90deg); } }


/* Keep the end-turn control away from the card and attack actions. */
@media (orientation: landscape) {
  .duel-screen .right-rail .end-seal {
    position: absolute;
    grid-area: 2 / 1 / 3 / 2;
    inset: 0 0 auto;
    z-index: 2;
    width: min(100%, 8.5rem);
    min-height: 2.75rem;
    margin-inline: auto;
    padding-inline: .15rem;
    font-size: clamp(.7rem, 1.25vw, .98rem);
  }
}

@media (orientation: landscape) and (max-width: 680px) {
  .duel-screen .right-rail .end-seal span { display: none; }
}
