/*
 * Responsive contract
 * - >= 1280px: styles.css keeps the native 1280 x 720 pixel stage.
 * - < 1280px: the stage uses the available viewport instead of being scaled/cropped.
 * - < 768px: HUD, drawers, and modal decisions use the narrow-screen layout.
 */

:where(button, [href], [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 3px solid #fff0a3 !important;
  outline-offset: 2px;
}

@media (forced-colors: active) {
  :where(button, [href], [tabindex]:not([tabindex="-1"])):focus-visible {
    outline-color: Highlight !important;
  }
}

@media (max-width: 1279px) {
  :root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
  }

  html,
  body {
    width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    place-items: stretch;
    overscroll-behavior: none;
  }

  .game-shell {
    width: 100%;
    min-width: 0;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    transform: none;
    transform-origin: center;
  }

  .scene-layer,
  .cover-motion {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .cover-screen {
    background-size: cover;
  }

  .menu-dialog,
  .prologue-dialog,
  .tutorial-dialog,
  .result-dialog,
  .settings-dialog {
    max-width: calc(100vw - var(--safe-left) - var(--safe-right) - 16px);
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 16px);
    margin: auto;
    transform: none;
  }
}

@media (max-width: 767px), (max-height: 560px) and (max-width: 1279px) {
  .game-shell {
    grid-template-rows: 160px minmax(0, 1fr);
  }

  .topbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: 44px 56px 44px;
    gap: 4px;
    align-items: stretch;
    padding:
      max(4px, var(--safe-top)) max(4px, var(--safe-right)) 4px
      max(4px, var(--safe-left));
  }

  .brand-block {
    grid-column: 1 / 3;
    grid-row: 1;
    height: 44px;
    place-content: center start;
    padding-inline: 4px;
    text-align: left;
  }

  .brand-block .eyebrow {
    margin: 0;
    font-size: 11px;
    line-height: 14px;
    letter-spacing: 0.04em;
  }

  .brand-block h1 {
    font-size: 17px;
    line-height: 22px;
    white-space: nowrap;
  }

  .menu-open-button,
  .settings-open-button {
    position: static;
    grid-row: 1;
    width: 100%;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 5px 4px 7px;
    background-size: 100% 44px;
    font-size: 13px;
    line-height: 17px;
  }

  .menu-open-button {
    grid-column: 3;
  }

  .settings-open-button {
    grid-column: 4;
  }

  .day-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    height: 56px;
    background-size: 100% 56px;
  }

  .day-copy {
    font-size: 13px;
  }

  .day-copy span {
    left: 50%;
    width: min(46vw, 190px);
    translate: -50% 0;
  }

  #day-label {
    top: 5px;
    height: 18px;
  }

  #day-countdown {
    top: 34px;
    height: 17px;
    font-size: 12px;
    line-height: 17px;
  }

  .day-track {
    top: 23px;
    left: 50%;
    translate: -50% 0;
  }

  .stats {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    justify-content: stretch;
    min-width: 0;
  }

  .stat {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 15px 18px;
    width: 100%;
    height: 44px;
    padding: 5px 3px 4px;
    background-size: 100% 44px;
  }

  .stat-icon,
  .stat-icon.approved {
    display: none;
  }

  .stat-name {
    font-size: 11px;
    line-height: 14px;
  }

  .stat strong {
    font-size: 13px;
    line-height: 17px;
  }

  .pause-dock {
    z-index: 30;
    top: calc(max(4px, var(--safe-top)) + 46px);
    left: auto;
    right: max(4px, var(--safe-right));
    width: 132px;
    height: 44px;
  }

  .pause-dock button {
    width: 132px;
    height: 44px;
    background-size: 132px 44px;
    font-size: 13px;
  }

  .play-layout {
    min-width: 0;
    min-height: 0;
    padding:
      6px max(8px, var(--safe-right)) max(8px, var(--safe-bottom))
      max(8px, var(--safe-left));
  }

  .board {
    min-width: 0;
    min-height: 0;
    margin-bottom: 44px;
    padding-bottom: 56px;
    transition: margin-bottom 160ms steps(2, end);
  }

  .play-layout[data-side-panel="mission"] .board,
  .play-layout[data-side-panel="action"] .board {
    margin-bottom: min(372px, 48dvh);
  }

  .pack-selector {
    top: 4px;
    left: 0;
    justify-content: flex-start;
    gap: 6px;
    width: 100%;
    height: 58px;
    padding: 1px 4px 5px;
    overflow-x: auto;
    overflow-y: hidden;
    translate: none;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .pack-selector button {
    flex: 0 0 112px;
    width: 112px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    background-size: 112px 44px;
    font-size: 12px;
    scroll-snap-align: start;
  }

  .pack-selector button[data-priority="primary"] {
    flex-basis: 188px;
    width: 188px;
    height: 52px;
    background-size: 188px 52px;
  }

  .build-strip {
    top: 66px;
    left: 0;
    justify-content: flex-start;
    gap: 6px;
    width: 100%;
    max-width: none;
    min-height: 44px;
    padding: 0 4px;
    overflow-x: auto;
    overflow-y: hidden;
    translate: none;
    scrollbar-width: none;
  }

  .build-strip > * {
    flex: 0 0 auto;
    height: 44px;
    min-height: 44px;
    padding: 5px 10px 7px;
    background-size: 100% 44px;
    font-size: 12px;
  }

  .tidy-button {
    top: 116px;
    right: 4px;
    width: 148px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    background-size: 148px 44px;
    font-size: 13px;
  }

  .play-layout[data-side-panel="action"] .tidy-button {
    right: 4px;
  }

  .side-panel-toggle {
    top: auto;
    bottom: max(4px, var(--safe-bottom));
    width: calc(50% - 12px);
    min-width: 44px;
    height: 48px;
    min-height: 44px;
    padding: 6px 8px 8px;
    background-size: 100% 48px;
    font-size: 13px;
  }

  .mission-toggle,
  .mission-toggle[aria-expanded="true"] {
    left: max(8px, var(--safe-left));
  }

  .action-toggle,
  .action-toggle[aria-expanded="true"] {
    right: max(8px, var(--safe-right));
  }

  .mission-panel,
  .action-rail {
    top: auto;
    right: max(8px, var(--safe-right));
    bottom: calc(max(4px, var(--safe-bottom)) + 56px);
    left: max(8px, var(--safe-left));
    width: auto;
    max-width: none;
    filter: drop-shadow(3px 4px 0 rgb(8 25 25 / 48%));
  }

  .mission-panel {
    grid-template-rows: 54px minmax(0, 1fr) 96px;
    height: min(360px, calc(100% - 64px));
    padding: 10px 12px 12px;
    overflow: hidden;
  }

  .departure-list {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .mission-panel .action-button {
    width: min(200px, 100%);
    min-height: 44px;
  }

  .action-rail {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 6px;
    height: min(360px, calc(100% - 64px));
    min-height: 0;
    padding: 0;
    overflow: hidden;
  }

  .draw-panel {
    grid-template-rows: 68px minmax(0, 1fr);
    width: 120px;
    height: 100%;
    padding: 8px;
  }

  .draw-heading {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 22px 44px;
    width: 104px;
    height: 68px;
  }

  .draw-panel h2 {
    height: 22px;
    font-size: 12px;
    line-height: 16px;
  }

  .exploration-mode-button {
    width: 104px;
    height: 44px;
    min-height: 44px;
    background-size: 104px 44px;
    font-size: 12px;
    line-height: 16px;
  }

  .deck-source {
    min-width: 104px;
    min-height: 140px;
  }

  .log-panel {
    grid-template-rows: 28px 44px minmax(0, 1fr);
    width: 100%;
    height: 100%;
    padding: 12px 8px 10px;
  }

  .handbook-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
    height: 44px;
  }

  .handbook-tabs button {
    width: 100%;
    min-width: 36px;
    height: 44px;
    min-height: 44px;
    background-size: 100% 44px;
    font-size: 11px;
  }

  .handbook-view {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
  }

  .guide-view {
    grid-template-rows: 18px 30px 50px minmax(72px, 1fr) 44px;
  }

  .guide-formula {
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
  }

  .guide-formula .formula-token-action {
    flex-basis: 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .handbook-action,
  .equipment-slot,
  .camp-summary button,
  .compact-system-list button {
    min-height: 44px;
  }

  .equipment-slots {
    grid-template-rows: repeat(3, 44px);
  }

  .equipment-slot {
    height: 44px;
    background-size: 200px 44px;
    font-size: 12px;
  }

  .tutorial-coach-card {
    right: 4px !important;
    bottom: 60px !important;
    left: 4px !important;
    top: auto !important;
    width: auto;
    max-width: none;
    height: 230px;
    padding: 8px 14px 10px;
    border-width: 20px;
    border-image-width: 20px 22px;
  }

  .cover-screen {
    background-position: center;
  }

  .cover-content {
    top: max(42px, calc(var(--safe-top) + 24px));
    left: 50%;
    grid-template-rows: 76px auto;
    gap: 18px;
    width: min(336px, calc(100% - var(--safe-left) - var(--safe-right) - 24px));
    height: auto;
    overflow: visible;
    translate: -50% 0;
  }

  .cover-content h1 {
    height: 76px;
    font-size: 38px;
    line-height: 54px;
  }

  .cover-actions {
    width: 200px;
    justify-self: center;
  }

  .cover-actions .action-button {
    width: 200px;
    min-height: 52px;
  }

  .menu-dialog,
  .prologue-dialog,
  .tutorial-dialog,
  .result-dialog,
  .settings-dialog {
    width: calc(100vw - var(--safe-left) - var(--safe-right) - 12px) !important;
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 12px);
    max-width: 100%;
    max-height: 100%;
    border-width: 20px;
    border-image-width: 20px 22px;
  }

  .tutorial-dialog,
  .menu-dialog,
  .settings-dialog {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .tutorial-dialog[open] {
    grid-template-rows: max-content max-content 52px minmax(92px, auto) auto;
    align-content: center;
    gap: 8px;
    padding: 8px 10px;
  }

  .tutorial-dialog .panel-kicker {
    min-height: 18px;
    font-size: 12px;
    line-height: 18px;
  }

  .tutorial-dialog h2 {
    height: auto;
    min-height: 34px;
    font-size: 20px;
    line-height: 26px;
  }

  .tutorial-copy {
    width: 100% !important;
    height: auto !important;
    min-height: 92px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 19px;
  }

  .tutorial-actions {
    grid-template-rows: repeat(2, minmax(52px, auto));
    gap: 8px;
  }

  .tutorial-actions .action-button,
  .event-actions .action-button,
  .combat-actions .action-button,
  .ending-grid button,
  #ending-close,
  #meta-close,
  .settings-dialog button,
  .result-dialog .action-button {
    min-height: 44px;
  }

  .event-dialog[open] {
    grid-template-rows: max-content max-content 54px minmax(72px, auto) auto;
    align-content: center;
  }

  .event-dialog .tutorial-copy {
    min-height: 72px;
    font-size: 14px;
    line-height: 20px;
  }

  .event-actions {
    grid-template-columns: 1fr;
    grid-auto-rows: 68px;
    gap: 8px;
    width: 100%;
    height: auto;
  }

  .event-actions .action-button {
    width: min(260px, 100%);
    height: 68px;
    background-size: 100% 68px;
  }

  .event-actions .event-choice-title,
  .event-actions .event-choice-detail {
    max-width: 100%;
  }

  .combat-dialog[open] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: max-content max-content 210px auto auto 72px;
    align-content: center;
    gap: 5px;
  }

  .combat-dialog .battle-stage,
  .combat-dialog .battle-scene,
  .combat-dialog .combat-status-rows,
  .combat-dialog .combat-copy,
  .combat-dialog .combat-actions {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .combat-dialog .battle-stage,
  .combat-dialog .battle-scene {
    height: 210px;
  }

  .combat-dialog .battle-stage {
    background-size: cover;
  }

  .battle-actor {
    width: 46%;
  }

  .battle-actor.hero {
    left: 2%;
  }

  .battle-actor.monster {
    right: 2%;
  }

  .battle-health-track,
  .battle-actor b {
    width: 100%;
  }

  .battle-actor {
    bottom: 8px;
    grid-template-rows: 78px 10px 32px;
    height: 120px;
  }

  .battle-actor b {
    height: 32px;
    padding: 0 2px;
    font-size: 12px;
    line-height: 14px;
    white-space: normal;
  }

  .combat-status-rows {
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 0;
  }

  .combat-status-rows div {
    min-height: 24px;
    font-size: 12px;
    line-height: 16px;
  }

  .combat-copy {
    min-height: 54px;
    height: 54px;
    font-size: 13px;
    line-height: 18px;
  }

  .combat-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
  }

  .combat-actions .action-button {
    width: 100%;
    height: 72px;
    padding-inline: 5px;
    background-size: 100% 72px;
    font-size: 13px;
    line-height: 17px;
  }

  .combat-actions .action-button span {
    overflow: visible;
    font-size: 13px;
    line-height: 16px;
    text-overflow: clip;
    white-space: normal;
  }

  dialog.specialization-dialog,
  dialog.ending-dialog,
  dialog.meta-dialog {
    width: calc(100vw - var(--safe-left) - var(--safe-right) - 12px) !important;
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 12px) !important;
  }

  dialog.ending-dialog[open] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: max-content max-content max-content minmax(0, 1fr) 52px;
    align-content: stretch;
    gap: 5px;
    padding: 6px 8px;
  }

  .ending-dialog .tutorial-copy {
    min-height: 48px;
    padding: 4px 6px;
  }

  .ending-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(148px, 1fr);
    align-content: stretch;
    gap: 6px;
    padding: 0 2px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .ending-grid button {
    grid-template-rows: 28px minmax(74px, 1fr) 24px;
    width: 100%;
    min-height: 148px;
    padding: 8px 12px;
    background-size: 100% 58px;
  }

  .ending-grid button span {
    max-height: none;
    padding: 3px 4px;
  }

  .specialization-grid,
  .meta-dialog .meta-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    width: 100%;
    padding: 4px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .specialization-grid button,
  .meta-dialog .meta-grid button {
    width: 100%;
  }

  .meta-dialog[open] {
    grid-template-rows: max-content max-content max-content auto max-content minmax(0, 1fr) 52px;
    padding: 8px 10px;
  }

  .meta-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, 44px);
    width: 100%;
    height: auto;
  }

  .meta-tabs button {
    width: 100%;
    height: 44px;
    background-size: 100% 44px;
  }

  .meta-filter-copy {
    height: auto;
    min-height: 34px;
    padding: 4px 8px;
    white-space: normal;
  }

  .menu-dialog[open] {
    grid-template-rows: max-content max-content auto minmax(0, 1fr);
    align-content: stretch;
    gap: 6px;
    padding: 8px 10px;
  }

  .menu-dialog .menu-copy {
    height: auto;
    min-height: 52px;
    padding: 6px 10px;
    font-size: 13px;
    line-height: 19px;
  }

  .start-hub-body,
  .menu-dialog[data-mode="new-game"] .start-hub-body,
  .menu-dialog[data-mode="confirm-new"] .start-hub-body {
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    gap: 12px;
    width: 100%;
    height: auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .start-session-panel,
  .start-meta-panel,
  .menu-dialog[data-mode="new-game"] .start-session-panel,
  .menu-dialog[data-mode="confirm-new"] .start-session-panel {
    width: 100%;
    height: auto;
  }

  .start-session-panel {
    grid-template-rows: max-content max-content auto max-content;
  }

  .start-meta-panel {
    grid-template-rows: max-content max-content auto 52px;
  }

  .start-session-panel .starter-pack-field,
  .starter-pack-options {
    width: 100%;
    height: auto;
  }

  .starter-pack-field {
    grid-template-rows: 20px auto;
  }

  .starter-pack-options {
    grid-template-columns: 1fr;
    grid-auto-rows: 52px;
  }

  .starter-pack-choice {
    width: 100%;
  }

  .menu-meta-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: 68px;
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .menu-meta-grid button {
    width: 100%;
    height: 68px;
    background-size: 100% 68px;
  }

  .settings-dialog[open] {
    grid-template-rows: 58px 48px minmax(0, 1fr);
    gap: 6px;
  }

  .settings-close-button {
    width: 112px;
    height: 44px;
    background-size: 112px 44px;
    font-size: 13px;
  }

  .settings-tabs {
    gap: 4px;
  }

  .settings-tabs button {
    width: min(46%, 190px);
    height: 44px;
    background-size: 100% 44px;
    font-size: 13px;
  }

  #settings-general {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 12px 18px;
    overflow-y: auto;
  }

  .settings-section {
    grid-template-rows: max-content max-content max-content;
    gap: 10px;
    padding: 10px 8px;
  }

  .settings-section p {
    overflow: visible;
  }

  .settings-section button {
    width: min(240px, 100%);
    height: 44px;
    background-size: 100% 44px;
  }

  .settings-recipes-page {
    grid-template-rows: auto minmax(0, 1fr);
    padding-inline: 4px;
  }

  .recipe-catalog-toolbar {
    grid-template-rows: auto auto;
    height: auto;
  }

  #recipe-catalog-summary {
    min-height: 36px;
    height: auto;
    overflow: visible;
    white-space: normal;
  }

  .recipe-filter-tabs {
    flex-wrap: wrap;
  }

  .recipe-filter-tabs button {
    width: calc(33.333% - 5px);
    min-width: 78px;
    height: 44px;
    background-size: 100% 44px;
    font-size: 13px;
  }

  .recipe-catalog-list {
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    padding-inline: 2px;
  }

  .recipe-catalog-entry {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 8px;
    min-height: 140px;
    padding-inline: 6px;
  }

  .recipe-catalog-token {
    height: 48px;
    min-height: 48px;
    background-size: 100% 48px;
  }

  .prologue-dialog[open] {
    grid-template-rows: 44px auto;
    align-content: center;
  }

  .prologue-toolbar,
  .prologue-video {
    width: 100%;
  }

  .prologue-toolbar {
    grid-template-columns: minmax(0, 1fr) 88px;
    height: 44px;
  }

  .prologue-toolbar h2 {
    font-size: 13px;
    white-space: normal;
  }

  .prologue-close-button {
    width: 88px;
    height: 44px;
    background-size: 88px 44px;
  }

  .prologue-video {
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .result-dialog {
    height: auto;
    min-height: 300px;
    padding: 28px 24px 24px;
  }

  .result-dialog p:not(.panel-kicker) {
    min-height: 84px;
    max-height: none;
    overflow-y: auto;
    font-size: 13px;
    line-height: 19px;
  }
}

