:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #1f2330;
  --muted: #6b7080;
  --line: #d9d4c7;
  --x: #e0474c;
  --o: #2f7fd8;
  --accent: #1f2330;
  --accent-text: #ffffff;
  --win: #ffe89a;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171e;
    --surface: #1f222c;
    --text: #eceef4;
    --muted: #9aa0b2;
    --line: #343846;
    --x: #ff6b70;
    --o: #5aa5ff;
    --accent: #eceef4;
    --accent-text: #15171e;
    --win: #4a4220;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 420px;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 {
  margin: 8px 0;
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.x { color: var(--x); font-weight: 800; }
.o { color: var(--o); font-weight: 800; }

[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.card p { margin: 0 0 16px; color: var(--muted); }

#game { display: flex; flex-direction: column; gap: 16px; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }

.invite { text-align: left; }
.invite p { margin-bottom: 10px; }
.link-row { display: flex; gap: 8px; }
.link-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
#share { margin-top: 10px; width: 100%; }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.score {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.score span { font-size: 0.85rem; }
.score.draw span { color: var(--muted); font-size: 0.75rem; }
.score strong { font-size: 1.4rem; }
.score small { color: var(--muted); font-size: 0.7rem; min-height: 1em; }
.score.active[data-symbol="X"] { border-color: var(--x); box-shadow: 0 0 0 2px var(--x) inset; }
.score.active[data-symbol="O"] { border-color: var(--o); box-shadow: 0 0 0 2px var(--o) inset; }

.status {
  margin: 0;
  text-align: center;
  font-weight: 600;
  min-height: 1.5em;
}

.board {
  display: grid;
  /* minmax(0, 1fr) impede que o conteúdo (X/O) altere o tamanho das colunas/linhas */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px;
  aspect-ratio: 1;
  width: 100%;
}
.cell {
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  font-size: clamp(2.5rem, 14vw, 4rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
.cell:disabled { cursor: default; }
.board.playable .cell:not(:disabled):hover { background: var(--bg); }
.cell.X { color: var(--x); }
.cell.O { color: var(--o); }
.cell.win { background: var(--win); }
.cell.pop { animation: pop 0.2s ease-out; }
@keyframes pop { from { transform: scale(0.6); opacity: 0.3; } to { transform: scale(1); opacity: 1; } }

.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: calc(100% - 32px);
}
