:root {
  color-scheme: light dark;
  --ink: #101828;
  --ink-strong: #030712;
  --muted: #475467;
  --muted-strong: #344054;
  --on-dark: #f8fafc;
  --on-dark-strong: #ffffff;
  --on-dark-muted: #d7e3ef;
  --on-dark-soft: #b8c8d8;
  --line: rgba(17, 24, 39, 0.12);
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: #ffffff;
  --table: #f7fafc;
  --accent: #08756f;
  --accent-strong: #07534f;
  --red: #c24150;
  --yellow: #e0a100;
  --green: #15803d;
  --card: #3b5bdb;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  --shadow-deep: 0 34px 90px rgba(15, 23, 42, 0.24);
  --shadow-soft: 0 18px 44px rgba(15, 23, 42, 0.13);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-snap: cubic-bezier(0.19, 1, 0.22, 1);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at 16% 8%, rgba(255, 255, 255, 0.9), transparent 22%),
    radial-gradient(circle at 86% 22%, rgba(59, 91, 219, 0.13), transparent 28%),
    linear-gradient(120deg, rgba(15, 118, 110, 0.14), transparent 30%),
    linear-gradient(240deg, rgba(194, 65, 80, 0.12), transparent 34%),
    #edf1f5;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  text-rendering: geometricPrecision;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: grid;
  place-items: center;
  perspective: 1400px;
}

.tabletop {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(1220px, 100%);
  min-height: min(830px, calc(100vh - 40px));
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  background:
    url("/assets/felt-grain.png"),
    linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.46)),
    var(--table);
  box-shadow: var(--shadow-deep);
  backdrop-filter: blur(22px);
  transform-style: preserve-3d;
  animation: appEntrance 680ms var(--ease-out) both;
}

.tabletop::before,
.tabletop::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
}

.tabletop::before {
  background: url("/assets/surface-light.png") center / cover no-repeat;
  mix-blend-mode: screen;
  opacity: 0.86;
  transform: translate3d(-1%, -1%, 0) scale(1.04);
  animation: ambientDrift 14s ease-in-out infinite;
}

.tabletop::after {
  background:
    url("/assets/surface-vignette.png") center / cover no-repeat,
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat;
  opacity: 0.72;
}

.tabletop > * {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 10px;
}

.eyebrow,
.panel-heading,
.score-label,
.meta-list span,
.status-card span,
.control-group > span,
.hand-title span,
.guide-list span,
.number-control span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

.panel-heading,
.status-card span,
.control-group > span,
.number-control span {
  color: var(--muted-strong);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 950;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 0.96;
  color: var(--ink-strong);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.34);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.match-pill,
.top-setup-button,
.top-undo-button,
.top-new-button {
  position: relative;
  overflow: hidden;
  min-height: 44px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 10px 30px rgba(15, 23, 42, 0.08);
  font-weight: 900;
  color: var(--ink-strong);
  white-space: nowrap;
  transition:
    transform 160ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease,
    opacity 180ms ease,
    background-color 180ms ease;
}

.match-pill::before,
.top-setup-button::before,
.top-undo-button::before,
.top-new-button::before,
.game-tab::before,
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/assets/card-gloss.png") center / cover no-repeat;
  opacity: 0.26;
  pointer-events: none;
}

.top-undo-button,
.top-setup-button,
.top-new-button {
  cursor: pointer;
}

.top-setup-button {
  border-color: rgba(59, 91, 219, 0.22);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.32), transparent 48%),
    rgba(255, 255, 255, 0.76);
}

.top-new-button {
  border-color: rgba(15, 118, 110, 0.24);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 48%),
    var(--accent);
  color: #ffffff;
}

.match-pill {
  color: var(--ink-strong);
}

.top-undo-button span[aria-hidden="true"] {
  font-size: 1.2rem;
  line-height: 1;
}

.top-undo-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.top-setup-button:hover,
.top-undo-button:not(:disabled):hover,
.top-new-button:hover,
.game-tab:hover,
.icon-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
}

.turn-glyph {
  position: relative;
  isolation: isolate;
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8f1ef;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 950;
  box-shadow:
    inset -4px -5px 8px rgba(0, 0, 0, 0.16),
    inset 4px 5px 8px rgba(255, 255, 255, 0.32),
    0 5px 14px rgba(15, 23, 42, 0.12);
  animation: turnPulse 1.8s ease-in-out infinite;
}

.turn-glyph::after {
  content: "";
  position: absolute;
  inset: 12% 16% 56% 18%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.66);
  filter: blur(2px);
  opacity: 0.72;
}

