.mobile-volume {
  display: none;
}

/* Match mobileLayout in app.js, including wide phones in landscape. */
@media (max-width: 900px), (pointer: coarse) and (max-height: 600px) {
  body {
    margin: 0;
    touch-action: pan-x pan-y;
    overscroll-behavior: none;
  }
  html.mobile-battle,
  html.mobile-battle body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }
  html.mobile-battle body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
  }
  html.mobile-battle #app {
    height: 100dvh;
    overflow: clip;
  }
  button,
  a,
  input,
  select {
    touch-action: manipulation;
  }
  input,
  select,
  textarea {
    font-size: 16px;
  }
  #app {
    max-width: none;
  }
  .shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100dvh;
    zoom: 1;
    padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
  }
  .topbar,
  .bottom {
    flex: none;
    height: auto;
    min-height: 52px;
    gap: 8px;
    padding: 4px 10px;
  }
  .topbar {
    padding-top: max(4px, env(safe-area-inset-top));
  }
  .topbar button,
  .bottom .settings-button {
    height: 44px;
    line-height: normal;
    font-size: 16px;
  }
  .topbar .back-button {
    width: 44px;
    min-width: 44px;
  }
  .topbar .identity {
    min-width: 0;
    max-width: 30%;
    font-size: 15px;
  }
  .topbar .reference-button {
    width: 88px;
    min-width: 88px;
    padding-left: 20px;
  }
  .reference-button .ui-icon {
    left: 6px;
    width: 18px;
  }
  .gf-counter,
  .gf-counter.has-tiebreak {
    position: static;
    min-width: 0;
    margin-left: auto;
    padding: 3px 8px;
    font-size: 12px;
    white-space: nowrap;
  }
  .topbar .right {
    margin-left: auto;
  }
  .bottom {
    justify-content: space-between;
    flex-wrap: wrap;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  .bottom .settings-button {
    width: 116px;
    min-width: 116px;
    margin: 0 auto 0 0;
  }
  .footer-name {
    position: static;
    max-width: calc(100% - 176px);
    font-size: 14px;
  }
  .bottom:has(.bottom-hand) .footer-name {
    display: none;
  }
  .volume-control {
    position: static;
    width: 164px;
    height: 44px;
    margin-left: auto;
    align-items: center;
    flex: none;
  }
  .bottom .mute-button {
    width: 44px;
    height: 44px;
    flex: none;
  }
  .volume-steps {
    display: none;
  }
  .mobile-volume {
    display: block;
    width: 120px;
    height: 44px;
    margin: 0;
    accent-color: #efffec;
  }
  .bottom > .bottom-hand,
  .bottom .bottom-chat .bottom-hand {
    position: static;
    font-size: 13px;
    padding: 0 8px;
    line-height: 32px;
  }
  .bottom .bottom-chat,
  .bottom:has(.bottom-hand) .bottom-chat {
    position: static;
    order: 1;
    width: 100%;
    height: auto;
    min-width: 0;
    flex-wrap: wrap;
    gap: 6px;
  }
  .bottom .bottom-chat .bottom-hand {
    display: none;
  }
  .bottom .bottom-chat input:not([type="checkbox"]) {
    flex: 1;
    width: 0;
    min-width: 80px;
    height: 44px;
    font-size: 16px;
  }
  .bottom .bottom-chat label input {
    flex: none;
    width: 22px;
    height: 22px;
  }
  .bottom .bottom-chat label {
    min-height: 44px;
    gap: 4px;
  }
  .bottom .bottom-chat button {
    height: 44px;
    padding: 0 12px;
    font-size: 14px;
  }
  .screen {
    flex: 1;
    min-height: 0;
  }
  .home {
    height: auto;
    padding: 24px 16px;
  }
  .home .logo {
    width: 320px;
    height: 100px;
    max-width: 90%;
  }
  .auth-tabs {
    margin: 12px 0 16px;
  }
  .auth-tabs button {
    min-width: 0;
    width: 140px;
    min-height: 44px;
  }
  .birth,
  .auth-form {
    width: min(420px, 100%);
    max-width: 100%;
    margin: 0 auto;
    gap: 8px;
  }
  .birth label {
    margin: 0;
    font-size: 15px;
  }
  .birth input {
    width: 100%;
    max-width: 100%;
    height: 48px;
    margin: 0 0 8px;
    padding: 8px 12px;
    font-size: 16px;
  }
  .birth .big,
  .big {
    min-height: 56px;
    height: auto;
    font-size: 28px;
    line-height: 1.3;
    padding: 10px 16px;
    border-radius: 16px;
  }
  .home-note {
    margin-top: 20px;
    font-size: 13px;
    line-height: 1.7;
  }
  .menu {
    padding: 60px 16px 24px;
  }
  .mode-list {
    width: min(500px, 100%);
    max-width: 100%;
    gap: 16px;
  }
  .mode {
    min-height: 132px;
    height: auto;
    border-radius: 22px;
    padding: 8px;
    gap: 6px;
  }
  .mode strong {
    font-size: 32px;
    margin: 0;
  }
  .mode small {
    font-size: 15px;
    line-height: 1.5;
  }
  .mode-band {
    height: 30px;
    line-height: 30px;
    font-size: 13px;
  }
  .training-screen {
    padding: 28px 16px;
    gap: 24px;
  }
  .training-count,
  .training-start {
    width: min(480px, 100%);
    max-width: 100%;
    height: 64px;
    font-size: 30px;
    border-radius: 16px;
  }
  .training-options {
    width: min(480px, 100%);
    gap: 12px;
  }
  .training-doom {
    flex: 1 1 140px;
    width: auto;
    height: auto;
    padding: 8px;
    font-size: 18px;
  }
  .training-doom select {
    width: 100%;
    height: 44px;
    font-size: 16px;
  }
  .training-rules {
    position: static;
    transform: none;
    min-height: 44px;
    height: auto;
    max-width: 100%;
    white-space: normal;
  }
  .panel,
  .subscreen,
  .room-screen {
    padding: 16px;
  }
  .primary,
  .secondary,
  .danger,
  .chat-form button,
  .askuri-button {
    min-height: 44px;
  }
  .lobby-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .chat-form input,
  .room-screen select,
  .panel input {
    min-height: 44px;
    min-width: 0;
    font-size: 16px;
  }
  .settings-screen {
    height: calc(100dvh - 104px);
  }
  .settings-language {
    height: 150px;
    padding: 56px 16px 20px;
  }
  .settings-language span:first-child {
    top: 20px;
    left: 0;
    right: 0;
    font-size: 18px;
  }
  #language-select {
    height: 44px;
    font-size: 16px;
  }

  /* A bounded hand keeps the command controls on screen while browsing. */
  .shell.battle-shell {
    height: 100dvh;
    min-height: 0;
    overflow: clip;
  }
  .shell:has(.reference-screen),
  .shell:has(.settings-screen) {
    height: 100dvh;
    min-height: 0;
  }
  .screen.settings-screen {
    height: auto;
    min-height: 0;
  }
  .battle {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title title" "arena arena" "heading heading" "hand hand"
      "help help" "players players" "miracles miracles" "tools tools";
    grid-template-rows: auto auto auto minmax(72px, 1fr) auto auto auto auto;
    flex: 1;
    min-height: 0;
    height: auto;
    padding: 8px;
    gap: 6px;
    overflow: clip;
  }
  .battle-title,
  .battle:has(.has-used-items) .battle-title {
    grid-area: title;
    position: static;
    width: auto;
    min-height: 18px;
    margin: 0;
    font-size: 12px;
  }
  .battle-title .phase {
    display: inline;
    font-size: 14px;
  }
  .players,
  .players:has(.player:nth-child(7)) {
    grid-area: players;
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: auto;
    height: auto;
    min-height: 76px;
    max-height: 172px;
    overflow-y: auto;
    gap: 6px;
    padding: 2px;
    align-content: start;
  }
  .players .player,
  .players:has(.player:nth-child(7)) .player {
    display: block;
    height: auto;
    min-height: 76px;
    padding: 6px 8px;
    border: 2px solid #008f6f;
    border-radius: 10px;
    background: #f4ffddf5;
    overflow: hidden;
  }
  .player::before {
    display: none;
  }
  .players .player.active {
    border-color: #c88012;
    background: #fff3c4;
  }
  .players .player.target {
    box-shadow: inset 0 0 0 2px #c65d40;
  }
  .players .player-name {
    flex-wrap: wrap;
    font-size: 14px;
    line-height: 1.4;
    gap: 2px 4px;
  }
  .player-name > span {
    max-width: 100%;
  }
  .player-name small {
    font-size: 10px;
  }
  /* Before training again, the AI win-rate choice takes its own row. */
  .battle .battle-actions .win-rate-option {
    flex: 1 0 100%;
    justify-content: center;
  }
  /* The AI win rate stays in the name block here, after the artifact
     count. Where that line is full it moves down a line (the count with it
     when that is full too), so the name keeps its width, and the panels
     grow to hold that line rather than hide the stats. The one-line panels
     of portrait phones (no count) shrink the name instead. */
  .players:has(.win-rate) {
    grid-auto-rows: max-content;
  }
  .players .player-name .win-rate-slot {
    position: static;
    transform: none;
    /* As tall as the badge, not as a line of the (larger) name. */
    line-height: 0;
  }
  .players .player-name:has(.win-rate) {
    justify-content: flex-end;
  }
  .players .player-name:has(.win-rate) > span:not(.win-rate-slot) {
    min-width: 0;
    margin-right: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .players .player-name:has(.win-rate) small {
    flex-shrink: 0;
    white-space: nowrap;
  }
  .players .player-name .win-rate {
    padding: 0 3px;
    font-size: 11px;
  }
  .players .player .guardian {
    position: static;
    width: 24px;
    height: 24px;
  }
  .players .player .stats,
  .players:has(.player:nth-child(7)) .stats {
    font-size: 19px;
    gap: 8px;
    justify-content: space-between;
    margin-top: 3px;
  }
  .players .player .stats small {
    font-size: 10px;
    margin-right: 2px;
  }
  .players .stats .hp {
    color: #b52e36;
  }
  .players .stats .mp {
    color: #245eac;
  }
  .players .stats .cp {
    color: #89651b;
  }
  .player .hpbar {
    display: block;
  }
  .player .curse-badges {
    position: static;
    justify-content: flex-end;
    margin-top: 3px;
  }
  .battle > .hand-heading {
    display: flex;
    grid-area: heading;
    margin: 0;
    font-size: 15px;
  }
  .hand-heading small {
    display: none;
  }
  .battle .miracle-toggle {
    display: block;
    grid-area: miracles;
    justify-self: end;
    position: static;
    width: auto;
    height: auto;
    min-height: 44px;
    max-width: 180px;
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid #72968a;
    border-radius: 8px;
    background: #f4ffdd;
    color: #235c4b;
  }
  .battle > .hand,
  .battle > .hand:has(.card:nth-child(10)) {
    grid-area: hand;
    position: static;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    align-content: start;
    align-items: stretch;
    gap: 8px 6px;
    width: auto;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: none;
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-gutter: auto;
  }
  .hand .card {
    display: flex;
    align-items: center;
    height: auto;
    min-height: 88px;
    padding: 4px 3px;
    border: 1px solid #7d9d74;
    border-radius: 10px;
    background: #f4ffdd;
    box-shadow: 0 2px 3px #003c3020;
  }
  .hand .card .card-art {
    width: min(44px, 100%);
    height: auto;
    aspect-ratio: 1;
  }
  .hand .card img.art {
    width: 100%;
    height: 100%;
  }
  .hand .card .card-name {
    display: block;
    min-height: 14px;
    max-width: 100%;
    font-size: 9px;
    line-height: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hand .card .card-stat {
    display: block;
    max-width: 100%;
    font-size: 14px;
    line-height: 18px;
    min-height: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hand .card .detail,
  .hand .card .price {
    display: none;
  }
  .hand .card.selected {
    outline: 3px solid #ba680e;
    outline-offset: -1px;
    transform: none;
    background: #fff0b3;
  }
  .hand .card.learned {
    border-color: #4b88ab;
    background: #e6f0ff;
  }
  .battle > .card-inspector {
    display: none;
  }
  .battle > .card-help,
  .battle:has(.hand .card:nth-child(10)) > .card-help {
    grid-area: help;
    position: static;
    display: block;
    width: auto;
    min-height: 0;
    max-height: 40px;
    overflow-y: auto;
    margin: 0;
    padding: 4px 8px;
    font-size: 13px;
    background: #f4ffdd;
    border-radius: 6px;
  }
  .battle:not(:has(.hand .selected)) > .card-help {
    display: none;
  }
  .battle > .arena {
    grid-area: arena;
    position: relative;
    display: block;
    width: auto;
    height: auto;
    inset: auto;
    margin: 0;
    min-width: 0;
  }
  .battle .action-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
    min-height: 0;
    padding: 8px;
    border: 1px solid #008f6f;
    border-radius: 12px;
    background: #f8ffdf;
    text-align: center;
  }
  .battle .action-panel h2 {
    grid-column: 1 / -1;
    position: static;
    width: auto;
    clip-path: none;
    height: auto;
    max-width: none;
    margin: 0;
    border: 0;
    background: transparent;
    font-size: 17px;
    line-height: 1.4;
  }
  .action-panel .hint {
    grid-column: 1 / -1;
    position: static;
    min-height: 0;
    font-size: 12px;
    line-height: 1.5;
    margin: 3px 0;
  }
  .battle .action-panel .selected-preview {
    grid-column: 1 / -1;
    position: static;
    width: auto;
    height: auto;
    min-height: 0;
    max-height: 60px;
    overflow-y: auto;
    justify-content: center;
    gap: 4px;
    font-size: 13px;
    margin: 4px 0;
  }
  .selected-preview:not(:has(img)) {
    display: none;
  }
  .battle .selected-preview > img {
    display: block;
    width: 28px;
    height: 28px;
  }
  .battle .battle-actions,
  .battle .battle-aux-actions {
    position: static;
    width: auto;
    margin-top: 6px;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .battle .battle-actions {
    grid-column: 1;
  }
  .battle .battle-aux-actions {
    grid-column: 2;
    flex-wrap: nowrap;
    margin-left: 6px;
  }
  .battle .combat-defense .battle-aux-actions,
  .battle:has(.winner) .battle-actions {
    grid-column: 1 / -1;
    margin-left: 0;
  }
  .battle .battle-actions button,
  .battle .battle-aux-actions button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 14px;
  }
  .battle .battle-actions button {
    min-height: 48px;
    font-size: 21px;
  }
  .battle .action-panel .combat-summary {
    position: relative;
    width: 100%;
    height: 48px;
    min-height: 48px;
    line-height: 48px;
    margin: 4px 0;
  }
  .battle .action-panel .command-area,
  .arena > .log {
    display: none;
  }
  .battle .action-panel .attack-info {
    grid-column: 1 / -1;
    position: relative;
    inset: auto;
    width: auto;
    height: auto;
    font-size: 20px;
    margin: 4px 0;
  }
  .battle .action-panel .used-items {
    grid-column: 1 / -1;
    position: static;
    width: auto;
    margin-bottom: 6px;
    max-height: 130px;
    overflow-y: auto;
  }
  .battle.phase-turn .selection-board {
    display: none;
  }
  .battle .used-card-list {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: auto;
    height: auto;
    max-height: 90px;
    overflow-y: auto;
  }
  .battle .used-item {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: none;
  }
  .battle .action-panel > .purchase-controls {
    grid-column: 1 / -1;
    position: relative;
    inset: auto;
    margin: 8px auto;
    height: 140px;
  }
  .purchase-controls > .purchase-button {
    height: 60px;
  }
  .purchase-controls > [data-accept="false"] {
    top: 80px;
  }
  .purchase-controls .purchase-button > span {
    height: 60px;
    line-height: 60px;
    font-size: 28px;
  }
  .battle > .time-gauge {
    position: absolute;
    left: 8px;
    top: 0;
    width: calc(100% - 16px);
    max-width: none;
    height: 4px;
    margin: 0;
  }
  .battle-bottom {
    grid-area: tools;
    position: static;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin: 0;
  }
  .battle-bottom > span {
    display: none;
  }
  .battle-bottom > button,
  .battle-bottom > .card-odds-button {
    position: static;
    min-height: 44px;
    padding: 4px;
    margin: 0;
    border: 1px solid #789987;
    border-radius: 8px;
    background: #f4ffdd;
    color: #235c4b;
    font-size: 12px;
  }
  .battle-bottom > button + button {
    margin: 0;
  }
  .battle > .exchange-shell {
    grid-area: hand;
    position: relative;
    inset: auto;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow-y: auto;
  }
  .battle:has(.exchange-shell) > .hand {
    display: none;
  }
  .battle .exchange-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    height: auto;
    transform: none;
    padding: 4px;
  }
  .exchange-controls > .exchange-values {
    position: relative;
    inset: auto;
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: 100%;
    height: 44px;
    border-radius: 8px;
  }
  .exchange-controls .exchange-values > span {
    position: static;
    width: auto;
    height: 44px;
    line-height: 44px;
    text-align: center;
  }
  .exchange-controls .exchange-values > .exchange-resource {
    font-size: 14px;
  }
  .exchange-controls .exchange-values > .exchange-number {
    font-size: 24px;
  }
  .exchange-controls > .exchange-step {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    position: relative;
    inset: auto;
    width: auto;
    height: 44px;
  }
  .exchange-controls > .exchange-step::before {
    content: attr(data-resource-label);
    font-size: 12px;
    color: #ffeeaa;
  }
  .exchange-controls > [data-resource="mp"] {
    grid-column: 1;
  }
  .exchange-controls > [data-resource="cp"] {
    grid-column: 2;
  }
  .exchange-controls > [data-delta="10"] {
    grid-row: 2;
  }
  .exchange-controls > [data-delta="1"] {
    grid-row: 3;
  }
  .exchange-controls > [data-delta="-1"] {
    grid-row: 4;
  }
  .exchange-controls > [data-delta="-10"] {
    grid-row: 5;
  }
  .exchange-controls .exchange-step > span {
    position: static;
    line-height: 44px;
    font-size: 20px;
  }
  .battle .exchange-controls.exchange-extended {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .exchange-extended > [data-resource="cp"] {
    grid-column: 3;
  }
  .exchange-extended > [data-delta="1000"],
  .exchange-extended > [data-delta="100"] {
    grid-row: 2;
  }
  .exchange-extended > [data-delta="10"],
  .exchange-extended > [data-delta="1"] {
    grid-row: 3;
  }
  .exchange-extended > [data-delta="-1"],
  .exchange-extended > [data-delta="-10"] {
    grid-row: 4;
  }
  .exchange-extended > [data-delta="-100"],
  .exchange-extended > [data-delta="-1000"] {
    grid-row: 5;
  }
  .exchange-extended > [data-delta="10000"],
  .exchange-extended > [data-delta="-10000"] {
    grid-row: 6;
  }
  .exchange-extended
    > [data-resource="mp"]:is(
      [data-delta="100"],
      [data-delta="1"],
      [data-delta="-10"],
      [data-delta="-1000"],
      [data-delta="-10000"]
    ) {
    grid-column: 2;
  }
  .exchange-extended
    > [data-resource="cp"]:is(
      [data-delta="100"],
      [data-delta="1"],
      [data-delta="-10"],
      [data-delta="-1000"],
      [data-delta="-10000"]
    ) {
    grid-column: 4;
  }
  .exchange-extended .exchange-step > span {
    font-size: 16px;
  }
  .exchange-extended > .exchange-step::before {
    font-size: 10px;
  }
  .battle:has(.spectator-banner) {
    display: flex;
    flex-direction: column;
  }
  .spectator-banner {
    margin: auto 0;
  }

  /* Horizontal categories leave the full phone width for the reference. */
  .reference-screen {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 104px);
    min-height: 0;
    border: 0;
  }
  .reference-nav {
    position: static;
    display: flex;
    width: 100%;
    height: auto;
    padding: 8px;
    gap: 6px;
    flex: none;
    overflow-x: auto;
  }
  .reference-nav button:nth-child(n) {
    position: static;
    width: auto;
    height: 44px;
    margin: 0;
    padding: 4px 14px;
    flex: none;
    font-size: 16px;
    white-space: nowrap;
  }
  .reference-content {
    position: relative;
    inset: auto;
    width: 100%;
    height: auto;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px 16px;
  }
  .reference-guide,
  .reference-content .search {
    min-height: 44px;
    font-size: 16px;
  }
  .reference-screen .reference-preview {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
  }
  .reference-screen .reference-gallery,
  .reference-canvas,
  .reference-elements .rule-grid,
  .reference-elements .reference-notes {
    position: static;
    width: auto;
    height: auto;
    max-height: none;
    margin: 12px 0;
  }
  .reference-screen .catalog-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .reference-screen .catalog-item {
    position: static;
    width: 100%;
    height: auto;
    min-height: 44px;
    aspect-ratio: 1;
  }
  dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 24px);
    border-radius: 12px;
  }
  .modal-head {
    padding: 8px 12px;
    gap: 8px;
  }
  .modal-head h2 {
    font-size: 18px;
  }
  .modal-head button {
    flex: none;
    min-width: 44px;
    min-height: 44px;
  }
  .modal-body {
    padding: 16px;
    overflow-wrap: anywhere;
  }
  .rule-numbers,
  .rule-item-list,
  .rule-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .tabs button,
  .count-options button {
    min-height: 44px;
  }
}

