:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --background: oklch(1 0 0);
  --surface: oklch(0.97 0.004 235);
  --surface-strong: oklch(0.94 0.007 235);
  --ink: oklch(0.22 0.025 279);
  --muted: oklch(0.48 0.014 235);
  --muted-light: oklch(0.63 0.012 235);
  --border: oklch(0.87 0.009 235);
  --border-strong: oklch(0.72 0.016 235);
  --mint-soft: oklch(0.94 0.045 164);
  --mint-base: oklch(0.76 0.145 164);
  --mint-strong: oklch(0.56 0.145 164);
  --mint-ink: oklch(0.3 0.075 164);
  --sand-soft: oklch(0.94 0.025 85);
  --sand-base: oklch(0.79 0.065 85);
  --sand-ink: oklch(0.37 0.055 85);
  --danger-soft: oklch(0.95 0.025 24);
  --danger: oklch(0.52 0.16 24);
  --danger-strong: oklch(0.4 0.14 24);
  --radius-small: 8px;
  --radius-medium: 12px;
  --radius-large: 16px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --header-height: 68px;
  --z-banner: 20;
  --z-dialog: 40;
  --z-toast: 50;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--background);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--background);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:not(:disabled),
a {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid oklch(0.7 0.13 164 / 0.46);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--radius-small);
  background: var(--ink);
  color: white;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.site-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
  padding: max(12px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--background);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 750;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.pixel-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 5px);
  grid-template-rows: repeat(3, 5px);
  gap: 2px;
  width: 19px;
  height: 19px;
}

.pixel-mark i {
  display: block;
  width: 5px;
  height: 5px;
  background: var(--mint-strong);
}

.pixel-mark i:nth-child(1) { grid-area: 1 / 1; }
.pixel-mark i:nth-child(2) { grid-area: 1 / 3; }
.pixel-mark i:nth-child(3) { grid-area: 2 / 2; }
.pixel-mark i:nth-child(4) { grid-area: 3 / 1; }
.pixel-mark i:nth-child(5) { grid-area: 3 / 3; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.connection-pill,
.identity-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border-radius: 999px;
}

.connection-pill {
  padding: 7px 11px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.connection-dot,
.quiet-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint-strong);
}

.connection-pill[data-state="connecting"] .connection-dot,
.connection-pill[data-state="retrying"] .connection-dot {
  background: var(--sand-base);
}

.connection-pill[data-state="closed"] .connection-dot,
.connection-pill[data-state="error"] .connection-dot {
  background: var(--danger);
}

.identity-button {
  padding: 3px 10px 3px 4px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 680;
  transition: background-color 160ms var(--ease-out);
}

.identity-button:hover {
  background: var(--surface);
}

.avatar-dot,
.dialog-mark {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--mint-soft);
  color: var(--mint-ink);
  font-weight: 800;
}

.avatar-dot {
  width: 29px;
  height: 29px;
  font-size: 0.75rem;
}

.connection-banner {
  position: sticky;
  top: 0;
  z-index: var(--z-banner);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 42px;
  padding: 8px 20px;
  background: var(--sand-soft);
  color: var(--sand-ink);
  font-size: 0.88rem;
  font-weight: 650;
}

.text-button,
.back-button {
  border: 0;
  padding: 5px;
  background: transparent;
  color: inherit;
  font-weight: 720;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

main {
  width: 100%;
}

.screen {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 64px 0 max(80px, env(safe-area-inset-bottom));
}

.restoring-screen,
.expired-screen {
  display: grid;
  min-height: calc(100dvh - var(--header-height));
  place-items: center;
  padding-block: 32px;
}

.restore-card,
.expired-card {
  width: min(420px, 100%);
  text-align: center;
}

.restore-mark,
.expired-symbol {
  display: inline-block;
  margin-bottom: 18px;
  color: var(--mint-strong);
  font-size: 2rem;
  font-weight: 820;
  letter-spacing: 0.08em;
}

.restore-card h1,
.expired-card h1 {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.restore-card p,
.expired-card p {
  max-width: 38ch;
  margin: 12px auto 24px;
  color: var(--muted);
}

.loading-dots {
  display: inline-flex;
  gap: 5px;
}

.loading-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint-strong);
  animation: loading-pulse 900ms var(--ease-out) infinite alternate;
}