@media (pointer: coarse) and (max-width: 1279px) {
  button,
  [role="button"],
  [role="tab"],
  [role="radio"] {
    touch-action: manipulation;
  }

  .card,
  .deck-source {
    -webkit-tap-highlight-color: transparent;
  }
}

@media (max-height: 560px) and (min-width: 768px) and (max-width: 1279px) {
  .game-shell {
    grid-template-columns: 184px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .topbar {
    grid-column: 1;
    grid-row: 1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: 44px 56px 88px 44px;
    align-content: start;
  }

  .brand-block {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .day-panel {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .stats {
    grid-column: 1 / -1;
    grid-row: 3;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, 44px);
  }

  .menu-open-button {
    grid-column: 1;
    grid-row: 4;
  }

  .settings-open-button {
    grid-column: 2;
    grid-row: 4;
  }

  .play-layout {
    grid-column: 2;
    grid-row: 1;
  }

  .play-layout[data-side-panel="mission"] .board,
  .play-layout[data-side-panel="action"] .board {
    margin-bottom: 196px;
  }

  .mission-panel,
  .action-rail {
    height: 184px;
  }

  .mission-panel {
    grid-template-rows: 38px minmax(0, 1fr) 54px;
    padding: 6px 10px 8px;
  }

  .departure-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, 40px);
  }

  .mission-footer {
    grid-template-columns: 200px minmax(0, 1fr);
    grid-template-rows: 52px;
  }

  .tutorial-coach-card {
    height: 180px;
    grid-template-rows: 16px 24px minmax(40px, 1fr) 16px 44px;
  }

  .menu-dialog,
  .prologue-dialog,
  .tutorial-dialog,
  .result-dialog,
  .settings-dialog,
  dialog.specialization-dialog,
  dialog.ending-dialog,
  dialog.meta-dialog {
    width: min(760px, calc(100vw - var(--safe-left) - var(--safe-right) - 12px)) !important;
    height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 12px) !important;
    border-width: 16px;
    border-image-width: 16px 18px;
  }

  .settings-dialog {
    overflow: hidden;
  }

  .settings-dialog[open] {
    grid-template-rows: 44px 44px minmax(0, 1fr);
    gap: 4px;
  }

  .settings-heading {
    grid-template-rows: 14px 26px;
  }

  .settings-heading .panel-kicker {
    font-size: 12px;
    line-height: 14px;
  }

  .settings-heading h2 {
    font-size: 18px;
    line-height: 24px;
  }

  .settings-close-button {
    top: 0;
  }

  .settings-recipes-page {
    grid-template-rows: 64px minmax(0, 1fr);
    padding: 0 4px 6px;
  }

  .recipe-catalog-toolbar {
    grid-template-rows: 44px 16px;
    gap: 4px;
    height: 64px;
  }

  .recipe-filter-tabs {
    flex-wrap: nowrap;
    gap: 4px;
    width: 100%;
  }

  .recipe-filter-tabs button {
    width: calc((100% - 20px) / 6);
    min-width: 0;
    height: 44px;
    padding-inline: 2px;
    background-size: 100% 44px;
    font-size: 13px;
  }

  #recipe-catalog-summary {
    min-height: 16px;
    height: 16px;
    padding-inline: 4px;
    overflow: hidden;
    font-size: 12px;
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .recipe-catalog-list {
    padding: 4px 4px 8px;
  }

  .event-dialog[open] {
    grid-template-rows: 18px 30px 48px minmax(60px, auto) 68px;
    gap: 4px;
  }

  .event-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: 68px;
    gap: 10px;
  }

  .event-actions .action-button {
    width: 100%;
  }

  .combat-dialog[open] {
    grid-template-rows: 16px 28px 126px 28px 54px 52px;
    gap: 4px;
  }

  .combat-dialog .battle-stage,
  .combat-dialog .battle-scene {
    height: 126px;
  }

  .battle-actor {
    bottom: 6px;
    grid-template-rows: 58px 10px 20px;
    height: 92px;
  }

  .battle-actor > img {
    width: 58px;
    height: 58px;
  }

  .combat-status-rows {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .combat-status-rows div {
    height: 28px;
  }

  .combat-copy {
    min-height: 54px;
    height: 54px;
  }

  .combat-actions,
  .combat-actions .action-button {
    height: 52px;
  }

  .combat-actions .action-button {
    background-size: 100% 52px;
  }

  dialog.ending-dialog[open] {
    grid-template-rows: 18px 30px 40px minmax(0, 1fr) 48px;
    gap: 4px;
  }

  .ending-dialog .tutorial-copy {
    min-height: 40px;
  }

  .ending-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    grid-auto-rows: auto;
    gap: 6px;
  }

  .ending-grid button {
    grid-template-rows: 26px minmax(76px, 1fr) 24px;
    min-height: 164px;
    padding: 6px 8px;
  }

  .ending-grid button strong {
    font-size: 15px;
    line-height: 21px;
  }

  .ending-grid button span {
    font-size: 12px;
    line-height: 16px;
  }

  #ending-close {
    height: 48px;
  }
}

@media (max-width: 420px) {
  .recipe-catalog-list {
    grid-auto-rows: max-content;
    padding-inline: 0;
  }

  .recipe-catalog-entry {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: max-content max-content;
    align-items: start;
    align-content: start;
    gap: 8px;
    min-height: 0;
    height: auto;
    padding: 8px 10px;
    overflow: hidden;
    border-image-width: 8px 10px;
  }

  .recipe-catalog-output {
    grid-template-columns: 42px max-content;
    justify-content: center;
    width: 100%;
  }

  .recipe-catalog-output strong {
    min-height: 20px;
  }

  .recipe-catalog-route {
    grid-template-rows: max-content max-content max-content max-content;
    width: 100%;
  }

  .recipe-catalog-ingredients {
    max-width: 100%;
  }
}