.turn-glyph.black,
.turn-glyph.dark {
  background: radial-gradient(circle at 34% 28%, #4b5563, #111827 58%, #030712);
  color: #ffffff;
}

.turn-glyph.white,
.turn-glyph.light {
  background: radial-gradient(circle at 30% 24%, #ffffff, #eef2f7 58%, #b8c0cc);
  color: #111827;
}

.turn-glyph.red {
  background: radial-gradient(circle at 30% 24%, #ffb0b7, var(--red) 62%, #7f1d1d);
  color: #ffffff;
}

.turn-glyph.yellow {
  background: radial-gradient(circle at 30% 24%, #fff1a6, var(--yellow) 62%, #8a5a00);
  color: #111827;
}

.turn-glyph.card {
  border-radius: 6px;
  background: var(--card);
  color: #ffffff;
}

.turn-glyph.green {
  background: var(--green);
  color: #ffffff;
}

.onboarding-layer {
  display: none;
}

.onboarding-layer.open {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 28px);
}

.onboarding-scrim {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 18, 0.44);
  backdrop-filter: blur(12px);
  animation: resultRise 240ms var(--ease-out) both;
}

.onboarding-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(940px, 100%);
  max-height: min(760px, calc(100vh - 42px));
  padding: clamp(14px, 2vw, 20px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: var(--radius);
  background:
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(244, 247, 250, 0.72));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 34px 90px rgba(3, 7, 18, 0.28);
  animation: appEntrance 360ms var(--ease-out) both;
  color: var(--ink);
}

.onboarding-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/assets/surface-light.png") center / cover no-repeat;
  opacity: 0.44;
  pointer-events: none;
  mix-blend-mode: screen;
}

.onboarding-card > * {
  position: relative;
  z-index: 1;
}

.onboarding-head,
.onboarding-actions,
.onboarding-room {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.onboarding-head div {
  display: grid;
  gap: 3px;
}

.onboarding-head span,
.onboarding-section > span {
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 900;
}

.onboarding-head strong {
  font-size: clamp(1.45rem, 3vw, 2.4rem);
  line-height: 1;
  color: var(--ink-strong);
}

.onboarding-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.onboarding-steps button,
.onboarding-count-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  cursor: pointer;
  font-weight: 950;
  color: var(--ink-strong);
}

.onboarding-steps button.active,
.onboarding-count-grid button.active {
  border-color: rgba(15, 118, 110, 0.38);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(232, 241, 239, 0.84)),
    #e8f1ef;
  color: var(--accent-strong);
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.12);
}

.onboarding-body {
  min-height: 0;
  display: grid;
  gap: 14px;
  overflow: auto;
  padding-right: 2px;
}

.onboarding-section {
  display: grid;
  gap: 9px;
}

.onboarding-game-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.onboarding-count-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
}

.onboarding-seat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 9px;
}

.onboarding-seat-grid.has-private {
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
}

.onboarding-room .room-code {
  flex: 1 1 auto;
}

.onboarding-actions {
  justify-content: flex-end;
}

.ai-overview {
  min-height: 126px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.62);
}

.ai-overview strong {
  font-size: clamp(3rem, 9vw, 6.5rem);
  line-height: 0.88;
}

.ai-overview span {
  color: var(--muted-strong);
  font-weight: 900;
}

.onboarding-section.is-muted {
  opacity: 0.52;
}

.game-tab {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 66px;
  padding: 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 10px 26px rgba(15, 23, 42, 0.06);
  cursor: pointer;
  text-align: left;
  color: var(--ink-strong);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease;
}

.game-tab > * {
  position: relative;
  z-index: 1;
}

.game-tab span {
  grid-row: 1 / -1;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f1ef;
  color: var(--accent);
  font-weight: 950;
}

.game-tab strong {
  font-size: 0.95rem;
  line-height: 1.1;
}

.game-tab small {
  color: var(--muted-strong);
  font-weight: 800;
}

.game-tab.active {
  border-color: rgba(15, 118, 110, 0.4);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(232, 241, 239, 0.82)),
    rgba(232, 241, 239, 0.92);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    0 18px 40px rgba(15, 118, 110, 0.18);
  animation: activeBreath 2.8s ease-in-out infinite;
}

.game-layout {
  min-height: min(760px, calc(100vh - 132px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 286px);
  grid-template-areas:
    "board controls"
    "board scores";
  align-items: start;
  gap: 14px;
}

.score-panel {
  grid-area: scores;
}

.action-panel {
  grid-area: controls;
}

.panel {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.54),
    0 16px 44px rgba(15, 23, 42, 0.1);
}

.panel::before {
  opacity: 0.16;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.score-panel,
.action-panel {
  padding: 13px;
}

.panel-heading {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-transform: uppercase;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.68);
  cursor: pointer;
}

.score-grid {
  display: grid;
  gap: 10px;
}

.score-card {
  position: relative;
  overflow: hidden;
  min-height: 72px;
  padding: 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0.24)),
    rgba(255, 255, 255, 0.68);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.58),
    0 10px 24px rgba(15, 23, 42, 0.06);
  color: var(--ink);
}

.score-mark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8f1ef;
  color: var(--accent);
  font-weight: 950;
}

.score-card.black .score-mark {
  background: #111827;
  color: #ffffff;
}

.score-card.white .score-mark {
  background: #ffffff;
  color: #111827;
  box-shadow: inset 0 0 0 1px var(--line);
}