.loading-dots i:nth-child(2) { animation-delay: 120ms; }
.loading-dots i:nth-child(3) { animation-delay: 240ms; }

@keyframes loading-pulse {
  to { opacity: 0.28; transform: translateY(-2px); }
}

.home-screen {
  width: min(980px, calc(100% - 48px));
}

.home-hero {
  max-width: 680px;
  margin: 24px 0 54px;
}

.hero-mark {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 1.55rem;
  font-weight: 850;
  letter-spacing: 0.08em;
}

.hero-mark span,
.game-symbol span,
.game-card-mark span:last-child {
  color: var(--mint-strong);
}

.home-hero h1 {
  max-width: 12ch;
  margin: 0;
  font-size: clamp(2.8rem, 8vw, 5.4rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.home-hero > p:last-child {
  max-width: 42ch;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.18rem);
  text-wrap: pretty;
}

.home-actions {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 72px;
}

.button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-small);
  border: 1px solid transparent;
  font-weight: 760;
  line-height: 1.1;
  cursor: pointer;
  transition: transform 110ms var(--ease-out), background-color 160ms var(--ease-out), border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
}

.button:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: none;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-primary {
  border-color: var(--mint-strong);
  background: var(--mint-base);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--mint-strong);
}

.button-primary:not(:disabled):hover {
  background: oklch(0.79 0.15 164);
}

.button-secondary {
  border-color: var(--border-strong);
  background: var(--background);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--border-strong);
}

.button-secondary:not(:disabled):hover,
.button-quiet:not(:disabled):hover {
  background: var(--surface);
}

.button-quiet {
  border-color: var(--border);
  background: var(--surface);
  color: var(--ink);
}

.button-danger {
  border-color: var(--danger-strong);
  background: var(--danger);
  color: white;
  box-shadow: 0 2px 0 var(--danger-strong);
}

.button-large {
  min-height: 52px;
  padding-inline: 26px;
}

.button-small {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 0.78rem;
}

.join-form {
  width: min(360px, 100%);
}

.join-form > label,
.dialog label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.84rem;
  font-weight: 720;
}

.join-row {
  display: flex;
  gap: 8px;
}

input {
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-small);
  background: var(--background);
  color: var(--ink);
  padding: 10px 12px;
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

input::placeholder {
  color: var(--muted);
  opacity: 1;
}

input:focus {
  border-color: var(--mint-strong);
  box-shadow: 0 0 0 3px oklch(0.8 0.11 164 / 0.22);
  outline: 0;
}

.join-row input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 760;
}

.field-hint,
.field-error {
  display: block;
  min-height: 1.2em;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.78rem;
}

.field-error {
  color: var(--danger);
}

.game-catalog {
  width: min(560px, 100%);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading h2,
.invite-panel h2,
.chat-heading h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.015em;
}

.section-heading > span {
  color: var(--muted);
  font-size: 0.8rem;
}

.game-card {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  background: var(--background);
  width: 100%;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms var(--ease-out), background-color 160ms var(--ease-out), transform 110ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

.game-card:hover {
  border-color: var(--mint-strong);
  transform: translateY(-1px);
}

.game-card:active {
  transform: translateY(1px);
}

.game-card[aria-pressed="true"] {
  border-color: var(--mint-strong);
  background: var(--mint-soft);
  box-shadow: 0 2px 0 var(--mint-base);
}

.game-card + .game-card {
  margin-top: 10px;
}

.game-card-soon {
  background: var(--surface);
  color: var(--muted);
}

.game-card-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 850;
}

.game-card-available .game-card-mark {
  background: var(--mint-soft);
}

.compact-grid {
  color: var(--muted-light);
  font-size: 1.1rem;
}

.game-card-copy h3,
.game-card-copy p {
  margin: 0;
}

.game-card-copy small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 680;
}

.gomoku-card-mark {
  padding: 11px;
}

.gomoku-dot-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: 100%;
  aspect-ratio: 1;
}

.gomoku-dot-grid i {
  display: block;
  align-self: center;
  justify-self: center;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border-strong);
}

.gomoku-dot-grid i:nth-child(8),
.gomoku-dot-grid i:nth-child(13),
.gomoku-dot-grid i:nth-child(18) {
  width: 8px;
  height: 8px;
  background: var(--ink);
}

