:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #10192b;
  color: #eff4fd;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
main { max-width: 52rem; margin: auto; padding: 1rem max(0.85rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(0.85rem, env(safe-area-inset-left)); }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid #b2bdff; outline-offset: 3px; }
h1 { margin: 0 0 0.9rem; font-size: 1.45rem; }
h2 { margin: 0 0 0.65rem; font-size: 1.1rem; }
h2 span { margin-right: 0.2em; }

.legends { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 5.15rem), 1fr)); gap: 0.5rem; }
.legend { display: grid; align-content: start; gap: 0.35rem; padding: 0.35rem; border: 1px solid #344865; border-radius: 0.65rem; background: #18263d; }
.legend span { font-size: 0.72rem; line-height: 1.18; overflow-wrap: anywhere; }
.legend img, .cards img { display: block; width: 100%; aspect-ratio: 5 / 7; object-fit: contain; border-radius: 0.35rem; }
.legend:active, .back:active { background: #314266; }

.back { display: flex; align-items: center; gap: 0.55rem; padding: 0.55rem 0.8rem; min-height: 44px; border: 1px solid #3e5475; border-radius: 0.7rem; background: #192940; font-weight: 650; text-align: left; }
.back span:first-child { font-size: 1.45rem; line-height: 0.85; }
.turns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.3rem; margin: 0.75rem 0; padding: 0.25rem; border-radius: 0.8rem; background: #16213a; }
.turns button { min-height: 44px; padding: 0.45rem; border: 1px solid transparent; border-radius: 0.6rem; background: transparent; color: #bdcde6; font-weight: 650; }
.turns button[aria-pressed="true"] { background: #363f66; border-color: #6878a9; color: #f3f4ff; }

.plan { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.plan section { min-width: 0; padding: 0.65rem; border: 1px solid; border-radius: 0.8rem; }
.plan .incoming { background: radial-gradient(at top left, #21463d, #142b29 70%); border-color: #31554d; color: #b3e9d1; }
.plan .outgoing { background: radial-gradient(at top left, #4c303e, #2c2230 70%); border-color: #603e50; color: #ffc5c6; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 3.4rem), 1fr)); gap: 0.35rem; }
.fallback { display: grid; place-items: center; min-height: 4.25rem; padding: 0.25rem; border-radius: 0.4rem; background: #202b40; font-size: 0.75rem; text-align: center; overflow-wrap: anywhere; }
#empty, #error { color: #bdcde6; text-align: center; }

.deck-picker { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.75rem; color: #bdcde6; }
.deck-picker select { min-height: 44px; padding: 0.4rem 0.8rem; border: 1px solid #3e5475; border-radius: 0.65rem; background: #192940; color: #eff4fd; font: inherit; }

@media (orientation: portrait) {
  .plan { grid-template-columns: 1fr; grid-template-rows: repeat(2, minmax(calc((100svh - 12rem) / 2), auto)); }
  .plan .outgoing { grid-row: 1; }
  .plan .incoming { grid-row: 2; }
  .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (orientation: landscape) {
  main { display: flex; flex-direction: column; min-height: 100svh; max-width: none; }
  #matchup { display: flex; flex: 1; flex-direction: column; }
  .back { align-self: flex-start; }
  .plan { flex: 1; }
  .cards {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, clamp(4.75rem, 10vw, 8rem)), 1fr));
    align-content: start;
  }
}