/* Portrait follows the game board: command area, hand, then player status. */
@media (max-width: 900px) and (orientation: portrait) {
  .battle-shell .topbar .identity {
    display: none;
  }
  .battle-shell .gf-counter,
  .battle-shell .gf-counter.has-tiebreak {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    min-width: 128px;
    margin: 0;
    font-size: 20px;
    text-align: center;
  }
  .battle-shell .topbar .reference-button {
    width: 44px;
    min-width: 44px;
    padding: 0;
  }
  .battle-shell .reference-button .ui-icon {
    left: 12px;
    width: 20px;
  }
  .battle-shell .reference-button > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .battle {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "title" "arena" "hand" "help" "players" "miracles" "tools";
    grid-template-rows: auto auto minmax(72px, 1fr) auto auto auto auto;
  }
  .battle > .hand-heading {
    display: none;
  }
  .battle > .arena {
    position: relative;
    z-index: 3;
    padding-bottom: 8px;
    border-bottom: 4px solid #008f6f;
  }
  .battle.phase-turn .action-panel {
    min-height: clamp(120px, 21dvh, 178px);
    align-content: space-between;
  }
  .battle .action-panel:has(.combat-board) {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    gap: 6px;
  }
  .battle .action-panel:has(.combat-board) > h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .battle .action-panel:has(.combat-board) > .hint,
  .battle .action-panel:has(.combat-board) > .selected-preview {
    display: none;
  }
  .battle .action-panel .combat-board {
    display: grid;
    grid-column: 1 / -1;
    position: relative;
    width: 100%;
    max-height: none;
    overflow: visible;
    margin: 0;
    gap: 6px;
  }
  .battle .action-panel .used-items.combat-board {
    max-height: none;
  }
  .battle .action-panel .combat-board .combat-route {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr);
    gap: 6px;
    align-items: center;
    padding: 0;
    height: 28px;
  }
  .combat-route > span {
    min-width: 0;
    height: 28px;
    line-height: 26px;
    padding: 0 6px;
    border: 1px solid #aaa;
    border-radius: 18px;
    background: #f4ffdd;
    color: #008f6f;
    font-size: 14px;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .combat-route > span:last-child {
    color: #5544dd;
  }
  .combat-board .combat-route > span:first-child {
    color: #008f6f;
  }
  .combat-route > b {
    color: #ed77a6;
    font-size: 26px;
    line-height: 28px;
  }
  .battle .action-panel .combat-board .combat-columns {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 34px;
    inset: auto;
    width: 100%;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .battle .combat-board .combat-column {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: clamp(72px, 12dvh, 112px);
    gap: 6px;
    padding: 4px;
    border: 1px solid #55aa91;
    border-radius: 6px;
    background: #e3ffc85c;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .battle .combat-board .combat-column[data-combat-side="right"] {
    border-color: #8d94bd;
    background: #e6eeff5c;
  }
  .combat-board .used-caption,
  .combat-board .used-defense-label {
    display: none;
  }
  .battle .combat-board .used-item,
  .battle .combat-board .dream-reveal-face {
    height: auto;
    min-height: 54px;
    border-width: 2px;
    border-radius: 4px;
    flex-shrink: 0;
  }
  .combat-board :is(.used-item, .dream-reveal-face) > img {
    width: 42px;
    height: 42px;
    object-fit: contain;
  }
  .combat-board :is(.used-item, .dream-reveal-face) > .item-copy {
    padding: 2px 3px;
  }
  .combat-board :is(.used-item, .dream-reveal-face) strong {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    padding: 0;
    border: 0;
    font-size: 12px;
    line-height: 15px;
    white-space: normal;
  }
  .combat-board :is(.used-item, .dream-reveal-face) .detail-primary {
    padding-right: 24px;
    font-size: 14px;
    line-height: 20px;
  }
  .combat-board .detail-element {
    width: 14px;
    height: 14px;
  }
  .combat-board :is(.used-item, .dream-reveal-face) small {
    padding-right: 24px;
    font-size: 10px;
    line-height: 12px;
    max-height: 24px;
  }
  .combat-board :is(.used-item, .dream-reveal-face) .detail-badge {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .combat-board .used-item > .dream-reveal-face,
  .combat-board .used-item > .mp-weapon-cover {
    inset: -2px;
  }
  .combat-board > .guardian-portrait {
    position: absolute;
    left: 4px;
    top: 38px;
    width: calc(50% - 21px);
    height: 100px;
    object-fit: contain;
    margin: 0;
    pointer-events: none;
  }
  .battle .combat-defense .attack-info {
    grid-column: 1;
  }
  .battle .combat-defense .battle-actions {
    grid-column: 2;
  }
  .battle.phase-buy .action-panel > .purchase-controls {
    display: flex;
    gap: 6px;
    width: 100%;
    height: 48px;
    margin: 4px 0 0;
  }
  .battle.phase-buy .purchase-controls > .purchase-button {
    position: relative;
    inset: auto;
    flex: 1;
    width: auto;
    height: 48px;
  }
  .battle.phase-buy .purchase-controls .purchase-button > span {
    height: 48px;
    line-height: 48px;
    font-size: 22px;
  }
  .players,
  .players:has(.player:nth-child(7)) {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    max-height: 148px;
    gap: 4px;
  }
  .players .player,
  .players:has(.player:nth-child(7)) .player {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0 6px;
    min-height: 44px;
    padding: 4px 8px;
    border-radius: 22px;
  }
  .players .player-name {
    min-width: 0;
    max-width: none;
    flex-wrap: nowrap;
    font-size: 14px;
  }
  .players .player-name > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .players .player-name small {
    display: none;
  }
  /* One line per prophet: the AI win rate follows the name. */
  .players .player-name:has(.win-rate) {
    justify-content: flex-start;
  }
  .players .player-name:has(.win-rate) > span:not(.win-rate-slot) {
    margin-right: 0;
  }
  .players .player .stats,
  .players:has(.player:nth-child(7)) .stats {
    margin: 0;
    font-size: 18px;
    gap: 6px;
  }
  .players .player .stats small {
    font-size: 11px;
  }
  .player .hpbar {
    display: none;
  }
  .player .curse-badges {
    grid-column: 1 / -1;
    margin: 0;
  }
  .player .curse-badges:empty {
    display: none;
  }
  .battle .miracle-toggle {
    max-width: 220px;
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .players .player .stats,
  .players:has(.player:nth-child(7)) .stats {
    font-size: 16px;
    gap: 4px;
  }
}

@media (max-width: 600px) and (max-height: 700px) {
  .players,
  .players:has(.player:nth-child(7)) {
    max-height: 80px;
  }
  .battle .action-panel .hint,
  .battle > .card-help {
    display: none;
  }
  .battle .action-panel .selected-preview {
    max-height: 32px;
  }
  .battle .action-panel .used-items {
    max-height: 70px;
  }
}

@media (max-width: 600px) and (max-height: 700px) and (orientation: portrait) {
  .battle {
    grid-template-columns: minmax(60px, 1fr) minmax(0, 4fr);
    grid-template-areas: "arena arena" "hand hand" "players players" "miracles tools";
    grid-template-rows: auto minmax(72px, 1fr) auto auto;
    padding: 6px;
    gap: 4px;
  }
  .battle .miracle-toggle {
    width: 100%;
    max-width: none;
    font-size: 11px;
    padding: 2px;
  }
  .battle-bottom {
    gap: 4px;
  }
  .battle-bottom > button,
  .battle-bottom > .card-odds-button {
    font-size: 10px;
    padding: 2px;
  }
  .battle .battle-title {
    display: none;
  }
  .battle.phase-turn .action-panel {
    min-height: 0;
  }
  .battle .combat-board .combat-column {
    height: 62px;
  }
  .players,
  .players:has(.player:nth-child(7)) {
    max-height: 96px;
  }
  .battle-shell:has(.bottom-chat) .players {
    max-height: 48px;
  }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape),
  (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  .battle {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-template-areas: "players heading" "players hand" "arena hand" "tools tools";
    grid-template-rows: 36px minmax(40px, 1fr) auto auto;
    padding: 6px;
    gap: 4px 8px;
  }
  .battle .battle-title,
  .battle > .card-help {
    display: none;
  }
  .players,
  .players:has(.player:nth-child(7)) {
    max-height: 100%;
  }
  .players .player,
  .players:has(.player:nth-child(7)) .player {
    min-height: 66px;
  }
  .battle .miracle-toggle {
    grid-area: heading;
    justify-self: end;
    min-height: 32px;
  }
  .battle .action-panel {
    padding: 6px;
  }
  .action-panel .hint {
    display: none;
  }
  .battle .action-panel h2 {
    font-size: 14px;
  }
  .battle .action-panel .selected-preview {
    max-height: 32px;
  }
  .battle .action-panel .used-items {
    max-height: 70px;
  }
  .hand .card {
    min-height: 88px;
  }
}

@media (max-width: 600px) and (max-height: 700px),
  (max-width: 900px) and (max-height: 500px) and (orientation: landscape),
  (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  .battle .combat-defense .used-items {
    max-height: 24px;
    margin: 0;
  }
  .battle .combat-defense .used-card-list,
  .battle .combat-defense .used-caption,
  .battle .combat-defense h2,
  .battle .combat-defense .selected-preview {
    display: none;
  }
  .battle .combat-defense .attack-info {
    grid-column: 1;
    margin: 4px 4px 0 0;
  }
  .battle .combat-defense .battle-actions {
    grid-column: 2;
    margin-top: 4px;
  }
  .battle .combat-defense .battle-aux-actions {
    margin-top: 4px;
  }
  .battle.phase-buy .action-panel > .purchase-controls {
    display: flex;
    gap: 6px;
    width: 100%;
    height: 48px;
    margin: 4px 0 0;
  }
  .battle.phase-buy .purchase-controls > .purchase-button {
    position: relative;
    inset: auto;
    flex: 1;
    width: auto;
    height: 48px;
  }
  .battle.phase-buy .purchase-controls .purchase-button > span {
    height: 48px;
    line-height: 48px;
    font-size: 22px;
  }
  .battle.phase-buy .used-route,
  .battle.phase-buy .used-caption,
  .battle.phase-buy .action-panel h2 {
    display: none;
  }
}
