/* Jogo da Velha — tema único (azul-noite, coral, turquesa, dourado). Sem fontes externas, sem estilos inline. */
:root {
  --bg: #0b1226;
  --bg2: #101a33;
  --surface: #16224a;
  --surface2: #1c2b5c;
  --line: rgba(160, 180, 255, .16);
  --text: #eef2ff;
  --muted: #9fb0d9;
  --x: #ff6b57;
  --o: #2bb7a6;
  --gold: #ffd166;
  --danger: #ff8a7a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--font); color: var(--text); line-height: 1.45;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2c66 0%, transparent 60%), var(--bg);
  display: flex; flex-direction: column;
}
a { color: var(--gold); }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: rgba(11, 18, 38, .85);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: .2px; white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: url("../img/favicon.svg") center / cover no-repeat; flex: none; }
.topbar-right { display: inline-flex; align-items: center; gap: 14px; }
.toplink { color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem; padding: 6px 10px; border-radius: 10px; }
.toplink:hover { color: var(--text); background: var(--surface); }

/* ---------- botões ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-weight: 700; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.2; min-height: 44px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--surface2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, #ff826f, var(--x)); border-color: transparent; color: #2a0c07; box-shadow: 0 6px 18px rgba(255, 107, 87, .28); }
.btn-primary:hover { background: linear-gradient(180deg, #ff9382, #ff745f); }
.btn-ghost { background: transparent; }
.btn-teal { background: linear-gradient(180deg, #3cc9b8, var(--o)); border-color: transparent; color: #04211d; }
.btn-teal:hover { background: linear-gradient(180deg, #52d6c6, #33c0ae); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- páginas (início / ranking) ---------- */
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 28px 16px 40px; flex: 1; }
.hero { text-align: center; margin-bottom: 22px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(1.9rem, 5vw, 2.6rem); line-height: 1.1; letter-spacing: -.5px; }
.hero h1 .x { color: var(--x); } .hero h1 .o { color: var(--o); }
.hero p { margin: 0; color: var(--muted); font-size: 1.05rem; }

