.duel-app {
  max-width: none;
  min-height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}
.duel-app .lab-header {
  display: flex;
  max-width: none;
  margin-bottom: 6px;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.duel-app .lab-header img {
  width: auto;
  height: 40px;
  max-height: 40px;
}
.duel-app .lab-back {
  justify-self: auto;
  padding: 6px 12px;
  font-size: 13px;
}
.duel-app .lab-hud {
  grid-template-columns: 1fr auto 1fr;
}
.duel-countdown {
  min-width: 104px;
  text-align: center;
}
.duel-countdown small { display: block; }
.duel-countdown strong {
  display: inline-block;
  min-width: 1.4em;
  color: #b84b27;
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.duel-countdown span { margin-left: 2px; color: #6f4328; font-size: 12px; font-weight: 800; }
.duel-countdown[data-urgent="true"] strong { color: #d51f1f; animation: duel-countdown-pulse .65s ease-in-out infinite alternate; }
@keyframes duel-countdown-pulse { to { transform: scale(1.12); } }
.duel-app .lab-objective {
  min-width: 0;
  padding-left: 0;
  border-left: 0;
}
.duel-panel {
  max-width: 640px;
  margin: 0 auto;
  padding: 22px;
  border: 1px solid rgba(249,216,143,.62);
  border-radius: 18px;
  background: rgba(245,224,178,.94);
  color: #3d2416;
  box-shadow: 0 12px 28px rgba(28,9,3,.4);
}
.duel-panel h1 { margin: 0 0 8px; font: 900 28px "Kaiti SC", "STKaiti", serif; }
.duel-panel p { line-height: 1.55; }
.duel-panel label { display: grid; gap: 6px; margin: 16px 0; font-weight: 700; }
.duel-panel input, .duel-actions button {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid rgba(104,55,26,.28);
  border-radius: 10px;
  background: #fff8dd;
}
.duel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.duel-actions button, #duel-start {
  cursor: pointer;
  color: #fff7d9;
  background: linear-gradient(145deg, #b84b27, #7c2819);
  border: 1px solid #73311b;
}
#duel-code { width: 7.5em; text-transform: uppercase; letter-spacing: .2em; text-align: center; font-weight: 800; }
.duel-status { min-height: 1.4em; color: #7c2819; }
.duel-room-box {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(255,248,221,.75);
  text-align: center;
}
.duel-room-box strong { display: block; font-size: 42px; letter-spacing: .28em; color: #b84b27; }
#duel-start { margin-top: 12px; padding: 10px 20px; border-radius: 999px; }

.duel-board {
  display: flex;
  flex-direction: column;
  width: min(1200px, 100%);
  margin: 0 auto;
  min-height: calc(100dvh - 96px);
}
.duel-board[hidden] { display: none !important; }
.duel-regroup {
  align-self: center;
  min-width: 92px;
  padding: 8px 12px;
  border: 1px solid #7c3b20;
  border-radius: 999px;
  color: #fff6d8;
  background: linear-gradient(145deg, #b84b27, #7c2819);
  font-weight: 800;
}
.duel-regroup:disabled { opacity: .42; cursor: not-allowed; }
.duel-canvas-wrap {
  position: relative;
  aspect-ratio: auto !important;
  flex: 1 1 auto;
  height: min(52dvh, 640px);
  min-height: 300px;
}
#duel-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: 0;
  touch-action: none;
}
.duel-wait {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
  color: #fff6d8;
  text-align: center;
  font: 900 clamp(22px, 5vw, 36px) "Kaiti SC", "STKaiti", "KaiTi", serif;
  text-shadow: 0 2px 0 #5a2412, 0 8px 18px rgba(28, 9, 3, .55);
  background: rgba(42, 16, 8, .28);
}
.duel-wait[hidden] { display: none !important; }
.duel-result {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  pointer-events: none;
  background: rgba(28, 10, 4, .42);
  text-align: center;
}
.duel-result strong {
  margin: 0;
  color: #fff6d8;
  font: 900 clamp(22px, 5.4vw, 34px) "Kaiti SC", "STKaiti", "KaiTi", serif;
  text-shadow: 0 2px 0 #5a2412, 0 8px 18px rgba(28, 9, 3, .55);
}
.duel-result span {
  padding: 6px 14px;
  border-radius: 999px;
  color: #fff8e4;
  font: 800 16px "PingFang SC", "Microsoft YaHei", sans-serif;
  background: rgba(124, 40, 25, .88);
  box-shadow: 0 6px 16px rgba(28, 9, 3, .35);
}
.duel-result[data-actor="foe"] span { background: rgba(46, 78, 122, .92); }
.duel-result[data-task]:not([data-task=""]) strong {
  color: #fff0b5;
}
.duel-result[data-task]:not([data-task=""]) span {
  max-width: min(88vw, 560px);
  border: 1px solid rgba(155, 102, 31, .4);
  border-radius: 14px;
  color: #5b3413;
  background: rgba(255, 246, 213, .96);
  box-shadow: 0 8px 20px rgba(35, 20, 6, .38), inset 0 0 0 1px rgba(255, 255, 255, .58);
}
.duel-result[data-task]:not([data-task=""]) .duel-result-cards img {
  outline: 3px solid rgba(255, 220, 125, .9);
  box-shadow: 0 10px 26px rgba(67, 36, 6, .55);
}
.duel-result-cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: min(92%, 520px);
}
.duel-result-cards img {
  width: auto;
  height: min(22vh, 148px);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(20, 8, 3, .45);
  background: #ead7a4;
}
.duel-result[data-kind="match"] { pointer-events: auto; }
.duel-result button {
  pointer-events: auto;
  margin-top: 6px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  color: #3a1608;
  font: 800 16px "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #ffd56a;
  box-shadow: 0 6px 16px rgba(28, 9, 3, .35);
  cursor: pointer;
}
.duel-result button[hidden] { display: none !important; }
.duel-result[hidden] { display: none !important; }
.duel-app .lab-turn-banner {
  top: 64px;
  z-index: 7;
  font-size: clamp(20px, 5vw, 32px);
  padding: 10px 26px;
  min-width: 0;
  white-space: nowrap;
}
.duel-app .lab-duel-score {
  top: 12px;
  left: 12px;
  display: inline-flex;
  width: max-content;
  max-width: calc(100% - 24px);
  gap: 8px;
  padding: 6px 10px;
  font-size: 14px;
}
.duel-app .lab-duel-score span {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.duel-app .lab-duel-score span em {
  font-style: normal;
  font-weight: 800;
}
.duel-app .lab-duel-score span b { font-size: 20px; }
.duel-app .lab-turn-banner[data-actor="foe"] { background: rgba(46, 78, 122, .92); }
.duel-battle {
  display: grid;
  gap: 8px;
  padding: 10px 12px 8px;
  border-top: 1px solid rgba(98,50,23,.16);
  background: rgba(255, 248, 221, .86);
}
.duel-battle-meta {
  margin: 0;
  color: #6a3218;
  font-weight: 800;
  font-size: 14px;
}
.duel-battle-meta b { color: #b84b27; }
.duel-score-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.duel-score-row > span {
  flex: 0 0 2.6em;
  color: #4a2b18;
  font-weight: 900;
  font-size: 15px;
}
.duel-score-slots {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid rgba(120, 62, 28, .28);
  border-radius: 8px;
  background: rgba(255,255,255,.45);
}
.duel-mini-card {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  max-width: var(--duel-mini-w, 36px);
  aspect-ratio: 2 / 3;
  perspective: 280px;
}
.duel-mini-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .42s ease;
}
.duel-mini-card.is-face .duel-mini-inner { transform: rotateY(180deg); }
.duel-mini-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 4px;
  backface-visibility: hidden;
  box-shadow: 0 2px 4px rgba(40, 16, 6, .28);
}
.duel-mini-back::before {
  content: "";
  position: absolute;
  left: 8%;
  top: 36%;
  z-index: 1;
  width: 84%;
  height: 28%;
  border: 1px solid #17394a;
  border-radius: 50%;
  background: #ead7a4;
}
.duel-mini-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
  backface-visibility: hidden;
}
.duel-mini-card .face { transform: rotateY(180deg); box-shadow: 0 2px 4px rgba(40, 16, 6, .28); }
.duel-mini-back .brand {
  inset: auto;
  left: 5%;
  top: 39%;
  z-index: 2;
  width: 90%;
  height: auto;
  object-fit: contain;
}
.duel-log-wrap {
  display: grid;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(98,50,23,.16);
  background: rgba(255, 248, 221, .72);
}
.duel-log-wrap #duel-status { margin: 0; line-height: 1.5; font-size: 15px; }
.duel-round-log {
  margin: 0;
  padding: 0;
  max-height: 28vh;
  overflow: auto;
  list-style: none;
  display: grid;
  gap: 6px;
}
.duel-round-log li {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.55);
  color: #4a2b18;
  font-size: 14px;
  line-height: 1.45;
}
.duel-round-log li.is-self { border-left: 4px solid #b84b27; }
.duel-round-log li.is-foe { border-left: 4px solid #3d5f99; }

@media (max-width: 720px) {
  .duel-app .lab-header { display: flex; flex-direction: row; justify-content: center; align-items: center; gap: 8px; }
  .duel-app .lab-header img { height: 34px; max-height: 34px; width: auto; }
  .duel-app .lab-back { justify-self: auto; padding: 5px 10px; font-size: 12px; }
  .duel-board { min-height: calc(100dvh - 56px); }
  .duel-canvas-wrap { height: min(48dvh, 520px); min-height: 260px; }
  .duel-round-log { max-height: 16vh; }
  .duel-app .lab-hud {
    grid-template-columns: 1fr auto 1fr;
    gap: 8px 12px;
    padding: 10px 12px;
  }
  .duel-countdown { min-width: 82px; }
  .duel-countdown strong { font-size: 22px; }
  .duel-app .lab-objective, .duel-app .lab-counter {
    min-width: 0;
    padding-left: 0;
    border-left: 0;
  }
  .duel-app .lab-duel-score {
    left: 8px;
    top: 8px;
    gap: 7px;
    padding: 5px 8px;
    font-size: 12px;
  }
  .duel-app .lab-duel-score span b { font-size: 18px; }
  .duel-app .lab-turn-banner { top: 56px; font-size: 20px; }
  .duel-round-log { max-height: 22vh; }
}

@media (max-width: 420px) {
  .duel-canvas-wrap { height: min(44dvh, 460px); min-height: 240px; }
  .duel-panel { padding: 16px; }
  .duel-actions { flex-direction: column; align-items: stretch; }
  #duel-code { width: 100%; }
}
