:root {
  color-scheme: light;
  --bg: #f6f0e8;
  --ink: #1b1530;
  --muted: #655d73;
  --coral: #f27b62;
  --line: #1b1530;
  --paper: #fffdf9;
  --peach: #fde4d4;
  --sky: #d7eefc;
  --mint: #dcf3df;
  font-family: Outfit, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(rgba(27, 21, 48, 0.16) 1.1px, transparent 1.2px),
    linear-gradient(115deg, rgba(246, 240, 232, 0.2), rgba(214, 228, 244, 0.85));
  background-size: 22px 22px, 100% 100%;
}

button, a { font: inherit; color: inherit; }

.nav, main {
  width: min(1080px, calc(100% - 32px));
  margin-inline: auto;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 22px;
  padding: 22px 0 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  text-decoration: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand strong {
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}

.brand-text span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.mark {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 14px;
  background:
    linear-gradient(var(--paper), var(--paper)) 9px 9px / 10px 10px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 23px 9px / 10px 10px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 9px 23px / 10px 10px no-repeat,
    linear-gradient(var(--coral), var(--coral)) 23px 23px / 10px 10px no-repeat,
    var(--ink);
}

.hub-back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--coral);
}

.hub-back .arrow {
  display: block;
  width: 1em;
  line-height: 1;
  text-align: center;
}

.exit-game {
  padding: 0.45rem 0.9rem;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--coral);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(27, 21, 48, 0.12);
}

.nav .exit-game.hidden { display: none; }

main { flex: 1; padding: 18px 0 36px; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 6px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3aaa5a;
}

h1 {
  margin: 0;
  max-width: 12ch;
  font-family: Fraunces, Georgia, serif;
  font-weight: 700;
  font-size: clamp(3.2rem, 7vw, 5.4rem);
  letter-spacing: -0.045em;
  line-height: 0.95;
}

h1 em {
  font-style: italic;
  font-weight: 620;
  color: var(--coral);
}

.lede {
  max-width: 36rem;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.5;
}

.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 28px;
}

.mode {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-height: 180px;
  padding: 18px;
  text-align: left;
  border: 2.5px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 10px 0 rgba(27, 21, 48, 0.06);
  cursor: pointer;
}

.mode strong {
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.mode span:last-child {
  color: var(--muted);
  line-height: 1.4;
}

.mode-index {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.tone-peach { background: var(--peach); }
.tone-sky { background: var(--sky); }
.tone-lilac { background: #e7e0f8; }

.mode:hover { transform: translateY(-2px); }

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: min(100%, 720px);
  margin-inline: auto;
  padding-top: 12px;
}

.stage h2 {
  margin: 8px 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2.6rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.stage h2 em {
  font-style: italic;
  font-weight: 620;
  color: var(--coral);
}

.online-forms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  width: 100%;
  margin-top: 22px;
}

.panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 18px;
  text-align: left;
  border: 2.5px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 10px 0 rgba(27, 21, 48, 0.06);
}

.panel h3 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.panel label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 700;
}

.panel input {
  border: 2.5px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
}

.panel .btn { width: 100%; }

.online-error {
  min-height: 1.4em;
  margin: 14px 0 8px;
  color: #c4372a;
  font-weight: 700;
}

.share-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100%, 420px);
  margin-top: 22px;
  padding: 22px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  background: var(--peach);
  box-shadow: 0 10px 0 rgba(27, 21, 48, 0.06);
}

.share-card span {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2rem, 5vw, 2.8rem);
  letter-spacing: 0.12em;
  line-height: 1;
}

#copy-lobby {
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  padding: 8px 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

.lobby-players {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: min(100%, 420px);
  margin: 16px 0 18px;
  padding: 0;
  list-style: none;
}

.lobby-players li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 64px;
  padding: 10px 12px;
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
}

.lobby-players b {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.5rem;
}

#lobby-x b { color: var(--coral); }

.lobby-players li.is-wait {
  color: var(--muted);
  background: transparent;
}

#lobby { text-align: center; }

#lobby .lede { margin-inline: auto; }

.mode-label {
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.status {
  margin: 10px 0 0;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.status.is-result {
  font-style: italic;
  color: var(--coral);
}

#table .stage { width: min(100%, 980px); }

.play-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
  margin-top: 22px;
}

.leaderboard {
  width: 280px;
  flex: none;
  padding: 14px 14px 6px;
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 10px 0 rgba(27, 21, 48, 0.06);
  text-align: left;
}

.leaderboard h3 {
  margin: 0 0 8px;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  text-align: center;
}

.leaderboard table { width: 100%; border-collapse: collapse; }

.leaderboard th,
.leaderboard td {
  padding: 0.7rem 0.35rem;
  text-align: left;
  border-bottom: 2px solid rgba(27, 21, 48, 0.12);
}

.leaderboard th {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.leaderboard tr:last-child td { border-bottom: 0; }

.leaderboard .wins {
  text-align: right;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.25rem;
}

.leaderboard .mark-x,
.leaderboard .mark-o {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.15rem;
}

.leaderboard .mark-x { color: var(--coral); }

.leaderboard tr.is-on td { background: var(--peach); }

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 118px));
  gap: 12px;
  width: fit-content;
  padding: 16px;
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  background: var(--peach);
  box-shadow: 0 10px 0 rgba(27, 21, 48, 0.06);
}

.cell {
  width: 118px;
  height: 118px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  font-family: Fraunces, Georgia, serif;
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.cell:hover:not(:disabled) { background: #fff; }

.cell:disabled { cursor: default; }

.cell.x { color: var(--coral); }
.cell.o { color: var(--ink); }

.cell.winning {
  background: var(--mint);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.btn {
  padding: 12px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--coral);
}

.btn-quiet {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(27, 21, 48, 0.12);
}

.btn-exit {
  background: var(--paper);
  color: var(--coral);
  box-shadow: 3px 3px 0 rgba(27, 21, 48, 0.12);
}

.leave-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(27, 21, 48, 0.45);
}

.leave-modal.hidden { display: none; }

.leave-card {
  width: min(400px, 100%);
  padding: 22px 20px 18px;
  text-align: center;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  box-shadow: 7px 7px 0 var(--ink);
}

.leave-card h3 {
  margin: 0 0 6px;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.7rem;
  font-weight: 620;
}

.leave-card p {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 600;
}

.leave-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.hidden { display: none; }

@media (max-width: 900px) {
  .modes, .online-forms { grid-template-columns: 1fr; }
  .play-row { flex-direction: column; }
  .leaderboard { width: min(100%, 420px); }
}

@media (max-width: 720px) {

  .board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(100%, 380px);
  }

  .cell {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    font-size: 2.6rem;
  }
}