.score-card.red .score-mark {
  background: var(--red);
  color: #ffffff;
}

.score-card.yellow .score-mark {
  background: var(--yellow);
  color: #111827;
}

.score-card.card .score-mark {
  border-radius: 6px;
  background: var(--card);
  color: #ffffff;
}

.score-card strong {
  grid-column: 1 / -1;
  font-size: 1.55rem;
  line-height: 1;
  color: var(--ink-strong);
}

.meta-list {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.meta-list div {
  min-height: 40px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
}

.meta-list strong {
  text-align: right;
  color: var(--ink-strong);
}

.board-zone {
  grid-area: board;
  min-width: 0;
  min-height: 100%;
  display: grid;
  place-items: start center;
  padding-top: 2px;
}

.game-surface {
  width: 100%;
  display: grid;
  place-items: center;
  animation: surfaceSettle 520ms var(--ease-out) both;
}

.board-frame {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 820px, calc(100vh - 126px));
  aspect-ratio: 1;
  padding: clamp(10px, 1.8vw, 18px);
  border: 1px solid rgba(89, 54, 24, 0.28);
  border-radius: var(--radius);
  background:
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
    linear-gradient(135deg, rgba(255, 255, 255, 0.34), rgba(88, 50, 19, 0.1)),
    linear-gradient(30deg, #d7a65a, #f0cf88 46%, #ad7037);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    inset 0 -18px 40px rgba(92, 50, 14, 0.16),
    0 22px 54px rgba(91, 55, 20, 0.2),
    0 3px 0 rgba(83, 47, 19, 0.16);
  transition:
    box-shadow 260ms ease,
    transform 260ms ease;
}

.board-frame::before,
.board-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
}

.board-frame::before {
  background: url("/assets/surface-light.png") center / cover no-repeat;
  opacity: 0.68;
  mix-blend-mode: screen;
  animation: ambientDrift 12s ease-in-out infinite reverse;
}

.board-frame::after {
  background: url("/assets/surface-vignette.png") center / cover no-repeat;
  opacity: 0.48;
}

.board-frame.is-complete {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    inset 0 -18px 40px rgba(92, 50, 14, 0.16),
    0 24px 58px rgba(15, 118, 110, 0.24);
}

#gomokuCanvas {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
  box-shadow:
    inset 0 0 0 1px rgba(70, 41, 16, 0.2),
    0 18px 34px rgba(64, 40, 18, 0.12);
}

.winner-overlay {
  position: absolute;
  inset: clamp(18px, 4vw, 46px);
  display: grid;
  place-items: center;
  gap: 16px;
  align-content: center;
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.78);
  color: #ffffff;
  text-align: center;
  backdrop-filter: blur(12px);
  animation: resultRise 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.winner-overlay strong {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
}

.winner-overlay button,
.primary-button,
.secondary-button {
  min-height: 46px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 950;
  transition:
    transform 160ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease,
    opacity 180ms ease;
}

.winner-overlay button,
.primary-button {
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.22);
}

.secondary-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.action-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 148px);
  overflow: auto;
  overscroll-behavior: contain;
}

.control-group,
.status-card,
.guide-list,
.number-control {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0.18)),
    rgba(255, 255, 255, 0.66);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.control-group,
.status-card,
.guide-list {
  padding: 13px;
}

.status-card {
  display: grid;
  gap: 6px;
}

.status-card strong {
  line-height: 1.25;
  color: var(--ink-strong);
}

.segmented {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.segmented button {
  position: relative;
  overflow: hidden;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  cursor: pointer;
  font-weight: 900;
  color: var(--ink);
}

.segmented button.active {
  border-color: rgba(15, 118, 110, 0.38);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.58), rgba(232, 241, 239, 0.62)),
    #e8f1ef;
  color: var(--accent-strong);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.1);
}

.seat-panel {
  display: grid;
  gap: 12px;
}

.seat-toolbar,
.room-code,
.rack-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.seat-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.seat-toolbar select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  padding: 0 10px;
  font-weight: 950;
}

.compact {
  min-height: 36px;
  padding: 0 12px;
}

.room-code {
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 118, 110, 0.08);
}

.room-code span {
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 900;
}

.room-code strong {
  color: var(--accent-strong);
  letter-spacing: 0.08em;
}

.seat-grid {
  display: grid;
  gap: 8px;
}

.seat-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 74px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0.2)),
    rgba(255, 255, 255, 0.64);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.58),
    0 10px 24px rgba(15, 23, 42, 0.06);
  transition:
    transform 180ms var(--ease-out),
    box-shadow 180ms ease;
  color: var(--ink);
}

.seat-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/assets/card-gloss.png") center / cover no-repeat;
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}

.seat-card > * {
  position: relative;
  z-index: 1;
}

.seat-card:hover {
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 16px 30px rgba(15, 23, 42, 0.1);
}

.seat-card.private-seat a {
  grid-column: 1 / -1;
}

.seat-card.compact-seat {
  min-height: 64px;
}

.seat-card strong,
.seat-card span,
.seat-card a {
  display: block;
}

