:root {
  --paper: #fffdf9;
  --paper-2: #f7fbff;
  --ink: #27364a;
  --ink-strong: #17243a;
  --muted: #718198;
  --line: rgba(78, 111, 145, 0.18);
  --line-strong: rgba(78, 111, 145, 0.28);
  --sky: #61b8ef;
  --sky-deep: #287cc4;
  --sky-soft: #dff3ff;
  --mint: #69cdb7;
  --mint-deep: #249478;
  --mint-soft: #def8ef;
  --coral: #ff8580;
  --coral-deep: #d95d5a;
  --coral-soft: #ffe7e5;
  --yellow: #ffc85c;
  --yellow-soft: #fff3c9;
  --violet: #a78be7;
  --violet-soft: #eee8ff;
  --danger: #d85058;
  --table-blue: #3d8dcc;
  --table-blue-deep: #235f9a;
  --table-blue-soft: #68afe1;
  --wood-a: #d99256;
  --wood-b: #8d4d2c;
  --shadow-sm: 0 8px 24px rgba(59, 88, 125, 0.12);
  --shadow-md: 0 18px 52px rgba(59, 88, 125, 0.18);
  --shadow-lg: 0 30px 90px rgba(29, 62, 101, 0.28);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 30px;
  --sans: Inter, "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --serif: "Noto Serif CJK SC", "Source Han Serif SC", STSong, serif;
  --base-font: clamp(16px, calc(0.35vw + 8px), 22px);
  font-size: var(--base-font);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--paper-2);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font: 1rem/1.55 var(--sans);
  background:
    radial-gradient(circle at 8% 7%, rgba(97, 184, 239, 0.20), transparent 31%),
    radial-gradient(circle at 90% 18%, rgba(255, 200, 92, 0.22), transparent 29%),
    linear-gradient(145deg, #f9fdff 0%, #fffdf8 48%, #f4fbff 100%);
  overflow-x: hidden;
}

body.game-active {
  overflow: hidden;
  background: #1f5f98;
}

body.game-active .topbar,
body.game-active .page-aurora {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button,
a {
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.hidden {
  display: none !important;
}

.page-aurora {
  position: fixed;
  z-index: -1;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(70px);
}

.aurora-a {
  width: 30rem;
  height: 30rem;
  left: -10rem;
  top: 12rem;
  background: rgba(105, 205, 183, 0.25);
}

.aurora-b {
  width: 27rem;
  height: 27rem;
  right: -8rem;
  bottom: 2rem;
  background: rgba(255, 133, 128, 0.18);
}

/* ---------- Lobby header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: 0.6rem clamp(1rem, 4vw, 4.5rem);
  border-bottom: 1px solid rgba(97, 151, 194, 0.14);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(24px) saturate(1.15);
  box-shadow: 0 4px 22px rgba(61, 111, 151, 0.06);
}

.brand {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.brand img {
  width: clamp(42px, 3vw, 58px);
  height: clamp(42px, 3vw, 58px);
  filter: drop-shadow(0 6px 12px rgba(40, 124, 196, 0.18));
}

.brand-copy {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  column-gap: 0.55rem;
  line-height: 1.1;
}

.brand-copy b {
  color: var(--coral-deep);
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.brand-copy strong {
  color: var(--ink-strong);
  font-size: 1rem;
  font-weight: 800;
}

.brand-copy small {
  grid-column: 1 / -1;
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.engine-state {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(247, 251, 255, 0.9);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.engine-state i,
.engine-mini i {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #aab5c2;
  box-shadow: 0 0 0 0.25rem rgba(170, 181, 194, 0.14);
}

.engine-state i.ok,
.engine-mini i.ok {
  background: var(--mint-deep);
  box-shadow: 0 0 0 0.25rem rgba(36, 148, 120, 0.16);
}

.engine-state i.bad,
.engine-mini i.bad {
  background: var(--danger);
  box-shadow: 0 0 0 0.25rem rgba(216, 80, 88, 0.16);
}

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.soft-button,
.text-button,
.tool-button,
.mini-button,
.secondary-button {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-weight: 750;
  transition: 160ms ease;
}

.soft-button {
  padding: 0.6rem 0.9rem;
  font-size: 0.78rem;
}

.soft-button:hover,
.secondary-button:hover,
.tool-button:hover,
.mini-button:hover {
  border-color: rgba(40, 124, 196, 0.42);
  background: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ---------- Lobby ---------- */

main {
  width: 100%;
}

.lobby-screen {
  width: min(2400px, calc(100% - clamp(1.5rem, 6vw, 7rem)));
  margin: 0 auto;
  padding: clamp(2rem, 4vw, 4.8rem) 0 clamp(3rem, 6vw, 7rem);
}

.hero-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, 0.92fr);
  align-items: center;
  gap: clamp(2rem, 5vw, 6rem);
  min-height: clamp(390px, 36vw, 590px);
  padding: clamp(2rem, 5vw, 5.2rem);
  overflow: hidden;
  border: 1px solid rgba(103, 154, 195, 0.20);
  border-radius: clamp(26px, 3vw, 46px);
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.97), rgba(247, 252, 255, 0.90)),
    radial-gradient(circle at 82% 20%, rgba(255, 200, 92, 0.34), transparent 34%);
  box-shadow: var(--shadow-md);
}

.hero-card::before,
.hero-card::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
}

.hero-card::before {
  width: 21rem;
  height: 21rem;
  right: -7rem;
  top: -8rem;
  background: rgba(255, 133, 128, 0.10);
}

.hero-card::after {
  width: 16rem;
  height: 16rem;
  left: 44%;
  bottom: -10rem;
  background: rgba(105, 205, 183, 0.14);
}

.hero-copy,
.hero-preview {
  position: relative;
  z-index: 1;
}

