@import url("styles/brand.css");
/* MORTAL COMMA — layout a tutto schermo con letterboxing.
   Il canvas ha risoluzione interna fissa (640x360); lo scaliamo via JS
   mantenendo le proporzioni, e lo sfondo nero fa da bande (letterbox). */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}
/* Lo sfondo della UI copre tutta la finestra; lo schermo di gioco (canvas e menu) sta dentro, grande quanto dice Opzioni → Schermo. */
:root { --p1: #e5352b; --p1-text: #ff8a80; --p2: #2f8bff; --p2-text: #83c7ff; } /* P1 rosso, P2 blu ovunque */
html { background: var(--surface) url("../assets/ui/menu/background.png?v=20261117b") center / 100% 100% no-repeat; }

body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  font-family: "Courier New", monospace;
}

#game {
  /* pixel netti quando scaliamo (no sfocatura) */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #101418;
  box-shadow: 0 0 0 1px #2a2f36;
}

@font-face {
  font-family: "Press Start";
  src: url("../assets/ui/fonts/PressStart2P-Regular.ttf") format("truetype");
  font-display: swap;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
button, select, input { font: inherit; }
select { color: var(--text); background-color: var(--surface); border: 1px solid var(--gold); border-radius: 3px; padding: .55rem .7rem; }
/* Tutti i bottoni con la cornice del kit (button-frame.png = button.png senza margini trasparenti). */
button {
  color: var(--text); background: none; border-radius: 0; cursor: pointer; padding: .35rem .3rem;
  border: solid; border-width: 10px 30px;
  border-image: url("../assets/ui/menu/button-frame.png?v=20261117b") 110 330 fill / 10px 30px stretch;
}
button:not(:disabled):hover { filter: brightness(1.25); }
button:disabled { opacity: .55; cursor: wait; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #ffdf68; outline-offset: 3px; }
.panel, dialog { color: var(--text); padding: 24px 32px; }
/* Cornice dei dialog: border-image tiene gli angoli decorati a misura fissa, così titolo e pulsanti non ci finiscono sopra a qualunque larghezza. */
dialog { background: var(--surface); border: 44px solid transparent; border-image: url("../assets/ui/menu/background.png?v=20261117b") 240 fill / 44px stretch; box-shadow: 0 12px 60px #000a; padding: 8px 20px; }
.panel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: var(--screen-w, 94vw); max-height: var(--screen-h, 96vh); overflow: auto;
  text-align: center;
}
/* Fuori dal match il canvas non serve: i menu stanno al suo posto. */
body:has(> .panel:not([hidden])) #game { visibility: hidden; }
.logo { width: min(75%, 430px); height: 86px; object-fit: contain; }
header p, .hint, footer { color: #c3cad4; font-size: 12px; line-height: 1.5; }
.player-tabs, .actions { display: flex; justify-content: center; gap: 12px; margin: 14px 0; flex-wrap: wrap; }
.player-tabs button[aria-pressed="true"], #settings-tabs [aria-selected="true"] { color: #ffdf68; filter: brightness(1.3) drop-shadow(0 0 4px #ffdf68); }
.roster { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); max-width: 860px; gap: 8px; margin: auto; }
.character-card { position: relative; padding: 0; aspect-ratio: 2 / 3; background: transparent; border: 0; border-image: none; }
.character-card .frame, .character-card .cursor { position: absolute; width: 100%; height: 100%; inset: 0; }
.character-card .portrait { position: absolute; left: 15%; top: 15%; width: 70%; height: 69%; object-fit: contain; object-position: bottom; }
.character-card .cursor { pointer-events: none; }
.character-card .cursor.p2 { transform: scale(.94); }
.character-card { container-type: inline-size; }
/* Il nome si rimpicciolisce con la carta (cqw) e resta dentro la cornice. */
.character-card span { position: absolute; bottom: 9%; left: 12%; width: 76%; font: min(8px, 5.7cqw)/1.25 "Press Start", monospace; white-space: normal; text-wrap: balance; }
#selection-status { font-size: 13px; margin-top: 8px; min-height: 18px; }
.arena-picker { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 14px 0 6px; }
.arena-picker label { text-align: left; }
.arena-picker select { display: block; margin-top: 4px; max-width: 100%; }
#stage-preview { width: 148px; height: 63px; object-fit: cover; border: 1px solid var(--gold); }
.asset-button { min-width: 138px; padding: .6rem .4rem; font-weight: bold; }
footer { margin-top: 10px; font-size: 10px; }
#load-status { min-height: 18px; color: #ffdf68; }
#match-options { flex-shrink: 0; min-width: 120px; font-size: 12px; }
.result-panel { background: url("../assets/ui/results/results-frame.png?v=20261117b") center / 100% 100% no-repeat; padding: 55px 65px; }
.result-panel h2 { font: 14px "Press Start", monospace; line-height: 1.8; }
.result-content { display: flex; justify-content: center; align-items: center; gap: 30px; min-height: 230px; }
#result-portrait { width: 170px; height: 220px; object-fit: contain; }
#result-score { font: 24px "Press Start", monospace; margin-bottom: 24px; }
blockquote { max-width: 280px; line-height: 1.5; }
dialog { max-height: 92vh; overflow: auto; margin: auto; width: min(92vw, 560px); }
dialog::backdrop { background: #000b; }
dialog h2 { margin-bottom: 24px; font-size: 20px; }
dialog > label, dialog > select, dialog > input[type="range"] { display: block; width: 100%; margin: 12px 0; }
#volume-value { float: right; }
@media (max-width: 560px) {
  .panel { padding: 16px; }
  #lobby { max-height: 96vh; }
  .roster { gap: 5px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .character-card span { font-size: min(8px, 5.7cqw); }
  .arena-picker { gap: 8px; }
  .arena-picker label { min-width: 0; flex: 1; }
  .arena-picker select { width: 100%; }
  #stage-preview { width: 90px; height: 50px; }
  .result-content { gap: 12px; min-height: 180px; }
  #result-portrait { width: 100px; height: 160px; }
  .result-panel h2 { font-size: 11px; }
}

.controls-guide { color: var(--text); font: 14px/1.6 "Courier New", monospace; text-align: left; }
.controls-guide .p1 { color: var(--p1-text); }
.controls-guide .p2 { color: var(--p2-text); }
#versus .controls-guide { margin: 12px auto; max-width: 690px; }
/* Barra del match: comandi P1 a sinistra, pausa al centro, P2 a destra; bordi diversi per giocatore. */
#match-toolbar { flex-shrink: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 4px 12px; width: 100%; background: var(--surface); }
#match-toolbar .controls-guide { padding: 2px 10px; font-size: 13px; }
#match-toolbar .controls-guide[data-player="p1"] { border-left: 5px solid var(--p1); background: linear-gradient(90deg, #e5352b33, transparent); }
#match-toolbar .controls-guide[data-player="p2"] { border-right: 5px double var(--p2); background: linear-gradient(270deg, #2f8bff33, transparent); text-align: right; }
#match-toolbar .controls-guide { font-weight: bold; }
#match-toolbar .hint { font-weight: normal; }
@media (max-width: 760px) {
  #match-toolbar { gap: 4px; padding: 4px 8px; }
  .controls-guide { font-size: 12px; }
}

.hint a { color: #ffdf68; text-decoration: underline; }

#bindings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
#bindings fieldset { border: 1px solid var(--gold); padding: 8px; min-width: 0; }
#bindings button { display: block; width: 100%; margin: 6px 0; text-align: left; font-size: 13px; }
#binding-status { margin: 12px 0; }
dialog h3 { margin-top: 20px; }

#dossier { width: min(96vw, 1040px); }
.dossier-tabs { flex-shrink: 0; display: flex; gap: 6px; overflow-x: auto; padding: 6px 2px 10px; margin-bottom: 12px; scrollbar-width: thin; }
.dossier-tab { flex: 0 0 76px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px; border: 2px solid rgb(201 165 90 / .33); border-image: none; background: #10243e; font-size: 10px; line-height: 1.2; }
.dossier-tab img { width: 64px; height: 64px; object-fit: contain; image-rendering: pixelated; }
.dossier-tab.stage img { object-fit: cover; }
.dossier-tab.character + .dossier-tab.stage { margin-left: 14px; }
.dossier-tab[aria-selected="true"] { border-color: #ffdf68; background: #8c201f; color: #ffdf68; }
.dossier-figure { position: relative; }
.dossier-figure img { display: block; width: 100%; aspect-ratio: 21 / 9; object-fit: cover; border: 2px solid var(--gold); image-rendering: pixelated; }
.dossier-figure.character img { width: auto; height: 200px; aspect-ratio: auto; margin: 0 auto; border: 0; }
/* Bloccato: annerito con il punto di domanda sopra (fascicolo e miniature). */
.dossier-figure.locked img, .dossier-tab.locked img { filter: brightness(0); }
.dossier-figure.locked::after, .dossier-tab.locked::after { content: "?"; position: absolute; inset: 0; display: grid; place-items: center; color: #ffdf68;
  font: 64px "Press Start", monospace; text-shadow: 4px 4px 0 #8c201f; pointer-events: none; }
.dossier-tab { position: relative; }
.dossier-tab.locked::after { font-size: 26px; bottom: 18px; }
.dossier-code { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--gold); }
.dossier-code label { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dossier-code input { background: #101d32; color: var(--text); border: 1px solid var(--gold); padding: 8px; width: 170px; }
.dossier-code .hint { width: 100%; }
#dossier-entry p { margin: 10px 0; line-height: 1.5; }
.comic-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.comic-strip figure { border: 2px solid var(--gold); background: #10243e; }
.comic-strip img { width: 100%; aspect-ratio: 1; object-fit: contain; image-rendering: pixelated; }
.comic-strip figcaption { padding: 10px; font-size: 13px; line-height: 1.5; border-top: 1px solid var(--gold); }
#result-unlock { color: #ffdf68; }
@media (max-width: 560px) { .comic-strip { grid-template-columns: 1fr; } .comic-strip img { max-height: 180px; } }

.character-card.bonus { filter: drop-shadow(0 0 3px #d6ad4b); }
.character-card .lock-label { position: absolute; left: 0; top: 48%; width: 100%; padding: 5px 0; background: rgb(7 23 47 / .87); color: #ffdf68; font-size: 10px; }

/* Opzioni e fascicolo a dimensione fissa: header e tab fermi in alto, solo .dialog-body scorre. */
#settings { width: min(96vw, 1040px); }
#settings[open], #dossier[open] { display: flex; flex-direction: column; overflow: hidden; height: min(92vh, 680px); }
.dialog-body { flex: 1; min-height: 0; overflow: auto; padding-right: 6px; }
.settings-header { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; }
.settings-header h2 { margin: 0; }
.settings-header button { font-size: 13px; }
#settings-tabs { flex-shrink: 0; display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; padding: 4px 0; }
#settings-tabs button { font-size: 13px; }
.settings-panel > label, .settings-panel > select, .settings-panel > input[type="range"] { display: block; width: 100%; margin: 12px 0; }
.settings-panel > button { margin: 12px 4px 8px 0; }
.settings-panel output { float: right; }
#screen-size-output { display: block; float: none; margin: 10px 0; }
#input-test { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
#input-test kbd { background: #101d32; border: 1px solid var(--gold); padding: 6px; font: 12px "Courier New", monospace; color: #cdd6df; }
#input-test kbd.pressed { background: #ffdf68; color: var(--surface); border-color: var(--text); }
#input-test:focus-visible { outline: 3px solid #ffdf68; outline-offset: 3px; }
#import-save { max-width: 100%; }
#storage-status, #save-status { margin: 14px 0; }
@media (max-width: 560px) { #settings { padding: 16px; } #bindings { grid-template-columns: 1fr; } }

/* Frontend arcade: asset esistenti, movimento leggero e controlli accessibili. */
.menu-actions { display: grid; gap: 12px; margin: 20px auto; max-width: 520px; }
.menu-actions button { min-height: 44px; }
/* Caricamento: P1 a sinistra, countdown al centro, P2 a destra e specchiato (si guardano). */
.versus-portraits { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; margin: 16px 0; }
.versus-countdown { font: clamp(40px, 8vw, 88px) "Press Start", monospace; color: #ffdf68; text-shadow: 4px 4px 0 #8c201f, 8px 8px 0 #000; }
.versus-portraits .p2 img { transform: scaleX(-1); }
.versus-portraits .p1 img { border: 4px solid var(--p1); background: linear-gradient(#e5352b44, rgb(7 23 47 / .8)); }
.versus-portraits .p2 img { border: 6px double var(--p2); background: linear-gradient(#2f8bff44, rgb(7 23 47 / .8)); }
.versus-portraits img { width: 100%; height: min(35vh, 250px); object-fit: contain; image-rendering: pixelated; }
#training-tools { width: 100%; flex-shrink: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 8px; color: #fff; background: rgb(7 23 47 / .96); font-size: 12px; }
#training-tools select { padding: 5px; }
#help p, #session-stats p, #abandon-confirm p { margin: 16px 0; line-height: 1.6; }
#pause button, #help button, #session-stats button { min-height: 44px; }

/* Chicche burocratiche */
.closed-sign { display: inline-block; margin: 4px 0 0; padding: 6px 14px; font: 11px "Press Start", monospace; color: #c8102e; background: var(--text); border: 4px double #c8102e; transform: rotate(-3deg); box-shadow: 4px 4px 0 #000; }
#load-status.istruttoria::after { content: ""; display: block; height: 8px; margin: 6px auto 0; max-width: 320px; border: 1px solid var(--gold);
  background: linear-gradient(#ffdf68 0 0) left / 99% 100% no-repeat; animation: istruttoria 1.2s ease-out both; }
@keyframes istruttoria { from { background-size: 0 100%; } }
.verdict { position: relative; }
.verdict-stamp { position: absolute; left: 50%; top: 55%; width: 120%; transform: translate(-50%, -50%) rotate(-12deg); pointer-events: none; animation: stamp-in .35s .4s cubic-bezier(.3, 1.8, .5, 1) both; }
.verdict.loser #result-loser { width: 100px; height: 140px; object-fit: contain; filter: grayscale(.8) brightness(.7); transform: scaleX(-1); }
.verdict.loser .verdict-stamp { width: 140%; transform: translate(-50%, -50%) rotate(10deg); animation-delay: .7s; }
@keyframes stamp-in { from { opacity: 0; scale: 3; } }
#result-protocol { margin-top: 4px; }
#dossier-entry { position: relative; }
.dossier-stamp { position: absolute; right: 8px; top: 8px; z-index: 1; padding: 4px 10px; font: 13px "Press Start", monospace; color: #3fae5a; border: 3px double currentColor; transform: rotate(8deg); background: rgb(7 23 47 / .8); }
.dossier-stamp.reserved { color: #c8102e; }
.determina { width: min(92vw, 620px); color: #1d1a14; background: #f3e7c9; border: 0; border-image: none; padding: 24px 32px; font: 14px/1.55 Georgia, "Times New Roman", serif; text-align: left; }
.determina h2 { font: bold 17px Georgia, serif; text-align: center; text-transform: uppercase; }
.determina p { margin: 8px 0; }
.determina-center { text-align: center; font-weight: bold; letter-spacing: .2em; }
.determina-sign { text-align: right; font-style: italic; margin-top: 18px !important; }
.determina button { color: var(--text); margin-top: 10px; }
@media (prefers-reduced-motion: reduce) { .verdict-stamp, #load-status.istruttoria::after { animation: none; } }
.result-content { flex-wrap: wrap; }

/* P1 rosso, P2 blu: carte selezionate, pulsanti giocatore, confronto. */
.character-card.pick-p1 { box-shadow: 0 0 0 3px var(--p1), 0 0 18px var(--p1); }
.character-card.pick-p2 { box-shadow: 0 0 0 3px var(--p2), 0 0 18px var(--p2); }
.character-card.pick-p1.pick-p2 { box-shadow: 0 0 0 3px var(--p1), 0 0 0 7px var(--p2), 0 0 18px #fff8; }
.character-card.pick-p1::before, .character-card.pick-p2::after { position: absolute; top: -8px; z-index: 2; padding: 3px 5px; color: #fff; font: 8px "Press Start", monospace; box-shadow: 2px 2px 0 #000; }
.character-card.pick-p1::before { content: "P1"; left: -6px; background: var(--p1); }
.character-card.pick-p2::after { content: "P2"; right: -6px; background: var(--p2); }
#choose-p1 { color: var(--p1-text); } #choose-p2 { color: var(--p2-text); }
#choose-p1[aria-pressed="true"] { color: #fff; filter: brightness(1.2) drop-shadow(0 0 6px var(--p1)); }
#choose-p2[aria-pressed="true"] { color: #fff; filter: brightness(1.2) drop-shadow(0 0 6px var(--p2)); }
.versus-portraits .p1 figcaption { color: var(--p1-text); } .versus-portraits .p2 figcaption { color: var(--p2-text); }
.versus-portraits .p1 img { filter: drop-shadow(0 0 10px var(--p1)); } .versus-portraits .p2 img { filter: drop-shadow(0 0 10px var(--p2)); }
/* Opzioni sempre in alto a destra (home: nella fila servizi). */
.corner-options { position: absolute; top: 12px; right: 12px; z-index: 3; font-size: 13px; }

/* Selezione: bordo giallo su passaggio del mouse e sulla riga attiva da tastiera. */
#lobby :is(button, select, .roster):is(:hover, :focus) { outline: 3px solid #ffdf68; outline-offset: 3px; }
#lobby .character-card:is(:hover, :focus) { outline-offset: 0; }
.roster { padding: 4px; border-radius: 2px; }
.character-card.locked .portrait { filter: brightness(0); }

/* Brand applicato alle superfici comuni, anche fuori dal menu iniziale. */
body { color: var(--text); padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
html { background-color: var(--surface); }
header p, .hint, footer { color: var(--muted); }
button { min-height: 44px; }
button:disabled { cursor: default; opacity: .55; }
select, input { accent-color: var(--accent); }
#app-theme { width: 100%; margin: 8px 0 12px; }
#install-status { max-width: 60ch; }
:root[data-theme="paper"] .panel:not(.sportello), :root[data-theme="paper"] dialog:not(.determina) { border-image: none; background: var(--surface); border: 2px solid var(--gold); color: var(--text); }
:root[data-theme="paper"] button:not(.stamp), :root[data-theme="paper"] .character-card { color: var(--text); }
:root[data-theme="paper"] .character-card span, :root[data-theme="paper"] .lock-label, :root[data-theme="paper"] .dossier-tab { color: #F4E8C9; }
@supports (height: 100dvh) { .sportello { height: 100dvh; } dialog { max-height: 92dvh; } }
:root[data-theme="paper"] button:not(.stamp):not(.character-card):not(.dossier-tab) { background: #FCF7E9; border: 2px solid #8e6e32; border-image: none; color: #111820; }
:root[data-theme="paper"] .comic-strip figure { background: #FCF7E9; }
:root[data-theme="paper"] .dossier-code input { background: #FCF7E9; }
:root[data-theme="paper"] #load-status, :root[data-theme="paper"] #result-unlock { color: #71321f; }
:root[data-theme="paper"] .sportello-menu button small { color: #354553; }
:root[data-theme="paper"] { --p1-text: #92201b; --p2-text: #174e80; }
:root[data-theme="paper"] #settings-tabs [aria-selected="true"], :root[data-theme="paper"] .player-tabs button[aria-pressed="true"] { color: #111820; background: #C9A55A !important; filter: none; }
.closed-sign { background: #F4E8C9; }

/* Pannelli compatti sui desktop, spazio verticale disponibile anche in 4K. */
#lobby, #versus { width: min(var(--screen-w), 1500px); max-height: 96vh; }
.selection-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.selection-player { min-width: 0; padding: 12px; border: 2px solid var(--p1); }
.selection-player.p2 { border-color: var(--p2); }
.selection-player h2 { font-size: 18px; margin-bottom: 10px; }
.selection-player .roster { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.character-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; margin-bottom: 12px; text-align: left; }
.character-stats label { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-items: center; font-size: 12px; }
.character-stats meter { width: 100%; height: 12px; accent-color: var(--gold); }
#dossier { width: min(96vw, 1240px); }
#dossier[open] { height: min(94vh, 960px); }
.dossier-figure:not(.character) { width: min(100%, 480px); margin: 12px auto; }
.comic-strip { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.comic-strip img { height: 160px; }
#versus .controls-guide { max-width: none; font-size: 13px; line-height: 1.6; }
#versus .controls-guide p { margin: 8px 0; }
.versus-portraits { align-items: start; }
@media (min-width: 2400px) {
  #lobby, #versus { width: min(72vw, 1900px); font-size: 20px; }
  .selection-player h2 { font-size: 26px; }
  .character-stats label, #versus .controls-guide { font-size: 18px; }
  .character-card span { font-size: min(12px, 5.7cqw); }
  #dossier { width: min(80vw, 1600px); font-size: 20px; }
  #dossier[open] { height: min(90vh, 1400px); }
  .comic-strip img { height: 220px; }
}
@media (max-width: 700px) {
  .selection-panels { gap: 8px; }
  .selection-player { padding: 6px; }
  .selection-player .roster { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; }
  .character-stats { grid-template-columns: 1fr; gap: 3px; }
  .character-stats label { font-size: 10px; }
  #versus .controls-guide { font-size: 11px; }
  .versus-portraits { gap: 6px; grid-template-columns: 1fr 28px 1fr; }
  dialog { border-width: 20px; padding: 8px; }
}