.seat-card span {
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.seat-card a {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  text-decoration: none;
}

.seat-card .qr {
  width: 54px;
  height: 54px;
  border-radius: 6px;
  image-rendering: pixelated;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.86),
    0 10px 20px rgba(15, 23, 42, 0.1);
}

.ai-chip {
  width: 54px;
  height: 54px;
  display: grid !important;
  place-items: center;
  border-radius: 8px;
  background: #111827;
  color: #ffffff !important;
}

.seat-card.human:not(.private-seat) .ai-chip {
  background: #e8f1ef;
  color: var(--accent-strong) !important;
}

.guide-list {
  display: grid;
  gap: 8px;
}

.guide-list span {
  line-height: 1.35;
  color: var(--ink);
}

.button-stack {
  display: grid;
  gap: 10px;
}

.grid-board {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 800px, calc(100vh - 126px));
  aspect-ratio: 1;
  display: grid;
  gap: 5px;
  padding: clamp(10px, 1.8vw, 16px);
  border-radius: var(--radius);
  background:
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent),
    #0f766e;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -18px 44px rgba(3, 50, 45, 0.22),
    0 22px 54px rgba(15, 118, 110, 0.2);
}

.grid-board::before,
.grid-board::after,
.connect-board::before,
.connect-board::after,
.card-table::before,
.card-table::after,
.mahjong-board::before,
.mahjong-board::after,
.generic-table::before,
.generic-table::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 0;
}

.grid-board::before,
.connect-board::before,
.card-table::before,
.mahjong-board::before,
.generic-table::before {
  background: url("/assets/surface-light.png") center / cover no-repeat;
  opacity: 0.62;
  mix-blend-mode: screen;
  animation: ambientDrift 13s ease-in-out infinite;
}

.grid-board::after,
.connect-board::after,
.card-table::after,
.mahjong-board::after,
.generic-table::after {
  background:
    url("/assets/surface-vignette.png") center / cover no-repeat,
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat;
  opacity: 0.42;
}

.grid-board > *,
.connect-board > *,
.card-table > *,
.mahjong-board > *,
.generic-table > * {
  position: relative;
  z-index: 1;
}

.reversi-board {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.grid-cell {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.045)),
    rgba(255, 255, 255, 0.09);
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -8px 16px rgba(3, 50, 45, 0.1);
  transition:
    transform 160ms var(--ease-out),
    background-color 160ms ease,
    box-shadow 160ms ease;
}

.grid-cell:hover {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -8px 16px rgba(3, 50, 45, 0.1),
    0 8px 18px rgba(15, 23, 42, 0.1);
}

.grid-cell.hint::after,
.hint-dot {
  content: "";
  position: absolute;
  inset: 28%;
  border: 2px dashed rgba(255, 255, 255, 0.52);
  border-radius: 50%;
  animation: hintPulse 1.4s ease-in-out infinite;
}

.disc,
.connect-disc {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  isolation: isolate;
  animation: pieceDrop 420ms var(--ease-snap) both;
  box-shadow:
    inset -4px -6px 10px rgba(0, 0, 0, 0.26),
    inset 4px 6px 10px rgba(255, 255, 255, 0.2),
    0 10px 22px rgba(15, 23, 42, 0.2);
}

.disc::before,
.connect-disc::before {
  content: "";
  position: absolute;
  inset: 62% -20% -28%;
  background: url("/assets/piece-shadow.png") center / 100% 100% no-repeat;
  opacity: 0.72;
  pointer-events: none;
  z-index: -1;
}

.disc::after,
.connect-disc::after {
  content: "";
  position: absolute;
  inset: 8% 18% 56% 18%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0) 66%);
  filter: blur(1px);
  opacity: 0.72;
  pointer-events: none;
}

.disc.dark {
  background: radial-gradient(circle at 34% 28%, #4b5563, #111827 58%, #030712);
}

.disc.light {
  background: radial-gradient(circle at 30% 24%, #ffffff, #eef2f7 58%, #b8c0cc);
}

.connect-board {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 880px, calc((100vh - 138px) * 1.16));
  aspect-ratio: 7 / 6;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius);
  background:
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent),
    #1f4b99;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -20px 44px rgba(11, 36, 84, 0.28),
    0 22px 54px rgba(31, 75, 153, 0.22);
}

.column-hotspot {
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(100% / 7);
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 2;
}

.column-hotspot:nth-child(1) { left: 0%; }
.column-hotspot:nth-child(2) { left: 14.285%; }
.column-hotspot:nth-child(3) { left: 28.57%; }
.column-hotspot:nth-child(4) { left: 42.855%; }
.column-hotspot:nth-child(5) { left: 57.14%; }
.column-hotspot:nth-child(6) { left: 71.425%; }
.column-hotspot:nth-child(7) { left: 85.71%; }

.connect-cell {
  position: relative;
  border-radius: 50%;
  background: rgba(237, 241, 245, 0.94);
  box-shadow:
    inset 0 7px 14px rgba(15, 23, 42, 0.24),
    inset 0 -2px 8px rgba(255, 255, 255, 0.72);
}

