:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #12131d;
  color: #f5f3ff;
  --subtle: #aba9bd;
  --surface: #1d1e2c;
  --tile: #282a3c;
  --border: #34364a;
  --purple: #c3afff;
  --mint: #71ead2;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(ellipse at 50% 0%, #2a2244, transparent 29rem);
}
.shell {
  width: min(100%, 30rem);
  margin: 0 auto;
  padding: calc(1.5rem + env(safe-area-inset-top)) clamp(1rem, 5vw, 2rem)
    calc(1.5rem + env(safe-area-inset-bottom));
}
header { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.35rem; }
h1 { font-size: clamp(1.45rem, 6vw, 2.05rem); letter-spacing: -.055em; margin: 0; line-height: 1.1; }
.logo {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .1em;
  padding: .5rem;
  background: #352951;
  border: 1px solid #51406d;
  border-radius: .8rem;
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1;
}
.x { color: var(--purple); }
.o { color: var(--mint); }
button, input { font: inherit; }
button { border: 0; border-radius: .7rem; color: inherit; cursor: pointer; min-height: 2.75rem; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: .25rem;
  margin-bottom: .8rem;
  border: 1px solid var(--border);
  border-radius: .9rem;
  background: #181925;
}
.modes button { background: transparent; color: var(--subtle); font-weight: 650; }
.modes button[aria-pressed="true"] { background: #393050; color: #f6efff; }
.game { background: var(--surface); border: 1px solid var(--border); border-radius: 1.15rem; padding: .85rem; }
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  min-height: 2rem;
  margin: 0 .15rem .7rem;
  font-size: .8rem;
  font-weight: 650;
  color: var(--subtle);
}
#status { text-align: right; color: var(--mint); }
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .45rem; }
.cell {
  display: grid;
  place-items: center;
  min-height: 0;
  aspect-ratio: 1;
  background: var(--tile);
  border: 1px solid var(--border);
  border-radius: .8rem;
}
.cell:not(:disabled):hover { background: #34354e; border-color: #656287; }
.cell.win { background: #34304a; border-color: currentColor; }
.cell span { display: block; position: relative; width: 48%; aspect-ratio: 1; }
.cell.o span { border: clamp(4px, 1.5vw, 7px) solid currentColor; border-radius: 50%; }
.cell.x span::before, .cell.x span::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 118%;
  height: clamp(4px, 1.5vw, 7px);
  border-radius: 1rem;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(45deg);
}
.cell.x span::after { transform: translate(-50%, -50%) rotate(-45deg); }
.score { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; margin-top: .65rem; }
.score div { display: grid; gap: .25rem; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: .8rem; padding: .5rem; }
.score span { color: var(--subtle); font-size: .76rem; }
.score strong { font-size: 1.35rem; line-height: 1; }
.bottom, .invite-actions { display: flex; gap: .45rem; }
.bottom { margin-top: .65rem; }
.bottom button, .invite-actions button { flex: 1; }
.primary, .secondary { padding-inline: .75rem; font-weight: 700; }
.primary { color: #231837; background: var(--purple); }
.secondary { background: var(--tile); }
.primary:hover, .secondary:hover { filter: brightness(1.1); }
.primary:disabled { opacity: .65; }
#room-menu { text-align: center; padding: 1.5rem .5rem 1.85rem; }
p { color: var(--subtle); font-size: .9rem; line-height: 1.5; }
#notice { margin: .65rem 0 0; color: #f8cdbb; }
.invite p { margin: .75rem 0 .4rem; }
.invite input { width: 100%; margin-bottom: .5rem; padding: .55rem; border: 1px solid var(--border); border-radius: .55rem; background: #151621; color: var(--subtle); }
