* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #10201f;
  --panel: #1b2f2d;
  --panel2: #24403d;
  --ink: #eef3e9;
  --muted: #9db8a8;
  --accent: #e3b23c;
  --green: #4caf7d;
  --red: #d95555;
  --blue: #4d7fd0;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}
.hidden { display: none !important; }
.view { min-height: 100vh; display: flex; flex-direction: column; }
button {
  background: var(--panel2); color: var(--ink); border: 1px solid #3a5a55;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--accent); color: #222; border: none; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
input {
  background: #142523; border: 1px solid #3a5a55; color: var(--ink);
  padding: 10px 12px; border-radius: 8px; font-size: 15px; width: 100%;
}
h1 { font-size: 22px; }
h2 { font-size: 16px; margin-bottom: 10px; color: var(--accent); }
.tag { background: var(--panel2); border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--muted); }
.error { color: var(--red); min-height: 20px; margin-top: 8px; font-size: 14px; }
.subtitle { color: var(--muted); font-size: 14px; }

/* ===== auth ===== */
#view-auth { align-items: center; justify-content: center; }
.auth-box {
  background: var(--panel); padding: 36px; border-radius: 16px; width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,.4); text-align: center;
}
.auth-box h1 { margin-bottom: 4px; }
.auth-box .subtitle { margin-bottom: 20px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { flex: 1; background: transparent; border: 1px solid #3a5a55; }
.tab.active { background: var(--accent); color: #222; border: none; font-weight: 600; }
#auth-form { display: flex; flex-direction: column; gap: 10px; }

/* ===== header ===== */
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid #0a1413;
}
.header-right { display: flex; gap: 10px; align-items: center; }
.header-left { display: flex; gap: 12px; align-items: center; }
.btn-help {
  width: 34px; height: 34px; border-radius: 50%; font-weight: 700; font-size: 16px;
  background: var(--panel2); border: 1px solid #3a5a55; color: var(--accent);
  display: flex; align-items: center; justify-content: center; padding: 0;
}
button.danger { background: var(--red); color: #fff; border: none; font-weight: 600; }
.help-box { width: 620px; max-width: 94vw; }
.help-content { overflow-y: auto; max-height: 62vh; font-size: 14px; line-height: 1.55; padding-right: 6px; }
.help-content h3 { color: var(--accent); margin: 14px 0 6px; font-size: 15px; }
.help-content p, .help-content li { color: #d9e6da; margin-bottom: 6px; }
.help-content ol, .help-content ul { padding-left: 20px; }
.help-table { border-collapse: collapse; margin: 8px 0; font-size: 13px; width: 100%; }
.help-table th, .help-table td { border: 1px solid #3a5a55; padding: 4px 8px; text-align: center; }
.help-table td:first-child { text-align: left; }
.help-table th { background: var(--panel2); color: var(--accent); }

/* ===== lobby ===== */
.lobby-main { display: grid; grid-template-columns: 1fr 320px; gap: 16px; padding: 16px 20px; flex: 1; }
.panel { background: var(--panel); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.table-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel2); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
}
.table-row .info small { color: var(--muted); display: block; }
#online-list { list-style: none; }
#online-list li { padding: 4px 0; border-bottom: 1px solid #24403d; }
#leaderboard { width: 100%; border-collapse: collapse; font-size: 14px; }
#leaderboard th, #leaderboard td { text-align: left; padding: 5px 4px; border-bottom: 1px solid #24403d; }
#leaderboard th { color: var(--muted); font-weight: 500; }

/* ===== modais ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: var(--panel); border-radius: 14px; padding: 26px; width: 420px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.mode-pick { display: flex; flex-direction: column; gap: 10px; }
.mode-opt {
  display: flex; gap: 10px; align-items: flex-start; background: var(--panel2);
  padding: 12px; border-radius: 10px; cursor: pointer;
}
input[type="radio"] { width: auto; accent-color: var(--accent); }
.zone-caption { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
/* placar da sala no cabeçalho do jogo */
.scoreboard {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel2); border-radius: 10px; padding: 4px 12px;
  border: 1px solid #3a5a55; font-size: 13px;
}
.scoreboard .sb-name { color: var(--muted); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard .sb-you { color: var(--green); font-weight: 600; }
.scoreboard .sb-opp { color: var(--blue); font-weight: 600; }
.scoreboard .sb-score { font-size: 16px; }
.scoreboard .sb-score b { font-size: 18px; }
.scoreboard .sb-you-score { color: var(--green); }
.scoreboard .sb-opp-score { color: var(--blue); }
.scoreboard .sb-lifetime { color: var(--muted); font-size: 11px; border-left: 1px solid #3a5a55; padding-left: 8px; }

/* histórico do perfil */
.stats { display: flex; gap: 12px; justify-content: space-around; }
.hist-row {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center;
  padding: 6px 8px; border-bottom: 1px solid #24403d; font-size: 13px;
}
.hist-row .res { font-weight: 800; text-align: center; border-radius: 5px; }
.hist-row .res.w { color: var(--green); }
.hist-row .res.l { color: var(--red); }
.hist-row .meta { color: var(--muted); font-size: 11px; }
.hist-row .when { color: var(--muted); font-size: 11px; white-space: nowrap; }
.rival-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 6px 8px; border-bottom: 1px solid #24403d; font-size: 13px;
}
.rival-row .rec b.w { color: var(--green); }
.rival-row .rec b.l { color: var(--red); }
.rival-row .bar { width: 90px; height: 8px; border-radius: 4px; background: var(--red); overflow: hidden; }
.rival-row .bar span { display: block; height: 100%; background: var(--green); }
.stat { text-align: center; }
.stat span { font-size: 30px; font-weight: 700; color: var(--accent); }
.stat label { display: block; color: var(--muted); font-size: 13px; }

/* ===== jogo ===== */
/* sem seleção de texto na área de jogo: viabiliza o pressionar-e-segurar
   nas cartas (zoom) sem menu de seleção do navegador/celular */
.game-main, .game-main * {
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#chat-panel, #chat-panel * { user-select: text; -webkit-user-select: text; }
.waiting { text-align: center; padding: 60px; font-size: 18px; color: var(--muted); }
.game-main { display: flex; flex-direction: column; gap: 10px; padding: 10px 14px; flex: 1; min-height: 0; }
.game-grid {
  display: grid;
  grid-template-columns: clamp(330px, 27vw, 420px) minmax(0, 1fr) clamp(280px, 22vw, 340px);
  gap: 12px; align-items: start;
}
.side-col {
  background: var(--panel); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; min-height: 300px;
  max-height: calc(100vh - 185px); overflow-y: auto;
}
/* impede o flex de espremer as seções umas sobre as outras — a coluna rola */
.side-col > * { flex-shrink: 0; }
.my-zone { border-top: 3px solid var(--green); }
.opp-zone { border-top: 3px solid var(--blue); }
.zone-head { font-size: 14px; color: var(--muted); margin: 4px 0; line-height: 1.7; }
.board-wrap { position: relative; background: var(--panel); border-radius: 14px; }
#board { width: 100%; max-height: 62vh; display: block; }

/* mercado negro no topo */
.bm-bar {
  background: var(--panel); border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 14px; align-items: center;
}
.bm-bar h2 { margin: 0; white-space: nowrap; }
#bm-supply { display: flex; gap: 10px; flex: 1; justify-content: center; }
.bm-bar .bmcard {
  margin: 0; flex: 1; max-width: 320px;
  display: grid; grid-template-columns: 62px 1fr; gap: 8px; font-size: 11px;
  align-items: start;
}
.bm-bar .bmcard .bm-art { width: 62px; height: 100%; min-height: 58px; margin: 0; grid-row: 1 / span 3; }
.bm-bar .bmcard .bname { font-size: 12px; }
#center-area {
  position: absolute; inset: 90px 130px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; pointer-events: none;
}
#center-area > * { pointer-events: auto; }
#played-cards { display: flex; gap: 14px; }
.pc-slot { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.pc-tag {
  font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 8px;
  letter-spacing: .5px; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.pc-tag.open-tag { background: var(--accent); color: #222; }
.pc-tag.hidden-tag { background: #3a3a46; color: #d8d8e0; border: 1px solid #6a6a7a; }
.prompt { font-size: 15px; font-weight: 600; text-align: center; text-shadow: 0 2px 6px #000; }
#action-buttons { display: flex; gap: 8px; }

.meeple { transition: transform .6s ease; filter: drop-shadow(0 3px 3px rgba(0,0,0,.35)); }

/* cartas */
.hand, .inplay { display: flex; gap: 8px; flex-wrap: wrap; min-height: 30px; }
/* mão sempre em UMA linha: as cartas encolhem para caber na coluna */
.hand { flex-wrap: nowrap; gap: 6px; }
.hand .card {
  flex: 1 1 0; min-width: 0; max-width: 96px;
  height: auto; aspect-ratio: 92 / 124;
}
/* agentes em jogo: grade que encolhe conforme a quantidade */
.inplay { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 74px)); }
.inplay .card, .inplay .card.mini {
  width: 100%; height: auto; aspect-ratio: 72 / 96;
}
.card {
  width: 92px; height: 124px; border-radius: 10px; padding: 6px;
  display: flex; flex-direction: column; cursor: default; position: relative;
  color: #fff; font-size: 12px; box-shadow: 0 3px 8px rgba(0,0,0,.35);
  border: 2px solid transparent; flex-shrink: 0; user-select: none;
}
.card.art { background-size: cover; background-position: center; padding: 0; }
.card .pt-label {
  margin-top: auto; background: rgba(12,24,20,.82); color: #fff; font-size: 10px;
  font-weight: 600; text-align: center; padding: 2px 3px; border-radius: 0 0 8px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-hl {
  position: absolute; left: 5%; width: 24%; height: 14%;
  border: 3px solid var(--accent); border-radius: 7px;
  box-shadow: 0 0 6px rgba(227,178,60,.9); pointer-events: none;
}
.card.selectable { cursor: pointer; }
.card.selectable:hover { transform: translateY(-4px); transition: transform .12s; }
.card.sel-up { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.card.sel-down { border-color: #999; box-shadow: 0 0 0 3px #999; filter: brightness(.8); }
.card.back { background-size: cover; background-position: center; border: 2px solid #33475c; }
.card.mini { width: 72px; height: 96px; font-size: 10px; }
.card.mini .pt-label { font-size: 8.5px; }
.count-badge {
  position: absolute; top: -6px; right: -6px; background: var(--accent); color: #222;
  border-radius: 50%; width: 19px; height: 19px; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 11px;
}
.bmcard {
  background: #2a2033; border: 1px solid #6a4a7a; border-radius: 10px;
  padding: 8px; font-size: 12px; margin-bottom: 8px;
}
.bmcard .bm-art {
  width: 100%; height: 74px; object-fit: cover; object-position: top;
  border-radius: 6px; display: block; margin-bottom: 6px;
}
.bm-inplay .bmcard .bm-art { height: 44px; }
.bmcard .bname { font-weight: 700; color: #d8a8e8; }
.bmcard .btype { font-size: 10px; color: var(--muted); }
.bmcard.selectable { cursor: pointer; }
.bmcard.selectable:hover { outline: 2px solid var(--accent); }
.bmcard .warn { color: #d9a555; font-size: 10px; }
.bm-inplay { display: flex; gap: 6px; flex-wrap: wrap; }
.bm-inplay .bmcard { margin: 0; max-width: 180px; }

#hand-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; position: relative; z-index: 3; }
.hand, .inplay { position: relative; z-index: 1; }
#online-list li { display: flex; align-items: center; gap: 6px; }
#online-list li .st { font-size: 13px; }
#online-list li button {
  margin-left: auto; padding: 2px 10px; font-size: 12px; border-radius: 6px;
}

/* log compacto no quadro do oponente */
.log-mini {
  margin-top: auto; background: #142523; border: 1px solid #2c4a45;
  border-radius: 10px; padding: 8px 10px;
}
.log-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 4px;
}
.log-head button {
  padding: 1px 7px; font-size: 13px; border-radius: 6px; line-height: 1.4;
}
#game-log { overflow-y: auto; font-size: 11.5px; height: 120px; }
#game-log p { padding: 2px 0; border-bottom: 1px dashed #2c4a45; color: #cfe0d5; }
#game-log p:last-child { color: #fff; font-weight: 600; }
#game-log-full p { padding: 4px 0; border-bottom: 1px dashed #2c4a45; color: #cfe0d5; font-size: 14px; }
#game-log-full p:last-child { color: #fff; font-weight: 600; }

/* ===== chat ===== */
#chat-fab, #log-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 70;
  width: 46px; height: 46px; border-radius: 50%; font-size: 20px;
  background: rgba(27,47,45,.85); border: 1px solid #3a5a55;
  display: flex; align-items: center; justify-content: center;
}
#log-fab { bottom: 70px; }
#chat-fab:hover, #log-fab:hover { background: var(--panel2); }
/* no web o log vive no ícone 📜; a caixinha embutida é só do mobile */
.log-mini { display: none; }
#chat-panel { bottom: 124px; }
#chat-unread {
  position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff;
  border-radius: 50%; min-width: 18px; height: 18px; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
#chat-panel {
  position: fixed; right: 16px; bottom: 72px; z-index: 70;
  width: 300px; height: 280px; background: #142523;
  border: 1px solid #3a5a55; border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.chat-head { padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--accent); border-bottom: 1px solid #2c4a45; }
#chat-msgs { flex: 1; overflow-y: auto; padding: 8px 10px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
#chat-msgs .cm b { color: var(--accent); }
#chat-msgs .cm.mine b { color: var(--green); }
#chat-form { display: flex; border-top: 1px solid #2c4a45; }
#chat-form input { border: none; border-radius: 0; background: transparent; flex: 1; font-size: 13px; }
#chat-form button { border: none; border-radius: 0; background: transparent; font-size: 15px; padding: 6px 12px; }

/* zoom de carta (botão direito) */
.zoom-box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 480px; text-align: center;
}
.zoom-box img {
  max-height: 68vh; max-width: 90vw; border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.7);
}
#zoom-caption {
  background: var(--panel); border-radius: 12px; padding: 12px 18px;
  font-size: 15px; max-width: 420px;
}
#zoom-caption .zc-title { font-weight: 700; color: var(--accent); font-size: 17px; }
#zoom-caption .zc-sub { color: var(--muted); font-size: 12px; margin-bottom: 6px; }

/* animação de revelação/recrutamento */
.card.flipping { transform: rotateY(90deg) !important; }
#played-cards .card { transition: transform .25s ease; backface-visibility: hidden; }
.fly-clone { pointer-events: none; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #fff; padding: 10px 20px; border-radius: 10px;
  z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.toast.info { background: var(--panel2); border: 1px solid var(--accent); color: var(--ink); }
.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(227,178,60,.55); } }

/* telas médias: aperta espaçamentos para tudo caber */
@media (max-width: 1350px) {
  .side-col { padding: 8px; gap: 6px; }
  .hand { gap: 4px; }
  .inplay { grid-template-columns: repeat(auto-fill, minmax(48px, 64px)); gap: 6px; }
  .bm-inplay .bmcard { font-size: 10px; max-width: 150px; }
  .bm-inplay .bmcard .bm-art { height: 34px; }
  #game-log { height: 100px; }
  .zone-head { font-size: 12px; }
}
@media (max-width: 1100px) {
  .lobby-main { grid-template-columns: 1fr; }
  .game-grid { grid-template-columns: 1fr; }
  .board-wrap { order: -1; }
  .hand .card { max-width: 92px; }
}