.connect-disc.red {
  background: radial-gradient(circle at 30% 24%, #ffb0b7, var(--red) 62%, #7f1d1d);
}

.connect-disc.yellow {
  background: radial-gradient(circle at 30% 24%, #fff1a6, var(--yellow) 62%, #8a5a00);
}

.card-table,
.mahjong-board {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 900px);
  min-height: min(760px, calc(100vh - 132px));
  padding: clamp(16px, 3vw, 28px);
  display: grid;
  align-content: center;
  gap: 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.24);
  background:
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
    radial-gradient(circle at 22% 0%, rgba(255, 255, 255, 0.28), transparent 34%),
    radial-gradient(circle at 82% 18%, rgba(59, 91, 219, 0.18), transparent 36%),
    linear-gradient(145deg, #137365 0%, #1e4f58 50%, #142d3e 100%);
  color: var(--on-dark);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.68),
    inset 0 -28px 60px rgba(2, 18, 28, 0.24),
    0 26px 62px rgba(14, 61, 72, 0.2);
}

.card-table,
.mahjong-board,
.generic-table {
  text-shadow: 0 1px 10px rgba(3, 7, 18, 0.26);
}

.hand-row {
  display: grid;
  gap: 10px;
}

.hand-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hand-title strong {
  font-size: 1.35rem;
}

.card-table .hand-title span {
  color: var(--on-dark-muted);
}

.playing-cards {
  min-height: 138px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  perspective: 900px;
}

.playing-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 86px;
  aspect-ratio: 2.5 / 3.5;
  padding: 10px;
  display: grid;
  align-content: space-between;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 8px;
  background: #ffffff;
  color: #111827;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    inset 0 -10px 20px rgba(15, 23, 42, 0.03),
    0 14px 28px rgba(15, 23, 42, 0.14);
  transform-origin: 50% 85%;
  animation: cardIn 460ms var(--ease-snap) both;
  transition:
    transform 180ms var(--ease-out),
    box-shadow 180ms ease;
  text-shadow: none;
}

.playing-card::after,
.memory-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: url("/assets/card-gloss.png") center / cover no-repeat;
  opacity: 0.54;
  pointer-events: none;
  z-index: 2;
}

.playing-card::before {
  content: "";
  position: absolute;
  inset: 10% -42%;
  background: linear-gradient(105deg, transparent 22%, rgba(255, 255, 255, 0.42) 48%, transparent 66%);
  opacity: 0;
  transform: translateX(-38%) skewX(-12deg);
  pointer-events: none;
  z-index: 3;
  animation: sheenTravel 5.4s ease-in-out infinite;
}

.playing-card:hover {
  transform: translateY(-5px) rotateX(5deg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    inset 0 -10px 20px rgba(15, 23, 42, 0.03),
    0 22px 38px rgba(15, 23, 42, 0.18);
}

.playing-card:nth-child(2) { animation-delay: 36ms; }
.playing-card:nth-child(3) { animation-delay: 72ms; }
.playing-card:nth-child(4) { animation-delay: 108ms; }
.playing-card:nth-child(5) { animation-delay: 144ms; }
.playing-card:nth-child(6) { animation-delay: 180ms; }
.playing-card:nth-child(7) { animation-delay: 216ms; }
.playing-card:nth-child(8) { animation-delay: 252ms; }
.playing-card:nth-child(9) { animation-delay: 288ms; }
.playing-card:nth-child(10) { animation-delay: 324ms; }

.playing-card span {
  font-size: 1.4rem;
  font-weight: 950;
}

.playing-card small {
  font-size: 1.3rem;
}

.playing-card.red-suit {
  color: var(--red);
}

.playing-card.back {
  place-items: center;
  background:
    radial-gradient(circle at 25% 18%, rgba(255, 255, 255, 0.24), transparent 26%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.13) 0 7px, transparent 7px 14px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent),
    var(--card);
  color: #ffffff;
}

.deck-stack {
  position: relative;
  overflow: hidden;
  justify-self: center;
  width: 88px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.12) 0 2px, transparent 2px 8px),
    #111827;
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 14px 28px rgba(15, 23, 42, 0.16);
}

.deck-stack small {
  color: var(--on-dark-muted);
  font-weight: 800;
}

.floating-result {
  position: absolute;
  inset: auto 24px 24px;
  min-height: 58px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.86);
  color: #ffffff;
  font-size: 1.4rem;
  font-weight: 950;
  animation: resultRise 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.memory-board {
  width: min(100%, 620px, calc(100vh - 210px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  perspective: 1100px;
}

.memory-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.34)),
    #dbeafe;
  cursor: pointer;
  font-size: clamp(1.6rem, 5vw, 3rem);
  font-weight: 950;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.54),
    0 14px 28px rgba(15, 23, 42, 0.1);
  transform-style: preserve-3d;
  transition:
    transform 360ms var(--ease-snap),
    background-color 180ms ease,
    opacity 180ms ease,
    box-shadow 180ms ease;
}

