/* O aspeto da interface do jogo (HUD).
   Ideia: painéis "de jogo" cor de creme, com contorno castanho grosso,
   cantos redondos e uma sombra dura por baixo (como um botão de brinquedo).
   As cores ficam todas aqui em cima, como "variáveis", para mudar num sítio só. */
:root {
  --ink: #3b2a1e;          /* contornos e texto */
  --ink-soft: #7a634f;     /* texto secundário */
  --cream: #fff6e5;        /* fundo dos painéis */
  --cream-deep: #ffe7bd;   /* carta escolhida */
  --gold: #ffc531;
  --orange: #ff7a1a;
  --red: #e8452c;
  --green: #3fa34d;
  --blue: #2b6fb8;
  --hard-shadow: 0 4px 0 var(--ink);
  --soft-shadow: 0 10px 24px rgba(30, 20, 10, .28);
  --font: 'Fredoka', 'Baloo 2', system-ui, sans-serif;
}

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #a9d4f5; font-family: var(--font); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
#game canvas { display: block; }
button { font-family: inherit; }
[hidden] { display: none !important; }

/* ============ Barra de cima ============ */
.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  pointer-events: none; /* deixa arrastar a câmara por entre os painéis */
}
.topbar > * { pointer-events: auto; }

/* Nome do nível, numa "fita" */
.level-badge {
  display: flex; flex-direction: column; min-width: 0;
  padding: 6px 16px 7px; border: 3px solid var(--ink); border-radius: 16px;
  background: var(--cream); box-shadow: var(--hard-shadow), var(--soft-shadow);
}
.level-kicker {
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--orange);
}
.level-name {
  font-size: 20px; font-weight: 700; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

/* Contador de moedas */
.coin-counter {
  position: relative; display: flex; align-items: center; gap: 8px;
  height: 48px; padding: 0 18px 0 6px; box-sizing: border-box;
  border: 3px solid var(--ink); border-radius: 999px;
  background: linear-gradient(#fff9ec, #ffe7bd); box-shadow: var(--hard-shadow), var(--soft-shadow);
}
.coin { width: 38px; height: 38px; display: block; color: var(--ink); }
.coin svg { width: 100%; height: 100%; display: block; }
.budget-value {
  font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.2ch; text-align: right;
}
/* Quando o dinheiro muda: a moeda pula e roda, e o número pisca de cor */
.coin-counter.spend .coin, .coin-counter.gain .coin { animation: coin-flip .5s ease-out; }
.coin-counter.spend .budget-value { animation: flash-red .6s ease-out; }
.coin-counter.gain .budget-value { animation: flash-green .6s ease-out; }
@keyframes coin-flip {
  0% { transform: scale(1) rotateY(0); }
  40% { transform: scale(1.3) rotateY(180deg); }
  100% { transform: scale(1) rotateY(360deg); }
}
@keyframes flash-red { 0%, 40% { color: var(--red); } 100% { color: var(--ink); } }
@keyframes flash-green { 0%, 40% { color: var(--green); } 100% { color: var(--ink); } }

/* O "+€200" / "−€500" que sobe e desaparece */
.budget-delta {
  position: absolute; right: 14px; top: 100%; margin-top: 4px;
  font-size: 18px; font-weight: 700; white-space: nowrap; pointer-events: none;
  text-shadow: 0 2px 0 var(--cream), 0 0 6px var(--cream);
  animation: delta-float 1.1s ease-out forwards;
}
.budget-delta.spend { color: var(--red); }
.budget-delta.gain { color: var(--green); }
@keyframes delta-float {
  0% { opacity: 0; transform: translateY(-6px) scale(.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.1); }
  100% { opacity: 0; transform: translateY(18px) scale(1); }
}

/* Botões redondos pequenos (o do som) */
.round-button {
  width: 48px; height: 48px; padding: 8px; flex: none; cursor: pointer;
  border: 3px solid var(--ink); border-radius: 50%; color: var(--ink);
  background: var(--cream); box-shadow: var(--hard-shadow), var(--soft-shadow);
  transition: transform .1s, box-shadow .1s;
}
.round-button svg { width: 100%; height: 100%; display: block; }
.round-button:hover { transform: translateY(-2px); }
.round-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.round-button .sound-off { display: none; }
.round-button[aria-pressed="true"] .sound-on { display: none; }
.round-button[aria-pressed="true"] .sound-off { display: block; }

/* Bússola do vento (na construção mostra a previsão; no desastre, o vento de cada hora).
   Fica no meio da barra de cima, ENTRE o nome do nível e as moedas (é uma peça da fila,
   não fica "por cima"): assim nunca os tapa. Se faltar espaço, o nome do nível encolhe (…)
   e, numa janela muito estreita, o texto da bússola passa para duas linhas
   (max-width = a largura toda menos o lugar das moedas, do som e de um bocadinho do nome). */
.wind-chip {
  position: relative; flex: none; max-width: calc(100% - 365px); box-sizing: border-box; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 5px 16px 5px 5px; border: 3px solid var(--ink); border-radius: 999px;
  background: var(--cream); box-shadow: var(--hard-shadow), var(--soft-shadow);
  animation: drop-in .45s cubic-bezier(.3, 1.6, .5, 1);
}
/* As moedas e o som nunca encolhem: quem encolhe é o nome do nível (até um mínimo). */
.topbar .level-badge { min-width: 92px; }
.topbar-right { flex: none; }

/* O mostrador redondo. --compass-size = o tamanho.
   O mostrador em si não roda (é um círculo): quem se mexe são as letras e a seta (hud.js). */
.compass { --compass-size: 56px; position: relative; width: var(--compass-size); height: var(--compass-size); flex: none; }
.compass-dial, .compass-ring { position: absolute; inset: 0; border-radius: 50%; }
.compass-dial {
  box-sizing: border-box; border: 3px solid var(--ink);
  background: radial-gradient(circle, #fff 0 38%, #dff0fb 39%);
}
/* As letras ficam por cima do contorno do mostrador. Cada uma vai para o seu ângulo (--at,
   que o hud.js mede no ecrã para cada direção), anda até à borda e roda ao contrário: fica direita.
   (Com a câmara de lado, o E não fica a 90° do N no ecrã; por isso cada letra tem o seu ângulo.) */
.compass-ring { pointer-events: none; }
.compass-letter {
  position: absolute; left: 50%; top: 50%;
  width: 13px; height: 13px; box-sizing: border-box; border-radius: 50%;
  background: var(--cream); box-shadow: 0 0 0 1.5px var(--ink);
  color: var(--ink); font-size: 9.5px; font-weight: 700; line-height: 13px; text-align: center;
  transform: translate(-50%, -50%) rotate(var(--at))
             translateY(calc(var(--compass-size) / -2 + 1.5px))
             rotate(calc(-1 * var(--at)));
}
.compass-north {
  width: auto; height: 15px; padding: 0 4px; border-radius: 6px; box-shadow: none;
  background: var(--red); color: #fff; font-size: 11px; line-height: 15px;
  --at: 0deg;
}
/* Posições de partida (antes do primeiro desenho); depois o hud.js põe os ângulos verdadeiros */
.compass-east { --at: 90deg; }
.compass-south { --at: 180deg; }
.compass-west { --at: 270deg; }
/* A seta atravessa o mostrador de um lado ao outro */
.compass-arrow { position: absolute; inset: 5px; }
.compass-arrow svg { width: 100%; height: 100%; display: block; }

/* As palavras: a etiqueta pequena, a linha grande (de onde vem → para onde vai o fogo) e os números */
.wind-words { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.wind-label { font-size: 10px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--blue); }
.wind-main { font-size: 17px; line-height: 1.1; transform-origin: left center; }
/* Cada metade nunca se parte ao meio; se faltar espaço, "→ fire goes south" desce de linha */
.wind-from, .wind-to { display: inline-block; white-space: nowrap; }
.wind-from { font-weight: 700; }
.wind-to { font-weight: 600; color: #c23a1c; } /* cor de fogo, um pouco escura para se ler no creme */
.wind-details { font-size: 12.5px; font-weight: 500; color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
@keyframes drop-in {
  from { opacity: 0; transform: translateY(-30px) scale(.8); }
  to { opacity: 1; transform: none; }
}

/* A direção do vento mudou: um anel dourado sai da bússola, ela dá um pulo e o texto pisca */
.wind-chip::after {
  content: ''; position: absolute; inset: -3px; border-radius: inherit; pointer-events: none; opacity: 0;
}
.wind-chip.wind-changed::after { animation: wind-ring .6s ease-out; }
.wind-chip.wind-changed .compass { animation: wind-pop .6s ease-out; }
.wind-chip.wind-changed .wind-main { animation: wind-pop-text .6s ease-out; }
@keyframes wind-ring {
  0% { opacity: 1; box-shadow: 0 0 0 0 var(--gold); }
  100% { opacity: 0; box-shadow: 0 0 0 14px var(--gold); }
}
@keyframes wind-pop { 35% { transform: scale(1.18) rotate(-8deg); } }
@keyframes wind-pop-text { 35% { transform: scale(1.04); color: var(--orange); } }
@keyframes wind-flash-text { 35% { color: var(--orange); } }

/* ============ Caixa de informação (#info): uma "pastilha" debaixo da barra de cima ============ */
#info {
  position: fixed; left: 50%; top: 94px; transform: translateX(-50%); z-index: 5; /* por baixo da bússola */
  max-width: calc(100% - 32px); box-sizing: border-box;
  padding: 6px 14px; border-radius: 999px;
  background: rgba(59, 42, 30, .78); color: #fff6e5;
  font-size: 14px; font-weight: 500; text-align: center; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}
/* Durante o fogo, a pastilha fica cor de fogo (o relógio do incêndio) */
body[data-phase="disaster"] #info { background: rgba(200, 52, 20, .9); font-weight: 600; }
body[data-phase="result"] #info { background: rgba(59, 42, 30, .88); font-weight: 600; }

/* ============ Barra de baixo: cartas + botão de começar ============ */
#hud {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 10;
  display: flex; align-items: flex-end; justify-content: center; gap: 14px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

/* A bandeja das cartas */
.build-panel {
  order: 1; display: flex; gap: 8px; padding: 8px;
  border: 3px solid var(--ink); border-radius: 20px;
  background: rgba(255, 246, 229, .92); box-shadow: var(--hard-shadow), var(--soft-shadow);
  animation: rise-in .4s cubic-bezier(.3, 1.4, .5, 1);
}
.build-panel[hidden] { display: none; }
@keyframes rise-in { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }

/* Uma carta de ferramenta */
.tool-card {
  position: relative; width: 92px; padding: 8px 6px 7px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 3px solid var(--ink); border-radius: 14px; color: var(--ink);
  background: linear-gradient(#ffffff, #fff1d6); box-shadow: 0 4px 0 #c9a87c;
  transition: transform .12s, box-shadow .12s, background .12s;
}
.tool-card:hover { transform: translateY(-4px); box-shadow: 0 8px 0 #c9a87c; }
.tool-card:active { transform: translateY(2px); box-shadow: 0 1px 0 #c9a87c; }
.tool-card:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.tool-card.selected {
  transform: translateY(-8px); background: linear-gradient(#fff7e0, var(--cream-deep));
  border-color: var(--orange); box-shadow: 0 8px 0 #d9600e, 0 0 0 4px rgba(255, 197, 49, .55);
}
.tool-icon { width: 46px; height: 46px; display: block; }
.tool-icon svg { width: 100%; height: 100%; display: block; }
.tool-card.selected .tool-icon { animation: wiggle .5s ease-in-out; }
@keyframes wiggle { 25% { transform: rotate(-10deg); } 60% { transform: rotate(8deg); } 100% { transform: none; } }
.tool-name { font-size: 14px; font-weight: 600; line-height: 1.1; text-align: center; }
.tool-price {
  display: flex; align-items: center; gap: 3px;
  padding: 1px 8px 1px 3px; border-radius: 999px; background: var(--ink); color: #ffe27a;
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.tool-price.free { padding: 1px 8px; color: #bfe6ff; }
.mini-coin { width: 15px; height: 15px; display: block; color: var(--ink); }
.mini-coin svg { width: 100%; height: 100%; display: block; }
.tool-hotkey {
  position: absolute; top: -9px; left: -9px; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--gold);
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
/* Sem dinheiro para esta ferramenta: carta acinzentada e preço a vermelho */
.tool-card.unaffordable { cursor: not-allowed; background: #e9e3da; box-shadow: 0 4px 0 #b9b0a4; }
.tool-card.unaffordable:hover { transform: none; }
.tool-card.unaffordable .tool-icon { filter: grayscale(1); opacity: .5; }
.tool-card.unaffordable .tool-name { color: var(--ink-soft); }
.tool-card.unaffordable .tool-price { background: var(--red); color: #fff; }
.tool-card.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { translate: -5px 0; } 40%, 80% { translate: 5px 0; } }

/* O botão grande e redondo "Start disaster" */
.start-button {
  order: 2; position: relative; flex: none; width: 112px; height: 112px; padding: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  border: 4px solid var(--ink); border-radius: 50%; color: #fff;
  background: radial-gradient(circle at 35% 28%, #ff9a4a, var(--red) 62%, #b3260f);
  box-shadow: 0 6px 0 #7a1d05, var(--soft-shadow);
  transition: transform .15s;
  animation: pop-up .45s cubic-bezier(.3, 1.6, .5, 1), pulse 1.8s ease-in-out infinite;
}
.start-flame { width: 52px; height: 52px; display: block; margin-top: -4px; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .25)); }
.start-flame svg { width: 100%; height: 100%; display: block; }
.start-button:hover .start-flame { animation: flicker .35s ease-in-out infinite alternate; }
.start-label {
  font-size: 13px; font-weight: 700; line-height: 1; text-transform: uppercase; letter-spacing: .04em;
  text-shadow: 0 2px 0 #7a1d05; max-width: 84px; text-align: center;
}
.start-button:hover { transform: scale(1.06); }
.start-button:active { transform: translateY(4px) scale(1.02); box-shadow: 0 2px 0 #7a1d05; }
.start-button:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }
/* Depois de carregar, o botão desaparece (o desastre já começou) */
.start-button:disabled { display: none; }
@keyframes pop-up { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 0 #7a1d05, var(--soft-shadow), 0 0 0 0 rgba(255, 122, 26, .55); }
  50% { box-shadow: 0 6px 0 #7a1d05, var(--soft-shadow), 0 0 0 14px rgba(255, 122, 26, 0); }
}
@keyframes flicker { from { transform: scale(1) rotate(-3deg); } to { transform: scale(1.12, 1.18) rotate(3deg); } }

/* ============ Mensagens "toast" ============ */
.toast-stack {
  position: fixed; left: 50%; bottom: 168px; transform: translateX(-50%); z-index: 20;
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
  width: max-content; max-width: calc(100% - 32px);
}
.toast {
  padding: 8px 18px; border: 3px solid var(--ink); border-radius: 999px;
  background: var(--cream); box-shadow: var(--hard-shadow), var(--soft-shadow);
  font-size: 16px; font-weight: 600; text-align: center;
  animation: toast-in .35s cubic-bezier(.3, 1.6, .5, 1);
}
.toast.success { background: #e3f6dc; color: #1f6b2a; }
.toast.error { background: #ffe1da; color: #b3260f; animation: toast-in .35s cubic-bezier(.3, 1.6, .5, 1), shake .35s .1s; }
/* Clique no Parque Natural: verde de floresta, com um cadeado à frente. */
.toast.locked { background: #e2f0d6; color: #2f5d2a; animation: toast-in .35s cubic-bezier(.3, 1.6, .5, 1), shake .35s .1s; }
.toast.locked::before { content: '\1F512'; margin-right: 6px; } /* \1F512 = o emoji do cadeado */
.toast.again { animation: toast-bump .3s ease-out; }
.toast.leaving { animation: toast-out .3s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.7); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-12px) scale(.9); } }
@keyframes toast-bump { 50% { transform: scale(1.1); } }
body[data-phase="disaster"] .toast-stack, body[data-phase="result"] .toast-stack { bottom: 40px; }

/* ============ Cartão do resultado ============ */
.result-card {
  position: fixed; left: 50%; top: 50%; z-index: 30; transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px)); box-sizing: border-box; padding: 20px 20px 18px;
  border: 4px solid var(--ink); border-radius: 24px; text-align: center;
  background: var(--cream); box-shadow: 0 6px 0 var(--ink), 0 20px 50px rgba(0, 0, 0, .4);
  animation: pop-in .5s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.6); } to { opacity: 1; transform: translate(-50%, -50%); } }
.result-title {
  margin: -38px auto 14px; width: fit-content; padding: 6px 22px;
  border: 4px solid var(--ink); border-radius: 14px;
  background: var(--orange); color: #fff; font-size: 26px; font-weight: 700;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25); box-shadow: 0 4px 0 var(--ink);
}
.result-card.good .result-title { background: var(--green); }
.result-stats { display: flex; gap: 12px; justify-content: center; }
.result-stat {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 6px; border: 3px solid var(--ink); border-radius: 16px; background: #fff;
}
.result-icon { width: 52px; height: 52px; display: block; color: var(--ink); }
.result-icon svg { width: 100%; height: 100%; display: block; }
.result-number { font-size: 30px; font-weight: 700; line-height: 1.05; }
.result-number small { font-size: 18px; color: var(--ink-soft); }
.result-label { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.result-stat.lost { background: #ffe1da; }
.result-stat.lost .result-number { color: var(--red); }
.result-stat.lost .result-icon { filter: grayscale(.8) brightness(.6); }
.result-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.result-button {
  padding: 10px 20px; cursor: pointer; border: 3px solid var(--ink); border-radius: 14px;
  background: var(--gold); color: var(--ink); font-size: 17px; font-weight: 700;
  box-shadow: 0 4px 0 var(--ink); transition: transform .1s, box-shadow .1s;
}
.result-button.secondary { background: #fff; }
/* "Try again (same night)": verde, para se distinguir do "Play again" (jogo novo). */
.result-button.retry { background: #9fd88a; }
.result-button:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.result-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* Estrelas do resultado (0 a 3) */
.result-stars { display: flex; justify-content: center; gap: 6px; margin: -4px 0 12px; }
.star { width: 46px; height: 46px; stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.star.on { fill: var(--gold); animation: star-pop .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.star.on:nth-child(2) { animation-delay: .15s; }
.star.on:nth-child(3) { animation-delay: .3s; }
.star.off { fill: #e9dcc4; }
@keyframes star-pop { from { transform: scale(0); } to { transform: scale(1); } }

/* "What really happened": a história real e as fontes */
.result-story {
  margin-top: 14px; padding: 10px 12px; text-align: left; max-height: 26vh; overflow-y: auto;
  border: 3px solid var(--ink); border-radius: 16px; background: #fff;
}
.story-heading { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--orange); }
.story-text { margin: 4px 0 6px; font-size: 14px; line-height: 1.35; }
.story-sources { margin: 0 0 6px; padding-left: 18px; font-size: 12.5px; columns: 2; }
.story-sources a { color: var(--blue); }
.credit { font-size: 11.5px; color: var(--ink-soft); }
.credit a { color: var(--blue); }
/* A linha curta dos créditos. O botão "Full credits" parece um link; a zona de clique é maior do
   que a letra (padding com margem negativa), para se acertar com o dedo. */
.credit-short { position: relative; }
.credit-tail { white-space: nowrap; }
.credit-toggle {
  padding: 6px 4px; margin: -6px -4px; border: 0; background: none; font: inherit; color: var(--blue);
  text-decoration: underline; cursor: pointer;
}
.credit-toggle::after { content: ' \25B8'; }                         /* ▸ fechado */
.credit-toggle[aria-expanded="true"]::after { content: ' \25BE'; }   /* ▾ aberto */
.credit-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
/* Os créditos completos abrem num balão POR CIMA da linha curta: o cartão não muda de tamanho. */
.credit-full {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 1;
  max-height: 40vh; overflow-y: auto; padding: 8px 10px;
  border: 3px solid var(--ink); border-radius: 12px; background: #fff; box-shadow: var(--hard-shadow);
}

/* A carta de erro do index.html (só quando o jogo não arranca: sem 3D ou sem internet) */
body.fatal .topbar, body.fatal #info { visibility: hidden; }
/* O foco do teclado nos botões das cartas: um anel azul que se vê bem por cima da borda escura */
.result-button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.fatal-text { margin: 4px 0 14px; font-size: 15px; line-height: 1.45; text-align: left; }
.fatal-link { text-decoration: none; color: inherit; background: #fff; }

/* Cartão do briefing (antes de construir): o resto da interface espera por baixo */
body.briefing #hud, body.briefing #info { visibility: hidden; }
.briefing-card { width: min(520px, calc(100% - 32px)); text-align: left; }
.briefing-card .result-title { background: var(--blue); }
.briefing-name { font-size: 22px; font-weight: 700; }
.briefing-place { font-size: 13px; color: var(--ink-soft); }
.briefing-text { margin: 10px 0; font-size: 15px; line-height: 1.4; max-height: 42vh; overflow-y: auto; }
.briefing-card .result-buttons { justify-content: flex-end; }
/* "Your goal": as regras das estrelas e o aviso da ignição escondida */
.briefing-goal { margin: 0 0 10px; padding: 8px 12px; border: 3px solid var(--ink); border-radius: 16px; background: #fff; }
.goal-list { list-style: none; margin: 4px 0; padding: 0; font-size: 14.5px; line-height: 1.5; }
.goal-stars { display: inline-block; min-width: 3.2em; color: #e0a100; font-weight: 700; }
.goal-hint { margin: 4px 0 0; font-size: 14px; font-weight: 600; color: var(--orange); }

/* Onde se perderam casas, no cartão do fim */
.result-lost { margin: 10px 0 0; font-size: 14px; font-weight: 600; color: var(--red); }

/* "Same night, three plans": o teu plano, não fazer nada e o plano do perito, na MESMA noite */
.result-compare {
  margin-top: 12px; padding: 8px 12px 10px; text-align: left;
  border: 3px solid var(--ink); border-radius: 16px; background: #fff;
}
/* Cada linha: nome | barra | número | estrelas */
.compare-row {
  display: grid; grid-template-columns: 6.6em 1fr 4.6em auto; align-items: center; gap: 8px;
  margin-top: 5px; padding: 3px 6px; border: 2px solid transparent; border-radius: 10px;
}
.compare-row.player { border-color: var(--ink); background: var(--cream-deep); }
.compare-name { display: flex; flex-direction: column; line-height: 1.1; font-size: 13.5px; font-weight: 600; }
.compare-row.player .compare-name { font-weight: 700; }
.compare-note { font-size: 11px; font-weight: 600; color: var(--red); }
.compare-bar {
  height: 12px; border: 2px solid var(--ink); border-radius: 999px; background: #efe4d0; overflow: hidden;
}
.compare-fill { display: block; height: 100%; background: var(--green); }
.compare-row.stars-2 .compare-fill { background: var(--gold); }
.compare-row.stars-1 .compare-fill { background: var(--orange); }
.compare-row.stars-0 .compare-fill { background: var(--red); }
.compare-number { font-size: 15px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.compare-stars { display: flex; gap: 1px; }
.compare-stars .star { width: 15px; height: 15px; stroke-width: 2.4; animation: none; }
/* As lições da noite: frases curtas por baixo das barras */
.compare-lessons { margin: 8px 0 0; padding-left: 18px; font-size: 13.5px; line-height: 1.35; }
.compare-lessons li + li { margin-top: 3px; }
/* "Lucky night": a faixa no topo quando não fazer nada também salvava tudo */
.result-lucky {
  margin: -4px auto 10px; width: fit-content; padding: 3px 14px; border: 3px solid var(--ink); border-radius: 999px;
  background: var(--gold); font-size: 14px; font-weight: 700;
}
/* Com a comparação o cartão fica mais alto. Para caber no ecrã: o cartão fica mais largo (os quatro
   botões cabem numa linha e as lições ocupam menos linhas), os números de cima ficam mais pequenos
   e a história real encolhe (desliza por dentro). */
.result-card.has-compare { width: min(640px, calc(100% - 32px)); }
.result-card.has-compare .result-button { padding-left: 16px; padding-right: 16px; }
.result-card.has-compare .result-stars { margin-bottom: 8px; }
.result-card.has-compare .result-stars .star { width: 40px; height: 40px; }
.result-card.has-compare .result-stat { padding: 6px; }
.result-card.has-compare .result-icon { width: 40px; height: 40px; }
.result-card.has-compare .result-story { max-height: 14vh; }
/* Ecrãs com pouca altura (portátil pequeno) E telemóveis altos e estreitos: o cartão desliza por
   dentro e os botões ficam colados em baixo. Sem isto, num telemóvel com mais de 760px de altura o
   cartão ficava maior do que o ecrã e o "Finish playtest" saía para fora (revisão de 26/11).
   (Abaixo de 520px manda o bloco "Ecrãs baixos".) */
@media (min-height: 521px) and (max-height: 760px), (min-height: 761px) and (max-width: 640px) {
  .result-card.has-compare { max-height: calc(100dvh - 24px); overflow-y: auto; padding-bottom: 0; }
  .result-card.has-compare .result-title { margin: 0 auto 8px; }
  .result-card.has-compare .result-story { max-height: none; overflow: visible; }
  .result-card.has-compare .result-buttons {
    position: sticky; bottom: 0; margin: 12px -20px 0; padding: 10px 20px 12px;
    background: var(--cream); border-top: 3px solid var(--ink);
  }
  /* A barra de deslizar come um pouco da largura: botões um pouco mais pequenos, numa só linha */
  .result-card.has-compare .result-button { padding: 8px 12px; font-size: 16px; }
}
@media (max-height: 520px) {
  .result-compare { margin-top: 8px; padding: 6px 10px 8px; }
  .compare-row { margin-top: 3px; padding: 2px 6px; }
  .compare-lessons { font-size: 13px; margin-top: 6px; }
  .result-lucky { margin: 0 auto 6px; font-size: 13px; }
  /* Aqui desliza a carta toda (ver o bloco "Ecrãs baixos" lá em baixo), não a história */
  .result-card.has-compare .result-story { max-height: none; }
  .result-card.has-compare .result-icon { width: 32px; height: 32px; }
  .result-card.has-compare .result-stars .star { width: 32px; height: 32px; }
}

/* "Back to results": aparece depois do "Look around" */
.back-to-results { position: fixed; left: 50%; bottom: 20px; z-index: 30; transform: translateX(-50%); }
.back-to-results:hover { transform: translateX(-50%) translateY(-2px); }
.back-to-results:active { transform: translateX(-50%) translateY(3px); }

/* ============ Marcadores por cima do mapa (mapMarkers.js) ============ */
/* Ficam por baixo da interface (z-index baixo) e não apanham cliques. */
.map-markers { position: fixed; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }
body.cinematic .map-markers { display: none; } /* durante a cena do cigarro */
.map-marker { position: absolute; left: 0; top: 0; will-change: transform; }
/* O quartel: um ícone num balão creme, sempre visível */
.map-marker.station .marker-icon {
  display: block; width: 30px; height: 30px; padding: 3px; border: 3px solid var(--ink); border-radius: 50%;
  background: var(--cream); box-shadow: 0 3px 0 var(--ink); color: var(--ink);
}
.map-marker.station .marker-icon svg { width: 100%; height: 100%; display: block; }
/* "?" nos sítios onde o cigarro pode cair: o fogo começa num deles */
.map-marker.mystery {
  width: 26px; height: 26px; line-height: 22px; text-align: center; box-sizing: border-box;
  border: 3px solid var(--ink); border-radius: 50%; background: var(--gold);
  font-size: 17px; font-weight: 700; color: var(--ink); opacity: .85;
}
/* Casa perdida: um círculo vermelho */
.map-marker.lost {
  width: 16px; height: 16px; box-sizing: border-box; border: 3px solid var(--red); border-radius: 50%;
  background: rgba(232, 69, 44, .25);
}

/* ============ Cartão da lei ("The law", lawCard.js) ============ */
/* Abre por cima de qualquer outro cartão (z-index maior), com um fundo escuro por trás.
   A carta é uma coluna: o título e o botão "Close" ficam sempre à vista
   e só o texto do meio (.law-body) desliza se não couber no ecrã. */
.law-backdrop { position: fixed; inset: 0; z-index: 39; background: rgba(30, 20, 10, .45); }
.law-card {
  z-index: 40; width: min(520px, calc(100% - 32px)); text-align: left;
  display: flex; flex-direction: column; max-height: calc(100dvh - 72px);
}
.law-card .result-title { flex: none; background: var(--ink); }
.law-card .result-buttons { flex: none; justify-content: flex-end; }
.law-body { min-height: 0; overflow-y: auto; }
.law-heading { font-size: 22px; font-weight: 700; }
.law-intro, .law-source, .law-canada { margin: 6px 0; font-size: 14.5px; line-height: 1.4; }
.law-source { font-size: 13px; color: var(--ink-soft); }
/* As três larguras: a largura numa pastilha dourada, o artigo da lei em cinzento */
.law-strips { list-style: none; margin: 8px 0; padding: 0; font-size: 14.5px; line-height: 1.35; }
.law-strips li { margin: 0 0 6px; padding-left: 4.8em; text-indent: -4.8em; }
.law-width {
  display: inline-block; min-width: 3.4em; margin-right: .3em; padding: 0 6px; text-indent: 0;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--gold);
  font-weight: 700; text-align: center;
}
.law-article { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }
/* "In the game": como o jogo arredonda a lei aos quadrados */
.law-game { margin: 8px 0; padding: 8px 12px; border: 3px solid var(--ink); border-radius: 16px; background: #fff; }
.law-game-text { margin: 4px 0 0; font-size: 14px; line-height: 1.4; }
.law-links { margin: 6px 0; padding-left: 18px; font-size: 13.5px; }
.law-links a { color: var(--blue); }
/* No cartão do briefing, o botão "The law" fica à esquerda e "Prepare the village" à direita */
.briefing-card [data-do="law"] { margin-right: auto; }
@media (max-height: 520px) {
  /* Ecrã baixo: a carta inteira desliza, como as outras (ver o bloco "Ecrãs baixos" abaixo) */
  .law-card { display: block; max-height: calc(100dvh - 16px); }
  .law-body { overflow: visible; }
  .law-heading { font-size: 18px; }
}

/* ============ Ecrãs estreitos (telemóvel, janela pequena) ============ */
@media (max-width: 640px) {
  .topbar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .level-badge { padding: 4px 10px 5px; border-radius: 12px; }
  .level-kicker { display: none; }
  .level-name { font-size: 15px; }
  .coin-counter { height: 40px; padding: 0 12px 0 4px; gap: 4px; }
  .coin { width: 30px; height: 30px; }
  .budget-value { font-size: 18px; }
  .round-button { width: 40px; height: 40px; padding: 6px; }
  /* A bússola desce para uma segunda linha, ao centro, para não tapar o resto.
     (translate centra-a sem estragar a animação de entrada, que usa transform.) */
  .wind-chip {
    position: absolute; left: 50%; top: 52px; margin: 0; translate: -50% 0;
    width: max-content; max-width: 100%; box-sizing: border-box; padding: 3px 12px 3px 3px; gap: 7px;
  }
  .compass { --compass-size: 46px; }
  .compass-arrow { inset: 4px; }
  .wind-label { font-size: 9px; }
  .wind-main { font-size: 14px; }
  .wind-details { font-size: 11px; }
  /* A caixa #info fica por baixo da bússola (a bússola só se esconde na cena do cigarro,
     e aí a #info também se esconde) */
  #info { top: 130px; font-size: 12px; padding: 4px 10px; }

  #hud { left: 8px; right: 8px; bottom: 8px; flex-direction: column; align-items: center; gap: 8px; }
  .start-button { order: 0; align-self: flex-end; width: 84px; height: 84px; }
  .start-flame { width: 38px; height: 38px; }
  .start-label { font-size: 10px; max-width: 64px; }
  .build-panel { gap: 6px; padding: 6px; border-radius: 16px; }
  .tool-card { width: 72px; padding: 6px 3px 5px; border-radius: 12px; }
  .tool-icon { width: 34px; height: 34px; }
  .tool-name { font-size: 11.5px; }
  .tool-price { font-size: 11px; }
  .mini-coin { width: 12px; height: 12px; }
  .tool-hotkey { display: none; } /* no telemóvel não há teclado */
  .toast-stack { bottom: 226px; } /* por cima do botão de começar (com folga para 2 linhas) */
  .toast { font-size: 14px; padding: 6px 14px; }
  .result-title { font-size: 21px; }
  .result-number { font-size: 24px; }
}
@media (max-width: 360px) {
  .tool-card { width: 64px; }
  .tool-name { font-size: 10.5px; }
}

/* ============ Ecrãs baixos (telemóvel deitado) ============ */
/* A carta nunca pode ser mais alta do que o ecrã: senão o botão para começar
   fica de fora e o jogo nem arranca. A carta passa a deslizar por dentro e os
   botões ficam sempre colados em baixo, à vista. */
@media (max-height: 520px) {
  .result-card {
    max-height: calc(100dvh - 16px); overflow-y: auto; padding: 10px 16px 0;
    border-radius: 18px;
  }
  /* O título deixa de "espreitar" por cima da carta (seria cortado pelo deslizar) */
  .result-title { margin: 0 auto 8px; font-size: 19px; padding: 4px 16px; }
  /* As caixas de texto já não precisam de deslizar sozinhas: desliza a carta toda */
  .briefing-text, .result-story { max-height: none; overflow: visible; }
  .briefing-text { font-size: 14px; margin: 6px 0; }
  .result-stars { margin: 0 0 6px; }
  .star { width: 34px; height: 34px; }
  .result-icon { width: 36px; height: 36px; }
  .result-number { font-size: 22px; }
  .result-buttons {
    position: sticky; bottom: 0; margin: 10px -16px 0; padding: 8px 16px 10px;
    background: var(--cream); border-top: 3px solid var(--ink);
  }
  .result-button { padding: 7px 16px; font-size: 15px; }

  /* Painel das ferramentas e botão de começar mais pequenos: o mapa precisa da altura */
  #hud { bottom: 6px; }
  .build-panel { gap: 6px; padding: 6px; border-radius: 16px; }
  .tool-card { width: 76px; padding: 5px 3px 4px; border-radius: 12px; }
  .tool-icon { width: 30px; height: 30px; }
  .tool-name { font-size: 11.5px; }
  .tool-price { font-size: 11px; }
  .start-button { width: 80px; height: 80px; }
  .start-flame { width: 34px; height: 34px; }
  .start-label { font-size: 10px; }
  #info { font-size: 12px; padding: 3px 10px; }
}

/* Telemóvel deitado (baixo mas largo): a barra de cima fica mais pequena, para a bússola
   caber numa só fila entre o nome do nível e as moedas, sem tapar a caixa #info por baixo. */
@media (max-height: 520px) and (min-width: 641px) {
  .topbar { top: 8px; left: 8px; right: 8px; gap: 8px; }
  .level-badge { padding: 4px 12px 5px; border-radius: 13px; }
  .level-kicker { font-size: 9.5px; }
  .level-name { font-size: 16px; }
  .coin-counter { height: 40px; padding: 0 12px 0 4px; gap: 4px; }
  .coin { width: 30px; height: 30px; }
  .budget-value { font-size: 18px; }
  .round-button { width: 40px; height: 40px; padding: 6px; }
  .wind-chip { max-width: calc(100% - 310px); padding: 3px 12px 3px 3px; gap: 7px; }
  .compass { --compass-size: 46px; }
  .compass-arrow { inset: 4px; }
  .wind-label { font-size: 9px; }
  .wind-main { font-size: 14.5px; }
  .wind-details { font-size: 11px; }
  #info { top: 82px; }
}

/* Quem pede menos movimento no sistema não vê as animações a repetir */
@media (prefers-reduced-motion: reduce) {
  .start-button, .start-button:hover .start-flame { animation: none; }
  /* A bússola não pula nem lança o anel quando o vento muda: só o texto muda de cor */
  .wind-chip.wind-changed::after, .wind-chip.wind-changed .compass { animation: none; }
  .wind-chip.wind-changed .wind-main { animation: wind-flash-text .6s ease-out; }
}
