/* Fontes servidas localmente (a CSP do hub não permite Google Fonts). */
@font-face { font-family: 'Barlow Condensed'; font-weight: 500; font-display: swap; src: url('fonts/barlow-condensed-500.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url('fonts/barlow-condensed-600.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-display: swap; src: url('fonts/barlow-condensed-700.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 800; font-display: swap; src: url('fonts/barlow-condensed-800.woff2') format('woff2'); }
@font-face { font-family: 'DM Mono'; font-weight: 500; font-display: swap; src: url('fonts/dm-mono-500.woff2') format('woff2'); }

:root {
  color-scheme: dark;
  --ink: #f5f0e6;
  --muted: #9caa9c;
  --night: #0d1513;
  --panel: #15231f;
  --line: rgba(245, 240, 230, 0.14);
  --lime: #d7fa59;
  --blue: #4398ff;
  --red: #e9545f;
  font-family: 'Barlow Condensed', Impact, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: #0d1513; overflow: hidden; }
body::before { content: ''; position: fixed; inset: 0; pointer-events: none; opacity: .3; background: repeating-linear-gradient(135deg, transparent 0 38px, rgba(215,250,89,.025) 39px 40px); }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------------- ecrãs ---------------- */
.overlay { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 24px; overflow-y: auto; background: radial-gradient(circle at 50% 12%, #29483a 0, rgba(9,17,15,.96) 62%); backdrop-filter: blur(3px); }
.overlay.is-hidden { display: none; }
.panel { width: min(600px, 100%); padding: clamp(24px, 5vw, 48px); border: 1px solid rgba(215,250,89,.26); background: rgba(21,35,31,.96); box-shadow: 0 24px 80px rgba(0,0,0,.45); }
.panel-tight { width: min(460px, 100%); text-align: center; }
.panel-tight .menu-list { text-align: left; }
.panel .brand-mark { margin-bottom: 40px; }
.panel h1 { font-size: clamp(38px, 7vw, 68px); margin: 8px 0 8px; line-height: .92; }
.panel p { color: var(--muted); font: 13px/1.6 'DM Mono', monospace; margin: 0 0 26px; }
.panel p strong { color: var(--lime); font-weight: 500; }

#resultScore { font: 500 24px 'DM Mono', monospace; color: var(--ink); letter-spacing: .2em; margin-top: 6px; }
.menu-list { display: grid; gap: 8px; }
.menu-button { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 15px 18px; border: 1px solid var(--line); background: #1d302a; text-align: left; transition: .18s; }
.menu-button strong { color: var(--lime); font-size: 22px; letter-spacing: .05em; }
.menu-button span { color: var(--muted); font: 11px 'DM Mono', monospace; text-align: right; }
.menu-button:hover, .menu-button:focus-visible { border-color: var(--lime); background: #29483a; transform: translateX(5px); outline: none; }

.option-group { margin-bottom: 22px; }
.option-label { display: block; color: var(--muted); font: 11px 'DM Mono', monospace; letter-spacing: .16em; margin-bottom: 9px; }
.option-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { flex: 1 1 110px; padding: 13px 10px; border: 1px solid var(--line); background: #1d302a; font-size: 18px; letter-spacing: .06em; transition: .18s; }
.chip:hover { border-color: rgba(215,250,89,.6); }
.chip.is-active { background: var(--lime); color: var(--night); border-color: var(--lime); font-weight: 800; }

.button-row { display: flex; gap: 10px; margin-top: 26px; }
.primary-button { flex: 2; border: 0; background: var(--lime); color: var(--night); padding: 14px 20px; font-size: 19px; font-weight: 800; letter-spacing: .06em; transition: .18s; }
.primary-button:hover { filter: brightness(1.12); }
.ghost-button { flex: 1; border: 1px solid var(--line); background: transparent; padding: 14px 18px; font-size: 16px; letter-spacing: .06em; transition: .18s; }
.ghost-button:hover { border-color: var(--lime); }

/* ---------------- online ---------------- */
.panel-wide { width: min(720px, 100%); }
.field { display: block; margin-bottom: 14px; }
.field input { width: 100%; padding: 13px 14px; border: 1px solid var(--line); background: #122019; color: var(--ink); font: 600 22px 'Barlow Condensed', Impact, sans-serif; letter-spacing: .04em; outline: none; transition: .15s; }
.field input:focus { border-color: var(--lime); }
.net-status { min-height: 1.4em; color: var(--lime) !important; margin: 0 0 10px !important; }
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin: 6px 0 12px; }
.lobby-col { display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line); background: #1a2c26; padding: 14px 16px 16px; }
.lobby-col.home { border-top: 3px solid var(--blue); }
.lobby-col.away { border-top: 3px solid var(--red); }
.lobby-title { font: 11px 'DM Mono', monospace; letter-spacing: .14em; }
.lobby-col.home .lobby-title { color: var(--blue); }
.lobby-col.away .lobby-title { color: var(--red); }
.lobby-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; min-height: 64px; align-content: start; }
.lobby-col li { font-size: 20px; font-weight: 700; letter-spacing: .03em; }
.lobby-col li.is-me { color: var(--lime); }
.lobby-col li.is-me::after { content: ' (tu)'; font: 11px 'DM Mono', monospace; color: var(--muted); }
.lobby-col li.is-host::before { content: '★ '; color: var(--lime); }
.lobby-col li.lobby-empty { color: var(--muted); font: 12px 'DM Mono', monospace; }
.lobby-col .ghost-button { flex: none; margin-top: auto; }
.lobby-col .ghost-button.is-current { border-color: var(--lime); color: var(--lime); }
.lobby-spec { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); font: 12px 'DM Mono', monospace; margin-bottom: 18px; }
.link-button { border: 0; background: none; color: var(--lime); font: 12px 'DM Mono', monospace; letter-spacing: .08em; padding: 4px 0; }
.link-button:hover { text-decoration: underline; }

.keybind-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(238px, 1fr)); gap: 10px; }
.keybind-col { border: 1px solid var(--line); background: #1a2c26; padding: 14px 16px 16px; }
.keybind-title { display: block; font: 11px 'DM Mono', monospace; letter-spacing: .12em; margin-bottom: 10px; }
.keybind-title.home { color: var(--blue); }
.keybind-title.away { color: var(--red); }
.keybind-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.keybind-row > span { color: var(--muted); font: 12px 'DM Mono', monospace; }
.key-button { min-width: 94px; padding: 8px 10px; border: 1px solid var(--line); background: #122019; font: 12px 'DM Mono', monospace; letter-spacing: .04em; transition: .15s; }
.key-button:hover { border-color: var(--lime); }
.key-button.is-listening { background: var(--lime); color: var(--night); border-color: var(--lime); }
.key-button.is-clash { border-color: var(--red); }

.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-bottom: 22px; }
.help-card { border: 1px solid var(--line); background: #1a2c26; padding: 16px; }
.help-team { display: block; font: 11px 'DM Mono', monospace; letter-spacing: .12em; margin-bottom: 12px; }
.help-team.home { color: var(--blue); }
.help-team.away { color: var(--red); }
.help-card dl { margin: 0; display: grid; gap: 7px; }
.help-card dl > div { display: flex; align-items: baseline; gap: 10px; }
.help-card dt { min-width: 74px; padding: 3px 6px; border: 1px solid var(--line); font: 11px 'DM Mono', monospace; text-align: center; }
.help-card dd { margin: 0; color: var(--muted); font: 12px 'DM Mono', monospace; }
.help-touch { margin-bottom: 18px; }
.help-touch dt { min-width: 84px; }

/* ---------------- jogo: ecrã inteiro, campo sempre completo ---------------- */
.game-shell { width: 100%; height: 100vh; height: 100dvh; margin: 0; padding: 0; display: flex; flex-direction: column; }
.game-shell > * { flex: 0 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 12px clamp(14px, 2.5vw, 32px); }
.brand-mark { letter-spacing: .08em; font-size: 18px; display: flex; align-items: center; gap: 7px; }
.brand-mark strong { background: var(--lime); color: var(--night); padding: 2px 5px; font-weight: 800; }
.brand-mark span { width: 12px; height: 12px; background: var(--lime); display: inline-block; transform: rotate(45deg); margin-right: 2px; }
.match-label { color: var(--muted); font: 500 11px 'DM Mono', monospace; letter-spacing: .12em; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 12px var(--lime); margin-right: 8px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-button { border: 1px solid var(--line); background: transparent; width: 36px; height: 36px; font: 700 15px 'DM Mono', monospace; letter-spacing: -1px; transition: .2s; }
.icon-button:hover { background: var(--lime); color: var(--night); }
#muteButton { font-size: 15px; letter-spacing: 0; }
#muteButton[aria-pressed="true"] { opacity: .5; }
@keyframes score-pop { 0% { transform: scale(1); } 30% { transform: scale(1.45); color: var(--lime); } 100% { transform: scale(1); } }
.score-block > span.is-scored { animation: score-pop .7s ease-out; display: inline-block; }

.scoreboard { display: flex; align-items: center; justify-content: center; gap: clamp(30px, 8vw, 105px); padding: 12px clamp(14px, 2.5vw, 32px) 10px; }
.team { display: flex; align-items: center; gap: 12px; font-size: 20px; letter-spacing: .08em; font-weight: 700; }
.team-badge { display: grid; place-items: center; width: 42px; height: 42px; font: 700 20px 'DM Mono', monospace; border-radius: 50%; }
.home-badge { background: var(--blue); color: #fff; box-shadow: 0 0 0 5px rgba(67,152,255,.14); }
.away-badge { background: var(--red); color: #fff; box-shadow: 0 0 0 5px rgba(233,84,95,.14); }
.score-block { display: grid; grid-template-columns: auto auto auto; align-items: center; column-gap: 10px; text-align: center; }
.score-block > span { font-size: clamp(38px, 5vw, 56px); line-height: .8; font-weight: 800; }
.score-divider { color: var(--lime); font-weight: 500 !important; }
.score-block small { grid-column: 1 / -1; margin-top: 9px; color: var(--muted); font: 12px 'DM Mono', monospace; letter-spacing: .08em; }

/* o campo ocupa toda a largura e toda a altura que sobra */
.pitch-wrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; border-top: 1px solid rgba(215,250,89,.25); border-bottom: 1px solid rgba(215,250,89,.25); }
canvas { display: block; width: 100%; height: 100%; background: #0f2019; }

.controls-panel { display: flex; justify-content: space-between; gap: 24px; align-items: center; padding: 10px clamp(14px, 2.5vw, 32px) 12px; }
.eyebrow { color: var(--lime); font: 11px 'DM Mono', monospace; letter-spacing: .15em; }
.control-copy { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.control-copy h2 { font-size: clamp(18px, 1.8vw, 24px); line-height: 1; margin: 0; font-weight: 700; white-space: nowrap; }
.control-copy p { color: var(--muted); font: 12px/1.4 'DM Mono', monospace; margin: 0; }
.legend { display: flex; align-items: center; gap: 9px; color: var(--muted); font: 11px 'DM Mono', monospace; white-space: nowrap; }
.key-chip { padding: 7px 8px; border: 1px solid var(--line); color: var(--ink); }

/* =========================================================================
   VERSÃO TELEMÓVEL — ativa com body.mobile (automático em ecrãs táteis,
   ou forçada na página /mobile). Campo em ecrã inteiro, HUD por cima,
   joystick à esquerda e botões à direita, nos cantos que a vista
   isométrica deixa vazios.
   ========================================================================= */
.touch-controls, .rotate-hint, [data-mobile-only] { display: none; }
body.mobile [data-desktop-only] { display: none !important; }
body.mobile [data-mobile-only] { display: block; }
body.mobile { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
body.mobile.in-match { touch-action: none; overscroll-behavior: none; }
body.mobile .field input { -webkit-user-select: text; user-select: text; }

/* campo em ecrã inteiro com o placar numa cápsula por cima */
body.mobile .game-shell { position: fixed; inset: 0; height: auto; display: block; }
body.mobile .pitch-wrap { position: absolute; inset: 0; height: auto; border: 0; }
body.mobile .controls-panel { display: none; }
body.mobile .topbar {
  position: absolute; z-index: 3; border: 0; padding: 0;
  top: calc(env(safe-area-inset-top, 0px) + 10px); right: max(12px, env(safe-area-inset-right, 0px));
}
body.mobile .topbar .brand-mark, body.mobile .match-label { display: none; }
body.mobile .icon-button { width: 40px; height: 40px; background: rgba(9,18,15,.72); border-radius: 10px; }
body.mobile .scoreboard {
  position: absolute; z-index: 3; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  gap: 14px; padding: 6px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(9,18,15,.78); justify-content: center;
}
body.mobile .team { font-size: 14px; gap: 6px; }
body.mobile .team-badge { width: 24px; height: 24px; font-size: 12px; box-shadow: none; }
body.mobile .score-block { column-gap: 5px; }
body.mobile .score-block > span { font-size: 28px; }
body.mobile .score-block small { margin-top: 3px; font-size: 10px; }

/* comandos: só aparecem com a partida a decorrer */
body.mobile.in-match .touch-controls { display: block; }
.touch-controls { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.stick-zone { position: absolute; left: 0; top: 64px; bottom: 0; width: 46%; pointer-events: auto; touch-action: none; }
.stick-base {
  position: absolute; left: calc(max(20px, env(safe-area-inset-left, 0px)) + 62px); bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  width: 124px; height: 124px; margin: 0 0 0 -62px; border-radius: 50%;
  border: 2px solid rgba(215,250,89,.28); background: radial-gradient(circle, rgba(215,250,89,.08), rgba(9,18,15,.5) 70%);
  transition: opacity .15s; opacity: .75;
}
.stick-base.is-active { opacity: 1; margin: -62px 0 0 -62px; bottom: auto; transition: none; }
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f0ffb0, var(--lime) 55%, #93b52a); box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.touch-actions {
  position: absolute; right: max(18px, env(safe-area-inset-right, 0px)); bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: grid; grid-template-columns: auto auto; grid-template-areas: "swap pass" ". shoot"; gap: 10px; align-items: end; pointer-events: auto;
}
.touch-key {
  border-radius: 50%; border: 2px solid rgba(245,240,230,.25); background: rgba(9,18,15,.72); color: var(--ink);
  font: 700 13px 'Barlow Condensed', Impact, sans-serif; letter-spacing: .08em; touch-action: none; -webkit-touch-callout: none;
  display: grid; place-items: center;
}
.touch-key.active { background: var(--lime); color: var(--night); border-color: var(--lime); transform: scale(.94); }
.touch-swap { grid-area: swap; width: 58px; height: 58px; font-size: 11px; }
.touch-pass { grid-area: pass; width: 72px; height: 72px; }
.touch-shoot { grid-area: shoot; width: 92px; height: 92px; font-size: 16px; border-color: rgba(215,250,89,.55); }

/* telemóvel ao alto: sugere rodar, mas deixa jogar */
@media (orientation: portrait) {
  body.mobile.in-match:not(.portrait-ok) .rotate-hint {
    position: fixed; inset: 0; z-index: 8; display: grid; place-content: center; justify-items: center; gap: 12px;
    padding: 24px; text-align: center; background: rgba(9,18,15,.94);
  }
  body.mobile .stick-zone { width: 50%; }
  body.mobile .stick-base { width: 104px; height: 104px; margin-left: -52px; }
  body.mobile .stick-base.is-active { margin: -52px 0 0 -52px; }
  body.mobile .touch-shoot { width: 80px; height: 80px; }
}
.rotate-hint strong { font-size: 30px; letter-spacing: .03em; }
.rotate-hint span { max-width: 30ch; color: var(--muted); font: 13px/1.5 'DM Mono', monospace; }
.rotate-hint .ghost-button { flex: none; margin-top: 8px; }
.rotate-phone {
  width: 46px; height: 76px; border: 3px solid var(--lime); border-radius: 9px;
  animation: rotate-phone 2.2s ease-in-out infinite;
}
@keyframes rotate-phone { 0%, 25% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
@media (prefers-reduced-motion: reduce) { .rotate-phone { animation: none; transform: rotate(-90deg); } }

/* menus em ecrãs baixos (telemóvel deitado) */
@media (max-height: 500px) {
  .overlay { padding: 12px; place-items: start center; }
  .panel { padding: 18px 22px; }
  .panel .brand-mark { margin-bottom: 10px; }
  .panel h1 { font-size: 34px; }
  .panel p { margin-bottom: 14px; }
  .menu-button { padding: 10px 14px; }
  .menu-button strong { font-size: 19px; }
  .button-row { margin-top: 14px; }
  .option-group { margin-bottom: 12px; }
  .chip { padding: 9px 8px; }
}

@media (max-width: 680px) {
  .match-label { display: none; }
  .brand-mark { font-size: 15px; }
  .scoreboard { gap: 16px; justify-content: space-between; }
  .team { font-size: 15px; gap: 7px; }
  .team-badge { width: 30px; height: 30px; font-size: 14px; }
  .score-block > span { font-size: 38px; }
  .control-copy h2 { display: none; }
  .control-copy p { font-size: 11px; }
  .panel .brand-mark { margin-bottom: 24px; }
}

/* sala em portáteis e ecrãs médios: opções lado a lado e equipas mais baixas */
@media (max-height: 860px) {
  [data-screen="lobby"] .panel { padding-block: 22px; }
  [data-screen="lobby"] .panel h1 { font-size: clamp(30px, 5vw, 46px); }
  #lobbyHostOptions { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  #lobbyHostOptions .option-group { margin-bottom: 10px; }
  .lobby-col ul { min-height: 40px; }
  [data-screen="lobby"] .button-row { margin-top: 12px; }
}
@media (max-height: 380px) {
  [data-screen="lobby"] .panel > p, [data-screen="lobby"] .panel > .eyebrow { display: none; }
  [data-screen="lobby"] .panel h1 { font-size: 22px; }
  .lobby-col .ghost-button { padding: 5px 8px; }
}

/* telemóvel deitado (≤ 460 px de altura): cada menu cabe num só ecrã, sem scroll */
@media (max-height: 460px) {
  .overlay { padding: 8px 12px; place-items: center; }
  .panel { padding: 12px 18px; }
  .panel h1 { font-size: 26px; margin: 2px 0 6px; }
  .panel p { font-size: 11.5px; line-height: 1.45; margin-bottom: 8px; }
  .panel .brand-mark { margin-bottom: 4px; font-size: 15px; }
  .eyebrow { font-size: 10px; }
  .button-row { margin-top: 8px; }
  .primary-button, .ghost-button { padding: 9px 14px; font-size: 15px; }
  .option-group { margin-bottom: 8px; }
  .option-label { margin-bottom: 5px; }
  .chip { padding: 6px 8px; font-size: 15px; flex-basis: 70px; }
  /* menu principal: descrição fora, botões em duas colunas */
  [data-screen="menu"] .panel { width: min(720px, 100%); }
  [data-screen="menu"] .panel > p, [data-screen="menu"] .panel > .eyebrow { display: none; }
  [data-screen="menu"] .menu-list { grid-template-columns: 1fr 1fr; gap: 6px; }
  [data-screen="menu"] .menu-button { padding: 10px 12px; }
  [data-screen="menu"] .menu-button span { font-size: 10.5px; }
  /* sala: equipas mais baixas e opções lado a lado */
  .lobby-grid { gap: 8px; margin: 4px 0 6px; }
  .lobby-col { padding: 8px 10px; gap: 6px; }
  .lobby-col ul { min-height: 22px; gap: 2px; }
  .lobby-col li { font-size: 16px; }
  .lobby-col .ghost-button { padding: 6px 10px; font-size: 14px; }
  .lobby-spec { margin-bottom: 6px; }
  #lobbyHostOptions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  #lobbyHostOptions .option-group { margin-bottom: 4px; }
  [data-screen="lobby"] .panel { padding-block: 10px; }
  [data-screen="lobby"] .panel h1 { font-size: 24px; }
  [data-screen="lobby"] .button-row { margin-top: 6px; }
  .lobby-col ul { min-height: 22px; }
  #lobbyWait { margin: 0; }
  /* ajuda */
  [data-screen="help"] .panel { width: min(760px, 100%); }
  .help-touch { margin-bottom: 8px; padding: 10px 12px; }
  .help-touch dl { grid-template-columns: 1fr 1fr; gap: 6px 14px; }
  .help-card dd { font-size: 11px; }
  .help-team { margin-bottom: 6px; }
}

/* ecrãs baixos: corta o supérfluo para o campo ficar com o máximo de altura */
@media (max-height: 720px) {
  .control-copy h2 { display: none; }
  .scoreboard { padding-top: 8px; padding-bottom: 6px; }
  .score-block small { margin-top: 6px; }
}


/* página publicada: ocupa exatamente o espaço dentro das margens seguras */
html, body { height: 100%; }
.game-shell { height: 100%; }
a.menu-button { color: inherit; text-decoration: none; }