.gomoku-dot-grid i:nth-child(19),
.gomoku-dot-grid i:nth-child(20) {
  width: 8px;
  height: 8px;
  border: 1px solid var(--border-strong);
  background: var(--background);
}

.game-card-copy h3 {
  font-size: 1rem;
}

.game-card-copy p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.83rem;
}

.game-card-status,
.sand-tag,
.state-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 760;
}

.game-card-status {
  padding: 5px 9px;
  background: var(--mint-soft);
  color: var(--mint-ink);
}

.game-card-soon .game-card-status {
  background: var(--surface-strong);
  color: var(--muted);
}

.invite-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: min(680px, 100%);
  margin: -20px 0 42px;
  padding: 18px;
  border: 1px solid var(--sand-base);
  border-radius: var(--radius-medium);
  background: var(--sand-soft);
}

.invite-card h2,
.invite-card p {
  margin: 0;
}

.invite-card h2 {
  margin-top: 6px;
  font-size: 1.05rem;
}

.invite-card p {
  margin-top: 3px;
  color: var(--sand-ink);
  font-size: 0.86rem;
}

.sand-tag {
  width: fit-content;
  margin: 0;
  padding: 5px 10px;
  background: var(--sand-soft);
  color: var(--sand-ink);
}

.room-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 56px;
}

.back-button {
  color: var(--muted);
  text-decoration: none;
}

.back-button:hover {
  color: var(--ink);
}

.room-code-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--sand-soft);
  color: var(--sand-ink);
  font-size: 0.76rem;
}

.room-code-chip strong {
  letter-spacing: 0.12em;
}

.lobby-screen {
  width: min(760px, calc(100% - 48px));
}

.lobby-heading {
  max-width: 560px;
  margin-bottom: 40px;
}

.game-symbol {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
  font-size: 1.8rem;
  font-weight: 850;
  letter-spacing: 0.08em;
}

.symbol-stone {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.symbol-stone-black {
  background: var(--ink);
}

.symbol-stone-white {
  border: 2px solid var(--border-strong);
  background: var(--background);
}

.lobby-heading h1 {
  margin: 14px 0 0;
  font-size: clamp(2.2rem, 6vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.lobby-heading > p:last-child {
  margin: 14px 0 0;
  color: var(--muted);
}

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

.player-seat {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 80px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
}

.player-seat[data-empty="true"] {
  border-style: dashed;
  color: var(--muted);
}

.seat-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  font-weight: 800;
}

.player-seat[data-self="true"] .seat-avatar {
  background: var(--mint-soft);
  color: var(--mint-ink);
}

.seat-copy {
  min-width: 0;
}

.seat-copy strong,
.seat-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-copy span,
.seat-status {
  color: var(--muted);
  font-size: 0.76rem;
}

.host-tag {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--sand-soft);
  color: var(--sand-ink);
  font-size: 0.68rem;
  font-weight: 760;
  vertical-align: 1px;
}

.seat-status[data-online="true"] {
  color: var(--mint-ink);
}

.lobby-actions {
  margin-top: 24px;
  text-align: center;
}

.lobby-actions .button {
  width: min(360px, 100%);
}

.lobby-actions p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.invite-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 54px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.invite-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.invite-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.game-screen {
  padding-top: 34px;
}

.game-topline {
  margin-bottom: 28px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 0.92fr);
  align-items: start;
  gap: 42px;
}

.board-panel {
  min-width: 0;
}

.game-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.round-label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.game-heading-row h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  letter-spacing: -0.035em;
}

.state-badge {
  padding: 6px 10px;
  background: var(--mint-soft);
  color: var(--mint-ink);
}

.state-badge[data-state="paused"],
.state-badge[data-state="finished"] {
  background: var(--sand-soft);
  color: var(--sand-ink);
}

.game-players {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 16px;
}

.game-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  border-radius: var(--radius-small);
  background: var(--surface);
}

.game-player:last-child {
  flex-direction: row-reverse;
  text-align: right;
}

.game-player[data-active="true"] {
  background: var(--mint-soft);
}

.player-mark {
  display: grid;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 7px;
  background: var(--background);
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 850;
}

.player-mark[data-mark="O"] {
  color: var(--mint-strong);
}

.player-mark[data-mark="BLACK"] {
  color: var(--ink);
  font-size: 1.35rem;
}

