:root {
  --ink: #172b27;
  --green-950: #0b2420;
  --green-900: #102f29;
  --green-800: #17453b;
  --green-700: #1f5b4b;
  --jade: #2d7a62;
  --gold: #d8aa59;
  --gold-light: #f1d59a;
  --cream: #f5f2e9;
  --paper: #fffdf7;
  --muted: #7a847f;
  --red: #b94b43;
  --shadow: 0 18px 50px rgba(16, 47, 41, .12);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100dvh; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }
img { -webkit-user-drag: none; user-select: none; }
img.tile { aspect-ratio: 190 / 240; border-radius: 4%; }
img.tile[src*="Back.svg"] { box-shadow: 1px 0 0 rgba(255,255,255,.24); }

.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--green-900); font-size: 20px; font-weight: 800; letter-spacing: 2px; }
.brand-mark { display: grid; place-items: center; width: 39px; height: 43px; border-radius: 7px; background: var(--green-800); border: 1px solid rgba(255,255,255,.18); color: var(--gold-light); font-family: serif; font-size: 24px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); }
.brand-light { font-weight: 400; margin-left: 5px; opacity: .76; }
.brand-button { border: 0; background: transparent; padding: 0; }
.brand-large { color: white; font-size: 24px; }
.brand-large .brand-mark { background: var(--gold); color: var(--green-950); width: 45px; height: 49px; }
.eyebrow, .small-kicker { color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: 3px; }
.muted { color: var(--muted); }

