/* Lo scontro (28 ottobre, Rod): una scena a sé, plancia contro plancia.
   Il fondo è il legno scuro della cabina con il filo d'ottone; le due parti sono di carta, come le plance
   al tavolo; in mezzo la conta dei colpi, incisa come le coppette di un tavoliere. Sotto le carte e il pulsante.
   Sta in basso sopra il tavolo: la camera inquadra il vassoio dei dadi nello spazio che resta sopra. */

.duel-layer { position: absolute; inset: 0; z-index: 7; display: flex; justify-content: center; align-items: flex-end; padding: 0 12px 12px; pointer-events: none; }
.duel-layer:empty { display: none; }
.table[data-duel] .dock { display: none; }
.app--2d .duel-layer { position: fixed; }

.duel {
  pointer-events: auto; width: min(1120px, 100%); max-height: calc(100% - 72px);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden;
  background: linear-gradient(180deg, #2c1c11 0%, #1d130c 100%);
  border: 1px solid rgba(201, 160, 78, 0.6); border-radius: 18px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), 0 30px 60px -30px rgba(0, 0, 0, 0.9);
  color: var(--deck-ink);
}
.duel.is-entering { animation: duel-in var(--t-sheet) var(--ease-sheet) both; }
@keyframes duel-in { from { transform: translateY(28px); opacity: 0; } }

.duel__head { display: flex; align-items: baseline; gap: 14px; padding: 12px 18px 8px; min-width: 0; }
.duel__kind { display: inline-flex; align-items: center; gap: 6px; color: var(--brass-bright); font-weight: 700; font-size: var(--t-15); flex: none; }
.duel__kind .icon { width: 20px; height: 20px; align-self: center; }
.duel__title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: var(--t-30); line-height: 1.05; color: #fbf3e2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.duel__arena {
  display: grid; grid-template-columns: minmax(210px, 250px) minmax(0, 1fr) minmax(210px, 250px); gap: 14px;
  padding: 4px 16px 14px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; align-items: stretch;
}

/* --- le due parti: carta chiara, come le plance --- */
.duel__side {
  background: #fbf6ea; color: var(--ink); border-radius: 12px; padding: 12px; display: grid; gap: 10px; align-content: start;
  border: 1px solid rgba(201, 160, 78, 0.55); position: relative; min-width: 0;
}
.duel-side__head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.duel-side__name { font-family: var(--font-display); font-weight: 700; font-size: var(--t-22); line-height: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.duel-side__role { margin-left: auto; font-size: var(--t-13); color: var(--ink-3); font-weight: 700; }

.duel-hearts { display: flex; flex-wrap: wrap; gap: 4px; }
.duel-heart { display: grid; place-items: center; width: 34px; height: 34px; }
.duel-heart .icon { width: 30px; height: 30px; }
.duel-heart.is-on { color: var(--heart); }
.duel-heart.is-on .icon { fill: var(--heart); }
.duel-heart.is-off { color: rgba(42, 30, 20, 0.28); }
.duel-heart.is-off .icon { fill: none; }

.duel-stat { display: grid; gap: 4px; }
.duel-stat__label { font-size: var(--t-13); color: var(--ink-2); font-weight: 700; }
.duel-stat__row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 26px; }
.duel-cannon { width: 26px; height: 26px; color: var(--ink); }
.duel-none { font-size: var(--t-13); color: var(--ink-3); }
.duel-track { position: relative; display: flex; align-items: center; gap: 8px; height: 22px; }
.duel-track::before { content: ''; flex: 1; height: 8px; border-radius: 8px; background: rgba(42, 30, 20, 0.12); }
.duel-track__fill { position: absolute; left: 0; top: 7px; height: 8px; border-radius: 8px; background: var(--key-red); width: calc((100% - 30px) * var(--v)); }
.duel-track b { width: 22px; text-align: right; font-size: var(--t-15); }
.duel-stat--gear { display: flex; flex-wrap: wrap; gap: 6px; }
.duel-gear { display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-13); font-weight: 700; padding: 3px 8px 3px 4px; border-radius: 999px; background: rgba(42, 30, 20, 0.07); }
.duel-gear .icon { width: 20px; height: 20px; }