.player-mark[data-mark="WHITE"] {
  border: 1px solid var(--border-strong);
  background: var(--background);
  color: var(--background);
  font-size: 1.35rem;
  text-shadow: 0 0 0 var(--border-strong);
}

.game-player-name {
  min-width: 0;
}

.game-player-name strong,
.game-player-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-player-name strong {
  font-size: 0.86rem;
}

.game-player-name span {
  color: var(--muted);
  font-size: 0.7rem;
}

.versus {
  align-self: center;
  color: var(--muted-light);
  font-size: 0.7rem;
  font-weight: 800;
}

.turn-status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  min-height: 48px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-small);
  background: var(--surface);
}

.turn-status strong {
  font-size: 0.92rem;
}

.turn-status span {
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

.turn-status.is-your-turn {
  background: var(--mint-soft);
}

.turn-status.turn-changed {
  animation: turn-confirm 220ms var(--ease-out);
}

@keyframes turn-confirm {
  50% { transform: translateY(-1px); box-shadow: 0 2px 0 var(--mint-base); }
}

.game-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(6px, 1vw, 10px);
  width: min(100%, 590px);
  margin: 0 auto;
  padding: clamp(8px, 1.4vw, 12px);
  border-radius: var(--radius-medium);
  background: var(--surface-strong);
}

.game-board button {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--background);
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(2.4rem, 9vw, 5.2rem);
  font-weight: 820;
  line-height: 1;
  transition: transform 110ms var(--ease-out), border-color 160ms var(--ease-out), background-color 160ms var(--ease-out);
}

.game-board button:not(:disabled):hover {
  border-color: var(--mint-strong);
  background: var(--mint-soft);
  transform: translateY(-1px);
}

.game-board button:not(:disabled):active,
.game-board button[data-pending="true"] {
  transform: translateY(2px);
}

.game-board button[data-pending="true"]::after {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--mint-strong);
  animation: pending-pulse 650ms var(--ease-out) infinite alternate;
}

@keyframes pending-pulse {
  to { opacity: 0.34; transform: scale(0.72); }
}

.game-board button:disabled {
  cursor: default;
}

.game-board button[data-mark="O"] {
  color: var(--mint-strong);
}

.game-board button[data-winning="true"] {
  border-color: var(--mint-strong);
  background: var(--mint-soft);
}

.game-board button.just-confirmed {
  animation: piece-confirm 230ms var(--ease-out);
}

@keyframes piece-confirm {
  from { transform: scale(0.88); opacity: 0.45; }
  to { transform: scale(1); opacity: 1; }
}

.gomoku-board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  width: min(100%, 650px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: clamp(8px, 1.5vw, 14px);
  border: 1px solid oklch(0.79 0.035 85);
  border-radius: var(--radius-medium);
  background: var(--sand-soft);
  box-shadow: 0 2px 0 oklch(0.77 0.03 85 / 0.45);
  touch-action: manipulation;
}

.gomoku-cell {
  position: relative;
  display: grid;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: default;
}

.gomoku-cell[data-can-move="true"] {
  cursor: pointer;
}

.gomoku-cell:focus-visible {
  z-index: 4;
  outline: 2px solid var(--mint-strong);
  outline-offset: -2px;
}

.gomoku-cross {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
}

.gomoku-cross::before,
.gomoku-cross::after {
  content: "";
  position: absolute;
  background: oklch(0.58 0.025 85 / 0.62);
}

.gomoku-cross::before {
  top: calc(50% - 0.5px);
  left: 0;
  width: 100%;
  height: 1px;
}

.gomoku-cross::after {
  top: 0;
  left: calc(50% - 0.5px);
  width: 1px;
  height: 100%;
}

.gomoku-cell[data-x="0"] .gomoku-cross::before { left: 50%; width: 50%; }
.gomoku-cell[data-x="14"] .gomoku-cross::before { width: 50%; }
.gomoku-cell[data-y="0"] .gomoku-cross::after { top: 50%; height: 50%; }
.gomoku-cell[data-y="14"] .gomoku-cross::after { height: 50%; }