.memory-card.visible {
  transform: rotateY(180deg);
  background: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    0 18px 34px rgba(15, 23, 42, 0.15);
}

.memory-card span {
  display: inline-block;
  transform: rotateY(180deg);
}

.memory-card:not(.visible) span {
  transform: none;
  color: rgba(17, 24, 39, 0.38);
}

.memory-card.matched {
  background: #e8f1ef;
  border-color: rgba(15, 118, 110, 0.32);
  animation: matchedPop 480ms var(--ease-snap) both;
}

.memory-score-grid {
  grid-template-columns: 1fr;
}

.mahjong-board {
  text-align: center;
}

.generic-table {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: min(100%, 900px);
  min-height: min(760px, calc(100vh - 132px));
  padding: clamp(18px, 4vw, 34px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius);
  background:
    url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
    radial-gradient(circle at 22% 0%, rgba(255, 255, 255, 0.28), transparent 34%),
    radial-gradient(circle at 82% 18%, rgba(59, 91, 219, 0.18), transparent 36%),
    linear-gradient(145deg, #137365 0%, #1e4f58 50%, #142d3e 100%);
  color: var(--on-dark);
  text-align: center;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.68),
    inset 0 -28px 60px rgba(2, 18, 28, 0.24),
    0 26px 62px rgba(14, 61, 72, 0.2);
}

.table-emblem {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: rgba(15, 118, 110, 0.12);
  color: var(--on-dark-strong);
  font-size: 3rem;
  font-weight: 950;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 18px 36px rgba(15, 118, 110, 0.14);
  animation: emblemFloat 4.4s ease-in-out infinite;
}

.table-emblem::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/assets/card-gloss.png") center / cover no-repeat;
  opacity: 0.42;
  pointer-events: none;
}

.generic-table h2,
.generic-table p {
  margin: 0;
}

.generic-table p {
  max-width: 460px;
  color: var(--on-dark-muted);
  font-weight: 800;
  line-height: 1.55;
}

.generic-table h2,
.card-table .hand-title strong,
.mahjong-board .rack-heading strong {
  color: var(--on-dark-strong);
  text-shadow: 0 1px 12px rgba(3, 7, 18, 0.28);
}

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

.seat-radar span {
  position: relative;
  overflow: hidden;
  padding: 8px 10px;
  border-radius: 999px;
  background: #ffffff;
  color: #172033;
  font-weight: 900;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.68),
    0 10px 20px rgba(15, 23, 42, 0.06);
}

.seat-radar .ai {
  background: #111827;
  color: #ffffff;
}

.mahjong-total {
  position: relative;
  overflow: hidden;
  min-height: 160px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.78), transparent 48%),
    rgba(255, 255, 255, 0.72);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    0 16px 30px rgba(15, 118, 110, 0.08);
  color: #111827;
  text-shadow: none;
}

.mahjong-total strong {
  font-size: clamp(4rem, 11vw, 8rem);
  line-height: 0.92;
}

.mahjong-total em {
  color: var(--accent);
  font-style: normal;
  font-weight: 950;
}

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

.mahjong-table-view {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mahjong-seat,
.private-rack {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0.18)),
    rgba(255, 255, 255, 0.68);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.54),
    0 12px 26px rgba(15, 23, 42, 0.07);
  color: var(--ink);
  text-shadow: none;
}

.mahjong-seat {
  min-height: 90px;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 6px;
  text-align: left;
}

.mahjong-seat.active {
  border-color: rgba(15, 118, 110, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.68),
    0 18px 34px rgba(15, 118, 110, 0.16);
  animation: activeBreath 2.8s ease-in-out infinite;
}

.mahjong-seat span,
.rack-heading span {
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.discard-line {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.discard-line em,
.mahjong-tile {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-width: 30px;
  min-height: 38px;
  padding: 5px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 6px;
  background:
    linear-gradient(145deg, #fffefa 0%, #fff4d8 52%, #ead6ac 100%);
  color: #111827;
  font-style: normal;
  font-weight: 950;
  text-shadow: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    inset 0 -5px 9px rgba(116, 85, 38, 0.13),
    0 8px 16px rgba(15, 23, 42, 0.08);
  transform-origin: 50% 90%;
  animation: tileRise 360ms var(--ease-snap) both;
}

.discard-line em::after,
.mahjong-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: url("/assets/tile-gloss.png") center / cover no-repeat;
  pointer-events: none;
  opacity: 0.58;
}

.private-rack {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.tile-rack {
  min-height: 54px;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: center;
  perspective: 900px;
}

.mahjong-tile {
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease;
}

.mahjong-tile:hover {
  transform: translateY(-7px) rotateX(5deg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -5px 9px rgba(116, 85, 38, 0.12),
    0 18px 26px rgba(15, 23, 42, 0.16);
}

.empty-rack {
  color: var(--muted-strong);
  font-weight: 900;
}

.mahjong-summary span {
  position: relative;
  overflow: hidden;
  padding: 8px 10px;
  border-radius: 999px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), transparent),
    rgba(15, 118, 110, 0.1);
  color: var(--accent-strong);
  font-weight: 900;
  text-shadow: none;
}

.mahjong-total span {
  color: var(--muted-strong);
  font-weight: 900;
}

.mahjong-board p {
  margin: 0;
  color: var(--on-dark-muted);
  font-weight: 800;
}

.mahjong-controls {
  display: grid;
  gap: 12px;
}

.number-control {
  min-height: 58px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.number-control input {
  width: 82px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  text-align: center;
  font-weight: 950;
  color: var(--ink-strong);
}

.mahjong-checks {
  margin-top: 10px;
  display: grid;
  gap: 7px;
}

.mahjong-check {
  position: relative;
  overflow: hidden;
  min-height: 42px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0.2)),
    rgba(255, 255, 255, 0.74);
  cursor: pointer;
  font-weight: 900;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.56);
}