.duel__side--event { justify-items: center; background: transparent; border: 0; padding: 0; }
.duel-card-wrap { position: relative; }
.duel__side--event .card--event { --card-w: 168px; }
.duel-threat { margin: 0; display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-15); color: #f3c9b9; font-weight: 700; }
.duel-threat .icon { width: 20px; height: 20px; color: #f08a74; }
.duel-flag { display: grid; place-items: center; padding: 6px 0; }
.duel-flag .icon { width: 72px; height: 72px; color: var(--ink); }

.duel-backs { display: flex; gap: 6px; flex-wrap: wrap; min-height: 34px; align-items: center; }
.duel-back { width: 24px; height: 34px; border-radius: 4px; background: #2a1a10; box-shadow: inset 0 0 0 2px #c9a04e55; }
.duel-back--big { width: 64px; height: 92px; border-radius: 8px; flex: none; }

/* --- in mezzo: la conta --- */
.duel__center { display: grid; gap: 14px; justify-items: center; align-content: start; padding-top: 6px; min-width: 0; position: relative; }
.duel-count-wrap { display: grid; gap: 8px; justify-items: center; width: 100%; }
.duel-count { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.duel-socket { display: grid; justify-items: center; gap: 4px; }
.duel-socket__cup {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 38%, #120b07 0%, #24170e 70%); box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.8), 0 0 0 1.5px rgba(201, 160, 78, 0.45);
}
.duel-socket.is-defeat .duel-socket__cup { box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.8), 0 0 0 2px #e08060; }
.duel-socket.is-on .duel-socket__cup { background: radial-gradient(circle at 50% 35%, #fffaf0 0%, #eadcc0 100%); box-shadow: 0 0 0 1.5px var(--brass-bright), 0 0 14px rgba(255, 200, 120, 0.35); }
.duel-socket.is-cannon .duel-socket__cup { background: radial-gradient(circle at 50% 35%, #f4dfa8 0%, #c9a04e 100%); }
.duel-socket__cup .icon { width: 30px; height: 30px; color: var(--heart); }
.duel-socket.is-cannon .duel-socket__cup .icon { color: #2a1a10; }
.duel-socket__marks { display: flex; gap: 2px; min-height: 22px; }
.reward-mark { display: inline-flex; align-items: center; gap: 2px; padding: 2px 6px 2px 4px; border-radius: 999px; background: rgba(255, 244, 220, 0.12); color: #fbf3e2; font-size: var(--t-13); }
.reward-mark .icon { width: 18px; height: 18px; }
.reward-mark--sink { color: #f3c9b9; }
.duel-rule { margin: 0; text-align: center; font-size: var(--t-15); color: var(--deck-ink-2); max-width: 46ch; }

.duel-dice { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.duel-die { display: grid; gap: 6px; justify-items: center; }
.duel-die .die { width: 64px; height: 64px; }
.duel-die .die--blank .die__body { fill: rgba(255, 244, 220, 0.05); stroke: rgba(201, 160, 78, 0.55); stroke-dasharray: 6 5; }
.duel-die.is-hit .die { filter: drop-shadow(0 0 10px rgba(255, 120, 90, 0.55)); }
.duel-die.is-revealed .die { animation: die-land 360ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes die-land { from { transform: translateY(-10px) scale(1.15); opacity: 0; } }
.duel-die__label { font-size: var(--t-13); font-weight: 700; color: var(--deck-ink-2); min-height: 1.3em; }
.duel-die__choice { display: flex; gap: 6px; }
.duel-die__pick { border: 0; padding: 0; background: none; border-radius: 16px; cursor: pointer; box-shadow: 0 0 0 3px #59c8ff, 0 0 18px rgba(89, 200, 255, 0.6); animation: pick-breathe 1.6s ease-in-out infinite; }
@keyframes pick-breathe { 50% { box-shadow: 0 0 0 3px #59c8ff, 0 0 6px rgba(89, 200, 255, 0.3); } }
.duel-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; font-size: var(--t-13); color: var(--deck-ink-2); }
.duel-legend li { display: inline-flex; align-items: center; gap: 5px; }
.duel-legend .icon { width: 18px; height: 18px; }
.duel-rolling { margin: 0; font-size: var(--t-15); color: var(--deck-ink-2); }

.duel-verdict { text-align: center; display: grid; gap: 4px; justify-items: center; }
.duel-verdict__title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: var(--t-48); line-height: 1; color: #fbf3e2; }
.duel-verdict--won .duel-verdict__title { color: #9fe0b8; }
.duel-verdict--lost .duel-verdict__title { color: #ff9c86; }
.duel-verdict__line { margin: 0; font-size: var(--t-17); color: var(--deck-ink); max-width: 44ch; }
.duel-verdict__loot { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.duel-verdict__loot .reward-mark { font-size: var(--t-15); padding: 4px 10px 4px 6px; background: rgba(201, 160, 78, 0.22); }
.duel-verdict__loot .reward-mark .icon { width: 22px; height: 22px; }

/* --- sotto: le carte e il pulsante --- */
.duel__decide { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 18px; align-items: end; padding: 12px 16px 14px; border-top: 1px solid rgba(201, 160, 78, 0.35); background: rgba(0, 0, 0, 0.18); }
.duel__decide.is-rolling { opacity: 0.5; pointer-events: none; }
.duel-hand { display: grid; gap: 6px; min-width: 0; }
.duel-hand__title { margin: 0; font-size: var(--t-13); font-weight: 700; color: var(--deck-ink-2); display: flex; gap: 10px; flex-wrap: wrap; }
.duel-hand__warn { color: #ffb68f; }
.duel-hand__row { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: thin; padding: 2px 2px 4px; align-items: flex-start; }
.duel-card-slot { display: grid; gap: 4px; justify-items: center; flex: none; }
.duel-card-slot__say { font-size: var(--t-13); color: #9fdcff; font-weight: 700; max-width: 140px; text-align: center; }
.duel-card {
  width: 140px; min-height: 92px; padding: 8px 10px; border-radius: 10px; text-align: left; flex: none;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; column-gap: 8px; row-gap: 2px; align-items: start;
  background: #f6efe0; color: var(--ink); border: 1px solid rgba(42, 30, 20, 0.2); font: inherit; cursor: pointer;
  transition: transform var(--t-state) var(--ease-out), box-shadow var(--t-state) var(--ease-out), opacity var(--t-state);
}
.duel-card__art { grid-row: 1 / span 2; width: 28px; height: 28px; color: var(--ink); }
.duel-card__name { font-weight: 800; font-size: var(--t-15); line-height: 1.15; }
.duel-card__fx { font-size: var(--t-13); color: var(--ink-2); line-height: 1.25; }
.duel-card.is-live { border-color: var(--brass-bright); box-shadow: 0 0 0 1.5px var(--brass-bright), 0 6px 16px -8px rgba(255, 190, 90, 0.7); }
@media (hover: hover) and (pointer: fine) { .duel-card.is-live:hover { transform: translateY(-3px); } }
.duel-card.is-live:active { transform: translateY(1px); }
.duel-card:disabled { cursor: default; opacity: 0.5; }
.duel-card.is-armed { box-shadow: 0 0 0 3px #59c8ff, 0 0 18px rgba(89, 200, 255, 0.55); }
.duel-card--key { border-color: var(--key); box-shadow: 0 0 0 2px var(--key); }
.duel-card--key .duel-card__art { width: 34px; height: 34px; }
.duel-card:focus-visible, .duel-die__pick:focus-visible { outline: 3px solid #59c8ff; outline-offset: 2px; }
.duel .card--back { --card-w: 78px; }

.duel-bar { display: grid; gap: 8px; justify-items: end; align-content: end; }
.duel-bar__more { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.duel-bar__more:empty { display: none; }
.duel-bar__more .hint { color: var(--deck-ink-2); margin: 0; }
.duel-bar .btn--go { min-width: 220px; min-height: 52px; font-size: var(--t-17); }
.duel-bar .btn:not(.btn--primary) { background: #fbf6ea; }

/* --- l'esito: chi vince si alza, chi perde trema e si spegne --- */
.duel__side.is-struck { animation: struck 420ms var(--ease-out) both; animation-delay: var(--s); }
@keyframes struck { 0%, 100% { transform: none; } 20% { transform: translateX(6px) rotate(0.6deg); box-shadow: 0 0 0 2px #ff6a4d; } 45% { transform: translateX(-5px); } 70% { transform: translateX(3px); } }
/* lo stato finale resta; le animazioni partono solo quando l'esito arriva (.is-fresh-result) */
.duel__side.is-victor { transform: translateY(-4px); box-shadow: 0 0 0 2.5px var(--accent, var(--brass-bright)), 0 14px 30px -14px rgba(0, 0, 0, 0.8); }
.duel__side.is-beaten { filter: saturate(0.35) brightness(0.82); }
.duel__side--event.is-victor { transform: none; box-shadow: none; }
.is-fresh-result .duel__side.is-victor { animation: victor 700ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes victor { from { transform: none; box-shadow: none; } }
.is-fresh-result .duel__side--event.is-victor { animation: none; }
.is-fresh-result .duel__side.is-beaten { animation: beaten 760ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes beaten {
  0% { transform: none; filter: none; }
  15% { transform: translateX(-7px) rotate(-0.8deg); }
  35% { transform: translateX(6px) rotate(0.6deg); }
  55% { transform: translateX(-3px); }
  100% { transform: none; filter: saturate(0.35) brightness(0.82); }
}
.duel-heart.is-breaking { animation: heart-break 640ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes heart-break {
  0% { color: var(--heart); transform: scale(1); }
  25% { color: #ff5a44; transform: scale(1.35) rotate(-10deg); filter: drop-shadow(0 0 8px #ff5a44); }
  100% { color: rgba(42, 30, 20, 0.28); transform: scale(1); }
}
.duel-heart.is-healing { animation: heart-heal 600ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes heart-heal { from { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.2); } }
.duel-socket.is-new .duel-socket__cup { animation: stamp 440ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes stamp {
  0% { transform: scale(1.9); opacity: 0; }
  55% { transform: scale(0.9); opacity: 1; box-shadow: 0 0 0 2px #ffd27a, 0 0 26px rgba(255, 190, 90, 0.9); }
  100% { transform: scale(1); }
}
.duel-stamp {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) rotate(-14deg);
  font-family: var(--font-print); font-size: 30px; color: #b0261c; padding: 2px 14px; border: 3px solid #b0261c; border-radius: 6px;
  background: rgba(255, 248, 236, 0.85); pointer-events: none;
}
.is-fresh-result .duel__side--event.is-defeated .duel-stamp { animation: stamp-card 420ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes stamp-card { from { transform: translate(-50%, -50%) rotate(-14deg) scale(2.2); opacity: 0; } }
.duel__side--event.is-defeated .card--event { transform: rotate(-4deg) translateY(4px); filter: saturate(0.5); }
.is-fresh-result .duel__side--event.is-defeated .card--event { animation: card-down 600ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes card-down { from { transform: none; filter: none; } }
.duel-verdict.is-fresh { animation: verdict-in 520ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes verdict-in { from { transform: scale(1.35); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .duel, .duel__side, .duel-heart, .duel-socket__cup, .duel-stamp, .card--event, .duel-verdict, .duel-die .die { animation-duration: 1ms !important; animation-delay: 0ms !important; }
  .duel-die__pick { animation: none; }
}

/* --- computer piccolo e tablet orizzontale --- */
@media (max-width: 1179px) and (min-width: 760px) {
  .duel__arena { grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) minmax(170px, 210px); gap: 10px; padding: 2px 12px 10px; }
  .duel__side--event .card--event { --card-w: 140px; }
  .duel-socket__cup { width: 42px; height: 42px; }
  .duel-verdict__title { font-size: var(--t-30); }
  .duel__title { font-size: var(--t-22); }
}
@media (max-height: 820px) and (min-width: 760px) {
  .duel__head { padding: 8px 16px 4px; }
  .duel__title { font-size: var(--t-22); }
  .duel__side--event .card--event { --card-w: 128px; }
  .duel-heart { width: 28px; height: 28px; }
  .duel-heart .icon { width: 24px; height: 24px; }
  .duel-card { min-height: 76px; }
  .duel-die .die { width: 54px; height: 54px; }
  .duel-verdict__title { font-size: var(--t-30); }
  .duel__decide { padding: 8px 14px 10px; }
}

/* --- telefono e tablet verticale: foglio in basso; le due parti affiancate, la conta sotto --- */
@media (max-width: 759px), (max-width: 1179px) and (orientation: portrait) {
  .duel-layer { padding: 0; }
  .duel { width: min(680px, 100%); border-radius: 16px 16px 0 0; border-bottom: 0; }
  .duel__head { padding: 10px 14px 4px; gap: 10px; }
  .duel__title { font-size: var(--t-22); }
  .duel__arena { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 2px 10px 8px; gap: 8px; }
  .duel__center { grid-column: 1 / -1; grid-row: 2; gap: 10px; padding-top: 0; }
  .duel__side { padding: 9px; gap: 6px; }
  .duel-side__name { font-size: var(--t-17); }
  .duel-side__role { display: none; }
  .duel-heart { width: 24px; height: 24px; }
  .duel-heart .icon { width: 22px; height: 22px; }
  .duel-cannon { width: 22px; height: 22px; }
  .duel__side--event { grid-template-columns: auto; }
  .duel__side--event .card--event { --card-w: 104px; }
  .duel-threat { font-size: var(--t-13); }
  .duel-socket__cup { width: 38px; height: 38px; }
  .duel-socket__cup .icon { width: 24px; height: 24px; }
  .duel-count { gap: 7px; }
  .duel-die .die { width: 50px; height: 50px; }
  .duel-dice { gap: 12px; }
  .duel-rule { font-size: var(--t-13); }
  .duel-verdict__title { font-size: var(--t-30); }
  .duel-verdict__line { font-size: var(--t-15); }
  .duel__side .hint--minor { display: none; }
  .duel__decide { grid-template-columns: minmax(0, 1fr); padding: 8px 10px max(10px, env(safe-area-inset-bottom)); gap: 8px; }
  .duel-card { width: 126px; min-height: 76px; padding: 7px 8px; }
  .duel-bar { justify-items: stretch; }
  .duel-bar__more { justify-content: stretch; }
  .duel-bar__more .btn { flex: 1 1 0; }
  .duel-bar .btn--go { min-width: 0; width: 100%; }
}
@media (max-width: 380px) {
  .duel-stat__label { font-size: 0.75rem; }
  .duel__side--event .card--event { --card-w: 96px; }
}

/* monete e chiavi di chi attacca */
.duel-stat--purse { display: flex; gap: 12px; flex-wrap: wrap; }
.duel-purse { display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-15); }
.duel-purse .icon { width: 22px; height: 22px; }
.duel-purse.is-empty { opacity: 0.4; }
@media (max-width: 759px), (max-width: 1179px) and (orientation: portrait) {
  .is-dueling .viewbar { display: none; }
  .duel-stat__more { display: none; }
  .duel-legend { display: none; }
  .duel-track { height: 16px; }
  .duel-track__fill { top: 4px; }
  .duel-hearts { gap: 2px; }
  .duel-card { min-height: 64px; }
  .duel-card__art { width: 22px; height: 22px; }
  .duel.is-rolling .duel__decide { display: none; }
  /* sul telefono il titolo «Le tue carte» non serve; restano l'avviso delle carte di troppo e i titoli delle scelte */
  .duel-hand__title--mine:not(:has(.duel-hand__warn)) { display: none; }
  .duel-hand__title--mine .duel-hand__label { display: none; }
  .duel { max-height: 80%; }
  .duel-stat { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px; }
  .duel-stat__row { min-height: 0; justify-content: flex-end; }
  .duel-stat--purse { justify-content: space-between; gap: 6px; }
  .duel-purse { font-size: var(--t-13); }
  .duel-purse .icon { width: 18px; height: 18px; }
  .duel-backs { justify-content: flex-end; min-height: 0; }
  .duel-back { width: 18px; height: 26px; }
  .duel-count-wrap { gap: 4px; }
  .duel-socket__marks { min-height: 20px; }
  .duel-card { width: 118px; min-height: 0; }
  .duel-card__fx { font-size: 0.75rem; }
  .duel-bar__more .btn { min-height: 44px; padding-top: 6px; padding-bottom: 6px; }
  .duel-bar .btn--go { min-height: 48px; }
  /* prima del tiro i dadi sono ancora nel vassoio: si legge la regola; dopo il tiro contano i dadi */
  .duel__center.is-before .duel-dice { display: none; }
  .duel__center:not(.is-before) .duel-rule { display: none; }
  .duel__side--event .card--event { --card-w: 96px; }
}

/* il nemico che resiste si avventa: la carta scatta verso chi attacca */
.duel__side--event.is-victor .card--event { box-shadow: 0 0 0 2px #e0604a, 0 0 18px rgba(255, 90, 60, 0.35); }
.is-fresh-result .duel__side--event.is-victor .card--event { animation: lunge 640ms var(--ease-out) both; animation-delay: var(--d); }
@keyframes lunge {
  0% { transform: none; }
  30% { transform: translateX(-18px) rotate(-3deg); box-shadow: 0 0 0 3px #ff6a4d, 0 0 30px rgba(255, 90, 60, 0.7); }
  100% { transform: none; box-shadow: 0 0 0 2px #e0604a, 0 0 18px rgba(255, 90, 60, 0.35); }
}
