:root {
  --night: #061c17;
  --night-soft: #0b2a22;
  --felt-deep: #073f34;
  --felt: #0a5845;
  --felt-light: #11705a;
  --bone: #f5efdf;
  --bone-edge: #d9ccb1;
  --ink: #1b201c;
  --muted-ink: #5d655e;
  --lacquer: #a7352d;
  --lacquer-dark: #78231f;
  --brass: #d5ae57;
  --brass-light: #f0d78e;
  --jade: #45a889;
  --white: #fffdf7;
  --danger: #e55f52;
  --shadow-deep: 0 18px 45px rgb(0 0 0 / 34%);
  --shadow-tile: 0 3px 0 #0b735f, 0 6px 0 #074637, 0 10px 15px rgb(0 0 0 / 32%);
  --tile-w: clamp(30px, 4.45vw, 54px);
  --tile-h: calc(var(--tile-w) * 1.38);
  --radius: 14px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--bone);
  background: var(--night);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--night); }
body { min-height: 100dvh; overflow: hidden; overscroll-behavior: contain; }
button, input, select { font: inherit; }
button { touch-action: manipulation; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--brass-light); outline-offset: 3px;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 2000; padding: 10px 16px;
  color: var(--ink); background: var(--white); border-radius: 8px;
}
.skip-link:focus { top: 12px; }