.mahjong-check strong {
  color: var(--accent-strong);
}

.mahjong-check.active {
  border-color: rgba(15, 118, 110, 0.38);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.56), rgba(232, 241, 239, 0.7)),
    #e8f1ef;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.68),
    0 10px 24px rgba(15, 118, 110, 0.1);
}

@keyframes appEntrance {
  0% {
    opacity: 0;
    transform: translate3d(0, 12px, 0) rotateX(1.5deg) scale(0.985);
    filter: saturate(0.94) blur(1px);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotateX(0) scale(1);
    filter: saturate(1) blur(0);
  }
}

@keyframes ambientDrift {
  0%,
  100% {
    transform: translate3d(-1.2%, -1%, 0) scale(1.04);
    opacity: 0.66;
  }

  50% {
    transform: translate3d(1.4%, 0.8%, 0) scale(1.07);
    opacity: 0.9;
  }
}

@keyframes surfaceSettle {
  0% {
    opacity: 0;
    transform: translate3d(0, 10px, 0) scale(0.988);
    filter: blur(1px);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    filter: blur(0);
  }
}

@keyframes turnPulse {
  0%,
  100% {
    transform: scale(1);
    filter: brightness(1) drop-shadow(0 0 0 rgba(15, 118, 110, 0));
  }

  50% {
    transform: scale(1.08);
    filter: brightness(1.08) drop-shadow(0 0 10px rgba(15, 118, 110, 0.28));
  }
}

@keyframes pieceDrop {
  0% {
    opacity: 0;
    transform: translate3d(0, -18px, 0) scale(0.78);
    filter: blur(1px);
  }

  62% {
    opacity: 1;
    transform: translate3d(0, 2px, 0) scale(1.06);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    filter: blur(0);
  }
}

@keyframes cardIn {
  0% {
    opacity: 0;
    transform: translate3d(0, 18px, 0) rotateX(9deg) rotateZ(-2deg) scale(0.96);
    filter: blur(1px);
  }

  70% {
    opacity: 1;
    transform: translate3d(0, -2px, 0) rotateX(-1deg) rotateZ(0.5deg) scale(1.012);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotateX(0) rotateZ(0) scale(1);
    filter: blur(0);
  }
}

@keyframes tileRise {
  0% {
    opacity: 0;
    transform: translate3d(0, 10px, 0) rotateX(8deg) scale(0.94);
  }

  70% {
    opacity: 1;
    transform: translate3d(0, -2px, 0) rotateX(-2deg) scale(1.025);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotateX(0) scale(1);
  }
}

@keyframes sheenTravel {
  0%,
  70%,
  100% {
    opacity: 0;
    transform: translateX(-46%) skewX(-12deg);
  }

  80% {
    opacity: 0.62;
  }

  92% {
    opacity: 0;
    transform: translateX(46%) skewX(-12deg);
  }
}

@keyframes activeBreath {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.045);
  }
}

@keyframes hintPulse {
  0%,
  100% {
    opacity: 0.42;
    transform: scale(0.88);
  }

  50% {
    opacity: 0.86;
    transform: scale(1.04);
  }
}

@keyframes matchedPop {
  0%,
  100% {
    transform: rotateY(180deg) scale(1);
  }

  52% {
    transform: rotateY(180deg) scale(1.06);
  }
}

@keyframes emblemFloat {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  50% {
    transform: translate3d(0, -5px, 0);
  }
}

@keyframes resultRise {
  0% {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.96);
    filter: blur(1px);
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    filter: blur(0);
  }
}

