:root {
  --paper: #f8f6ef;
  --tile: #fcf9ef;
  --edge: #e8e3d7;
  --ink: #1e201a;
  --olive: #40592a;
  --rust: #b9512d;
  --board: min(350px, 46svh);
  color: var(--ink);
  background: var(--paper) radial-gradient(circle, #d8d2c2 0.8px, transparent 1.1px) center / 23px 23px;
  font-family: system-ui, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 30px 20px;
}

button, input { font: inherit; }

.game {
  width: min(100%, 445px);
  text-align: center;
}

h1 {
  font-size: clamp(2.9rem, 10vw, 4.5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.052em;
  margin: 0 0 30px;
}

#start { padding-top: clamp(20px, 8vh, 62px); }

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(6px, 2vw, 9px);
  width: min(100%, var(--board));
  margin-inline: auto;
}

.cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border-radius: clamp(12px, 4vw, 18px);
  border: 1.5px solid var(--edge);
  background: var(--tile);
  color: inherit;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button.cell[aria-disabled="false"] { cursor: pointer; }
button.cell[aria-disabled="false"]:hover { background: #f0f1e4; border-color: #bac4a6; }
button.cell[aria-disabled="false"]:active { transform: scale(0.95); }
.cell.win { background: #e7eedc; border-color: #a1b58c; }
.cell.win:has(.o) { background: #f7e5da; border-color: #d6ab96; }

.mark {
  display: grid;
  place-items: center;
  width: 62%;
  aspect-ratio: 1;
  position: relative;
  container-type: inline-size;
}

.cell .mark.x { width: 71%; }

.mark.x::before, .mark.x::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  height: 19%;
  border-radius: 100px;
  background: var(--olive);
  transform: rotate(45deg);
}

.mark.x::after { transform: rotate(-45deg); }

.mark.o::before {
  content: "";
  width: 100%;
  aspect-ratio: 1;
  border: 18cqw solid var(--rust);
  border-radius: 50%;
  box-sizing: border-box;
}

.scores {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.score {
  display: grid;
  place-items: center;
  gap: 5px;
  border-radius: 18px;
  border: 1.5px solid var(--edge);
  background: var(--tile);
  padding: 10px;
  font-weight: 700;
  font-size: 1.08rem;
}

.score-value {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 1.65rem;
  line-height: 1;
}

.score-value .mark { width: 24px; }

.status {
  min-height: 1.4em;
  margin: 20px 0;
  font-size: clamp(1.05rem, 4.5vw, 1.5rem);
  font-weight: 750;
  letter-spacing: -0.025em;
}

.action {
  width: 100%;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  padding: 12px 14px;
  border: 2px solid var(--olive);
  border-radius: 15px;
  font-size: clamp(1rem, 4.5vw, 1.3rem);
  font-weight: 750;
  line-height: 1.15;
  text-decoration: none;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.action:active { transform: translateY(2px); }
.action:disabled { opacity: 0.66; cursor: wait; }
.action.primary { color: #fffef8; background: var(--olive); }
.action.primary:hover:not(:disabled) { background: #31471f; }
.action.secondary { color: var(--ink); background: var(--tile); }
.action.secondary:hover { background: #f1efe5; }
#create { margin-top: clamp(32px, 6vh, 54px); }
#copy, #next, #home { margin-top: 26px; }

.arrow {
  position: absolute;
  right: 24px;
  width: 22px;
  height: 3px;
  border-radius: 3px;
  background: currentColor;
}

.arrow::after {
  content: "";
  position: absolute;
  right: 0;
  top: -5px;
  width: 10px;
  height: 10px;
  border-top: 3px solid;
  border-right: 3px solid;
  transform: rotate(45deg);
  border-radius: 2px;
}

.link {
  position: relative;
  width: 27px;
  height: 20px;
  flex: none;
  color: var(--olive);
  transform: rotate(-42deg);
}

.link::before, .link::after {
  content: "";
  position: absolute;
  top: 4px;
  width: 14px;
  height: 7px;
  border: 2px solid;
  border-radius: 12px;
}
.link::before { left: 0; }
.link::after { right: 0; }

:focus-visible { outline: 3px solid var(--olive); outline-offset: 3px; }

.notice { margin: 16px 0 0; font-weight: 650; }

#invite {
  margin-top: 10px;
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--tile);
  color: var(--ink);
}

@media (max-width: 480px) {
  body { padding: 24px 18px; }
  h1 { margin-bottom: 24px; }
  .scores { gap: 9px; }
  .status { margin: 16px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