.notice { background: rgba(255, 138, 122, .12); border: 1px solid rgba(255, 138, 122, .45); color: #ffd3cc; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }

.card { background: linear-gradient(180deg, var(--surface), #131d40); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card .sub { margin: 0 0 14px; color: var(--muted); font-size: .95rem; }
.cards { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin-top: 16px; }
@media (max-width: 620px) { .cards { grid-template-columns: 1fr; } }

.nickbox { margin-bottom: 16px; }
.field { display: block; }
.field > span { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #0e1731; color: var(--text); min-height: 46px;
}
.input[readonly] { color: var(--gold); font-weight: 700; }
.input::placeholder { color: #6f80ad; }
.hint { margin: 8px 2px 0; font-size: .88rem; color: var(--muted); min-height: 1.3em; }
.hint.warn { color: var(--danger); }

.play-card { display: flex; align-items: center; gap: 18px; padding: 22px; }
.play-card .txt { flex: 1; min-width: 0; }
.play-card .btn { flex: none; min-width: 170px; font-size: 1.05rem; padding: 14px 22px; }
.mini-board { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 78px; height: 78px; }
.mini-board i { background: rgba(255, 255, 255, .07); border-radius: 6px; position: relative; }
@media (max-width: 560px) {
  .play-card { flex-direction: column; text-align: center; }
  .play-card .btn { width: 100%; }
}

/* escolha de símbolo */
.symbols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 14px; }
.sym-opt input { position: absolute; opacity: 0; pointer-events: none; }
.sym-opt span {
  display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 8px; border-radius: 12px;
  border: 2px solid var(--line); background: #0e1731; cursor: pointer; font-weight: 700; min-height: 52px;
}
.sym-opt input:checked + span { border-color: var(--gold); background: #17234d; }
.sym-opt input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }

/* glifos X e O desenhados em CSS */
.g-x, .g-o { display: inline-block; width: 22px; height: 22px; position: relative; flex: none; }
.g-x::before, .g-x::after { content: ""; position: absolute; left: 50%; top: -2px; width: 4px; height: 26px; margin-left: -2px; background: var(--x); border-radius: 3px; transform: rotate(45deg); }
.g-x::after { transform: rotate(-45deg); }
.g-o { border: 4px solid var(--o); border-radius: 50%; }

.links { text-align: center; margin-top: 22px; }
.links a { color: var(--muted); font-weight: 600; }

/* ---------- rodapé ---------- */
.site-footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 16px; border-top: 1px solid var(--line); }
.site-footer p { margin: 2px 0; }

/* ---------- ranking ---------- */
.tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.tabs .btn[aria-pressed="true"] { background: var(--surface2); border-color: var(--gold); color: var(--gold); }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.rank { width: 100%; border-collapse: collapse; }
.rank th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 14px; background: #131d40; }
.rank td { padding: 12px 14px; border-top: 1px solid var(--line); }
.rank .num { text-align: right; font-variant-numeric: tabular-nums; }
.rank td.pos { width: 54px; color: var(--muted); font-weight: 700; }
.rank td.pts { font-weight: 800; color: var(--gold); }
.rank tr.top1 td.pos, .rank tr.top2 td.pos, .rank tr.top3 td.pos { color: #1b1300; }
.medal { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 800; font-size: .85rem; color: #1b1300; }
.medal.m1 { background: #ffd166; } .medal.m2 { background: #d5dbe8; } .medal.m3 { background: #e0a070; }
.who { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; word-break: break-word; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
@media (max-width: 520px) {
  .rank th, .rank td { padding: 10px 8px; }
  .rank .hide-sm { display: none; }
}

/* ---------- avatar ---------- */
.avatar { position: relative; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; flex: none; background: #22336f; display: grid; place-items: center; border: 2px solid var(--line); }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar .initial { font-size: 1.25rem; color: var(--muted); text-transform: uppercase; }
.avatar.sm { width: 32px; height: 32px; } .avatar.sm .initial { font-size: .95rem; }

/* ---------- partida ---------- */
.game { width: 100%; max-width: 560px; margin: 0 auto; padding: 14px 14px 22px; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.messages { width: 100%; }
.alert { background: rgba(255, 138, 122, .14); border: 1px solid rgba(255, 138, 122, .5); color: #ffd3cc; padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; font-size: .92rem; }

.versus { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: stretch; gap: 10px; }
.pcard {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-width: 0;
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; transition: border-color .2s, box-shadow .2s;
}
.pcard.active { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(255, 209, 102, .12); }
.pinfo { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pname { font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.psub { font-size: .78rem; color: var(--muted); min-height: 1em; }
.pcard .badge { flex: none; }
.pcard .badge .g-x, .pcard .badge .g-o { width: 20px; height: 20px; }
.pcard .badge .g-x::before, .pcard .badge .g-x::after { height: 24px; }
.pcard.offline { opacity: .7; }

.clock {
  align-self: center; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums;
  background: conic-gradient(var(--gold) var(--pct, 0%), rgba(255, 255, 255, .1) 0);
  position: relative;
}
.clock::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--bg2); }
.clock span { position: relative; }
.clock.urgent { color: var(--danger); animation: pulse .8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

@media (max-width: 460px) {
  .versus { grid-template-columns: 1fr 1fr; }
  .clock { grid-column: 1 / -1; grid-row: 1; justify-self: center; width: 48px; height: 48px; font-size: 1rem; }
  .pcard { padding: 8px; gap: 8px; }
  .avatar { width: 42px; height: 42px; }
}

.status-text { margin: 2px 0 0; font-size: 1.15rem; font-weight: 700; text-align: center; min-height: 1.5em; }
.status-text.mine { color: var(--gold); }

.board-wrap { position: relative; width: min(100%, 440px, calc(100dvh - 380px)); min-width: 250px; aspect-ratio: 1; }
.board { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); grid-template-rows: repeat(var(--n, 3), 1fr); gap: 8px; }
.board[data-n="4"] { gap: 6px; }
.board[data-n="5"] { gap: 5px; }
.board[data-n="4"] .cell { border-radius: 12px; }
.board[data-n="5"] .cell { border-radius: 10px; }
.board[data-n="4"] .cell svg { width: 66%; height: 66%; }
.board[data-n="5"] .cell svg { width: 70%; height: 70%; }
.board[data-n="5"] .cell svg path, .board[data-n="5"] .cell svg circle { stroke-width: 12; }
.cell {
  appearance: none; border: 0; border-radius: 14px; background: linear-gradient(180deg, var(--surface2), var(--surface));
  display: grid; place-items: center; padding: 0; cursor: default; position: relative;
  box-shadow: inset 0 0 0 1px var(--line); transition: background .15s, transform .08s;
}
.cell.playable { cursor: pointer; }
.cell.playable:hover { background: linear-gradient(180deg, #27397a, #1d2d63); }
.cell.playable:active { transform: scale(.97); }
.cell.last { box-shadow: inset 0 0 0 2px rgba(255, 209, 102, .55); }
.cell.win { background: linear-gradient(180deg, #3a3a1f, #2c2a17); box-shadow: inset 0 0 0 2px var(--gold); }
.cell svg { width: 62%; height: 62%; overflow: visible; }
.cell .mk-x { stroke: var(--x); } .cell .mk-o { stroke: var(--o); }
.cell svg path, .cell svg circle { fill: none; stroke-width: 14; stroke-linecap: round; }
.cell svg .draw { stroke-dasharray: 100; stroke-dashoffset: 100; animation: draw .32s ease-out forwards; }
.cell svg .draw2 { animation-delay: .16s; }
.cell.fresh svg .draw { }
@keyframes draw { to { stroke-dashoffset: 0; } }
.cell.old svg .draw { animation: none; stroke-dashoffset: 0; }
/* prévia fantasma do símbolo na casa livre (só computador) */
@media (hover: hover) {
  .cell.playable.ghost-x:hover::after, .cell.playable.ghost-o:hover::after { content: ""; position: absolute; width: 34%; height: 34%; opacity: .35; }
  .cell.playable.ghost-o:hover::after { border: 7px solid var(--o); border-radius: 50%; }
  .cell.playable.ghost-x:hover::after { background:
      linear-gradient(45deg, transparent 43%, var(--x) 43% 57%, transparent 57%),
      linear-gradient(-45deg, transparent 43%, var(--x) 43% 57%, transparent 57%); }
}

.win-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-line line { stroke: var(--gold); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 400; stroke-dashoffset: 400; animation: line .5s ease-out .15s forwards; filter: drop-shadow(0 0 6px rgba(255, 209, 102, .7)); }
@keyframes line { to { stroke-dashoffset: 0; } }

.invite { width: 100%; text-align: center; background: var(--surface); border: 1px dashed rgba(255, 209, 102, .5); border-radius: 14px; padding: 12px; }
.invite p { margin: 0 0 8px; color: var(--muted); font-size: .92rem; }
.code-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.code-row code { font-size: 1.25rem; font-weight: 800; letter-spacing: .12em; color: var(--gold); background: #0e1731; padding: 8px 14px; border-radius: 10px; }
.actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- diálogos ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(5, 9, 22, .72); display: grid; place-items: center; padding: 16px; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.dialog { width: min(100%, 380px); background: linear-gradient(180deg, var(--surface2), var(--surface)); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px 22px; text-align: center; box-shadow: var(--shadow); animation: pop .22s ease; }
@keyframes pop { from { transform: translateY(10px) scale(.96); opacity: 0; } }
.dialog-icon { font-size: 2.6rem; line-height: 1; margin-bottom: 8px; }
.dialog-title { margin: 0 0 6px; font-size: 1.5rem; }
.dialog-title.win { color: var(--gold); } .dialog-title.lose { color: var(--danger); }
.dialog-text { margin: 0 0 18px; color: var(--muted); }
.dialog-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.dialog-actions .btn { flex: 1; min-width: 130px; }

/* ---------- compartilhar ---------- */
.share { position: relative; display: inline-block; }
.share-btn { display: inline-flex; align-items: center; gap: 8px; flex: none; width: max-content; white-space: nowrap; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer; min-height: 40px; }
.share-btn:hover { background: var(--surface2); }
.share-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: 250px; margin: 0; padding: 8px; list-style: none; background: #14204a; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.share-title { display: none; font-weight: 800; padding: 6px 10px 10px; }
.share-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; border: 0; background: transparent; color: var(--text); text-decoration: none; border-radius: 10px; cursor: pointer; text-align: left; font-weight: 600; }
.share-item:hover { background: var(--surface2); }
.share-ico { display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none; }
.share-backdrop { display: none; }
@media (max-width: 700px) {
  .share-menu { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; border-radius: 20px 20px 0 0; padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); z-index: 70; }
  .share-title { display: block; }
  .share-backdrop { display: block; position: fixed; inset: 0; background: rgba(5, 9, 22, .6); z-index: 65; }
  .share-backdrop[hidden] { display: none; }
  .share-btn-txt { display: none; }
  .share-btn { padding: 8px 10px; }
}
#f-join .btn { margin-top: 14px; }

/* escolha do tamanho do tabuleiro */
.sizebox { margin-bottom: 16px; }
.sizebox > span { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.size-opt input { position: absolute; opacity: 0; pointer-events: none; }
.size-opt span { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border-radius: 12px; border: 2px solid var(--line); background: #0e1731; cursor: pointer; font-weight: 800; min-height: 64px; justify-content: center; }
.size-opt small { font-weight: 500; color: var(--muted); font-size: .75rem; }
.size-opt input:checked + span { border-color: var(--gold); background: #17234d; }
.size-opt input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }
.card .sizes { margin-bottom: 12px; }
.card .size-opt span { min-height: 54px; padding: 8px 4px; }