.button { min-height: 43px; border-radius: 9px; border: 1px solid transparent; padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; font-weight: 650; transition: transform .16s, filter .16s, background .16s; }
.button:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.04); }
.button:not(:disabled):active { transform: translateY(0); }
.button-primary { color: white; background: var(--green-700); box-shadow: 0 7px 18px rgba(31,91,75,.2); }
.button-gold { color: #2a281f; background: linear-gradient(135deg, #f0d79e, #d5a24e); box-shadow: 0 7px 20px rgba(186,135,50,.2); }
.button-outline { color: var(--green-800); background: transparent; border-color: rgba(23,69,59,.28); }
.button-danger { color: var(--red); background: #fff7f4; border-color: #ecd3cc; }
.button-wide { width: 100%; }
.icon-button { width: 38px; height: 38px; border: 1px solid rgba(23,69,59,.15); border-radius: 50%; background: rgba(255,255,255,.75); color: var(--green-900); font-size: 20px; display: grid; place-items: center; }
.text-button { border: 0; background: none; color: var(--jade); }
.segmented { display: inline-flex; padding: 4px; border-radius: 10px; background: #e8e9e1; gap: 3px; }
.segmented button { border: 0; border-radius: 7px; padding: 8px 15px; background: transparent; color: #6c7771; font-size: 13px; }
.segmented button.active { color: var(--green-800); background: var(--paper); box-shadow: 0 2px 8px rgba(16,47,41,.08); font-weight: 700; }

.auth-view { min-height: 100dvh; background: radial-gradient(circle at 15% 15%, #235648 0, transparent 38%), linear-gradient(130deg, var(--green-950), #12372f 65%, #0d2924); display: grid; grid-template-columns: minmax(360px, 1fr) minmax(380px, 480px); align-items: center; gap: 8vw; padding: 7vw 11vw; position: relative; overflow: hidden; }
.auth-view::before { content: ""; position: absolute; inset: 0; opacity: .055; background-image: repeating-linear-gradient(45deg, transparent 0 17px, #fff 18px 19px); pointer-events: none; }
.auth-intro, .auth-card { position: relative; z-index: 2; }
.auth-intro h1 { font-family: "Songti SC", "STSong", serif; color: #fff9ea; font-size: clamp(42px, 5vw, 72px); line-height: 1.24; letter-spacing: 4px; margin: 25px 0 22px; font-weight: 500; }
.auth-intro h1 em { color: var(--gold-light); font-style: normal; }
.auth-description { color: rgba(238,244,232,.67); line-height: 1.9; font-size: 15px; }
.feature-row { display: flex; gap: 25px; margin-top: 36px; color: #d4dfd5; font-size: 13px; }
.feature-row span::before { content: "✓"; color: var(--gold); margin-right: 8px; }
.auth-decoration img { position: absolute; width: 115px; opacity: .075; transform: rotate(16deg); }
.auth-decoration img:nth-child(1) { left: 2%; bottom: -35px; }
.auth-decoration img:nth-child(2) { left: 42%; top: -30px; transform: rotate(-25deg); }
.auth-decoration img:nth-child(3) { right: 2%; bottom: 4%; }
.auth-card { background: rgba(255,253,247,.97); border: 1px solid rgba(255,255,255,.55); border-radius: 20px; padding: 38px; box-shadow: 0 35px 80px rgba(0,0,0,.26); }
.auth-card-heading h2 { margin: 8px 0; font-size: 27px; }
.auth-card-heading p { color: var(--muted); font-size: 13px; margin: 0 0 25px; }
.auth-tabs { display: flex; margin-bottom: 24px; }
.auth-tabs button { flex: 1; }
#auth-form label { display: block; font-size: 13px; font-weight: 650; margin: 17px 0; }
#auth-form input { display: block; width: 100%; height: 48px; border: 1px solid #dedfd6; border-radius: 9px; background: white; padding: 0 14px; margin-top: 8px; outline: none; color: var(--ink); }
#auth-form input:focus { border-color: var(--jade); box-shadow: 0 0 0 3px rgba(45,122,98,.1); }
.form-error { min-height: 20px; color: var(--red); font-size: 12px; margin: 4px 0 10px; }
.auth-note { text-align: center; color: #91958e; font-size: 11px; margin: 20px 0 0; }
.auth-note strong { color: #a77832; }

.topbar { height: 70px; padding: 0 max(22px, calc((100vw - 1440px)/2)); display: flex; align-items: center; justify-content: space-between; background: rgba(255,253,247,.95); border-bottom: 1px solid #e6e4db; position: relative; z-index: 20; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.connection-status { font-size: 11px; color: #75817b; display: flex; align-items: center; gap: 6px; }
.connection-status i { width: 7px; height: 7px; border-radius: 50%; background: #d69c48; }
.connection-status.online i { background: #43a273; box-shadow: 0 0 0 3px rgba(67,162,115,.12); }
.connection-status.offline i { background: var(--red); }
.coin-pill { display: flex; align-items: center; gap: 8px; border-radius: 20px; padding: 5px 13px 5px 6px; background: #f3ecdc; color: #765624; font-size: 14px; }
.coin-icon { width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center; background: #d9ae61; color: #fff7e5; font-family: serif; font-size: 12px; border: 2px solid #edcf97; }
.profile-button { display: flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--ink); font-size: 13px; }
.profile-button > span:first-child { width: 33px; height: 33px; border-radius: 50%; display: grid; place-items: center; color: #f7e8c6; background: var(--green-700); font-weight: 700; }

.lobby-view { max-width: 1440px; margin: 0 auto; padding: 28px 28px 45px; }
.lobby-hero { min-height: 190px; border-radius: 17px; padding: 32px 38px; color: white; background: radial-gradient(circle at 85% 25%, rgba(217,175,95,.18), transparent 28%), linear-gradient(110deg, #153e34, #1c4b3e); position: relative; overflow: hidden; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.lobby-hero h1 { font-family: "Songti SC", serif; font-size: 31px; font-weight: 500; margin: 10px 0; letter-spacing: 2px; }
.lobby-hero h1 span { color: var(--gold-light); }
.lobby-hero p:not(.eyebrow) { color: rgba(255,255,255,.62); margin: 0; font-size: 13px; }
.quick-start { min-width: 265px; min-height: 68px; justify-content: flex-start; padding: 0 20px; position: relative; z-index: 2; }
.quick-start .button-icon { font-size: 22px; }
.quick-start span:nth-child(2) { text-align: left; font-size: 16px; }
.quick-start small { display: block; font-size: 10px; opacity: .65; font-weight: 400; margin-top: 3px; }
.quick-start b { margin-left: auto; font-size: 20px; }
.hero-tiles { position: absolute; right: 28%; top: -23px; display: flex; transform: rotate(13deg); opacity: .07; }
.hero-tiles img { width: 130px; margin-left: -35px; }
.lobby-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 25px; margin-top: 29px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-heading h2 { display: inline; font-size: 20px; margin: 0 12px 0 0; }
.section-heading > div > span { font-size: 11px; color: var(--muted); }
.room-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.room-card { background: var(--paper); border: 1px solid #e5e4da; border-radius: 14px; padding: 20px; min-height: 182px; position: relative; overflow: hidden; transition: border .2s, transform .2s, box-shadow .2s; }
.room-card:hover { border-color: #bdcfc4; transform: translateY(-3px); box-shadow: 0 13px 30px rgba(20,54,45,.08); }
.room-card::after { content: attr(data-mark); position: absolute; right: 10px; top: -22px; font-family: serif; font-size: 100px; color: rgba(31,91,75,.035); pointer-events: none; }
.room-card-top { display: flex; justify-content: space-between; align-items: center; }
.room-mode { display: inline-flex; align-items: center; border-radius: 5px; padding: 4px 8px; background: #e8f0e9; color: var(--green-700); font-size: 10px; font-weight: 700; }
.room-mode.four { background: #f2e9dc; color: #94662d; }
.room-status { color: #849088; font-size: 10px; }
.room-status::before { content: ""; display: inline-block; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: #67a27d; }
.room-status.playing::before { background: #d19c51; }
.room-card h3 { font-size: 18px; margin: 13px 0 4px; }
.room-level { color: var(--muted); font-size: 11px; }
.room-card-bottom { display: flex; align-items: flex-end; justify-content: space-between; margin-top: 20px; }
.room-specs { display: flex; gap: 19px; }
.room-specs span { display: block; color: #919890; font-size: 9px; margin-bottom: 4px; }
.room-specs b { font-size: 13px; font-weight: 650; }
.room-join { min-height: 36px; padding: 0 14px; font-size: 12px; position: relative; z-index: 2; }
.lobby-sidebar { display: flex; flex-direction: column; gap: 16px; }
.side-card { background: var(--paper); border: 1px solid #e5e4da; border-radius: 14px; padding: 19px; }
.side-card-title { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 14px; }
.side-card-title button { border: 0; background: none; color: var(--jade); font-size: 10px; padding: 0; }
.side-card-title small { color: var(--muted); font-weight: 400; font-size: 10px; }
.rule-highlight { display: flex; gap: 12px; align-items: center; margin: 18px 0; padding: 13px; background: #f0f2e9; border-radius: 9px; }
.rule-highlight > strong { display: grid; place-items: center; flex: 0 0 39px; height: 44px; border-radius: 6px; color: #b64035; background: white; font-family: serif; font-size: 25px; box-shadow: 0 3px 0 #c8cabe; }
.rule-highlight b { font-size: 12px; }
.rule-highlight p { color: var(--muted); font-size: 9px; margin: 5px 0 0; }
.mini-rules { list-style: none; padding: 0; margin: 0; }
.mini-rules li { color: #67736d; font-size: 11px; padding: 7px 0; border-bottom: 1px solid #efeee7; }
.mini-rules li:last-child { border: 0; }
.mini-rules span { color: #b59b6b; font-family: serif; margin-right: 8px; }
.leaderboard { margin-top: 12px; }
.leader-row { display: flex; align-items: center; gap: 9px; padding: 8px 0; font-size: 11px; }
.leader-rank { width: 18px; color: #9a9e96; font-family: serif; }
.leader-row:nth-child(-n+3) .leader-rank { color: #b28338; font-weight: 800; }
.leader-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-coins { color: #84652e; font-weight: 700; }
.fair-play { text-align: center; font-size: 9px; color: #9a9e97; letter-spacing: 1px; }

.room-view { background: var(--green-950); min-height: calc(100dvh - 70px); }
.room-topline { height: 55px; padding: 0 25px; display: flex; align-items: center; gap: 12px; color: #f5efdf; background: linear-gradient(rgba(12,36,29,.76), rgba(12,36,29,.88)), url('/assets/textures/dark-paneled-wood.jpg') center / 520px; border-bottom: 1px solid rgba(224,190,125,.22); box-shadow: 0 4px 16px rgba(0,0,0,.2); position: relative; z-index: 10; }
.room-topline .icon-button { background: rgba(255,255,255,.06); color: #eee5ce; border-color: rgba(255,255,255,.12); }
.room-topline > div:nth-child(2) { display: flex; flex-direction: column; }
.room-topline strong { font-size: 14px; letter-spacing: 1px; }
.room-topline span { font-size: 9px; color: rgba(255,255,255,.5); margin-top: 3px; }
.room-round { margin-left: auto; text-align: right; display: flex; flex-direction: column; }
.room-round b { font-size: 11px; color: var(--gold-light); }
.room-topline > .icon-button:last-child { margin-left: 8px; }
.mahjong-table { height: calc(100dvh - 125px); min-height: 570px; position: relative; overflow: hidden; background-color: #164c3c; background-image: radial-gradient(ellipse at center, rgba(20,112,77,.84), rgba(4,48,35,.91)), url('/assets/textures/velour-velvet.jpg'); background-size: auto, 560px; box-shadow: inset 0 0 110px rgba(0,0,0,.28); }
.table-texture { position: absolute; inset: 0; opacity: .025; pointer-events: none; background-image: repeating-linear-gradient(0deg, transparent 0 3px, #fff 4px), repeating-linear-gradient(90deg, transparent 0 5px, #000 6px); }
.mahjong-table::before { content: ""; position: absolute; width: 66%; height: 61%; left: 17%; top: 16%; border-radius: 45%; border: 2px solid rgba(231,204,143,.24); box-shadow: inset 0 0 80px rgba(0,0,0,.12), 0 0 0 8px rgba(8,36,27,.18), 0 12px 35px rgba(0,0,0,.12); }
.mahjong-table::after { content: ""; position: absolute; inset: 10px; border: 9px solid transparent; border-image: url('/assets/textures/dark-paneled-wood.jpg') 22 round; border-radius: 18px; opacity: .65; box-shadow: inset 0 0 0 1px rgba(231,199,137,.25); pointer-events: none; z-index: 2; }
.table-center { position: absolute; left: 50%; top: 43%; transform: translate(-50%, -50%); width: 190px; min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 3; }
.turn-timer { width: 61px; height: 61px; display: grid; place-items: center; border-radius: 15px; transform: rotate(45deg); border: 1px solid rgba(235,211,158,.4); background: rgba(8,43,34,.5); box-shadow: 0 5px 18px rgba(0,0,0,.18); }
.turn-timer span { transform: rotate(-45deg); color: var(--gold-light); font-family: serif; font-size: 26px; }
.turn-timer.active { border-color: var(--gold); box-shadow: 0 0 22px rgba(220,177,94,.25); }
#game-message { color: rgba(255,255,255,.76); font-size: 11px; margin: 17px 0 6px; text-align: center; min-height: 16px; max-width: 230px; }
.last-discard { display: none; }
.last-discard .tile { width: 39px; filter: drop-shadow(0 7px 6px rgba(0,0,0,.35)); animation: tile-place .2s ease-out; }
@keyframes tile-place { from { transform: translateY(-10px) scale(1.08); opacity: .5; } to { transform: translateY(0) scale(1); opacity: 1; } }
.dealer-label { color: rgba(255,255,255,.4); font-size: 9px; }

.player-seat { position: absolute; z-index: 4; width: 220px; }
.seat-right { right: 2.2%; top: 24%; }
.seat-left { left: 2.2%; top: 24%; }
.seat-top { left: 50%; top: 2.5%; transform: translateX(-50%); }
.seat-self { left: 2.2%; bottom: 155px; }
.player-card { display: flex; align-items: center; gap: 8px; width: max-content; padding: 6px 10px 6px 6px; border-radius: 30px; background: rgba(5,34,27,.65); border: 1px solid rgba(255,255,255,.1); color: white; transition: border .2s, box-shadow .2s; }
.player-card.current { border-color: var(--gold); box-shadow: 0 0 16px rgba(222,179,96,.25); }
.player-avatar { position: relative; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(145deg, #d7b976, #8f6d32); color: #183a30; font-weight: 800; font-size: 14px; border: 2px solid rgba(255,255,255,.4); }
.dealer-badge { position: absolute; right: -5px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%; background: #b44d3d; color: white; display: grid; place-items: center; font-size: 8px; border: 1px solid #e6b486; }
.player-name { font-size: 11px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { font-size: 8px; color: rgba(255,255,255,.52); margin-top: 3px; }
.player-meta .positive { color: #f0cd82; }
.player-meta .negative { color: #e99b8e; }
.liang-badge { color: #f0c57e; border: 1px solid rgba(240,197,126,.5); border-radius: 4px; padding: 1px 4px; margin-left: 5px; font-size: 8px; }
.opponent-hand { display: flex; margin: 7px 0 0 5px; height: 28px; }
.opponent-hand .tile { width: 15px; margin-right: 0; filter: drop-shadow(1px 2px 2px rgba(0,0,0,.25)); }
.seat-top .player-card { margin: 0 auto; }
.seat-top .opponent-hand { justify-content: center; }
.meld-row { display: flex; gap: 5px; margin-top: 6px; min-height: 27px; }
.meld { display: flex; padding: 2px; border-radius: 3px; background: rgba(0,0,0,.13); }
.meld .tile { width: 20px; margin-right: 0; }
.meld .concealed-tile:not(:first-child):not(:last-child) { opacity: .85; }
.discard-pool { display: grid; grid-template-columns: repeat(8, 24px); gap: 2px; margin-top: 7px; max-width: 210px; }
.discard-pool .tile { width: 24px; filter: drop-shadow(1px 2px 1px rgba(0,0,0,.2)); }
.seat-right .discard-pool { direction: rtl; }
.seat-right .player-card, .seat-right .meld-row { margin-left: auto; }
.seat-top .discard-pool { margin: 5px auto 0; }
.seat-self .opponent-hand { display: none; }
.river { position: absolute; z-index: 3; grid-template-columns: repeat(6, 28px); gap: 0; max-width: none; padding: 3px; border-radius: 5px; background: rgba(6,37,28,.14); direction: ltr; }
.river .tile { width: 28px; filter: drop-shadow(1px 2px 1px rgba(0,0,0,.22)); }
.river-self { left: 50%; bottom: 175px; transform: translateX(-50%); }
.river-top { left: 50%; top: 17%; transform: translateX(-50%); }
.river-left { left: 25%; top: 37%; }
.river-right { right: 25%; top: 37%; }
.river .latest-river { transform: translateY(-3px); border-radius: 3px; box-shadow: 0 0 0 2px #f1c66f, 0 0 9px rgba(241,198,111,.7); animation: tile-place .2s ease-out; }

.self-area { position: absolute; z-index: 8; left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(100%, 940px); display: flex; flex-direction: column; align-items: center; }
.self-melds { align-self: flex-end; display: flex; gap: 5px; margin: 0 20px 3px 0; }
.self-melds .meld .tile { width: 27px; }
.hand { --hand-tile: min(54px, calc((100vw - 32px) / 14)); display: flex; justify-content: center; align-items: flex-end; min-height: calc(var(--hand-tile) * 1.34 + 15px); padding: 14px 6px 2px; gap: 0; }
.tile-button { width: var(--hand-tile); flex: 0 0 var(--hand-tile); border: 0; background: none; padding: 0; position: relative; transition: transform .12s, filter .12s; }
.tile-button .tile { width: 100%; display: block; filter: drop-shadow(0 5px 3px rgba(0,0,0,.32)); }
.tile-button:not(:disabled):hover { transform: translateY(-6px); }
.tile-button.selected { transform: translateY(-13px); }
.tile-button.selected .tile { filter: drop-shadow(0 0 5px #f6d083) drop-shadow(0 5px 2px rgba(0,0,0,.25)); }
.tile-button:disabled { opacity: 1; }
.action-bar { min-height: 43px; margin-top: 4px; display: flex; align-items: center; gap: 10px; }
.special-actions { display: flex; gap: 7px; }
.special-actions .button { min-width: 51px; min-height: 38px; padding: 0 13px; }
.action-hu { background: #b84f40; color: white; }
.action-liang { background: #e3b75f; color: #293c32; }
.action-pass { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.24); color: white; }
.hand-hint { color: rgba(255,255,255,.42); font-size: 9px; margin: 5px 0 0; }

.waiting-panel { position: absolute; z-index: 7; left: 50%; top: 45%; transform: translate(-50%, -50%); width: min(480px, calc(100% - 32px)); padding: 32px; border: 1px solid rgba(241,216,163,.32); border-radius: 18px; background: linear-gradient(rgba(8,46,36,.9), rgba(8,39,31,.94)), url('/assets/textures/dark-paneled-wood.jpg') center / 480px; box-shadow: 0 25px 65px rgba(0,0,0,.32), inset 0 1px rgba(255,255,255,.08); text-align: center; color: white; backdrop-filter: blur(10px); }
.waiting-panel h2 { font-family: "Songti SC", serif; font-size: 27px; font-weight: 500; margin: 10px 0; }
.waiting-panel > p { color: rgba(255,255,255,.57); font-size: 12px; }
.waiting-panel > small { color: rgba(255,255,255,.35); font-size: 9px; }
.waiting-seats { display: flex; justify-content: center; gap: 13px; margin: 24px 0; }
.waiting-seat { width: 65px; }
.waiting-seat .player-avatar { margin: auto; width: 43px; height: 43px; }
.waiting-seat.empty .player-avatar { color: rgba(255,255,255,.3); background: rgba(255,255,255,.05); border: 1px dashed rgba(255,255,255,.2); }
.waiting-seat p { font-size: 10px; margin: 7px 0 2px; overflow: hidden; text-overflow: ellipsis; }
.waiting-seat small { font-size: 8px; color: #d5b776; }
.waiting-actions { display: flex; justify-content: center; gap: 10px; margin-bottom: 15px; }
.waiting-actions .button-outline { color: #e8dcc1; border-color: rgba(255,255,255,.25); }

.chat-panel { position: fixed; z-index: 30; right: 16px; bottom: 16px; width: 310px; height: 420px; padding: 16px; border-radius: 14px; background: var(--paper); box-shadow: 0 18px 55px rgba(0,0,0,.3); display: flex; flex-direction: column; }
.chat-heading { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 2px; }
.chat-message { font-size: 11px; line-height: 1.5; margin: 8px 0; overflow-wrap: anywhere; }
.chat-message b { color: var(--green-700); margin-right: 5px; }
.chat-message.system { color: #9a8359; text-align: center; font-size: 9px; }
.quick-phrases { display: flex; gap: 5px; margin-bottom: 10px; }
.quick-phrases button { border: 1px solid #e2e3da; border-radius: 12px; background: #f4f3ec; color: #6c756f; padding: 4px 8px; font-size: 9px; }
#chat-form { display: flex; gap: 6px; }
#chat-form input { min-width: 0; flex: 1; border: 1px solid #dedfd6; border-radius: 7px; padding: 0 9px; outline: none; }
#chat-form .button { min-height: 35px; padding: 0 12px; font-size: 11px; }

.result-overlay { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(4,25,20,.78); backdrop-filter: blur(7px); }
.result-card { width: min(560px, 100%); max-height: 90dvh; overflow-y: auto; padding: 31px; border-radius: 19px; background: var(--paper); box-shadow: 0 30px 90px rgba(0,0,0,.4); text-align: center; }
.result-card h2 { font-family: "Songti SC", serif; color: var(--green-800); font-size: 35px; margin: 8px 0; }
#result-subtitle { color: var(--muted); font-size: 12px; }
.result-details { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 20px 0; }
.result-detail { border-radius: 8px; padding: 12px 17px; background: #edf2e9; }
.result-detail b { display: block; font-size: 13px; }
.result-detail span { color: #a4752d; font-size: 11px; }
.horse-card { color: #875b25; background: #f6ead3; padding: 10px; border-radius: 8px; font-size: 12px; }
.result-scores { border-top: 1px solid #e7e5dc; margin-top: 18px; padding-top: 10px; }
.result-score { display: flex; justify-content: space-between; padding: 7px 12px; font-size: 12px; }
.result-score b.positive { color: #37805c; }
.result-score b.negative { color: var(--red); }
.result-actions { display: flex; justify-content: center; gap: 10px; margin-top: 22px; }

.rules-dialog, .profile-dialog { width: min(650px, calc(100% - 30px)); max-height: 88dvh; border: 0; border-radius: 18px; background: var(--paper); color: var(--ink); padding: 28px; box-shadow: 0 25px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(5,30,24,.72); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-heading h2 { margin: 5px 0 15px; }
.rules-content { overflow-y: auto; }
.rules-content section { border-top: 1px solid #e8e6dc; padding: 12px 0; }
.rules-content h3 { font-size: 14px; color: var(--green-700); margin: 0 0 7px; }
.rules-content p, .rules-content li { color: #657069; font-size: 12px; line-height: 1.8; }
.rules-content ul { margin: 0; padding-left: 20px; }
.license-note { font-size: 10px !important; color: #999b94 !important; }
.profile-dialog { width: min(380px, calc(100% - 30px)); }
#profile-content { margin-bottom: 20px; }
.profile-hero { display: flex; align-items: center; gap: 14px; padding: 10px 0 20px; }
.profile-hero .player-avatar { width: 52px; height: 52px; font-size: 20px; }
.profile-hero h3 { margin: 0 0 4px; }
.profile-hero p { margin: 0; color: var(--muted); font-size: 11px; }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.profile-stats div { background: #f0f1e9; border-radius: 8px; padding: 12px 6px; text-align: center; }
.profile-stats b { display: block; font-size: 18px; }
.profile-stats span { color: var(--muted); font-size: 9px; }
#profile-dialog > .button { margin-top: 9px; }
.toast { position: fixed; z-index: 100; left: 50%; top: 85px; transform: translate(-50%, -15px); padding: 11px 19px; border-radius: 9px; background: rgba(12,39,33,.94); color: white; box-shadow: 0 9px 30px rgba(0,0,0,.2); font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #a7463d; }

@media (max-width: 1000px) {
  .auth-view { padding: 6vw; gap: 5vw; }
  .lobby-layout { grid-template-columns: 1fr; }
  .lobby-sidebar { display: grid; grid-template-columns: 1fr 1fr; }
  .fair-play { grid-column: 1 / -1; }
  .player-seat { width: 180px; }
  .discard-pool { grid-template-columns: repeat(7, 21px); }
  .discard-pool .tile { width: 21px; }
}

@media (max-width: 700px) {
  .auth-view { display: flex; flex-direction: column; justify-content: center; padding: 28px 18px; gap: 25px; }
  .auth-intro { text-align: center; }
  .auth-intro .brand { font-size: 19px; }
  .auth-intro .eyebrow, .auth-description, .feature-row { display: none; }
  .auth-intro h1 { font-size: 30px; margin: 14px 0 0; line-height: 1.25; }
  .auth-intro h1 br { display: none; }
  .auth-card { width: min(100%, 430px); padding: 25px 22px; border-radius: 15px; }
  .auth-card-heading h2 { font-size: 22px; }
  .auth-card-heading p { margin-bottom: 18px; }
  .topbar { height: 58px; padding: 0 13px; }
  .topbar .brand { font-size: 15px; gap: 7px; letter-spacing: 0; }
  .topbar .brand-mark { width: 30px; height: 34px; font-size: 18px; }
  .topbar-right { gap: 9px; }
  .connection-status { display: none; }
  .profile-button > span:last-child { display: none; }
  .coin-pill { font-size: 11px; padding-right: 9px; }
  .profile-button > span:first-child { width: 29px; height: 29px; }
  .lobby-view { padding: 16px 13px 30px; }
  .lobby-hero { min-height: 210px; padding: 23px; display: block; }
  .lobby-hero h1 { font-size: 25px; }
  .lobby-hero p:not(.eyebrow) { font-size: 11px; }
  .quick-start { min-width: 0; width: 100%; min-height: 58px; margin-top: 23px; }
  .hero-tiles { right: -15px; }
  .section-heading { align-items: flex-start; gap: 13px; flex-direction: column; }
  .section-heading .segmented { width: 100%; }
  .section-heading .segmented button { flex: 1; }
  .room-grid { grid-template-columns: 1fr; gap: 11px; }
  .room-card { min-height: 164px; padding: 17px; }
  .room-card-bottom { margin-top: 16px; }
  .lobby-sidebar { display: block; }
  .side-card { margin-top: 15px; }
  .leaderboard-card { display: none; }
  .room-view { min-height: calc(100dvh - 58px); }
  .room-topline { height: 47px; padding: 0 10px; gap: 8px; }
  .room-topline .icon-button { width: 32px; height: 32px; }
  .room-topline strong { font-size: 12px; }
  .mahjong-table { height: calc(100dvh - 105px); min-height: 530px; }
  .mahjong-table::before { width: 92%; left: 4%; height: 58%; top: 15%; }
  .table-center { top: 43%; width: 145px; min-height: 105px; }
  .turn-timer { width: 44px; height: 44px; border-radius: 10px; }
  .turn-timer span { font-size: 19px; }
  #game-message { font-size: 9px; margin-top: 12px; max-width: 170px; }
  .last-discard .tile { width: 29px; }
  .player-seat { width: 135px; }
  .seat-left { left: 5px; top: 16%; }
  .seat-right { right: 5px; top: 16%; }
  .seat-top { top: 1.5%; }
  .seat-self { left: 7px; bottom: 144px; }
  .player-card { padding: 4px 7px 4px 4px; gap: 5px; }
  .player-avatar { width: 29px; height: 29px; font-size: 11px; }
  .player-name { max-width: 65px; font-size: 9px; }
  .player-meta { font-size: 7px; }
  .opponent-hand { height: 21px; margin-top: 4px; }
  .opponent-hand .tile { width: 9px; margin-right: 0; }
  .discard-pool { grid-template-columns: repeat(6, 18px); gap: 1px; margin-top: 4px; }
  .discard-pool .tile { width: 18px; }
  .river { grid-template-columns: repeat(6, 21px); padding: 2px; }
  .river .tile { width: 21px; }
  .river-self { bottom: 163px; }
  .river-top { top: 17%; }
  .river-left { left: 5%; top: 37%; }
  .river-right { right: 5%; top: 37%; }
  .meld-row { min-height: 21px; margin-top: 3px; }
  .meld .tile { width: 16px; }
  .seat-self .discard-pool { display: none; }
  .self-area { bottom: max(4px, env(safe-area-inset-bottom)); }
  .self-melds { margin-right: 8px; }
  .self-melds .meld .tile { width: 20px; }
  .hand { --hand-tile: min(48px, calc((100vw - 32px) / 14)); gap: 0; padding-left: 2px; padding-right: 2px; }
  .action-bar { gap: 5px; margin-top: 2px; }
  .special-actions { gap: 4px; }
  .special-actions .button { min-width: 42px; min-height: 36px; padding: 0 10px; font-size: 12px; }
  .hand-hint { font-size: 8px; margin-top: 3px; }
  .waiting-panel { padding: 24px 17px; top: 45%; }
  .waiting-panel h2 { font-size: 24px; }
  .waiting-seats { gap: 7px; }
  .waiting-seat { width: 55px; }
  .chat-panel { right: 8px; bottom: 8px; width: calc(100% - 16px); height: min(420px, 70dvh); }
  .result-card { padding: 24px 17px; }
  .rules-dialog { padding: 20px; }
}

@media (max-height: 650px) and (orientation: landscape) {
  .topbar { height: 50px; }
  .room-topline { height: 42px; }
  .mahjong-table { height: calc(100dvh - 92px); min-height: 300px; }
  .seat-left, .seat-right { top: 16%; }
  .seat-top { top: 1%; }
  .seat-self { bottom: 120px; }
  .river { grid-template-columns: repeat(6, 20px); }
  .river .tile { width: 20px; }
  .river-self { bottom: 96px; }
  .river-top { top: 18%; }
  .river-left { left: 19%; top: 42%; }
  .river-right { right: 19%; top: 42%; }
  .self-area { align-items: center; }
  .hand { --hand-tile: min(43px, calc((100vw - 32px) / 14)); padding-top: 8px; }
  .hand-hint { display: none; }
  .self-melds { position: absolute; right: 0; bottom: 45px; }
  .action-bar { position: absolute; right: 10px; bottom: 4px; flex-direction: column; align-items: flex-end; }
  .special-actions { max-width: 130px; flex-wrap: wrap; justify-content: flex-end; }
  .waiting-panel { top: 48%; padding: 18px 25px; }
  .waiting-seats { margin: 12px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