@media (max-width: 980px) {
  .app-shell {
    align-items: start;
  }

  .tabletop {
    min-height: auto;
    padding: 16px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "board"
      "controls"
      "scores";
    min-height: auto;
  }

  .onboarding-game-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-panel {
    max-height: none;
  }

  .score-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .memory-score-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meta-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-card,
  .guide-list,
  .button-stack,
  .mahjong-controls {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .tabletop {
    padding: 12px;
  }

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

  .top-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .match-pill {
    flex: 1 1 auto;
  }

  .game-tab {
    min-height: 58px;
  }

  .onboarding-layer.open {
    padding: 10px;
  }

  .onboarding-card {
    max-height: calc(100vh - 20px);
  }

  .onboarding-game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .onboarding-head,
  .onboarding-actions,
  .onboarding-room {
    align-items: stretch;
    flex-direction: column;
  }

  .score-grid,
  .meta-list,
  .action-panel {
    grid-template-columns: 1fr;
  }

  .board-frame,
  .grid-board,
  .memory-board,
  .card-table,
  .mahjong-board,
  .generic-table {
    width: 100%;
  }

  .playing-card {
    width: 68px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #edf4fb;
    --ink-strong: #ffffff;
    --muted: #c5d2df;
    --muted-strong: #dce7f2;
    --on-dark: #f8fafc;
    --on-dark-strong: #ffffff;
    --on-dark-muted: #dae6f2;
    --on-dark-soft: #b9c8d8;
    --line: rgba(255, 255, 255, 0.13);
    --panel: rgba(17, 24, 39, 0.68);
    --panel-strong: #111827;
    --table: #0d1117;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
    --shadow-deep: 0 34px 90px rgba(0, 0, 0, 0.48);
    --shadow-soft: 0 18px 44px rgba(0, 0, 0, 0.32);
  }

  html {
    background:
      radial-gradient(circle at 16% 8%, rgba(255, 255, 255, 0.09), transparent 24%),
      radial-gradient(circle at 86% 22%, rgba(59, 91, 219, 0.16), transparent 30%),
      linear-gradient(120deg, rgba(15, 118, 110, 0.18), transparent 30%),
      linear-gradient(240deg, rgba(194, 65, 80, 0.16), transparent 34%),
      #0d1117;
  }

  .tabletop,
  .onboarding-card {
    background:
      url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
      radial-gradient(circle at 16% 4%, rgba(255, 255, 255, 0.14), transparent 28%),
      linear-gradient(135deg, rgba(31, 41, 55, 0.94), rgba(12, 18, 30, 0.88)),
      #0f172a;
    border-color: rgba(255, 255, 255, 0.18);
  }

  h1,
  .onboarding-head strong {
    color: var(--ink-strong);
    text-shadow: 0 1px 18px rgba(0, 0, 0, 0.36);
  }

  .eyebrow,
  .room-code strong {
    color: #67e8f9;
    text-shadow: 0 1px 14px rgba(8, 145, 178, 0.28);
  }

  .match-pill,
  .top-setup-button,
  .top-undo-button,
  .game-tab,
  .score-card,
  .status-card,
  .control-group,
  .guide-list,
  .number-control,
  .secondary-button,
  .icon-button {
    background-color: rgba(17, 24, 39, 0.62);
    color: var(--ink-strong);
  }

  .tabletop::before,
  .grid-board::before,
  .connect-board::before,
  .card-table::before,
  .mahjong-board::before,
  .generic-table::before {
    opacity: 0.42;
  }

  .tabletop::after {
    opacity: 0.9;
  }

  .panel,
  .score-card,
  .status-card,
  .control-group,
  .guide-list,
  .number-control,
  .seat-card,
  .onboarding-steps button,
  .onboarding-count-grid button,
  .ai-overview,
  .mahjong-seat,
  .private-rack {
    background:
      linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
      rgba(17, 24, 39, 0.62);
    color: var(--ink);
  }

  .card-table,
  .mahjong-board,
  .generic-table {
    background:
      url("/assets/felt-grain.png") 0 0 / 256px 256px repeat,
      linear-gradient(135deg, rgba(31, 41, 55, 0.78), rgba(15, 23, 42, 0.62)),
      #10201d;
  }

  .mahjong-seat,
  .private-rack {
    color: var(--ink);
  }

  .game-tab small,
  .score-label,
  .meta-list span,
  .status-card span,
  .control-group > span,
  .guide-list span,
  .number-control span,
  .seat-card span,
  .mahjong-seat span,
  .rack-heading span,
  .onboarding-head span,
  .onboarding-section > span {
    color: var(--muted-strong);
  }

  .game-tab.active {
    border-color: rgba(103, 232, 249, 0.46);
    background:
      linear-gradient(135deg, rgba(45, 212, 191, 0.26), rgba(15, 23, 42, 0.88)),
      #102a2f;
    color: var(--ink-strong);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.16),
      0 18px 40px rgba(20, 184, 166, 0.18);
  }

  .game-tab.active small {
    color: var(--on-dark-muted);
  }

  .game-tab.active span {
    background: rgba(236, 253, 245, 0.96);
    color: #07534f;
  }

  .seat-card a {
    color: #67e8f9;
    text-shadow: 0 1px 12px rgba(8, 145, 178, 0.28);
  }

  .meta-list strong,
  .score-card strong,
  .status-card strong,
  .guide-list span {
    color: var(--ink-strong);
  }

  .top-new-button,
  .primary-button {
    color: #ffffff;
  }

  .playing-card {
    background: #f8fafc;
  }
}

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