/* ====================================================================
   Gomoku multijogador — folha de estilo
   (variaveis de base, botões e inputs partilhados vêm de ../base.css)
   ==================================================================== */

:root {
  --wood-1: #e3b872;
  --wood-2: #c9954c;
  --grid: rgba(60, 38, 12, .62);
  --stone-black: #1b211e;
  --stone-white: #f5f0e4;
}

html, body { height: 100%; margin: 0; }
body { overflow: hidden; }

.screen { height: 100%; }

/* ------------------------------------------------------------ ecrã inicial */

#home {
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  overflow: auto;
  padding: 24px 16px;
}

.home-card {
  width: min(470px, 100%);
  background: linear-gradient(180deg, rgba(28,44,35,.95), rgba(15,25,20,.95));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 28px 22px;
  box-shadow: 0 30px 70px rgba(0,0,0,.55);
}
.home-card .backhome { margin: -8px 0 10px -6px; }

.logo {
  margin: 0 0 4px;
  font-size: 36px;
  letter-spacing: -.02em;
  text-align: center;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.logo .pip {
  width: 20px; height: 20px; border-radius: 50%;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.5);
}
.logo .pip.black { background: radial-gradient(circle at 34% 28%, #4c5a54, var(--stone-black) 70%); }
.logo .pip.white { background: radial-gradient(circle at 34% 28%, #fff, #cfc6b2 78%); }
.tagline { margin: 0 0 26px; text-align: center; color: var(--txt-dim); font-size: 14px; }

.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--txt-dim); margin-bottom: 6px; }

.home-actions { display: grid; gap: 14px; }
.home-actions .btn.primary { padding: 13px; font-size: 16px; }
.or { text-align: center; color: var(--txt-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.joinrow { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.code-input { text-transform: uppercase; letter-spacing: .35em; font-weight: 700; text-align: center; }

.error { color: var(--danger); font-size: 13px; margin: 14px 0 0; text-align: center; }

.rules { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.rules summary { cursor: pointer; color: var(--txt-dim); font-size: 13px; }
.rules-body { font-size: 13px; color: var(--txt-dim); }
.rules-body p { margin: 10px 0; }
.rules-body strong { color: var(--txt); }
.rules-body em { color: var(--txt); font-style: normal; }

.home-foot { color: #5f7268; font-size: 12px; padding: 14px; text-align: center; }

.seg { display: grid; gap: 8px; }
.seg2 { grid-template-columns: 1fr 1fr; }
.seg3 { grid-template-columns: repeat(3, 1fr); }
.segbtn {
  background: rgba(0,0,0,.32);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 4px;
  cursor: pointer;
  color: var(--txt-dim);
  font-size: 14px; font-weight: 700;
  transition: border-color .15s, background .15s, color .15s;
}
.segbtn em { display: block; font-style: normal; font-size: 10px; font-weight: 500; opacity: .75; margin-top: 2px; }
.segbtn:hover { border-color: rgba(255,255,255,.22); color: var(--txt); }
.segbtn.on { border-color: #3ec488; background: rgba(62,196,136,.12); color: var(--txt); }

/* ------------------------------------------------------------- a mesa --- */

#room {
  display: grid;
  grid-template-columns: 1fr 330px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "stage panel";
  height: 100%;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: rgba(0,0,0,.35);
  border-bottom: 1px solid var(--line);
}
.room-code { display: flex; align-items: center; gap: 8px; }
.room-code .label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--txt-dim); }
.room-code strong { font-size: 19px; letter-spacing: .18em; color: var(--gold); }

.scoreboard {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  overflow-x: auto; max-width: 55%;
}
.scoreboard .schip {
  display: flex; align-items: baseline; gap: 5px;
  background: rgba(0,0,0,.3); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; white-space: nowrap; flex: none;
}
.scoreboard .schip .n { font-size: 11px; color: var(--txt-dim); max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
.scoreboard .schip .p { font-size: 14px; font-weight: 800; color: var(--gold); }
.scoreboard .schip.you { border-color: rgba(62,196,136,.5); background: rgba(62,196,136,.12); }
.scoreboard .target { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--txt-dim); flex: none; margin-left: 4px; }

/* --------------------------------------------------------------- palco --- */

.stage {
  grid-area: stage;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  padding: 12px 14px 14px;
  gap: 10px;
}

/* ----------------------------------------------------------- jogadores --- */

.players { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.pcardbox {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.36);
  border: 1px solid rgba(255,255,255,.10);
  transition: box-shadow .2s, border-color .2s, background .2s;
  min-width: 180px;
}
.pcardbox.turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(242,193,78,.35), 0 0 22px rgba(242,193,78,.28);
  background: rgba(60,45,10,.5);
}
.pcardbox.you { border-left: 3px solid #3ec488; }
.pcardbox.offline .pname { color: var(--txt-dim); }
.pcardbox.empty { opacity: .6; }

.stone-badge {
  width: 30px; height: 30px; border-radius: 50%;
  flex: none;
  box-shadow: inset 0 -3px 4px rgba(0,0,0,.4), 0 2px 5px rgba(0,0,0,.5);
}
.stone-badge.b { background: radial-gradient(circle at 34% 28%, #4c5a54, var(--stone-black) 72%); }
.stone-badge.w { background: radial-gradient(circle at 34% 28%, #fff, #cec5b1 80%); }
.stone-badge.none { background: rgba(255,255,255,.08); box-shadow: none; }

.pcardbox .who { min-width: 0; flex: 1; }
.pcardbox .pname { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.pcardbox .meta { font-size: 10.5px; color: var(--txt-dim); display: flex; gap: 5px; align-items: center; white-space: nowrap; }
.pcardbox .chip {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px;
}
.pcardbox .chip.ready { color: var(--green); border-color: rgba(46,163,106,.5); }

/* ---------------------------------------------------------- tabuleiro --- */

.boardwrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  /* Nada de overflow:auto: com o tabuleiro quadrado por aspect-ratio, uma
     barra de deslocamento estreitaria a caixa, que encolheria, que faria
     desaparecer a barra... sem fim. */
  overflow: hidden;
}

.boardbox {
  width: min(100%, 72vh, 640px);
  aspect-ratio: 1 / 1;
  padding: 2.6%;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--wood-1), var(--wood-2));
  box-shadow: 0 22px 50px rgba(0,0,0,.55), inset 0 0 0 1px rgba(255,255,255,.14);
}

/* Uma célula por intersecção. As linhas passam pelo meio de cada uma, o que
   dá a grelha certa do gomoku: joga-se nos cruzamentos, não nos quadrados. */
.board {
  width: 100%; height: 100%;
  display: grid;
  gap: 0;
}

.pt {
  position: relative;
  border: none;
  padding: 0;
  background: transparent;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}
.pt::before,
.pt::after {
  content: '';
  position: absolute;
  background: var(--grid);
}
.pt::before { left: 0; right: 0; top: 50%; height: 1px; transform: translateY(-.5px); }
.pt::after { top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-.5px); }
/* Nas bordas a linha só sai para dentro. */
.pt.first-col::before { left: 50%; }
.pt.last-col::before { right: 50%; }
.pt.first-row::after { top: 50%; }
.pt.last-row::after { bottom: 50%; }

/* Pontos de referência (hoshi). */
.pt.star { background-image: radial-gradient(circle at 50% 50%, var(--grid) 0 14%, transparent 14%); }

.pt.playable { cursor: pointer; }

.stone {
  position: absolute;
  left: 50%; top: 50%;
  width: 86%; height: 86%;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  transition: transform .16s ease, opacity .12s ease;
  z-index: 2;
  pointer-events: none;
  box-shadow: 0 .12em .28em rgba(0,0,0,.45);
}
.pt[data-v="b"] .stone,
.pt[data-v="w"] .stone { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.pt[data-v="b"] .stone { background: radial-gradient(circle at 33% 27%, #5a6862, var(--stone-black) 68%); }
.pt[data-v="w"] .stone { background: radial-gradient(circle at 33% 27%, #fff, #cdc4af 78%); }

/* Sombra da pedra que ias pôr. */
.pt.playable:hover .stone {
  transform: translate(-50%, -50%) scale(1);
  opacity: .42;
  background: var(--my-stone, #888);
}

/* Onde a regra de abertura deixa jogar. */
.pt.allowed::before,
.pt.allowed::after { background: rgba(62,196,136,.55); }
.pt.allowed .stone { opacity: .16; transform: translate(-50%, -50%) scale(.8); background: #3ec488; }
.pt.allowed.playable:hover .stone { opacity: .42; transform: translate(-50%, -50%) scale(1); background: var(--my-stone, #888); }

/* Última jogada e linha vencedora. */
.pt.last .stone { box-shadow: 0 0 0 .12em var(--gold), 0 .12em .28em rgba(0,0,0,.45); }
.pt.win .stone {
  box-shadow: 0 0 0 .14em #fff, 0 0 .6em .1em rgba(255,255,255,.75);
  animation: winpulse 1.2s ease-in-out infinite;
}
@keyframes winpulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.14); }
}

.turnhint { font-size: 13px; color: var(--txt-dim); min-height: 20px; text-align: center; }
.turnhint.active { color: var(--gold); font-weight: 600; }
.turnhint .aviso { color: #7fd6a8; }

/* --------------------------------------------------------------- lobby */

.lobby {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: auto;
  background: rgba(4,10,7,.66);
  z-index: 5;
}
.lobby-card {
  background: rgba(6,14,10,.93);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 24px;
  width: min(540px, 100%);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.lobby-card h2 { margin: 0 0 4px; font-size: 20px; }
.lobby-card .sub { margin: 0 0 18px; color: var(--txt-dim); font-size: 13px; }

.seatgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.seatslot {
  border: 1px solid var(--line);
  border-left: 3px solid rgba(255,255,255,.25);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,.03);
  display: flex; align-items: center; gap: 10px;
  min-height: 62px;
}
.seatslot .slotinfo { min-width: 0; flex: 1; }
.seatslot .slotname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seatslot .slotsub { font-size: 11px; color: var(--txt-dim); }
.seatslot .slotactions { display: flex; gap: 6px; }
.seatslot .chip.you {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px; color: var(--txt-dim);
}

.lobby-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.lobby-opts label > span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--txt-dim); display: block; margin-bottom: 4px; }
.lobby-opts select {
  width: 100%;
  background: #0e1713;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--txt);
  padding: 9px 10px;
  font: inherit;
}
.lobby-foot { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.lobby-foot .btn.primary { flex: 1; padding: 12px; }
.invite { font-size: 12px; color: var(--txt-dim); margin-top: 12px; text-align: center; word-break: break-all; }

/* --------------------------------------------------------------- painel */

.panel {
  grid-area: panel;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}
.panel-tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 6px 12px; cursor: pointer; color: var(--txt-dim); font-size: 13px;
}
.tab.active { background: var(--panel-2); border-color: var(--line); color: var(--txt); }
.panel-body { min-height: 0; position: relative; }
.tabpane { display: none; height: 100%; min-height: 0; }
.tabpane.active { display: grid; grid-template-rows: 1fr auto; }
.tabpane[data-pane="log"], .tabpane[data-pane="info"] { overflow: auto; display: none; }
.tabpane[data-pane="log"].active, .tabpane[data-pane="info"].active { display: block; padding: 12px; }

.chatlog { overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 7px; }
.msg { font-size: 13.5px; }
.msg .from { font-weight: 700; color: var(--gold); }
.msg.sys { color: var(--txt-dim); font-style: italic; font-size: 12.5px; }
.chatform { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

.log { list-style: none; margin: 0; padding: 0; font-size: 12.5px; color: var(--txt-dim); }
.log li { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.05); }

.info-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.06); font-size: 13px; gap: 10px; }
.info-row .k { color: var(--txt-dim); flex: none; }
#tableInfo h4 { margin: 16px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--txt-dim); }

/* ------------------------------------------------------ modal / toast --- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(2,8,5,.82);
  display: grid; place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal {
  background: linear-gradient(180deg, #1a2a21, #101a14);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 28px;
  width: min(460px, 100%);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  text-align: center;
}
.modal h2 { margin: 0 0 6px; font-size: 24px; }
.modal .sub { color: var(--txt-dim); margin: 0 0 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.badge-result {
  display: inline-block; margin-bottom: 10px;
  padding: 4px 14px; border-radius: 999px;
  background: rgba(242,193,78,.16); border: 1px solid rgba(242,193,78,.45);
  color: var(--gold); font-weight: 700; font-size: 13px;
  text-transform: uppercase; letter-spacing: .08em;
}
.finalscore { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 16px 0 6px; }
.finalscore .side { display: grid; justify-items: center; gap: 6px; }
.finalscore .side .stone-badge { width: 38px; height: 38px; }
.finalscore .side .big { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.finalscore .side .nm { font-size: 12px; color: var(--txt-dim); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finalscore .side.win .big { color: var(--gold); }
.finalscore .vs { color: var(--txt-dim); font-size: 13px; }

.toast {
  position: fixed;
  bottom: 22px; left: 50%; transform: translateX(-50%);
  background: rgba(10,18,13,.95);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13.5px;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  max-width: 90vw;
}
.toast.bad { border-color: rgba(255,107,107,.5); color: #ffb3b3; }

.only-mobile { display: none; }

/* ------------------------------------------------------------ responsivo */

@media (max-width: 1080px) {
  #room { grid-template-columns: 1fr 290px; }
}

@media (max-width: 860px) {
  #room {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "stage";
  }
  .panel {
    position: fixed; inset: 0 0 0 auto;
    width: min(360px, 92%);
    z-index: 40;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: -20px 0 50px rgba(0,0,0,.5);
  }
  .panel.open { transform: none; }
  .only-mobile { display: grid; margin-left: auto; }
  .scoreboard { max-width: 40%; }
  .scoreboard .schip .n { display: none; }
  .boardbox { width: min(100%, 64vh); }
  .pcardbox { min-width: 0; padding: 4px 10px 4px 6px; gap: 7px; }
  .pcardbox .meta { display: none; }
  .stone-badge { width: 24px; height: 24px; }
  .seatgrid, .lobby-opts { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar { gap: 8px; padding: 6px 8px; }
  .room-code .label { display: none; }
  .stage { padding: 8px; gap: 8px; }
  .boardbox { border-radius: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .stone { transition: opacity .1s; }
  .pt.win .stone { animation: none; }
}