.eyebrow {
  display: inline-flex;
  color: var(--sky-deep);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero-copy h1 {
  max-width: 13ch;
  margin: 0.7rem 0 1.2rem;
  color: var(--ink-strong);
  font-family: var(--serif);
  font-size: clamp(2.3rem, 4.4vw, 5.2rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.hero-copy h1 span,
.hero-copy h1 em {
  display: block;
}

.hero-copy h1 em {
  color: var(--coral-deep);
  font-style: normal;
}

.hero-copy p {
  max-width: 43rem;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.85;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1.5rem;
}

.hero-tags span {
  padding: 0.48rem 0.75rem;
  border: 1px solid rgba(40, 124, 196, 0.17);
  border-radius: 999px;
  color: #43627e;
  background: rgba(223, 243, 255, 0.66);
  font-size: 0.7rem;
  font-weight: 800;
}

.hero-preview {
  display: grid;
  place-items: center;
}

.preview-board {
  position: relative;
  width: min(100%, 600px);
  aspect-ratio: 1.34;
  border: clamp(9px, 1vw, 18px) solid #bf7648;
  border-radius: clamp(20px, 2vw, 34px);
  background:
    linear-gradient(rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01)),
    radial-gradient(circle at center, #71b6e2, #367fbc 72%, #2a669d);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.25),
    inset 0 0 70px rgba(12, 63, 104, 0.25),
    0 28px 60px rgba(43, 91, 132, 0.22);
  transform: perspective(950px) rotateX(3deg) rotateZ(-1.2deg);
}

.preview-board::before {
  content: "";
  position: absolute;
  inset: 15%;
  border: 1px solid rgba(18, 75, 117, 0.35);
  clip-path: polygon(17% 0, 83% 0, 100% 17%, 100% 83%, 83% 100%, 17% 100%, 0 83%, 0 17%);
}

.preview-center {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 25%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.50);
  border-radius: 22%;
  color: white;
  background: rgba(39, 72, 110, 0.76);
  box-shadow: 0 10px 24px rgba(22, 57, 89, 0.26);
}

.preview-center img {
  width: 35%;
  margin-bottom: 0.2rem;
}

.preview-center b {
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}

.preview-center small {
  font-size: 0.42rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  opacity: 0.78;
}

.preview-wall {
  position: absolute;
  border-radius: 6px;
  background: repeating-linear-gradient(90deg, #ffc45c 0 19px, #db8d2e 19px 21px);
  box-shadow: 0 4px 8px rgba(23, 63, 97, 0.24);
}

.preview-wall.top,
.preview-wall.bottom {
  width: 52%;
  height: 7%;
  left: 24%;
}

.preview-wall.top { top: 7%; }
.preview-wall.bottom { bottom: 10%; }

.preview-wall.left,
.preview-wall.right {
  width: 7%;
  height: 49%;
  top: 24%;
  background: repeating-linear-gradient(180deg, #ffc45c 0 19px, #db8d2e 19px 21px);
}

.preview-wall.left { left: 7%; }
.preview-wall.right { right: 7%; }

.preview-hand {
  position: absolute;
  left: 50%;
  bottom: -2%;
  display: flex;
  gap: 2px;
  transform: translateX(-50%);
}

.preview-hand i {
  width: clamp(28px, 3vw, 52px);
  aspect-ratio: 0.69;
  display: grid;
  place-items: center;
  padding: 0.2rem;
  border: 1px solid #dccdae;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(135deg, #fffefb, #f4ead8);
  box-shadow: 0 5px 10px rgba(30, 63, 90, 0.18);
  font-style: normal;
  font-size: clamp(0.48rem, 0.8vw, 0.72rem);
  font-weight: 900;
  writing-mode: vertical-rl;
}

.preview-hand .man { color: #bd3d45; }
.preview-hand .pin { color: #2b6db2; writing-mode: horizontal-tb; }
.preview-hand .sou { color: #228968; }
.preview-hand .honor.red { color: #dc3d49; font-size: 1.1rem; writing-mode: horizontal-tb; }

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.34fr) minmax(0, 0.66fr);
  gap: clamp(1rem, 2vw, 2rem);
  margin-top: clamp(1.3rem, 2.4vw, 2.5rem);
  align-items: start;
}

.glass-panel {
  border: 1px solid rgba(90, 137, 177, 0.20);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(20px);
}

.mode-panel,
.seats-panel {
  padding: clamp(1.15rem, 2vw, 2rem);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.1rem;
}

.section-index {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 14px;
  color: white;
  background: linear-gradient(135deg, var(--sky), var(--sky-deep));
  box-shadow: 0 8px 16px rgba(40, 124, 196, 0.22);
  font-size: 0.78rem;
  font-weight: 900;
}

.section-header h2 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 1.1rem;
  line-height: 1.2;
}

.section-header p {
  margin: 0.22rem 0 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.seats-title .text-button {
  margin-left: auto;
}

.text-button {
  padding: 0.55rem 0.75rem;
  color: var(--sky-deep);
  background: var(--sky-soft);
  font-size: 0.68rem;
}

.preset-list {
  display: grid;
  gap: 0.65rem;
}

.preset {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--ink);
  background: rgba(247, 251, 255, 0.72);
  text-align: left;
  transition: 160ms ease;
}

.preset:hover {
  border-color: rgba(40, 124, 196, 0.33);
  background: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.preset.active {
  border-color: rgba(40, 124, 196, 0.52);
  background: linear-gradient(100deg, #f2faff, #ffffff);
  box-shadow: 0 8px 22px rgba(40, 124, 196, 0.12);
}

.preset.active::after {
  content: "";
  position: absolute;
  inset: -1px;
  pointer-events: none;
  border: 2px solid rgba(97, 184, 239, 0.24);
  border-radius: 17px;
}

.preset-icon {
  display: grid;
  place-items: center;
  width: 2.55rem;
  height: 2.55rem;
  border-radius: 14px;
  font-style: normal;
  font-size: 1.05rem;
  font-weight: 900;
}

.preset-icon.coral { color: var(--coral-deep); background: var(--coral-soft); }
.preset-icon.sky { color: var(--sky-deep); background: var(--sky-soft); }
.preset-icon.mint { color: var(--mint-deep); background: var(--mint-soft); }

.preset span {
  min-width: 0;
  display: grid;
}

.preset span b {
  color: var(--ink-strong);
  font-size: 0.86rem;
}

.preset span small {
  margin-top: 0.16rem;
  color: var(--muted);
  font-size: 0.65rem;
}

.preset u {
  padding: 0.26rem 0.45rem;
  border-radius: 999px;
  color: var(--coral-deep);
  background: var(--coral-soft);
  font-size: 0.56rem;
  font-weight: 900;
  text-decoration: none;
}

.form-stack {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.form-stack > label,
.field {
  display: grid;
  gap: 0.36rem;
}

.form-stack > label > span,
.field > span {
  color: #557087;
  font-size: 0.65rem;
  font-weight: 850;
}

input,
select {
  width: 100%;
  min-height: 2.55rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  outline: none;
  color: var(--ink-strong);
  background: rgba(255, 255, 255, 0.94);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input:focus,
select:focus {
  border-color: var(--sky);
  background: white;
  box-shadow: 0 0 0 4px rgba(97, 184, 239, 0.14);
}

.switches {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.8rem;
}

.switch-row span {
  display: grid;
}

.switch-row b {
  color: var(--ink-strong);
  font-size: 0.76rem;
}

.switch-row small {
  margin-top: 0.13rem;
  color: var(--muted);
  font-size: 0.61rem;
}

.switch-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-row i {
  position: relative;
  width: 2.8rem;
  height: 1.55rem;
  border-radius: 999px;
  background: #d9e1e8;
  transition: 150ms ease;
}

.switch-row i::after {
  content: "";
  position: absolute;
  width: 1.15rem;
  height: 1.15rem;
  left: 0.2rem;
  top: 0.2rem;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(47, 72, 96, 0.20);
  transition: 150ms ease;
}

.switch-row input:checked + i {
  background: linear-gradient(90deg, var(--mint), #55bca4);
}

.switch-row input:checked + i::after {
  transform: translateX(1.25rem);
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.seat-card {
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(248, 251, 255, 0.82);
  transition: 160ms ease;
}

.seat-card:hover {
  border-color: rgba(40, 124, 196, 0.30);
  box-shadow: 0 10px 28px rgba(68, 111, 146, 0.10);
}

.seat-card.is-human {
  border-color: rgba(255, 133, 128, 0.48);
  background: linear-gradient(115deg, rgba(255, 244, 242, 0.94), rgba(255, 255, 255, 0.93));
}

.seat-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(7.2rem, 0.58fr);
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem;
  border-bottom: 1px solid var(--line);
}

.seat-avatar {
  width: 3.35rem;
  height: 3.35rem;
  border: 3px solid white;
  border-radius: 16px;
  box-shadow: 0 7px 15px rgba(66, 94, 126, 0.16);
}

.seat-meta {
  min-width: 0;
  display: grid;
  gap: 0.3rem;
}

.seat-meta span {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.10em;
}

.seat-name {
  min-height: 2.15rem;
  padding: 0.35rem 0.6rem;
  font-weight: 850;
}

.controller {
  min-height: 2.3rem;
  padding: 0.4rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 800;
}

.seat-body {
  padding: 0.8rem;
}

.builtin-note {
  min-height: 3.2rem;
  display: flex;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px dashed rgba(78, 111, 145, 0.24);
  border-radius: 13px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
  font-size: 0.65rem;
}

.llm-settings {
  display: grid;
  gap: 0.65rem;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.model-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
}

.mini-button {
  padding: 0.45rem 0.65rem;
  font-size: 0.62rem;
}

.advanced-toggle {
  justify-self: start;
  padding: 0;
  border: 0;
  color: var(--sky-deep);
  background: transparent;
  font-size: 0.63rem;
  font-weight: 850;
}

.advanced-toggle::after {
  content: "⌄";
  display: inline-block;
  margin-left: 0.3rem;
  transition: transform 150ms ease;
}

.advanced-toggle.open::after {
  transform: rotate(180deg);
}

.advanced {
  display: grid;
  gap: 0.6rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(237, 247, 255, 0.62);
}

.seat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.reason-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.reason-toggle input {
  width: 1rem;
  min-height: auto;
  height: 1rem;
}

.probe-status {
  min-height: 1rem;
  color: var(--muted);
  font-size: 0.60rem;
}

.probe-status.ok { color: var(--mint-deep); }
.probe-status.bad { color: var(--danger); }

.model-picker-temp {
  position: absolute;
  z-index: 12;
  left: 0;
  right: 0;
  top: calc(100% + 0.35rem);
  box-shadow: var(--shadow-md);
}

.launch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.launch-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.66rem;
}

.launch-row p b {
  margin-right: 0.35rem;
  color: var(--mint-deep);
}

.primary-button {
  display: inline-grid;
  place-items: center;
  min-width: 12.5rem;
  padding: 0.75rem 1.2rem;
  border: 0;
  border-radius: 15px;
  color: white;
  background: linear-gradient(135deg, #ff8c87, #ed6b67);
  box-shadow: 0 12px 28px rgba(217, 93, 90, 0.26);
  font-weight: 900;
  transition: 160ms ease;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(217, 93, 90, 0.33);
}

.primary-button span {
  font-size: 0.9rem;
}

.primary-button small {
  margin-top: 0.08rem;
  font-size: 0.52rem;
  letter-spacing: 0.12em;
  opacity: 0.82;
}

.primary-button.compact {
  min-width: 9.5rem;
}

.error-box {
  margin-top: 0.9rem;
  padding: 0.75rem 0.9rem;
  white-space: pre-wrap;
  border: 1px solid rgba(216, 80, 88, 0.28);
  border-radius: 13px;
  color: #ad3f47;
  background: #fff0f1;
  font-size: 0.7rem;
}

/* ---------- Full-screen game ---------- */

.game-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  width: 100vw;
  height: 100dvh;
  background: #245f97;
}

.game-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(116, 188, 235, 0.36), transparent 42%),
    linear-gradient(145deg, #2d76b2 0%, #225d96 100%);
}

.table-frame {
  position: absolute;
  inset: clamp(0.55rem, 1vw, 1.4rem);
  overflow: hidden;
  border-radius: clamp(18px, 1.4vw, 34px);
  background: var(--table-blue);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.24),
    inset 0 0 120px rgba(20, 67, 109, 0.24),
    0 20px 70px rgba(10, 37, 68, 0.42);
}

.wood-rim {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  border: clamp(10px, 1.1vw, 25px) solid transparent;
  border-image: linear-gradient(135deg, #e7a56a, #8c4a29 38%, #ca7944 72%, #7c4027) 1;
  box-shadow:
    inset 0 0 0 2px rgba(255, 238, 205, 0.46),
    inset 0 0 28px rgba(67, 26, 13, 0.40);
}

.board-svg {
  position: absolute;
  z-index: 1;
  inset: clamp(12px, 1.35vw, 31px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: clamp(12px, 1vw, 24px);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 34%),
    radial-gradient(circle at center, var(--table-blue-soft), var(--table-blue) 52%, var(--table-blue-deep));
}

.board-svg::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle, black, transparent 82%);
}

.board-svg > svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 10px 14px rgba(16, 52, 85, 0.20));
}

.board-svg svg text {
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", "Microsoft YaHei UI", serif;
  text-rendering: geometricPrecision;
}

.board-svg svg .yoyi-man text,
.board-svg svg text.yoyi-man {
  fill: #bf3540 !important;
}

.board-svg svg .yoyi-pin text,
.board-svg svg text.yoyi-pin {
  fill: #286db0 !important;
}

.board-svg svg .yoyi-sou text,
.board-svg svg text.yoyi-sou {
  fill: #168660 !important;
}

.board-svg svg .yoyi-honor-red text,
.board-svg svg text.yoyi-honor-red {
  fill: #d93643 !important;
}

.board-svg svg .yoyi-honor-green text,
.board-svg svg text.yoyi-honor-green {
  fill: #149267 !important;
}

.board-svg svg .yoyi-honor-dark text,
.board-svg svg text.yoyi-honor-dark {
  fill: #273748 !important;
}

.board-svg svg .yoyi-tile-face {
  fill: #fffdf7 !important;
  stroke: #cfbea1 !important;
  stroke-width: 1.2 !important;
}

.board-svg svg .yoyi-tile-back {
  fill: #f4a83d !important;
  stroke: #c87822 !important;
}

.board-placeholder {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  gap: 0.7rem;
  color: rgba(255, 255, 255, 0.86);
  font-weight: 800;
}

.board-placeholder img {
  width: 5rem;
  height: 5rem;
  filter: drop-shadow(0 12px 18px rgba(11, 49, 81, 0.26));
}

.game-toolbar {
  position: absolute;
  z-index: 20;
  left: 50%;
  top: clamp(0.8rem, 1.4vw, 1.6rem);
  transform: translateX(-50%);
  max-width: calc(100vw - 10rem);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.48rem;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 16px 44px rgba(20, 60, 95, 0.26);
  backdrop-filter: blur(18px) saturate(1.15);
}

.match-brief {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 0.45rem 0 0.15rem;
  white-space: nowrap;
}

.match-brief img {
  width: 2.15rem;
  height: 2.15rem;
}

.match-brief span {
  display: grid;
  line-height: 1.12;
}

.match-brief b {
  color: var(--ink-strong);
  font-size: 0.72rem;
}

.match-brief small {
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.49rem;
}

.match-brief i {
  font-style: normal;
}

.toolbar-divider {
  width: 1px;
  height: 1.85rem;
  background: var(--line);
}

.tool-button {
  min-height: 2.1rem;
  padding: 0.42rem 0.72rem;
  border-radius: 10px;
  font-size: 0.62rem;
  white-space: nowrap;
}

.tool-button.active {
  color: var(--sky-deep);
  border-color: rgba(40, 124, 196, 0.35);
  background: var(--sky-soft);
}

.tool-button.danger {
  color: var(--danger);
  border-color: rgba(216, 80, 88, 0.20);
  background: #fff2f2;
}

.icon-tool {
  min-width: 2.15rem;
  padding-inline: 0.55rem;
  font-size: 1rem;
  line-height: 1;
}

.toolbar-select {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
}

.toolbar-select select {
  width: auto;
  min-width: 3rem;
  min-height: 2.1rem;
  padding: 0.35rem 0.5rem;
  border-radius: 10px;
  font-size: 0.62rem;
}

.center-status-card {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  min-width: 7.2rem;
  min-height: 4.4rem;
  padding: 0.65rem 0.9rem;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 18px;
  color: white;
  background: rgba(29, 58, 91, 0.78);
  box-shadow: 0 12px 28px rgba(12, 43, 72, 0.28);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.center-status-card span {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.72rem;
  font-weight: 900;
}

.center-status-card b {
  margin-top: 0.16rem;
  color: #bfe7ff;
  font-size: 0.48rem;
  letter-spacing: 0.12em;
}

.thinking-badge {
  position: absolute;
  z-index: 18;
  left: 50%;
  top: clamp(5.4rem, 8vh, 8rem);
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 999px;
  color: var(--ink-strong);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 30px rgba(20, 60, 95, 0.22);
  font-size: 0.66rem;
  font-weight: 850;
}

.thinking-badge i {
  width: 0.65rem;
  height: 0.65rem;
  border: 2px solid rgba(40, 124, 196, 0.25);
  border-top-color: var(--sky-deep);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Player overlays */

.table-players {
  position: absolute;
  z-index: 9;
  inset: clamp(1.8rem, 3.4vw, 5.2rem);
  pointer-events: none;
}

.table-player {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: clamp(8rem, 11vw, 14.5rem);
  max-width: 16rem;
  padding: 0.42rem 0.58rem;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 14px;
  color: white;
  background: rgba(24, 56, 89, 0.68);
  box-shadow: 0 10px 24px rgba(11, 44, 75, 0.22);
  backdrop-filter: blur(9px);
  transition: 160ms ease;
}

.table-player.active {
  border-color: rgba(255, 232, 155, 0.95);
  background: rgba(30, 72, 109, 0.90);
  box-shadow: 0 0 0 3px rgba(255, 209, 97, 0.22), 0 12px 28px rgba(11, 44, 75, 0.28);
}

.table-player.active::after {
  content: "行动中";
  position: absolute;
  right: 0.45rem;
  top: -0.55rem;
  padding: 0.12rem 0.36rem;
  border-radius: 999px;
  color: #66420d;
  background: #ffe28a;
  font-size: 0.42rem;
  font-weight: 900;
}

.table-player img {
  width: clamp(2.3rem, 3vw, 4.2rem);
  height: clamp(2.3rem, 3vw, 4.2rem);
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 12px;
  background: white;
}

.table-player-copy {
  min-width: 0;
  display: grid;
  line-height: 1.15;
}

.table-player-copy b {
  max-width: 9.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.66rem;
}

.table-player-copy strong {
  margin-top: 0.17rem;
  color: #fff3ba;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.table-player-copy small {
  margin-top: 0.12rem;
  color: rgba(235, 246, 255, 0.78);
  font-size: 0.44rem;
}

.table-player.position-bottom {
  left: 17%;
  bottom: 2.5%;
}

.table-player.position-top {
  right: 3.5%;
  top: 5%;
}

.table-player.position-left {
  left: 1.4%;
  top: 50%;
  transform: translateY(-50%);
}

.table-player.position-right {
  right: 1.4%;
  top: 50%;
  transform: translateY(-50%);
}

/* Drawers */

.game-drawer {
  position: absolute;
  z-index: 31;
  top: clamp(0.8rem, 1.4vw, 1.6rem);
  bottom: clamp(0.8rem, 1.4vw, 1.6rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 22px;
  color: var(--ink);
  background: rgba(250, 253, 255, 0.95);
  box-shadow: 0 24px 70px rgba(12, 42, 72, 0.33);
  backdrop-filter: blur(22px) saturate(1.12);
  transition: transform 220ms cubic-bezier(.2,.8,.2,1), opacity 180ms ease;
}

.status-drawer {
  left: clamp(0.8rem, 1.4vw, 1.6rem);
  width: clamp(320px, 21vw, 540px);
}

.intel-drawer {
  right: clamp(0.8rem, 1.4vw, 1.6rem);
  width: clamp(360px, 26vw, 680px);
}

.status-drawer.is-closed {
  transform: translateX(calc(-100% - 2rem));
  opacity: 0;
  pointer-events: none;
}

.intel-drawer.is-closed {
  transform: translateX(calc(100% + 2rem));
  opacity: 0;
  pointer-events: none;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.drawer-header small {
  color: var(--sky-deep);
  font-size: 0.5rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.drawer-header h2 {
  margin: 0.12rem 0 0;
  color: var(--ink-strong);
  font-size: 1.02rem;
}

.drawer-header button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: white;
  font-size: 1.15rem;
  line-height: 1;
}

.drawer-scroll {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 0.9rem;
}

.drawer-handle {
  position: absolute;
  z-index: 29;
  top: 50%;
  display: flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.6rem 0.48rem;
  border: 1px solid rgba(255, 255, 255, 0.62);
  color: var(--ink-strong);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 30px rgba(10, 42, 72, 0.23);
  font-size: 0.58rem;
  font-weight: 900;
  writing-mode: vertical-rl;
  letter-spacing: 0.08em;
  transition: 160ms ease;
}

.drawer-handle:hover {
  background: white;
  transform: translateY(-50%) scale(1.03);
}

.drawer-handle.left {
  left: 0;
  transform: translateY(-50%);
  border-left: 0;
  border-radius: 0 14px 14px 0;
}

.drawer-handle.right {
  right: 0;
  transform: translateY(-50%);
  border-right: 0;
  border-radius: 14px 0 0 14px;
}

.drawer-handle i {
  font-style: normal;
  font-size: 1rem;
  writing-mode: horizontal-tb;
}

.drawer-handle.is-active {
  color: var(--sky-deep);
  background: #eff9ff;
}

.phase-card {
  display: grid;
  gap: 0.2rem;
  padding: 0.85rem;
  border: 1px solid rgba(97, 184, 239, 0.22);
  border-radius: 16px;
  background: linear-gradient(135deg, var(--sky-soft), white);
}

.phase-card span {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
}

.phase-card b {
  color: var(--ink-strong);
  font-size: 0.92rem;
}

.phase-card small {
  color: var(--sky-deep);
  font-size: 0.58rem;
  font-weight: 850;
}

.scoreboard {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.score-row {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.62rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.90);
}

.score-row.active {
  border-color: rgba(255, 200, 92, 0.58);
  background: linear-gradient(100deg, var(--yellow-soft), white);
}

.score-row.first::after {
  content: "1st";
  position: absolute;
  right: 0.4rem;
  top: -0.4rem;
  padding: 0.1rem 0.32rem;
  border-radius: 999px;
  color: #81570e;
  background: #ffe196;
  font-size: 0.43rem;
  font-weight: 900;
}

.turn-dot {
  position: absolute;
  left: -0.22rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 0.2rem rgba(255, 133, 128, 0.18);
}

.score-avatar {
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 12px;
}

.score-copy,
.score-points {
  min-width: 0;
  display: grid;
}

.score-copy b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-strong);
  font-size: 0.72rem;
}

.score-copy small,
.score-points small {
  margin-top: 0.13rem;
  color: var(--muted);
  font-size: 0.52rem;
}

.score-points {
  text-align: right;
}

.score-points b {
  color: var(--sky-deep);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.runtime-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.runtime-stats > div {
  display: grid;
  gap: 0.18rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(247, 251, 255, 0.86);
}

.runtime-stats span {
  color: var(--muted);
  font-size: 0.52rem;
}

.runtime-stats b {
  color: var(--ink-strong);
  font-size: 0.68rem;
}

.engine-mini {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 13px;
  color: var(--muted);
  background: var(--mint-soft);
  font-size: 0.56rem;
  font-weight: 750;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  padding: 0.7rem 0.9rem;
}

.tab {
  min-height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: rgba(247, 251, 255, 0.84);
  font-size: 0.66rem;
  font-weight: 850;
}

.tab.active {
  color: var(--sky-deep);
  border-color: rgba(40, 124, 196, 0.32);
  background: var(--sky-soft);
}

.tab-panel {
  display: none;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.tab-panel.active {
  display: flex;
}

.scroll-log {
  width: 100%;
  overflow: auto;
  padding: 0 0.9rem 0.9rem;
}

.scroll-log.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.66rem;
}

.decision-card,
.event-card {
  margin-top: 0.55rem;
  padding: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  box-shadow: 0 5px 14px rgba(68, 105, 137, 0.07);
}

.decision-card.fallback {
  border-color: rgba(255, 133, 128, 0.38);
  background: #fff8f7;
}

.log-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
}

.log-seat {
  padding: 0.15rem 0.34rem;
  border-radius: 7px;
  color: var(--sky-deep);
  background: var(--sky-soft);
  font-size: 0.48rem;
  font-weight: 900;
}

.log-head b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-strong);
  font-size: 0.68rem;
}

.log-head time {
  color: var(--muted);
  font-size: 0.48rem;
}

.log-model {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.51rem;
}

.log-action {
  margin-top: 0.5rem;
  color: var(--coral-deep);
  font-size: 0.68rem;
  font-weight: 900;
}

.log-action small {
  color: var(--muted);
  font-weight: 700;
}

.log-reason {
  margin: 0.45rem 0 0;
  color: #52687d;
  font-size: 0.60rem;
  line-height: 1.65;
}

.log-error {
  margin-top: 0.5rem;
  padding: 0.5rem;
  border-radius: 9px;
  color: #b3464d;
  background: #fff0f1;
  font-size: 0.53rem;
  white-space: pre-wrap;
}

.event-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.55rem;
}

.event-step {
  color: var(--sky-deep);
  font-size: 0.51rem;
  font-weight: 900;
}

.event-main {
  min-width: 0;
  display: grid;
  gap: 0.12rem;
}

.event-main b {
  color: var(--ink-strong);
  font-size: 0.63rem;
}

.event-main span {
  color: var(--muted);
  font-size: 0.56rem;
}

.event-actor {
  padding: 0.13rem 0.3rem;
  border-radius: 6px;
  color: var(--mint-deep);
  background: var(--mint-soft);
  font-size: 0.45rem;
  font-weight: 850;
}

/* Human hand */

.human-controls {
  position: absolute;
  z-index: 24;
  left: 50%;
  bottom: clamp(0.7rem, 1.2vw, 1.35rem);
  width: min(96vw, 1650px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.75rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.66);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 20px 54px rgba(10, 44, 75, 0.30);
  backdrop-filter: blur(18px) saturate(1.12);
}

.control-head {
  min-width: 7.2rem;
  display: grid;
  align-self: center;
  padding: 0 0.35rem;
}

.control-head span {
  color: var(--sky-deep);
  font-size: 0.48rem;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.control-head b {
  margin-top: 0.12rem;
  color: var(--ink-strong);
  font-size: 0.78rem;
}

.control-head small {
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.50rem;
}

.hand-tiles {
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(1px, 0.13vw, 4px);
  overflow-x: auto;
  padding: 0.15rem 0.2rem 0.3rem;
  scrollbar-width: thin;
}

.mahjong-tile {
  position: relative;
  flex: 0 0 auto;
  width: clamp(44px, 4.1vw, 96px);
  aspect-ratio: 0.70;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  padding: 0.25rem 0.15rem 0.38rem;
  border: 1px solid #cfbea1;
  border-bottom: clamp(5px, 0.45vw, 10px) solid #d59a43;
  border-radius: clamp(6px, 0.45vw, 11px) clamp(6px, 0.45vw, 11px) 4px 4px;
  color: #273748;
  background: linear-gradient(145deg, #fffefb 0%, #f7efdf 78%, #eee2cc 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.72),
    0 4px 8px rgba(29, 62, 92, 0.22);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.mahjong-tile:not(:disabled):hover {
  transform: translateY(-0.45rem);
  filter: brightness(1.03);
  box-shadow: 0 12px 20px rgba(25, 64, 98, 0.28);
}

.mahjong-tile.drawn {
  margin-left: clamp(4px, 0.5vw, 14px);
}

.mahjong-tile:disabled {
  filter: grayscale(0.55) opacity(0.72);
}

.tile-number {
  align-self: end;
  font-family: var(--serif);
  font-size: clamp(1.25rem, 2.2vw, 2.65rem);
  font-weight: 900;
  line-height: 1;
}

.tile-suit {
  align-self: start;
  font-family: var(--serif);
  font-size: clamp(0.55rem, 0.85vw, 1rem);
  font-weight: 900;
  line-height: 1;
}

.mahjong-tile.man { color: #ba3540; }
.mahjong-tile.pin { color: #286db0; }
.mahjong-tile.sou { color: #14825f; }
.mahjong-tile.honor { color: #273748; }
.mahjong-tile.red-five { color: #d92f3d; }

.mahjong-tile.pin .tile-number {
  display: grid;
  place-items: center;
  width: 72%;
  aspect-ratio: 1;
  border: 0.11em double currentColor;
  border-radius: 50%;
  font-family: var(--sans);
  font-size: clamp(1rem, 1.7vw, 2.15rem);
}

.mahjong-tile.sou .tile-number {
  text-shadow: 0.04em 0.04em 0 rgba(198, 58, 67, 0.28);
}

.special-actions {
  min-width: 8rem;
  max-width: 17rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  align-self: center;
}

.action-button {
  min-height: 2.35rem;
  padding: 0.45rem 0.72rem;
  border: 1px solid rgba(40, 124, 196, 0.24);
  border-radius: 11px;
  color: var(--sky-deep);
  background: var(--sky-soft);
  font-size: 0.62rem;
  font-weight: 900;
}

.action-button.win {
  color: #a83a3f;
  border-color: rgba(255, 133, 128, 0.34);
  background: var(--coral-soft);
}

.action-button.danger {
  color: #9b650f;
  border-color: rgba(255, 200, 92, 0.44);
  background: var(--yellow-soft);
}

.spectator-controls {
  position: absolute;
  z-index: 24;
  left: 50%;
  bottom: clamp(1.2rem, 2vw, 2.4rem);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.60);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: 0 16px 40px rgba(10, 44, 75, 0.28);
  backdrop-filter: blur(16px);
}

.spectator-controls button {
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 10px;
  color: white;
  background: linear-gradient(135deg, var(--sky), var(--sky-deep));
  font-size: 0.66rem;
  font-weight: 900;
}

.spectator-controls p {
  margin: 0;
  color: var(--muted);
  font-size: 0.58rem;
}

/* ---------- Modal / toast ---------- */

.modal {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 42, 64, 0.46);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(780px, 96vw);
  max-height: min(86dvh, 900px);
  overflow: auto;
  padding: clamp(1.2rem, 3vw, 2.2rem);
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow-lg);
}

.modal-card h2 {
  margin: 0.35rem 0 1rem;
  color: var(--ink-strong);
  font-size: 1.55rem;
}

.modal-close {
  position: absolute;
  right: 1rem;
  top: 1rem;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: white;
  font-size: 1.2rem;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.help-grid article {
  position: relative;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--paper-2);
}

.help-grid article > b {
  position: absolute;
  right: 0.7rem;
  top: 0.55rem;
  color: rgba(40, 124, 196, 0.16);
  font-size: 2rem;
}

.help-grid h3 {
  margin: 0;
  color: var(--ink-strong);
  font-size: 0.84rem;
}

.help-grid p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.66rem;
}

.notice {
  margin-top: 0.8rem;
  padding: 0.75rem;
  border-radius: 13px;
  color: #5b7185;
  background: var(--yellow-soft);
  font-size: 0.64rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.secondary-button {
  padding: 0.65rem 0.9rem;
}

.round-score-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.round-score-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
}

.round-score-row b {
  color: var(--ink-strong);
}

.round-score-row strong {
  color: var(--sky-deep);
}

.winner-detail {
  margin-top: 0.8rem;
  padding: 0.9rem;
  border: 1px solid rgba(255, 133, 128, 0.22);
  border-radius: 15px;
  background: #fff7f6;
}

.winner-detail h3 {
  margin: 0;
  color: var(--coral-deep);
  font-size: 0.9rem;
}

.winner-detail p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.65rem;
}

.yaku-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.yaku-list span {
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  color: #a84b4f;
  background: var(--coral-soft);
  font-size: 0.55rem;
  font-weight: 800;
}

.toast-region {
  position: fixed;
  z-index: 300;
  right: 1rem;
  bottom: 1rem;
  display: grid;
  gap: 0.55rem;
  width: min(25rem, calc(100vw - 2rem));
}

.toast {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
  font-size: 0.68rem;
  white-space: pre-wrap;
}

.toast.success {
  border-color: rgba(36, 148, 120, 0.30);
  background: #effbf7;
}

.toast.error {
  border-color: rgba(216, 80, 88, 0.30);
  background: #fff2f2;
}

/* ---------- Resolution adaptation ---------- */

@media (min-width: 2560px) {
  :root {
    --base-font: clamp(22px, 0.64vw, 27px);
  }

  .lobby-screen {
    width: min(2900px, calc(100% - 10vw));
  }

  .hero-card {
    min-height: 660px;
  }

  .game-toolbar {
    padding: 0.58rem;
    border-radius: 22px;
  }

  .tool-button,
  .toolbar-select select {
    min-height: 2.35rem;
  }

  .table-player {
    min-width: 13rem;
    padding: 0.54rem 0.7rem;
  }

  .status-drawer { width: clamp(440px, 18vw, 660px); }
  .intel-drawer { width: clamp(520px, 22vw, 820px); }

  .mahjong-tile {
    width: clamp(76px, 3.15vw, 118px);
  }

  .human-controls {
    width: min(94vw, 2300px);
  }
}

@media (max-width: 1320px) {
  .hero-card {
    grid-template-columns: 1fr;
  }

  .hero-copy h1 {
    max-width: 16ch;
  }

  .hero-preview {
    max-width: 760px;
    width: 100%;
    justify-self: center;
  }

  .lobby-grid {
    grid-template-columns: 1fr;
  }

  .mode-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
    gap: 1rem;
  }

  .mode-panel .section-header,
  .mode-panel .preset-list {
    grid-column: 1;
  }

  .mode-panel .form-stack,
  .mode-panel .switches {
    grid-column: 2;
  }

  .mode-panel .form-stack {
    grid-row: 1 / span 2;
    margin-top: 0;
  }

  .mode-panel .switches {
    margin-top: 0;
  }

  .game-toolbar {
    max-width: calc(100vw - 5rem);
  }

  .table-player.position-bottom { left: 10%; }
  .table-player.position-top { right: 10%; }
}

@media (max-width: 980px) {
  :root { --base-font: 16px; }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .engine-state {
    display: none;
  }

  .seat-grid {
    grid-template-columns: 1fr;
  }

  .mode-panel {
    display: block;
  }

  .mode-panel .form-stack {
    margin-top: 1rem;
  }

  .mode-panel .switches {
    margin-top: 1rem;
  }

  .launch-row {
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }

  .game-toolbar {
    left: 0.55rem;
    right: 0.55rem;
    top: 0.55rem;
    transform: none;
    max-width: none;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
  }

  .game-toolbar::-webkit-scrollbar { display: none; }

  .match-brief small,
  .toolbar-divider {
    display: none;
  }

  .game-drawer {
    top: auto;
    left: 0.55rem;
    right: 0.55rem;
    bottom: 0.55rem;
    width: auto;
    max-height: min(72dvh, 760px);
    border-radius: 20px;
  }

  .status-drawer.is-closed,
  .intel-drawer.is-closed {
    transform: translateY(calc(100% + 2rem));
  }

  .drawer-handle {
    top: auto;
    bottom: 0;
    writing-mode: horizontal-tb;
    transform: none !important;
    padding: 0.5rem 0.7rem;
  }

  .drawer-handle.left {
    left: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
  }

  .drawer-handle.right {
    right: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
  }

  .table-players {
    inset: 4.8rem 1.5rem 6rem;
  }

  .table-player {
    min-width: 7.3rem;
    padding: 0.32rem 0.4rem;
  }

  .table-player img {
    width: 2.25rem;
    height: 2.25rem;
  }

  .table-player-copy small {
    display: none;
  }

  .table-player.position-bottom { left: 1%; bottom: 0; }
  .table-player.position-top { right: 1%; top: 0; }
  .table-player.position-left { left: 0; }
  .table-player.position-right { right: 0; }

  .center-status-card {
    min-width: 6rem;
    min-height: 3.7rem;
  }

  .human-controls {
    width: calc(100vw - 1.1rem);
    bottom: 0.55rem;
    grid-template-columns: 1fr;
    gap: 0.35rem;
    padding: 0.45rem;
  }

  .control-head {
    display: none;
  }

  .special-actions {
    max-width: none;
    justify-content: center;
  }

  .mahjong-tile {
    width: clamp(38px, 6.3vw, 62px);
  }
}

@media (max-width: 680px) {
  .topbar {
    padding-inline: 0.8rem;
  }

  .brand-copy strong,
  .brand-copy small,
  .header-actions a {
    display: none;
  }

  .header-actions .soft-button {
    padding: 0.48rem 0.62rem;
  }

  .lobby-screen {
    width: calc(100% - 1rem);
    padding-top: 0.8rem;
  }

  .hero-card {
    min-height: 0;
    padding: 1.25rem;
    border-radius: 24px;
  }

  .hero-copy h1 {
    font-size: 2.2rem;
  }

  .hero-preview {
    display: none;
  }

  .glass-panel {
    border-radius: 22px;
  }

  .seats-title {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .seats-title .text-button {
    width: 100%;
    margin-left: 0;
  }

  .seat-head {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .controller {
    grid-column: 1 / -1;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }

  .game-toolbar {
    gap: 0.3rem;
  }

  .match-brief span,
  .tool-button#languageButton,
  .tool-button#stepButton {
    display: none;
  }

  .match-brief {
    padding-right: 0.1rem;
  }

  .table-player {
    min-width: 5.8rem;
  }

  .table-player-copy b {
    max-width: 4.4rem;
  }

  .table-player-copy strong {
    font-size: 0.58rem;
  }

  .table-player img {
    width: 1.9rem;
    height: 1.9rem;
  }

  .table-player.position-bottom,
  .table-player.position-top {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .table-player.position-bottom { bottom: 0; }
  .table-player.position-top { top: 0; }

  .table-player.position-left,
  .table-player.position-right {
    top: 50%;
    min-width: auto;
  }

  .table-player.position-left .table-player-copy,
  .table-player.position-right .table-player-copy {
    display: none;
  }

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

  .spectator-controls p {
    display: none;
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  .game-toolbar {
    top: 0.35rem;
    padding: 0.3rem;
  }

  .tool-button,
  .toolbar-select select {
    min-height: 1.8rem;
    padding-block: 0.3rem;
  }

  .table-players {
    inset: 3.5rem 1.2rem 4.2rem;
  }

  .human-controls {
    bottom: 0.35rem;
    padding: 0.35rem 0.5rem;
  }

  .mahjong-tile {
    width: clamp(34px, 4.3vw, 58px);
  }

  .control-head {
    display: none;
  }
}

@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;
  }
}

.game-screen.has-human-controls .table-player.position-bottom {
  bottom: clamp(7.5rem, 15vh, 12rem);
}

@media (max-width: 980px) {
  .game-screen.has-human-controls .table-player.position-bottom {
    bottom: clamp(6.5rem, 16vh, 9rem);
  }
}

/* The rules engine already renders the central round plate; keep it unobstructed. */
.center-status-card { display: none; }

/* ===== v0.2.1 gameplay UI refinement ===== */

.game-screen {
  background:
    radial-gradient(circle at 50% 35%, rgba(118, 202, 242, 0.26), transparent 38%),
    linear-gradient(180deg, #3178b7 0%, #1f5e97 100%);
}

.game-canvas {
  background:
    radial-gradient(circle at 50% 48%, rgba(116, 188, 235, 0.28), transparent 44%),
    linear-gradient(145deg, #2d76b2 0%, #225d96 100%);
}

.table-frame {
  inset: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(calc(100vw - 1.2rem), calc((100dvh - 1.2rem) * 1.68));
  aspect-ratio: 16 / 9;
  height: auto;
  max-height: calc(100dvh - 1.2rem);
  overflow: hidden;
}

.board-svg {
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 255, 255, 0.10), transparent 26%),
    radial-gradient(circle at 50% 50%, rgba(35, 117, 171, 0.16), transparent 58%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.022) 0 2px, transparent 2px 16px),
    linear-gradient(180deg, #2e76b3 0%, #276aa6 30%, #225f98 100%);
}

.board-svg::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.10), transparent 24%),
    radial-gradient(circle at 72% 74%, rgba(0, 0, 0, 0.08), transparent 30%);
  mix-blend-mode: soft-light;
}

.board-svg > svg {
  width: 100%;
  height: 100%;
}

/* Make full table tiles colorful, not only bottom hand */
.board-svg svg .yoyi-man,
.board-svg svg text.yoyi-man { color: #bf3540 !important; }
.board-svg svg .yoyi-pin,
.board-svg svg text.yoyi-pin { color: #286db0 !important; }
.board-svg svg .yoyi-sou,
.board-svg svg text.yoyi-sou { color: #168660 !important; }
.board-svg svg .yoyi-honor-red,
.board-svg svg text.yoyi-honor-red { color: #d93643 !important; }
.board-svg svg .yoyi-honor-green,
.board-svg svg text.yoyi-honor-green { color: #149267 !important; }
.board-svg svg .yoyi-honor-dark,
.board-svg svg text.yoyi-honor-dark { color: #273748 !important; }

.board-svg svg .yoyi-mark-fill { fill: currentColor !important; }
.board-svg svg .yoyi-mark-stroke { stroke: currentColor !important; }

.table-players {
  inset: clamp(1.4rem, 2.4vw, 3rem);
}

.table-player.position-bottom {
  left: 12%;
  bottom: 8.8%;
}

.table-player.position-top {
  right: 6.5%;
  top: 4.5%;
}

.table-player.position-left {
  left: 2.2%;
}

.table-player.position-right {
  right: 2.2%;
}

.human-controls {
  position: absolute;
  z-index: 25;
  left: 50%;
  bottom: clamp(0.75rem, 1.2vw, 1.25rem);
  width: min(92%, 1680px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.75rem;
  padding: 0.35rem 0.4rem 0.45rem;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.18), rgba(255,255,255,0.10));
  box-shadow: none;
  backdrop-filter: blur(4px);
}

.control-head {
  display: none;
}

.hand-tiles {
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(2px, 0.12vw, 5px);
  overflow: visible;
  padding: 0.15rem 0.35rem 0.2rem;
}

.special-actions {
  min-width: max-content;
  max-width: 18rem;
  justify-content: flex-end;
  gap: 0.45rem;
  padding-bottom: 0.3rem;
}

.mahjong-tile {
  width: clamp(52px, 3vw, 86px);
  border-color: #ccb88f;
  border-bottom-color: #d59a43;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.75),
    0 6px 11px rgba(9, 42, 72, 0.22);
}

.mahjong-tile:not(:disabled):hover {
  transform: translateY(-0.6rem) scale(1.03);
}

.mahjong-tile.drawn {
  margin-left: clamp(8px, 0.6vw, 16px);
}

.spectator-controls {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 26;
}

@media (min-width: 2100px) {
  .table-frame {
    width: min(calc(100vw - 1.6rem), calc((100dvh - 1.6rem) * 1.68));
    max-height: calc(100dvh - 1.6rem);
  }

  .mahjong-tile {
    width: clamp(72px, 2.55vw, 100px);
  }

  .table-player.position-bottom {
    bottom: 9.4%;
  }
}

@media (max-width: 980px) {
  .table-frame {
    width: calc(100vw - 0.55rem);
    max-height: calc(100dvh - 0.55rem);
    aspect-ratio: 1 / 1.45;
  }

  .human-controls {
    width: calc(100% - 0.75rem);
    grid-template-columns: 1fr;
    gap: 0.35rem;
    bottom: 0.35rem;
    padding: 0.25rem;
    background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.07));
  }

  .special-actions {
    min-width: 0;
    max-width: none;
    justify-content: center;
    padding-bottom: 0;
  }

  .mahjong-tile {
    width: clamp(38px, 7vw, 64px);
  }

  .table-player.position-bottom {
    bottom: 12%;
    left: 50%;
    transform: translateX(-50%);
  }

  .table-player.position-top {
    right: 50%;
    transform: translateX(50%);
  }
}

.game-screen.has-human-controls .table-player.position-bottom {
  bottom: 11.6%;
}

@media (max-width: 980px) {
  .game-screen.has-human-controls .table-player.position-bottom {
    bottom: 16.5%;
  }
}

/* Model catalogue v1: editable input with an anchored, searchable listbox. */
.model-combo{display:flex;align-items:stretch;gap:0;border:1px solid #bdcddd;border-radius:10px;background:#fff;min-width:0;}
.model-combo:focus-within{border-color:#4f93cc;box-shadow:0 0 0 3px #67b4ee26;}
.model-combo input[data-field="model"]{flex:1;min-width:0;border:0!important;box-shadow:none!important;border-radius:10px 0 0 10px;}
.model-combo .model-dropdown-toggle{margin:0;flex:0 0 2.3em;border:0;border-left:1px solid #d7e3ec;border-radius:0 9px 9px 0;font-size:1rem;}
.catalogue-note{display:block;font-size:.66rem;line-height:1.65;color:#617b92;font-weight:400;overflow-wrap:anywhere;margin-top:.3rem;}
.model-catalogue-popup{position:fixed;z-index:10010;display:flex;flex-direction:column;min-height:100px;overflow:hidden;background:#fff;border:1px solid #a8c7df;border-radius:10px;box-shadow:0 12px 32px #24476538;font-size:clamp(14px,.9vw,26px);color:#294761;}
.model-popup-status{font-size:.79em;padding:.55em .75em;color:#61788d;line-height:1.4;overflow-wrap:anywhere;flex:none;}
.model-popup-list{min-height:0;overflow:auto;overscroll-behavior:contain;flex:1;}
.model-popup-option{padding:.65em .8em;cursor:pointer;display:flex;align-items:center;justify-content:space-between;gap:.7em;line-height:1.35;border-bottom:1px solid #f0f4f8;}
.model-popup-option span{overflow-wrap:anywhere;min-width:0;}
.model-popup-option small{font-size:.65em;background:#eef5fb;color:#467694;border-radius:5px;padding:.3em .5em;white-space:nowrap;}
.model-popup-option:hover,.model-popup-option[aria-selected="true"]{background:#e7f3ff;}
.model-popup-refresh{border:0;border-top:1px solid #dce8f1;background:#f7fbff;color:#2979b9;cursor:pointer;padding:.65em;font-size:.78em;flex:none;}
.mortal-profile-row{display:flex;gap:.4rem;min-width:0;}
.mortal-profile-row select{flex:1;min-width:0;}