.gomoku-reference-point {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 16%;
  min-width: 3px;
  max-width: 5px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: oklch(0.46 0.025 85 / 0.72);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.gomoku-stone {
  position: relative;
  z-index: 2;
  display: block;
  width: 72%;
  aspect-ratio: 1;
  border: 0 solid transparent;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.72);
  pointer-events: none;
  transition: opacity 120ms var(--ease-out), transform 120ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

.gomoku-cell[data-stone="BLACK"] .gomoku-stone,
.gomoku-cell[data-pending-stone="BLACK"] .gomoku-stone {
  background: var(--ink);
}

.gomoku-cell[data-stone="WHITE"] .gomoku-stone,
.gomoku-cell[data-pending-stone="WHITE"] .gomoku-stone {
  border-width: 2px;
  border-color: var(--border-strong);
  background: var(--background);
}

.gomoku-cell[data-stone]:not([data-stone=""]) .gomoku-stone {
  opacity: 1;
  transform: scale(1);
}

.gomoku-cell[data-pending="true"] .gomoku-stone {
  opacity: 0.42;
  transform: scale(0.82);
  animation: pending-pulse 650ms var(--ease-out) infinite alternate;
}

.gomoku-cell[data-pending="true"]::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 84%;
  aspect-ratio: 1;
  border: 2px solid var(--mint-strong);
  border-radius: 50%;
  pointer-events: none;
}

@media (hover: hover) {
  .gomoku-cell[data-can-move="true"]:hover .gomoku-stone {
    opacity: 0.18;
    transform: scale(0.78);
  }

  .gomoku-cell[data-preview-stone="BLACK"]:hover .gomoku-stone {
    background: var(--ink);
  }

  .gomoku-cell[data-preview-stone="WHITE"]:hover .gomoku-stone {
    border-width: 2px;
    border-color: var(--border-strong);
    background: var(--background);
  }
}

.gomoku-cell[data-last-move="true"] .gomoku-stone::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--mint-strong);
  transform: translate(-50%, -50%);
}

.gomoku-cell[data-winning="true"] .gomoku-stone {
  box-shadow: 0 0 0 2px var(--mint-strong), 0 0 0 4px var(--mint-soft);
}

.gomoku-cell.just-confirmed .gomoku-stone {
  animation: piece-confirm 230ms var(--ease-out);
}

.round-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.gomoku-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 36px;
  margin: -4px 0 10px;
}

.gomoku-actions[hidden] {
  display: none;
}

.gomoku-actions span {
  color: var(--muted);
  font-size: 0.76rem;
}

.gomoku-actions .button:disabled {
  opacity: 0.52;
  cursor: default;
  transform: none;
}

.round-actions span {
  max-width: 32ch;
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 520px;
  max-height: min(680px, calc(100dvh - 150px));
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  background: var(--surface);
  overflow: hidden;
}

.chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-heading span:not(.quiet-dot) {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.quiet-dot {
  background: var(--mint-strong);
}

.chat-messages {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 16px;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.chat-message {
  max-width: 88%;
  margin-bottom: 14px;
}

.chat-message[data-self="true"] {
  margin-left: auto;
  text-align: right;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
}

.chat-message[data-self="true"] .message-meta {
  justify-content: flex-end;
}

.message-body {
  display: inline-block;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--background);
  color: var(--ink);
  font-size: 0.84rem;
  text-align: left;
  overflow-wrap: anywhere;
}

.chat-message[data-self="true"] .message-body {
  background: var(--mint-soft);
}

.chat-empty {
  margin: auto;
  padding: 20px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--background);
}

.chat-form input {
  flex: 1;
  min-height: 42px;
  background: var(--surface);
}

.send-button {
  min-width: 54px;
  border: 0;
  border-radius: var(--radius-small);
  background: var(--ink);
  color: white;
  font-weight: 720;
  cursor: pointer;
  transition: transform 110ms var(--ease-out), background-color 160ms var(--ease-out);
}

.send-button:hover {
  background: var(--mint-ink);
}

.send-button:active {
  transform: translateY(1px);
}

.dialog {
  width: min(430px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-large);
  background: var(--background);
  color: var(--ink);
  box-shadow: 0 8px 0 oklch(0.2 0.02 279 / 0.12);
}

.dialog::backdrop {
  background: oklch(0.18 0.02 279 / 0.42);
}

.dialog[open] {
  animation: dialog-in 190ms var(--ease-out);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
}

.dialog form {
  position: relative;
  padding: 28px;
}

.dialog h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.025em;
}

.dialog p {
  margin: 8px 0 22px;
  color: var(--muted);
}