.welcome-screen {
  position: relative; display: grid; min-height: 100dvh; place-items: center; overflow: hidden;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 45%, rgb(18 112 90 / 62%), transparent 38%),
    repeating-linear-gradient(45deg, transparent 0 28px, rgb(213 174 87 / 3%) 28px 30px),
    var(--night);
}
.welcome-screen::before {
  content: ""; position: absolute; inset: 18px; border: 1px solid rgb(213 174 87 / 24%);
  border-radius: 28px; pointer-events: none;
}
.welcome-pattern {
  position: absolute; inset: 0; display: grid; place-items: center; white-space: pre;
  font: 900 clamp(72px, 18vw, 260px)/1 "STKaiti", "KaiTi", serif;
  letter-spacing: .08em; color: rgb(213 174 87 / 4%); transform: rotate(-6deg) scale(1.12);
  user-select: none;
}
.welcome-panel {
  position: relative; width: min(500px, 100%); padding: 42px 48px 34px; text-align: center;
  border: 1px solid rgb(213 174 87 / 44%); border-radius: 24px;
  background: linear-gradient(155deg, rgb(9 52 43 / 96%), rgb(5 29 24 / 97%));
  box-shadow: var(--shadow-deep), inset 0 0 0 5px rgb(0 0 0 / 12%);
}
.brand-seal {
  display: grid; width: 68px; height: 68px; margin: -78px auto 22px; place-items: center;
  color: var(--bone); border: 2px solid #d96a5e; background: var(--lacquer);
  box-shadow: 0 7px 18px rgb(0 0 0 / 35%), inset 0 0 0 3px rgb(255 255 255 / 8%);
  transform: rotate(3deg);
}
.brand-seal span { font: 700 37px/1 "STKaiti", "KaiTi", serif; transform: rotate(-3deg); }
.eyebrow { margin: 0 0 8px; color: var(--brass); font-size: 12px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; }
.welcome-panel h1 { margin: 0; font: 700 clamp(42px, 7vw, 66px)/1.15 "STKaiti", "KaiTi", serif; letter-spacing: .08em; }
.welcome-copy { margin: 17px 0 26px; color: #d7dfd7; font-family: "Songti SC", "STSong", serif; line-height: 1.8; }
.name-field { display: grid; gap: 8px; text-align: left; }
.name-field span { color: #c3cec6; font-size: 13px; }
.name-field input {
  width: 100%; min-height: 48px; padding: 0 14px; color: var(--bone); border: 1px solid rgb(213 174 87 / 32%);
  border-radius: 10px; background: rgb(0 0 0 / 20%); font-size: 17px;
}
.welcome-actions { display: grid; gap: 10px; margin-top: 14px; }
.online-panel { display: grid; gap: 12px; margin-top: 14px; padding: 13px; border: 1px solid rgb(213 174 87 / 24%); border-radius: 12px; background: rgb(0 0 0 / 15%); }
.room-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.join-submit { width: 100%; margin-top: 12px; }
.online-panel .name-field input { min-height: 42px; font-size: 15px; }
.primary-button, .secondary-button, .action-button, .icon-button, .text-button {
  min-height: 44px; border: 0; transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}
.primary-button {
  padding: 0 22px; color: #231a0b; border: 1px solid #f1d98f; border-radius: 10px;
  background: var(--brass); box-shadow: 0 5px 0 #8c6c2f, 0 9px 18px rgb(0 0 0 / 24%); font-weight: 800;
}
.primary-button:hover { background: #e2be69; }
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #8c6c2f; }
.secondary-button { padding: 0 18px; color: var(--bone); border: 1px solid rgb(213 174 87 / 45%); border-radius: 10px; background: rgb(255 255 255 / 6%); }
.secondary-button:hover { background: rgb(255 255 255 / 11%); }
.text-button { color: #c3cec6; background: transparent; text-decoration: underline; text-underline-offset: 4px; }
.welcome-notes { display: flex; justify-content: center; gap: 14px; margin-top: 20px; color: #91a79d; font-size: 12px; }
.welcome-notes span + span::before { content: "·"; margin-right: 14px; color: var(--brass); }

.game-screen { display: grid; min-height: 100dvh; grid-template-rows: 58px 1fr; background: var(--night); }
.game-topbar {
  position: relative; z-index: 50; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-width: 0; padding: 0 max(12px, env(safe-area-inset-left)); border-bottom: 1px solid rgb(213 174 87 / 25%);
  background: #071f1a; box-shadow: 0 4px 18px rgb(0 0 0 / 22%);
}
.game-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.game-brand strong { display: block; font-family: "STKaiti", "KaiTi", serif; font-size: 19px; letter-spacing: .08em; }
.game-brand small { display: block; margin-top: 2px; color: #8da399; font-size: 11px; }
.mini-seal { display: grid; width: 34px; height: 34px; place-items: center; color: white; border: 1px solid #df7167; background: var(--lacquer); font-family: "STKaiti", serif; }
.topbar-center { display: flex; gap: 22px; color: #93a99f; font-size: 12px; }
.topbar-center b { margin-left: 5px; color: var(--bone); font-variant-numeric: tabular-nums; }
.topbar-actions { display: flex; justify-content: flex-end; gap: 8px; }
.icon-button {
  display: grid; width: 44px; padding: 0; place-items: center; color: #aec0b7; border-radius: 9px; background: transparent;
}
.icon-button:hover { color: var(--bone); background: rgb(255 255 255 / 7%); }
.icon-button.danger:hover { color: #ffb0a8; background: rgb(229 95 82 / 12%); }
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.muted .sound-wave { display: none; }

.mahjong-table {
  position: relative; min-height: 0; overflow: hidden; isolation: isolate;
  background:
    radial-gradient(ellipse at center, rgb(24 127 102 / 95%) 0%, rgb(10 88 69 / 98%) 48%, #064035 100%);
  box-shadow: inset 0 0 80px rgb(0 0 0 / 38%);
}
.mahjong-table::before {
  content: ""; position: absolute; z-index: -2; inset: 12px; border: clamp(7px, 1.2vw, 15px) solid #3b2316;
  border-radius: 38px; box-shadow: inset 0 0 0 3px #86673b, inset 0 0 36px rgb(0 0 0 / 65%), 0 0 0 2px #120d09;
}
.felt-stitch { position: absolute; z-index: -1; inset: 31px; border: 1px dashed rgb(237 215 150 / 16%); border-radius: 22px; pointer-events: none; }

.player-seat { position: absolute; z-index: 7; display: flex; align-items: center; gap: 8px; }
.seat-top { top: 2.5%; left: 50%; flex-direction: column; transform: translateX(-50%); }
.seat-left { top: 47%; left: 2.4%; flex-direction: column; transform: translateY(-50%); }
.seat-right { top: 47%; right: 2.4%; flex-direction: column; transform: translateY(-50%); }
.seat-profile, .human-profile {
  display: flex; align-items: center; gap: 7px; min-height: 32px; padding: 4px 10px; color: #dbe5df;
  border: 1px solid rgb(213 174 87 / 24%); border-radius: 999px; background: rgb(2 28 22 / 76%); box-shadow: 0 5px 12px rgb(0 0 0 / 22%);
}
.player-avatar { display: grid; width: 22px; height: 22px; place-items: center; color: #1e1a0f; border-radius: 50%; background: var(--brass); font: 800 12px/1 "STKaiti", serif; }
.player-name { max-width: 74px; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.player-score { color: var(--brass-light); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.dealer-chip { display: grid; width: 21px; height: 21px; place-items: center; color: white; border-radius: 50%; background: var(--lacquer); font-size: 11px; font-weight: 800; }
.turn-glow { box-shadow: 0 0 0 2px var(--brass), 0 0 20px rgb(213 174 87 / 40%); }
.opponent-hand { display: flex; gap: 2px; }
.seat-left .opponent-hand, .seat-right .opponent-hand { max-width: 180px; transform: scale(.72); transform-origin: top center; }
.tile-back-mini {
  width: clamp(13px, 1.55vw, 20px); height: clamp(26px, 2.8vw, 36px);
  border: 1px solid #d6c895; border-radius: 4px;
  background:
    linear-gradient(145deg, rgb(255 255 255 / 22%), transparent 28%),
    repeating-linear-gradient(45deg, #087055 0 3px, #075c49 3px 6px);
  box-shadow: 0 2px 0 #043f32, 0 4px 8px rgb(0 0 0 / 28%);
}
.exposed-sets, .human-melds { display: flex; align-items: flex-end; gap: 5px; min-height: 30px; }
.meld-group { display: flex; gap: 1px; padding: 2px; border-radius: 4px; background: rgb(0 0 0 / 12%); }

.river { position: absolute; z-index: 4; display: grid; grid-template-columns: repeat(6, minmax(17px, 1fr)); gap: 3px; width: min(27vw, 300px); min-height: 60px; padding: 3px; }
.river-top { top: 19%; left: 50%; transform: translateX(-50%) rotate(180deg); }
.river-bottom { bottom: 23%; left: 50%; transform: translateX(-50%); }
.river-left { top: 47%; left: 17%; transform: translateY(-50%) rotate(90deg); }
.river-right { top: 47%; right: 17%; transform: translateY(-50%) rotate(-90deg); }
.discard-tile {
  position: relative; display: grid; aspect-ratio: .75; min-width: 17px; padding: 2px; place-items: center; overflow: hidden;
  color: var(--ink); border: 1px solid #eee1c8; border-bottom-color: #b8aa8f; border-radius: 4px;
  background: linear-gradient(115deg, #fffdf6 0 68%, #e9dcc4 100%);
  box-shadow: 0 2px 0 #0a614f, 0 3px 4px rgb(0 0 0 / 22%);
}
.discard-tile .tile-face { width: 92%; height: 92%; }
.discard-tile .character-rank { font-size: 1.25em; }
.discard-tile .character-suit { font-size: .62em; }
.discard-tile .tile-pattern { transform: scale(.82); }
.discard-tile .flower-face span { display: none; }
.discard-tile.god::after { content: "财"; position: absolute; right: -2px; top: -3px; padding: 1px 2px; color: white; border-radius: 2px; background: var(--lacquer); font: 700 7px/1 sans-serif; }

.table-center {
  position: absolute; z-index: 6; left: 50%; top: 49%; display: grid; width: clamp(170px, 17vw, 230px); min-height: 132px;
  place-items: center; padding: 12px; border: 1px solid rgb(213 174 87 / 45%); border-radius: 50%;
  background: radial-gradient(circle, #0b4236 0 58%, #082f27 59%); box-shadow: 0 12px 30px rgb(0 0 0 / 30%), inset 0 0 0 5px rgb(213 174 87 / 7%);
  transform: translate(-50%, -50%);
}
.wind-compass { position: absolute; inset: -14px; color: rgb(240 215 142 / 52%); font: 700 11px/1 "STKaiti", serif; }
.wind-compass span { position: absolute; }
.wind-compass span:nth-child(1) { left: 50%; top: 0; transform: translateX(-50%); }
.wind-compass span:nth-child(2) { right: 1%; top: 50%; }
.wind-compass span:nth-child(3) { left: 50%; bottom: 0; transform: translateX(-50%); }
.wind-compass span:nth-child(4) { left: 1%; top: 50%; }
.center-tiles { display: flex; gap: 12px; margin-top: -2px; }
.center-tiles > div { display: grid; grid-template-columns: auto auto; align-items: center; gap: 4px; }
.center-tiles small { color: #8eaa9d; font-size: 9px; writing-mode: vertical-rl; }
.center-tiles .tile { width: 29px; height: 40px; box-shadow: 0 2px 0 #0b735f, 0 4px 0 #074637; }
.tile-empty { display: grid; width: 29px; height: 40px; place-items: center; color: #8eaa9d; border: 1px dashed rgb(213 174 87 / 38%); border-radius: 5px; font-size: 12px; }
.god-display { position: relative; }
.god-display::after { content: ""; position: absolute; inset: -4px; border: 1px solid var(--brass); border-radius: 5px; pointer-events: none; }
#turn-message { max-width: 150px; overflow: hidden; color: var(--bone); font-size: 12px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.center-counters { display: flex; align-items: center; gap: 7px; color: #9eb4aa; font-size: 9px; }
.center-counters i { width: 3px; height: 3px; border-radius: 50%; background: var(--brass); }

.human-seat { position: absolute; z-index: 10; bottom: max(8px, env(safe-area-inset-bottom)); left: 50%; width: min(96%, 980px); transform: translateX(-50%); }
.human-profile { position: absolute; left: 0; bottom: calc(var(--tile-h) + 11px); }
.human-melds { position: absolute; right: 0; bottom: calc(var(--tile-h) + 7px); }
.draw-hint {
  position: absolute; z-index: 30; left: 50%; bottom: calc(var(--tile-h) + 42px); display: flex; align-items: center; justify-content: center;
  min-height: 48px; color: #fff8df;
  opacity: 0; pointer-events: none; transform: translate(-50%, 8px) scale(.96);
  transition: opacity 180ms ease, transform 180ms ease;
}
.draw-hint.show {
  opacity: 1; transform: translate(-50%, 0) scale(1);
}
.draw-hint > span {
  color: var(--brass-light); font: 800 11px/1 "PingFang SC", sans-serif; letter-spacing: .08em;
}
.draw-hint-card {
  display: flex; align-items: center; gap: 8px; padding: 7px 13px 7px 10px;
  border: 1px solid rgb(240 215 142 / 78%); border-radius: 999px;
  background: linear-gradient(145deg, rgb(117 35 29 / 94%), rgb(7 35 29 / 92%));
  box-shadow: 0 12px 30px rgb(0 0 0 / 32%), inset 0 0 0 1px rgb(255 255 255 / 12%);
}
.draw-hint-card > span {
  color: var(--brass-light); font: 900 12px/1 "PingFang SC", sans-serif; letter-spacing: .08em;
}
.draw-hint strong { color: var(--bone); font-size: 12px; white-space: nowrap; }
.draw-hint .tile { box-shadow: 0 2px 0 #074637; }
.human-hand { display: flex; justify-content: center; align-items: flex-end; gap: clamp(1px, .25vw, 4px); min-height: calc(var(--tile-h) + 12px); padding: 0 4px; }
.tile {
  position: relative; display: grid; width: var(--tile-w); height: var(--tile-h); flex: 0 0 auto; place-items: center;
  padding: 6px 3px 7px; color: var(--ink); border: 1px solid #fffaf0; border-bottom-color: #b7a98e; border-radius: 7px 7px 5px 5px;
  background:
    linear-gradient(115deg, rgb(255 255 255 / 92%) 0 68%, rgb(232 219 194 / 96%) 100%),
    linear-gradient(#0b876f, #07513f);
  box-shadow: var(--shadow-tile); user-select: none;
}
button.tile { min-height: 0; }
.tile.drawn-tile {
  z-index: 6;
  box-shadow: 0 3px 0 #0b735f, 0 6px 0 #074637, 0 0 0 3px var(--brass-light), 0 0 22px rgb(240 215 142 / 72%);
  transform: translateY(-7px);
}
.tile::before {
  content: ""; position: absolute; inset: 3px; border: 1px solid rgb(93 101 94 / 15%);
  border-radius: 4px; pointer-events: none; box-shadow: inset 0 0 9px rgb(255 255 255 / 55%);
}
.tile::after {
  content: ""; position: absolute; left: 8%; right: 8%; bottom: 3px; height: 2px;
  border-radius: 999px; background: rgb(255 255 255 / 58%); pointer-events: none;
}
.tile-face {
  position: relative; z-index: 1; display: grid; width: 100%; height: 100%; place-items: center;
  filter: drop-shadow(0 .5px 0 rgb(255 255 255 / 75%));
}
.character-face { grid-template-rows: 1fr auto; gap: 1px; padding-top: 1px; }
.character-rank {
  color: #9d1f24; font: 900 clamp(18px, 2.2vw, 29px)/.9 "Songti SC", "STSong", serif;
  text-shadow: 0 1px 0 rgb(255 255 255 / 68%);
}
.character-suit {
  color: #a9282a; font: 900 clamp(9px, 1.05vw, 13px)/1 "Songti SC", "STSong", serif;
  transform: scaleX(.92);
}
.dot-face, .bamboo-face {
  grid-template-rows: 1fr; padding: 4px 3px;
}
.tile-rank-chip {
  position: absolute; z-index: 4; right: -2px; top: -3px; padding: 1px 3px;
  color: #fffdf6; border: 1px solid rgb(255 198 155 / 78%); border-radius: 999px;
  background: #a7352d; box-shadow: 0 1px 3px rgb(0 0 0 / 26%);
  font: 900 clamp(7px, .72vw, 9px)/1 "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: -.04em; white-space: nowrap;
}
.tile-pattern {
  display: grid; width: 100%; height: 100%; place-items: center;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: 0; transform: scale(1.02); transform-origin: center;
}
.dot-count-8 .tile-pattern { grid-template-rows: repeat(4, 1fr); }
.dot-layout-5 {
  transform: scale(.94);
}
.dot-layout-5 .dot-mark-3 {
  width: min(148%, 19px);
}
.dot-layout-7 {
  gap: 0 3px;
  transform: scale(.88);
}
.dot-layout-7 .dot-mark-7 {
  width: min(142%, 18px);
  box-shadow: inset 0 -1px 2px rgb(0 0 0 / 30%), 0 0 0 2px rgb(255 255 255 / 65%);
}
.mahjong-dot {
  display: grid; width: min(126%, 16px); aspect-ratio: 1; place-self: center; place-items: center;
  border-radius: 50%; border: 1px solid color-mix(in srgb, currentColor 84%, #121512);
  background:
    radial-gradient(circle, transparent 0 34%, #fffef7 35% 50%, currentColor 51% 62%, #fffef7 63% 74%, currentColor 75% 100%);
  box-shadow: inset 0 -1px 2px rgb(0 0 0 / 24%), 0 1px 0 rgb(255 255 255 / 72%);
}
.mahjong-dot i {
  display: grid; width: 62%; aspect-ratio: 1; place-items: center; border: 1px solid #fffdf6;
  border-radius: 50%; background: color-mix(in srgb, currentColor 88%, #fff 12%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 62%, #171b17);
}
.dot-core {
  display: block; width: 46%; aspect-ratio: 1; border-radius: 50%;
  background: #c53a37; box-shadow: 0 0 0 1px rgb(255 255 255 / 72%);
}
.mahjong-dot.one-dot {
  width: min(156%, 25px);
  background:
    radial-gradient(circle, #c73631 0 18%, #f3dfb6 19% 30%, #1d6d4d 31% 44%, #f9f3df 45% 54%, #1c5f43 55% 100%);
}
.mahjong-dot.one-dot i {
  width: 50%; background: radial-gradient(circle, #d73f39 0 42%, #f5e9c9 43% 66%, #1c6a4c 67% 100%);
}
.mahjong-dot.one-dot .dot-core { display: none; }
.dot-red { color: #b23a38; }
.dot-green { color: #1b6d4c; }
.dot-blue { color: #1e1f22; }
.bamboo-pattern {
  grid-template-rows: repeat(3, 1fr);
  gap: 1px 3px;
  transform: scale(.88);
}
.bamboo-layout-2 {
  grid-template-rows: repeat(3, 1fr);
  transform: scale(.8);
}
.bamboo-layout-3, .bamboo-layout-4, .bamboo-layout-5 {
  transform: scale(.86);
}
.bamboo-layout-5 {
  transform: scale(.78);
}
.bamboo-layout-5 .bamboo-mark-3 {
  width: min(88%, 12px);
  height: min(98%, 24px);
}
.bamboo-layout-7 {
  gap: 0 3px;
  transform: scale(.72);
}
.bamboo-layout-7 .bamboo-mark-7 {
  width: min(96%, 12px);
  height: min(98%, 24px);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 20%), 0 0 0 2px rgb(255 255 255 / 60%);
}
.bamboo-layout-8 {
  grid-template-rows: repeat(4, 1fr);
  transform: scale(.8);
}
.bamboo-layout-9 {
  transform: scale(.76);
}
.bamboo-compact .bamboo-stick {
  width: min(62%, 8px);
  height: min(80%, 17px);
}
.bamboo-stick {
  position: relative; display: block; width: min(72%, 10px); height: min(88%, 22px);
  place-self: center; overflow: hidden; color: #146d44; border: 1px solid color-mix(in srgb, currentColor 76%, #111);
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 78%), transparent 28% 66%, rgb(0 0 0 / 20%)),
    linear-gradient(180deg, color-mix(in srgb, currentColor 90%, #fff 10%), currentColor 54%, color-mix(in srgb, currentColor 72%, #000 28%));
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 16%), 0 1px 0 rgb(255 255 255 / 64%);
}
.bamboo-stick::before, .bamboo-stick::after {
  content: ""; position: absolute; left: 19%; right: 19%; height: 1px;
  border-radius: 999px; background: rgb(255 255 255 / 70%);
  box-shadow: 0 1px 0 rgb(0 0 0 / 22%);
}
.bamboo-stick::before { top: 33%; }
.bamboo-stick::after { top: 66%; }
.bamboo-joint {
  position: absolute; left: 15%; right: 15%; height: 2px; border-radius: 999px;
  background: color-mix(in srgb, currentColor 68%, #fff 32%);
  opacity: .92;
}
.bamboo-joint:first-child { top: 32%; }
.bamboo-joint:last-child { top: 64%; }
.stick-green { color: #126f44; }
.stick-blue { color: #126f44; }
.stick-red { color: #aa332f; }
.sparrow-face { padding: 1px 0 2px; }
.sparrow { width: 94%; height: 100%; overflow: visible; transform: scale(.96); transform-origin: center; }
.sparrow path, .sparrow circle { vector-effect: non-scaling-stroke; }
.sparrow-branch, .sparrow-feather { fill: none; stroke: #15704e; stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.sparrow-tail { fill: none; stroke: #245f8b; stroke-width: 4; stroke-linecap: round; }
.sparrow-body { fill: #20754e; stroke: #0e4c36; stroke-width: 2.2; }
.sparrow-wing { fill: #2f6697; stroke: #17466a; stroke-width: 2; }
.sparrow-head { fill: #b23631; stroke: #7c241f; stroke-width: 2; }
.sparrow-beak { fill: #d4a33f; stroke: #8c6421; stroke-width: 1.4; }
.sparrow-eye { fill: #111711; }
.sparrow-leaf { fill: #1a7a54; stroke: #0f5139; stroke-width: 1.5; }
.honor-face { padding: 3px; }
.honor-glyph {
  font: 900 clamp(20px, 2.35vw, 31px)/1 "Songti SC", "STSong", serif;
  color: #27342d; text-shadow: 0 1px 0 rgb(255 255 255 / 70%);
}
.tile.red-honor .honor-glyph { color: #a32327; }
.tile.green-honor .honor-glyph { color: #18704e; }
.white-dragon-frame {
  display: grid; width: 78%; height: 70%; place-items: center; border: 3px solid #285f96;
  border-radius: 3px; background: linear-gradient(135deg, rgb(40 95 150 / 10%), transparent);
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 65%), 0 1px 0 rgb(255 255 255 / 68%);
}
.white-dragon-frame i { width: 60%; height: 52%; border: 2px solid #285f96; border-radius: 2px; opacity: .82; }
.flower-face {
  grid-template-rows: 1fr auto; padding: 3px 2px; color: #8a3e83;
  font: 800 clamp(9px, 1vw, 13px)/1 "Songti SC", serif;
}
.flower-face svg { width: 88%; height: 82%; overflow: visible; }
.flower-stem { fill: none; stroke: #1c704d; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.flower-leaf { fill: #1d7a55; stroke: #115338; stroke-width: 1.3; }
.flower-bloom { fill: #a94688; stroke: #7a2b61; stroke-width: 1.5; }
.flower-core { fill: #d7a645; }
.tile-god-badge { position: absolute; z-index: 3; right: -4px; top: -5px; display: grid; width: 18px; height: 18px; place-items: center; color: #fff; border: 1px solid #ff9c8f; border-radius: 50%; background: var(--lacquer); font: 800 9px/1 sans-serif; box-shadow: 0 2px 4px rgb(0 0 0 / 30%); }
.human-hand .tile { appearance: none; transition: transform 160ms ease, filter 160ms ease; }
.human-hand .tile:hover { filter: brightness(1.05); transform: translateY(-5px); }
.human-hand .tile.selected { z-index: 5; box-shadow: 0 3px 0 #0b735f, 0 6px 0 #074637, 0 0 0 3px var(--brass), 0 11px 18px rgb(0 0 0 / 35%); transform: translateY(-11px); }
.human-hand .tile:disabled { cursor: default; filter: saturate(.7); opacity: .86; }
.human-hand .tile:disabled:hover { transform: none; }
.tile.tile-small { width: calc(var(--tile-w) * .48); height: calc(var(--tile-h) * .48); min-width: 20px; padding: 2px 1px; border-radius: 3px; box-shadow: 0 2px 0 #a99c83; }
.tile-small .tile-face { transform: scale(.9); }
.tile-small .character-rank, .tile-small .honor-glyph { font-size: clamp(9px, 1vw, 13px); }
.tile-small .character-suit, .tile-small .flower-face span { font-size: 6px; }
.tile-small .tile-pattern { transform: scale(.95); }
.tile-small .bamboo-pattern { transform: scale(.78); }
.tile-small .bamboo-layout-9 { transform: scale(.68); }
.tile-small .mahjong-dot { width: min(116%, 8px); }
.tile-small .bamboo-stick { width: min(64%, 6px); height: min(78%, 13px); }
.tile-small .tile-rank-chip { display: none; }
.tile-small .tile-god-badge { display: none; }

.action-bar { position: absolute; z-index: 25; left: 50%; bottom: calc(var(--tile-h) + 24px + env(safe-area-inset-bottom)); display: flex; min-height: 48px; align-items: center; justify-content: center; gap: 8px; padding: 5px 8px; border-radius: 14px; background: rgb(4 31 25 / 74%); box-shadow: 0 8px 20px rgb(0 0 0 / 24%); transform: translateX(-50%); backdrop-filter: blur(5px); }
.action-button { min-width: 64px; padding: 0 15px; color: var(--bone); border: 1px solid rgb(255 255 255 / 16%); border-radius: 10px; background: #173f35; box-shadow: 0 4px 0 #06251e; font-weight: 800; }
.action-button:hover { background: #205548; }
.action-button.primary-action { color: #20170a; border-color: #f0d589; background: var(--brass); box-shadow: 0 4px 0 #8b682d; }
.action-button.win-action { color: white; border-color: #e7786e; background: var(--lacquer); box-shadow: 0 4px 0 var(--lacquer-dark); }
.action-button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgb(0 0 0 / 40%); }
.action-hint { padding: 0 12px; color: #bed0c7; font-size: 13px; white-space: nowrap; }
.event-log { position: absolute; z-index: 9; left: 42px; bottom: 24px; max-width: 250px; padding: 6px 10px; overflow: hidden; color: #b7cbc1; border-left: 2px solid var(--brass); background: rgb(0 0 0 / 15%); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.modal {
  width: min(540px, calc(100% - 28px)); max-height: calc(100dvh - 28px); overflow: auto; padding: 30px;
  color: var(--ink); border: 1px solid var(--brass); border-radius: 18px; background: var(--bone);
  box-shadow: 0 28px 80px rgb(0 0 0 / 55%);
}
.modal::backdrop { background: rgb(2 15 12 / 72%); backdrop-filter: blur(4px); }
.modal h2 { margin: 0 0 18px; font: 700 34px/1.2 "STKaiti", "KaiTi", serif; }
.modal .eyebrow { color: #8b631d; }
.modal-ornament { width: 80px; height: 5px; margin: -30px auto 26px; border-radius: 0 0 5px 5px; background: var(--lacquer); }
.settlement-details { display: grid; gap: 8px; padding: 14px; border: 1px solid #d8caaa; border-radius: 10px; background: #fffaf0; color: var(--muted-ink); }
.settlement-details p { margin: 0; }
.settlement-breakdown {
  display: grid; gap: 9px; margin-top: 12px; padding: 12px;
  border: 1px solid #ddcda7; border-radius: 12px; background: #f9f0d9;
}
.settlement-breakdown:empty { display: none; }
.settlement-breakdown h3 {
  margin: 0 0 2px; color: #342719; font: 800 15px/1.2 "STKaiti", "KaiTi", serif; letter-spacing: .06em;
}
.breakdown-row {
  display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px;
  min-height: 34px; padding: 5px 7px; border-radius: 8px; background: rgb(255 253 246 / 72%);
}
.breakdown-row strong { color: #7a5420; font-size: 12px; }
.breakdown-tiles { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.breakdown-empty { color: #8a8171; font-size: 12px; }
.score-changes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 18px; }
.score-change { padding: 10px 6px; text-align: center; border-radius: 8px; background: #e8dfcc; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-change.positive { color: #116349; background: #dcecdf; }
.score-change.negative { color: #922b25; background: #f2dfd8; }
.match-over-note { margin: 12px 0; padding: 12px; color: #6f281f; border-left: 4px solid var(--lacquer); background: #f3ded4; line-height: 1.6; }
.swap-field { display: grid; gap: 7px; margin-bottom: 16px; }
.swap-field span { font-size: 13px; font-weight: 700; }
.swap-field select { min-height: 44px; padding: 0 10px; border: 1px solid #b9aa8d; border-radius: 8px; background: white; }
.settlement-dialog .primary-button { width: 100%; }
.rules-dialog { width: min(800px, calc(100% - 28px)); }
.modal-close { position: absolute; right: 13px; top: 10px; width: 44px; min-height: 44px; color: #5f5b51; border: 0; background: transparent; font-size: 30px; }
.rules-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.rules-columns section { padding: 14px; border-top: 3px solid var(--brass); background: #fffaf0; }
.rules-columns h3 { margin: 0 0 9px; font-family: "STKaiti", "KaiTi", serif; font-size: 20px; }
.rules-columns ul { margin: 0; padding-left: 19px; color: #4d514c; font-size: 13px; line-height: 1.7; }

.toast { position: fixed; z-index: 1500; left: 50%; bottom: 24px; max-width: min(90vw, 480px); padding: 10px 16px; color: var(--bone); border: 1px solid rgb(213 174 87 / 45%); border-radius: 10px; background: #102e27; box-shadow: var(--shadow-deep); opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.portrait-hint { display: none; }

@media (max-width: 900px) {
  :root { --tile-w: clamp(27px, 4.8vw, 42px); }
  .game-screen { grid-template-rows: 46px 1fr; }
  .game-topbar { grid-template-columns: 1fr auto; }
  .topbar-center { display: none; }
  .game-brand small { display: none; }
  .icon-button { width: 40px; min-height: 40px; }
  .river { width: 30vw; grid-template-columns: repeat(6, 1fr); gap: 2px; }
  .river-left { left: 14%; } .river-right { right: 14%; }
  .table-center { width: 150px; min-height: 112px; }
  .human-profile { bottom: calc(var(--tile-h) + 7px); }
  .action-bar { bottom: calc(var(--tile-h) + 16px + env(safe-area-inset-bottom)); }
  .event-log { display: none; }
  .seat-profile { transform: scale(.86); }
  .rules-columns { grid-template-columns: 1fr; }
}

@media (max-height: 430px) and (orientation: landscape) {
  :root { --tile-w: clamp(25px, 4.1vw, 34px); }
  .game-screen { grid-template-rows: 40px 1fr; }
  .game-topbar { padding-inline: 8px; }
  .mini-seal { width: 28px; height: 28px; }
  .game-brand strong { font-size: 16px; }
  .icon-button { width: 36px; min-height: 36px; }
  .mahjong-table::before { inset: 5px; border-width: 6px; border-radius: 20px; }
  .felt-stitch { inset: 17px; }
  .seat-top { top: 1.2%; }
  .seat-left, .seat-right { top: 42%; }
  .seat-left { left: .5%; } .seat-right { right: .5%; }
  .seat-profile { min-height: 25px; padding: 2px 7px; }
  .player-avatar { width: 18px; height: 18px; }
  .opponent-hand { transform: scale(.72); transform-origin: top center; }
  .river-top { top: 19%; }
  .river-bottom { bottom: 23%; }
  .river-left { left: 13%; } .river-right { right: 13%; }
  .table-center { top: 47%; width: 130px; min-height: 92px; padding: 6px; }
  .center-tiles .tile { width: 23px; height: 31px; }
  .center-tiles .tile-primary { font-size: 11px; }
  .center-counters { display: none; }
  .human-profile { bottom: calc(var(--tile-h) + 4px); transform: scale(.82); transform-origin: bottom left; }
  .human-melds { bottom: calc(var(--tile-h) + 3px); transform: scale(.78); transform-origin: bottom right; }
  .action-bar { bottom: calc(var(--tile-h) + 7px + env(safe-area-inset-bottom)); min-height: 38px; padding: 2px 5px; }
  .action-button { min-height: 36px; min-width: 55px; padding: 0 10px; font-size: 12px; }
}

@media (orientation: portrait) and (max-width: 900px) {
  .portrait-hint {
    position: fixed; z-index: 1800; inset: 0; display: grid; place-content: center; justify-items: center; padding: 28px;
    color: var(--bone); text-align: center; background: rgb(4 28 23 / 96%);
  }
  .portrait-hint.dismissed { display: none; }
  .portrait-hint strong { margin-top: 18px; font: 700 26px/1.3 "STKaiti", "KaiTi", serif; }
  .portrait-hint p { color: #abc0b6; }
  .rotate-device { width: 72px; height: 105px; padding: 7px; border: 3px solid var(--brass); border-radius: 12px; transform: rotate(68deg); animation: device-turn 1.5s ease-in-out 3 alternate; }
  .rotate-device span { display: block; width: 100%; height: 100%; border: 1px solid rgb(213 174 87 / 35%); border-radius: 5px; }
  .welcome-panel { padding-inline: 26px; }
}

@keyframes device-turn { to { transform: rotate(88deg); } }

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