.match-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.match-page--playing {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.match-page [hidden] {
  display: none !important;
}

.match-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.9rem;
  padding: 0.45rem 0.9rem;
  border-bottom: 1px solid #3c362c;
  background: #1d1a15;
}

.match-topbar__home {
  color: #f0c26b;
  font-size: 0.8rem;
  text-decoration: none;
}

.match-topbar__home:hover {
  text-decoration: underline;
}

.match-topbar__title {
  margin: 0;
  font-size: 1rem;
}

.match-hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.8rem;
  margin-left: auto;
  color: #d9cdb8;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.match-hud__turn {
  color: #f7e7b8;
  font-weight: 700;
}

.match-hud__side {
  color: #f0c26b;
}

.match-hud__meta {
  color: #cfc2ab;
}

.match-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

/* 开始页 */

.match-setup {
  box-sizing: border-box;
  width: min(720px, 100%);
  margin: auto;
  padding: clamp(1rem, 4vw, 2.5rem);
}

/* 五国皮肤：选卡页随阵营切换主色与主题图 */
.match-setup[data-faction] {
  border: 1px solid color-mix(in srgb, var(--faction-primary) 45%, #efe6d5);
  border-radius: 16px;
  background-color: rgba(20, 18, 15, 0.78);
  background-image:
    linear-gradient(180deg, rgba(20, 18, 15, 0.62), rgba(20, 18, 15, 0.92)),
    var(--faction-art, none);
  background-position: center top;
  background-size: cover;
}

.match-setup[data-faction] h2 {
  padding-left: 0.6rem;
  border-left: 4px solid color-mix(in srgb, var(--faction-accent) 50%, #efe6d5);
}

.match-setup[data-faction] .match-field select {
  border-color: color-mix(in srgb, var(--faction-primary) 40%, #5a5140);
}

.match-setup[data-faction] .match-start {
  border-color: color-mix(in srgb, var(--faction-accent) 55%, #b98a3c);
}

.match-setup h2 {
  margin: 0 0 0.4rem;
}

.match-setup__note {
  margin: 0 0 1.2rem;
  color: #cfc2ab;
  line-height: 1.6;
}

.match-loading {
  margin: auto;
  padding: 2rem;
  color: #cfc2ab;
}

.match-form {
  display: grid;
  gap: 0.9rem;
}

.match-field {
  display: grid;
  gap: 0.3rem;
}

.match-field__label {
  color: #e7dcc7;
  font-size: 0.82rem;
  font-weight: 600;
}

.match-field select {
  box-sizing: border-box;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid #5a5140;
  border-radius: 8px;
  background: #221e18;
  color: #efe6d5;
  font: inherit;
  font-size: 0.9rem;
}

.match-field select:focus-visible,
.match-start:focus-visible,
.match-action:focus-visible {
  outline: 2px solid #f0c26b;
  outline-offset: 2px;
}

.match-deck-summary {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid #4c4537;
  border-radius: 10px;
  background: rgba(20, 18, 15, 0.55);
  color: #d9cdb8;
  font-size: 0.8rem;
  line-height: 1.5;
}

.match-deck-summary:empty {
  display: none;
}

/* 阵营 / 盟国 / 卡组选择 */

.match-group {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.match-group > legend {
  margin-bottom: 0.35rem;
  padding: 0;
}

.faction-picker,
.ally-picker,
.deck-picker {
  display: grid;
  gap: 0.5rem;
}

.faction-picker {
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
}

.ally-picker {
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
}

.deck-picker {
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}

.faction-card,
.ally-card,
.deck-option {
  box-sizing: border-box;
  display: grid;
  align-content: start;
  gap: 0.2rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid #4c4537;
  border-radius: 10px;
  background: linear-gradient(160deg, #262119, #1b1814);
  color: #e7dcc7;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.faction-card {
  border-left: 4px solid var(--faction-card-primary, #6b6252);
}

.faction-card:hover,
.ally-card:hover,
.deck-option:hover {
  border-color: #8a7a56;
  background: linear-gradient(160deg, #2e2820, #211d17);
}

.faction-card[aria-pressed="true"],
.ally-card[aria-pressed="true"],
.deck-option[aria-pressed="true"] {
  border-color: var(--faction-card-accent, #f0c26b);
  background: linear-gradient(160deg, #37301f, #241f17);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--faction-card-accent, #f0c26b) 60%, transparent),
    0 6px 18px rgba(0, 0, 0, 0.35);
}

.faction-card:focus-visible,
.ally-card:focus-visible,
.deck-option:focus-visible {
  outline: 2px solid #f0c26b;
  outline-offset: 2px;
}

.faction-card__name {
  color: #f7e7b8;
  font-size: 0.95rem;
  font-weight: 700;
}

.faction-card__style {
  color: #f0c26b;
  font-size: 0.8rem;
  font-weight: 600;
}

.faction-card__theme {
  color: #cfc2ab;
  font-size: 0.72rem;
  line-height: 1.4;
}

.faction-card__keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.15rem;
}

.faction-card__keyword {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.3rem;
  border: 1px solid #4c4537;
  border-radius: 999px;
  background: rgba(20, 18, 15, 0.6);
  color: #d9cdb8;
  font-size: 0.68rem;
}

.faction-card__keyword-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.faction-card__count {
  color: #a99d88;
  font-size: 0.68rem;
}

.ally-card__name {
  color: #f7e7b8;
  font-size: 0.88rem;
  font-weight: 700;
}

.ally-card__meta {
  color: #cfc2ab;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.match-ally-count {
  margin: 0.35rem 0 0;
  color: #cfc2ab;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.match-ally-count[data-ok="true"] {
  color: #b9d6a1;
}

.match-ally-count[data-ok="false"] {
  color: #f0a58a;
}

.deck-option__name {
  color: #f7e7b8;
  font-size: 0.86rem;
  font-weight: 700;
}

.deck-option__meta {
  color: #cfc2ab;
  font-size: 0.7rem;
}

.deck-option__composition {
  color: #a99d88;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

/* 卡组构成与合法性 */

.deck-preview__header {
  display: grid;
  gap: 0.1rem;
}

.deck-preview__title {
  margin: 0;
  color: #f7e7b8;
  font-size: 0.95rem;
}

.deck-preview__subtitle {
  margin: 0;
  color: #cfc2ab;
  font-size: 0.75rem;
}

.deck-preview__stats,
.deck-preview__types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.deck-preview__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid #40392d;
  border-radius: 999px;
  background: rgba(10, 9, 7, 0.35);
  color: #cfc2ab;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.deck-preview__stat strong {
  color: #f7e7b8;
}

.deck-preview__stat[data-state="ok"] strong {
  color: #b9d6a1;
}

.deck-preview__stat[data-state="invalid"] {
  border-color: #9c5a48;
}

.deck-preview__stat[data-state="invalid"] strong {
  color: #f0a58a;
}

.deck-preview__type {
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  background: #2a241b;
  color: #cfc2ab;
  font-size: 0.7rem;
}

.deck-preview__legality {
  margin: 0;
  padding-top: 0.45rem;
  border-top: 1px dashed #40392d;
  color: #b9d6a1;
  font-size: 0.72rem;
}

.deck-preview__legality[data-ok="false"] {
  color: #f0a58a;
}

.match-start,
.match-action {
  padding: 0.45rem 1rem;
  border-radius: 9px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.match-start {
  border: 1px solid #b98a3c;
  background: linear-gradient(160deg, #7a4d1c, #4d3011);
  color: #ffe9bd;
  font-weight: 700;
}

.match-start:hover:not(:disabled) {
  background: linear-gradient(160deg, #925d24, #5c3a15);
}

.match-start:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.match-action {
  border: 1px solid #6b6252;
  background: #2a241b;
  color: #e7dcc7;
}

.match-action:hover:not(:disabled) {
  background: #3a3123;
}

.match-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* 对局 */

.match-battle {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.match-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid #3c362c;
  background: #1a1712;
}

/* 结算覆盖层 */

.match-result {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  padding: 1rem;
  place-items: center;
  background: rgba(10, 9, 7, 0.78);
  overflow-y: auto;
}

.match-result__card {
  box-sizing: border-box;
  width: min(30rem, 100%);
  padding: clamp(1rem, 3vw, 1.6rem);
  border: 1px solid #7d6b45;
  border-radius: 14px;
  background: linear-gradient(165deg, #2b251c, #191612);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.match-result__mode {
  margin: 0 0 0.3rem;
  color: #cfc2ab;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.match-result__title {
  margin: 0;
  color: #f7e7b8;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
}

.match-result__title[data-result="win"] {
  color: #ffd98a;
}

.match-result__title[data-result="loss"] {
  color: #f0a58a;
}

.match-result__title[data-result="draw"] {
  color: #d7d2c6;
}

.match-result[data-result="win"] .match-result__card {
  border-color: #c9a24d;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(242, 199, 107, 0.28),
    0 0 38px rgba(242, 199, 107, 0.16);
}

.match-result[data-result="loss"] .match-result__card {
  border-color: #9c5a48;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(224, 120, 92, 0.22);
}

.match-result[data-result="draw"] .match-result__card {
  border-color: #6f6a5e;
}

.match-result[data-result="win"] .match-result__score {
  color: #ffd98a;
}

.match-result[data-result="loss"] .match-result__score {
  color: #e8a58f;
}

.match-result[data-result="draw"] .match-result__score {
  color: #cfc2ab;
}

.match-result__score {
  margin: 0.3rem 0 0.9rem;
  color: #f0c26b;
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.match-result__stats {
  display: grid;
  gap: 0.25rem;
  margin: 0 0 0.9rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid #443d31;
  border-radius: 10px;
  background: rgba(20, 18, 15, 0.5);
  text-align: left;
}

.match-result__stat {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.match-result__stat dt {
  color: #cfc2ab;
}

.match-result__stat dd {
  margin: 0;
  color: #e7dcc7;
  text-align: right;
}

.match-result__saved {
  margin: 0 0 0.9rem;
  color: #d9cdb8;
  font-size: 0.75rem;
}

.match-result__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

/* 确认对话框 */

.match-confirm {
  box-sizing: border-box;
  width: min(24rem, calc(100vw - 2rem));
  padding: 1.2rem 1.3rem;
  border: 1px solid #7d6b45;
  border-radius: 14px;
  background: #221e18;
  color: #efe6d5;
}

.match-confirm::backdrop {
  background: rgba(10, 9, 7, 0.7);
}

.match-confirm__title {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.match-confirm__text {
  margin: 0 0 1rem;
  color: #d9cdb8;
  font-size: 0.85rem;
  line-height: 1.6;
}

.match-confirm__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .match-form {
    grid-template-columns: 1fr 1fr;
  }

  .match-deck-summary,
  .match-start {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .match-hud {
    margin-left: 0;
    flex-basis: 100%;
  }

  .match-actions {
    justify-content: stretch;
  }

  .match-actions .match-action {
    flex: 1 1 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .match-start,
  .match-action {
    transition: none;
  }
}

/* 短视口（100% 缩放下的 1366x768 / 1280x720 等）压缩顶栏与操作条：
   它们和手牌、战报同属固定开销，每省 1px 都留给战场，结构不变 */
@media (max-height: 800px) {
  .match-topbar {
    padding: 0.3rem 0.75rem;
    gap: 0.3rem 0.75rem;
  }

  .match-topbar .audio-control,
  .match-topbar .motion-control {
    padding: 0.08rem 0.4rem;
    font-size: 0.7rem;
  }

  .match-actions {
    padding: 0.22rem 0.75rem;
  }
}

[data-motion="reduced"] .match-start,
[data-motion="reduced"] .match-action {
  transition: none;
}