.dialog input {
  width: 100%;
}

.nickname-dialog .button {
  width: 100%;
  margin-top: 8px;
}

.dialog-mark {
  width: 44px;
  height: 44px;
  margin-bottom: 16px;
}

.undo-dialog-mark {
  display: grid;
  place-items: center;
  border-radius: var(--radius-small);
  background: var(--mint-soft);
  color: var(--mint-ink);
  font-size: 1.4rem;
  font-weight: 780;
}

.dialog-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  font-size: 1.2rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.toast {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: grid;
  gap: 2px;
  width: min(360px, calc(100% - 40px));
  padding: 13px 15px;
  border-radius: var(--radius-small);
  background: var(--ink);
  color: white;
  box-shadow: 0 4px 0 oklch(0.12 0.02 279 / 0.2);
  animation: toast-in 180ms var(--ease-out);
}

.toast strong {
  font-size: 0.86rem;
}

.toast span {
  color: oklch(0.86 0.01 235);
  font-size: 0.78rem;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (max-width: 820px) {
  .screen,
  .home-screen,
  .lobby-screen {
    width: min(680px, calc(100% - 32px));
  }

  .screen {
    padding-top: 44px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 34px;
  }

  .game-board {
    width: min(100%, 560px);
  }

  .gomoku-board {
    width: min(100%, 620px);
  }

  .chat-panel {
    min-height: 360px;
    max-height: 460px;
  }
}

@media (max-width: 600px) {
  :root { --header-height: 62px; }

  .site-header {
    padding-inline: max(16px, env(safe-area-inset-left));
  }

  .connection-pill {
    width: 12px;
    min-height: 12px;
    padding: 0;
    background: transparent;
  }

  .connection-pill #connection-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .identity-button {
    padding-right: 4px;
  }

  .identity-button > span:last-child {
    display: none;
  }

  .screen,
  .home-screen,
  .lobby-screen {
    width: calc(100% - 32px);
    padding-top: 36px;
  }

  .home-hero {
    margin-top: 14px;
    margin-bottom: 38px;
  }

  .home-hero h1 {
    font-size: clamp(2.7rem, 14vw, 4rem);
  }

  .home-actions {
    flex-direction: column;
    margin-bottom: 54px;
  }

  .home-actions > .button,
  .join-form {
    width: 100%;
  }

  .invite-card {
    align-items: stretch;
    flex-direction: column;
  }

  .game-card {
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 12px;
  }

  .game-card-mark {
    width: 52px;
    height: 52px;
  }

  .game-card-status {
    display: none;
  }

  .room-topline {
    margin-bottom: 38px;
  }

  .player-seats {
    grid-template-columns: 1fr;
  }

  .invite-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .invite-actions .button {
    flex: 1;
  }

  .game-topline {
    margin-bottom: 22px;
  }

  .game-players {
    grid-template-columns: 1fr 20px 1fr;
  }

  .game-player {
    align-items: flex-start;
    flex-direction: column;
  }

  .game-player:last-child {
    flex-direction: column;
    align-items: flex-end;
  }

  .turn-status {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .turn-status span {
    text-align: left;
  }

  .game-board {
    gap: 6px;
    padding: 7px;
  }

  .game-board button {
    font-size: clamp(2.5rem, 17vw, 4.6rem);
  }

  .gomoku-board {
    padding: 7px;
    border-radius: 10px;
  }

  .gomoku-cell {
    border-radius: 2px;
  }

  .gomoku-cell[data-stone="WHITE"] .gomoku-stone,
  .gomoku-cell[data-pending-stone="WHITE"] .gomoku-stone {
    border-width: 1.5px;
  }

  .round-actions {
    align-items: stretch;
    flex-direction: column;
    text-align: center;
  }

  .chat-panel {
    min-height: 340px;
    max-height: 58dvh;
  }

  .dialog form {
    padding: 24px 20px;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .button {
    width: 100%;
  }

  .toast {
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: calc(100% - 32px);
  }
}

@media (max-width: 360px) {
  .brand > span:last-child {
    font-size: 0.9rem;
  }

  .home-hero h1 {
    font-size: 2.65rem;
  }

  .join-row {
    align-items: stretch;
    flex-direction: column;
  }

  .room-code-chip span {
    display: none;
  }

  .game-player {
    padding: 8px;
  }

  .player-mark {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
