*{box-sizing:border-box}body{margin:0;background:#21182e;color:#fff4ed;font:16px system-ui,sans-serif}header{height:56px;display:flex;align-items:center;gap:18px;padding:0 2vw;background:#21182eec;border-bottom:1px solid #98708f}header strong{font: bold 22px Georgia,serif}header b{color:#ffaac8}header span{flex:1;color:#edcede}button,a{font:inherit;color:inherit;border:1px solid #917a9a;border-radius:24px;background:#322940;padding:6px 15px;text-decoration:none;cursor:pointer}button:hover,a:hover{border-color:#ffc591}main{position:relative;isolation:isolate;container-type:size;width:min(100cqw,177.58cqh);aspect-ratio:1671/941;overflow:hidden}.felt{position:absolute;left:50%;bottom:0;width:min(112cqw,198.89cqh);aspect-ratio:1647/761;transform:translateX(-50%);pointer-events:none;background:url(/assets/battle-table.webp) center bottom/contain no-repeat}aside,.badge,.counter{background:linear-gradient(145deg,#302d46,#171827);border:1px solid #987c90;box-shadow:0 4px 12px #10132180}aside{position:absolute;top:2%;left:1%;padding:9px 16px;border-radius:12px;color:#ffc780;font: bold clamp(18px,2cqw,30px) serif}small{font:12px system-ui;display:block}aside img{width:20px;vertical-align:middle}.seat,.river,.counter{position:absolute;transform:translate(-50%,-50%);text-align:center}.seat{width:clamp(94px,12cqw,180px)}.seat img.avatar{width:clamp(54px,8cqh,94px);border-radius:50%;border:2px solid #d6b18c;display:block;margin:auto}.badge{display:inline-block;border-radius:12px;padding:3px 12px;font-size:clamp(12px,1.2cqw,18px)}.badge b{display:block;color:#ffcd80}.current .badge{border-color:#ffcf86;box-shadow:0 0 12px #fbc26277}.s0{left:8%;top:88%}.s1{left:92%;top:44%}.s2{left:50%;top:4px;transform:translateX(-50%)}.s3{left:8%;top:44%}.backs{height:clamp(15px,3cqh,32px);display:flex;justify-content:center;margin-top:4px}.backs i{width:13px;border-radius:3px;background:linear-gradient(#f9edda 16%,#deb063 19%,#aa762e);border:1px solid #765735}.river{--river-width:clamp(110px,min(16cqw,34cqh),260px);display:grid;grid-template-columns:repeat(6,1fr);width:var(--river-width);align-content:start}.r0{left:50%;top:65%}.r1{left:71%;top:44%;transform:translate(-50%,-50%) rotate(-90deg)}.r2{left:50%;top:25%;transform:translate(-50%,-50%) rotate(180deg)}.r3{left:29%;top:44%;transform:translate(-50%,-50%) rotate(90deg)}.meld img{width:100%;display:block}.meld{display:inline-flex;margin:2px}.meld img{width:clamp(13px,1.55cqw,26px)}.counter{left:50%;top:44%;padding:12px 22px;border:4px ridge #57536c;border-radius:15px;color:#eec27a}.counter strong{display:block;color:#bfefff;font-size:clamp(19px,2.5cqw,36px)}.controls{position:absolute;bottom:17%;width:100%;text-align:center}.controls span{font-size:14px;color:#e5eaff;text-shadow:0 1px 4px #111}#actions button{margin:4px;background:linear-gradient(#755773,#3d2c4d)}#hand{position:absolute;bottom:3%;left:17%;right:5%;display:flex;justify-content:center;align-items:end}#hand button{border:0;background:none;padding:0;width:min(4.35cqw,7.3cqh);border-radius:5px;position:relative}#hand img{width:100%;display:block;filter:drop-shadow(0 4px 2px #131c30)}#hand button:enabled:hover img{transform:translateY(-10px)}#hand button:disabled{cursor:default}.drawn{margin-left:1%}.red{outline:2px solid #c64a48;outline-offset:-3px;border-radius:5px}.claimed{opacity:.48}.declared{border-bottom:3px solid #ff9aa1}dialog{border:1px solid #ab879f;border-radius:16px;color:#fff2ed;background:#28253a;padding:25px;max-width:min(430px,90cqw)}dialog::backdrop{background:#1610229c}dialog p{line-height:1.65}@media(max-width:650px){header{gap:6px;font-size:12px}header span{font-size:10px}header strong{font-size:15px}.s0{left:12%;top:78%}#hand{left:1%;right:1%;bottom:5%}#hand button{width:5.8cqw}.s1{left:88%}.s3{left:12%}.r1{left:72%;top:53%}.r3{left:28%;top:53%}.counter{padding:7px}.controls{bottom:16%}aside{padding:6px}.backs i{width:6px}}

#hand{gap:1px}
#hand button:enabled:hover::before{content:"";position:absolute;inset:-10px 0 0}
#hand button img{pointer-events:none;transition:transform .14s ease}
@media(hover:hover){#hand button:enabled img{will-change:transform}}
.river{--discard-gap:3px;gap:var(--discard-gap)}

@media(prefers-reduced-motion:reduce){#hand button img{transition:none}}
/* Keep printed faces readable while each river follows seat order. */
.river{transform-style:flat}
.r2 .table-tile{transform:rotateZ(180deg)}
.r1 .table-tile,.r3 .table-tile{
    width:81.8182%;
    justify-self:center;
    align-self:center;
}
.r1,.r3{
    grid-auto-rows:calc((var(--river-width) - 5 * var(--discard-gap)) / 6);
}
.r1 .table-tile{transform:rotateZ(90deg)}
.r3 .table-tile{transform:rotateZ(-90deg)}

.controls{pointer-events:none;z-index:1}.controls button{pointer-events:auto}
#actions{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:4px}
#actions .call{--glow:#ffcd7c;display:inline-flex;align-items:center;gap:8px;background:linear-gradient(135deg,#4a3446,#231f35);padding:4px 12px;border:1px solid var(--glow);border-radius:14px;box-shadow:0 0 9px color-mix(in srgb,var(--glow) 60%,transparent);color:var(--glow)}
#actions .chi{--glow:#d6abff}#actions .kan{--glow:#9bdfff}
.call strong,#tenpai strong{font: bold clamp(20px,2cqw,32px) serif}
.combination small{font-size:11px;margin-bottom:2px}
.combination img{width:clamp(15px,1.6cqw,25px);vertical-align:middle}
.call-target{outline:2px solid #ffcf7d;border-radius:4px;filter:drop-shadow(0 0 5px #ffac43)}
#tenpai:not(:empty){display:flex;align-items:center;justify-content:center;gap:3px;width:fit-content;max-width:94%;flex-wrap:wrap;margin:0 auto 4px;padding:3px 12px;background:linear-gradient(110deg,#193f37,#152c32);color:#ffdf96;border:1px solid #ccb170;border-radius:14px;pointer-events:auto}
#tenpai img{display:block;width:clamp(19px,2cqw,32px);height:auto;filter:drop-shadow(0 1px 1px #101c24)}
#tenpai small{margin:0 5px}
.riichi-marker{position:relative;display:inline-block;vertical-align:middle;margin:6px 0 14px;padding:0 13px;border:1px solid #f3a494;border-radius:12px;background:linear-gradient(#9f3245,#64142b);color:#fff4db;font:bold 14px/1.4 serif;letter-spacing:.12em;box-shadow:0 1px 8px #cd48604d}
.riichi-marker:after{content:"";position:absolute;top:calc(100% + 5px);left:8%;width:84%;height:5px;border-radius:5px;background:radial-gradient(circle,#bd1938 0 2px,transparent 2.5px),linear-gradient(#fffaf2,#dbc9be);box-shadow:0 1px 2px #391c31}
#table-effect:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    isolation: isolate;
    isolation: isolate;
    cursor: pointer;
}
/* Composite the stationary backdrop separately from the moving cut-in. */
#table-effect:not([hidden])::before {
    content:'';
    position:absolute;
    inset:0;
    z-index:-1;
    pointer-events:none;
    background:var(--effect-shade,#100d2340);
    backdrop-filter:blur(2px);
    transform:translateZ(0);
}
.effect-card {
    --fx: #6ccaff;
    --fx-ink: #124b8c;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 8px 16px;
    position: relative;
    isolation: isolate;
    overflow: visible;
    width: min(560px, 90cqw);
    padding: clamp(12px, 3cqw, 26px);
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    animation: effect-enter .26s ease-out both;
}
.effect-card::before {
    content: '';
    position: absolute;
    z-index: -1;
    inset: 26% -10% 8%;
    border-bottom: 3px solid var(--fx);
    border-radius: 50%;
    transform: rotate(-10deg);
    box-shadow: 0 8px 16px -5px var(--fx);
    animation: effect-sweep .4s ease-out both;
}
.effect-portrait { grid-template-columns: minmax(0, 1fr) auto; }
.effect-riichi,.effect-ron { --fx: #ff9882; --fx-ink: #971d37; }
.effect-tsumo { --fx: #ffd077; --fx-ink: #8a4115; }
.effect-kan { --fx: #d8a0ff; --fx-ink: #60198a; }
.effect-dora,.effect-draw { width: fit-content; max-width: 90cqw; text-align: center; }
.effect-copy small {
    width: fit-content;
    padding: 2px 10px;
    border: 1px solid var(--fx);
    border-radius: 20px;
}
.effect-copy strong {
    display: block;
    color: #fff3da;
    font: bold italic clamp(42px, 8cqw, 86px)/1.05 KaiTi, STKaiti, serif;
    text-shadow: 0 3px var(--fx-ink), 0 0 15px var(--fx);
}
.effect-dora strong,.effect-draw strong { font-size: clamp(24px, 5cqw, 42px); }
.effect-reason { display: block; margin-top: 5px; }
.effect-avatar {
    width: clamp(70px, 21cqw, 170px);
    aspect-ratio: 1;
    object-fit: cover;
    border: 0;
    border-radius: 50%;
    box-shadow: none;
}
.effect-tiles {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 3px;
}
.effect-tiles img {
    width: clamp(16px, 4.9cqw, 34px);
    border-radius: 3px;
    box-shadow: 0 2px 0 #c89453, 0 0 8px var(--fx);
}
.effect-dora .effect-tiles img { animation: effect-flip .38s ease-out both; }
.effect-stick {
    grid-column: 1 / -1;
    justify-self: center;
    width: 108px;
    height: 13px;
    border-radius: 4px;
    background: radial-gradient(circle, #b62139 0 4px, transparent 5px), #fff2dc;
    box-shadow: 0 0 10px var(--fx);
    animation: effect-stick .34s ease-out both;
}
#dora {
    display: inline-flex;
    gap: 1px;
    padding: 4px;
    border-radius: 5px;
    border-color: #65554a;
    background: #18171c;
    box-shadow: 0 2px 5px #10132199, inset 0 1px #93816b;
}
#dora > * {
    display: block;
    width: clamp(14px, 1.7cqw, 27px);
    aspect-ratio: 9 / 13;
    border-radius: 2px;
    box-shadow: 0 1px 1px #05050a;
}
#dora img { background: #f7f2e7; object-fit: fill; }
#dora .indicator-back {
    background: linear-gradient(110deg, #ffbf49, #ed9e2b 75%);
    box-shadow: inset 0 1px #ffe2a0, inset 0 -2px #b87522, 0 1px 1px #05050a;
}
#dora.dora-reveal img:last-of-type { filter: drop-shadow(0 0 5px #ffe699); }
@media(max-width:650px) { header > span { display: none; } }
#table-effect:has(.effect-own) { --effect-shade: #100d2399; }
.effect-own {
    width: min(780px, 88cqw);
    min-height: min(320px, 46cqh);
    background: transparent;
}
.effect-own .effect-avatar {
    width: clamp(96px, 27cqw, 255px);
    border-radius: 18px;
}
.effect-own::before {
    border-bottom-width: 5px;
    box-shadow: 0 12px 26px -4px var(--fx);
}
.effect-ron { --fx: #ffbd76; --fx-ink: #8c321b; }
#opponent-effects {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
}
#opponent-effects .effect-opponent {
    position: absolute;
    width: max-content;
    max-width: min(220px, 42cqw);
    padding: 6px 10px;
    gap: 3px 8px;
    border-radius: 12px;
    pointer-events: auto;
    cursor: pointer;
}
.effect-opponent::before { display: none; }
.effect-opponent .effect-avatar { width: clamp(28px, 4.2cqw, 48px); }
.effect-opponent .effect-copy small { font-size: 11px; padding: 1px 5px; }
.effect-opponent .effect-copy strong { font-size: clamp(22px, 3.1cqw, 35px); }
.effect-opponent .effect-tiles img { width: clamp(12px, 2cqw, 20px); }
.effect-opponent .effect-stick { width: 62px; height: 8px; }
.effect-seat-1 { right: 9%; top: 52%; }
.effect-seat-2 { left: 52%; top: 9%; }
.effect-seat-3 { left: 9%; top: 52%; }
.effect-seat-0 { left: 9%; bottom: 16%; }
.effect-skip { position: absolute; bottom: 6%; right: 4%; }
@keyframes effect-enter { from { opacity: 0; transform: translateX(8%) scale(.96); } }
@keyframes effect-sweep { from { opacity: 0; transform: translateX(-32%) rotate(-10deg); } }
@keyframes effect-flip { from { transform: perspective(180px) rotateY(90deg); } }
@keyframes effect-stick { from { opacity: 0; transform: translateY(-25px); } }
@media(prefers-reduced-motion:reduce) {
    .effect-card,.effect-card::before,.effect-dora .effect-tiles img,.effect-stick { animation: none; }
}

/* Project table objects together while screen controls stay readable. */
.table-perspective {
    position: absolute;
    inset: 0;
    perspective: clamp(560px, 105cqh, 1250px);
    perspective-origin: 50% 38%;
    pointer-events: none;
}
.table-plane {
    position: absolute;
    inset: 0;
    transform: rotateX(32deg);
    transform-origin: 50% 48%;
    transform-style: preserve-3d;
}
#rivers, #table-backs {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
}
.table-plane .r0 { top: 68%; }
.table-plane .r2 {
    top: auto;
    bottom: 66%;
    transform: translateX(-50%) rotate(180deg);
    --river-width: min(16cqw, calc(108cqh / var(--rows, 3)), 260px);
}
.table-plane .r1 { left: 64%; top: 46%; }
.table-plane .r3 { left: 36%; top: 46%; }

.table-plane .backs {
    position: absolute;
    margin: 0;
    gap: 2px;
    transform-style: preserve-3d;
}
/* Six surfaces share a footprint and depth. The same solid can stand up. */
.table-tile {
    --tile-depth: clamp(7px, 1.05cqw, 16px);
    position: relative;
    aspect-ratio: 90 / 110;
    transform-style: preserve-3d;
}
.river-paint { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; }
#rivers.painted .river { opacity:0; }
.river .table-tile { transform-style:flat; }
.river .table-tile .tile-face {
    display:block;
    position:absolute;
    background:none;
    transform:none;
    border-radius:12%;
}
.table-plane .backs:has(.table-tile)::before {
    content: '';
    position: absolute;
    pointer-events: none;
    background: #080f20a6;
}
.table-plane .backs:has(.table-tile)::before {
    inset: auto 1px calc(-1 * clamp(7px, 1.05cqw, 16px));
    height: clamp(7px, 1.05cqw, 16px);
    border-radius: 5px;
    transform: translate3d(3px, 5px, -1px);
    box-shadow: 0 0 5px #080f2099;
}
/* Compensate for the rotation of the side rows. */
.table-plane .backs1:has(.table-tile)::before {
    transform: translate3d(-5px, 3px, -1px);
}
.table-plane .backs3:has(.table-tile)::before {
    transform: translate3d(5px, -3px, -1px);
}
.tile-surface {
    position: absolute;
    display: block;
    backface-visibility: hidden;
    border-radius: calc(var(--tile-depth) * .22);
}
.tile-core {
    inset: calc(var(--tile-depth) * .035);
    border-radius: calc(var(--tile-depth) * .16);
    backface-visibility: visible;
    background: var(--core-color);
    transform: translateZ(calc(var(--tile-depth) * var(--core-depth)));
}
.tile-face {
    inset: 0;
    background: #f9f6f1;
    transform: translateZ(var(--tile-depth));
    overflow: hidden;
}
/* Straight walls end at the tangent points of the rounded footprint. */
:is(.river, .meld-rack) .table-tile {
    --corner: calc(var(--tile-depth) * .22);
}
:is(.river, .meld-rack) .tile-near, :is(.river, .meld-rack) .tile-far {
    left: var(--corner);
    width: calc(100% - 2 * var(--corner));
    border-radius: 0;
}
:is(.river, .meld-rack) .tile-left, :is(.river, .meld-rack) .tile-right {
    top: var(--corner);
    height: calc(100% - 2 * var(--corner));
    border-radius: 0;
}
:is(.river, .meld-rack) .tile-core {
    inset: 0;
    border-radius: var(--corner);
}
.tile-face img {
    display: block;
    width: 100%;
    height: 100%;
}
.tile-face::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.tile-back {
    inset: 0;
    background: linear-gradient(145deg, #edbf70, #aa702a);
    transform: rotateY(180deg);
}
.tile-near,.tile-far {
    left: 0;
    width: 100%;
    height: var(--tile-depth);
    background: linear-gradient(#ded8cc 60%, #b77828 61%);
    transform-origin: center top;
}
.tile-near { top: 100%; transform: translateZ(var(--tile-depth)) rotateX(-90deg); }
/* The far wall runs from the gold base up to the ivory face. */
.tile-far {
    top: 0;
    background: linear-gradient(#b77828 39%, #ded8cc 40%);
    transform: rotateX(90deg);
}
.tile-left,.tile-right {
    top: 0;
    width: var(--tile-depth);
    height: 100%;
    background: linear-gradient(to right, #bb7d30 39%, #ece4d7 40%);
    transform-origin: left center;
}
.tile-left { left: 0; transform: rotateY(-90deg); }
.tile-right {
    left: 100%;
    background: linear-gradient(to right, #d9d0c2 60%, #a86f27 61%);
    transform: translateZ(var(--tile-depth)) rotateY(90deg);
}
.table-plane .backs {
    height: auto;
}
.backs > .table-tile {
    width: clamp(9px, 1.5cqw, 23px);
    transform: rotateX(-90deg);
    transform-origin: center bottom;
}
.backs > .table-tile .tile-face {
    background: linear-gradient(145deg, #ebbb66, #ac712c);
}
.backs1 > .table-tile .tile-far,.backs3 > .table-tile .tile-far {
    background: linear-gradient(#b77828 40%, #ded8cc 41%);
}
.table-tile.claimed,.table-tile.declared,.table-tile.call-target {
    opacity: 1;
    border: 0;
    outline: 0;
    filter: none;
}
.table-tile.claimed .tile-face { opacity: .52; }
.table-tile.declared .tile-face::after { box-shadow: inset 0 -3px #ff9aa1; }
.table-tile.call-target .tile-face::after { box-shadow: inset 0 0 0 2px #ffcf7d; }
.seat-rail {
    position:absolute; display:flex; align-items:flex-end; gap:clamp(4px,.75cqw,12px);
    width:max-content; min-width:37cqw; transform-style:preserve-3d;
}
.rail-1 { left:86%; top:45%; transform:translate(-50%,-50%) rotateZ(-87deg); }
.rail-3 { left:14%; top:45%; transform:translate(-50%,-50%) rotateZ(87deg); }
.rail-2 { left:50%; top:-2%; min-width:44cqw; justify-content:flex-end; transform:translateX(-50%); }
.table-plane .seat-rail > .backs { position:relative; flex:none; align-self:flex-end; }

.s2 .badge { position: relative; perspective: clamp(440px, 85cqh, 960px); }
.s2 .opposite-hand {
    position: absolute;
    bottom: 25%;
    margin: 0;
    height: auto;
    gap: clamp(2px, .19cqw, 3px);
    transform: rotateX(54deg);
    transform-style: preserve-3d;
    pointer-events: none;
}
.opposite-hand.hand-left { right: calc(100% + 6px); }
.opposite-hand.hand-right { left: calc(100% + 6px); }
.opposite-hand > .table-tile {
    width: clamp(8px, 1.78cqw, 29px);
    --tile-depth: clamp(4px, .65cqw, 10px);
}
.opposite-hand:not(:empty)::before {
    content: '';
    position: absolute;
    inset: auto 0 -3px;
    height: 6px;
    background: #161728a6;
    border-radius: 50%;
    box-shadow: 0 2px 4px #11172a99;
}
.opposite-hand > .table-tile .tile-face {
    background: linear-gradient(112deg, #f5ce83 0%, #e2ac58 42%, #c18739 95%);
    box-shadow: inset 1px 1px 1px #ffe1a4, inset -1px -1px 1px #976a34;
}
.opposite-hand > .table-tile .tile-far {
    background: linear-gradient(#e8dfcd, #f6e8cc 64%, #d4a259 78%);
}

.table-plane .counter {
    top: 45%;
    padding: clamp(24px, 2cqw, 30px) clamp(28px, 4cqw, 54px);
    display: grid;
    row-gap: 2px;
    border-radius: 12px;
    box-shadow: 0 5px #131525, 0 8px 10px #0d142e9c;
}
.counter > #table-scores { position: absolute; inset: 0; pointer-events: none; }
.badge .seat-points {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .65em;
}
.wind-badge {
    display: inline-grid;
    place-items: center;
    width: 1.28em;
    height: 1.28em;
    border-radius: .24em;
    color: #261e30;
    font: bold clamp(12px, 1cqw, 16px)/1 KaiTi, STKaiti, serif;
    background: linear-gradient(145deg, var(--wind-light), var(--wind-color) 75%);
    box-shadow: inset 0 1px 1px #ffffffaa, 0 1px 2px #100d20;
}
.wind-0 { --wind-light: #ffe8a2; --wind-color: #edaf47; }
.wind-1 { --wind-light: #bcf1ff; --wind-color: #74bfdf; }
.wind-2 { --wind-light: #f8d6ff; --wind-color: #cc9cdb; }
.wind-3 { --wind-light: #eadccb; --wind-color: #c1a48d; }
#table-scores .wind-badge { position: absolute; font-size: clamp(9px, .85cqw, 13px); }
#table-scores [data-position="0"] { bottom: 4px; left: 5px; }
#table-scores [data-position="1"] { bottom: 4px; right: 5px; }
#table-scores [data-position="2"] { top: 4px; right: 5px; }
#table-scores [data-position="3"] { top: 4px; left: 5px; }
.table-score {
    position: absolute;
    color: #ffdb94;
    font: 700 clamp(8px, 1.05cqw, 14px)/1 system-ui, sans-serif;
    white-space: nowrap;
}
.score0 { bottom: 4px; left: 50%; transform: translateX(-50%); }
.score1 { right: 9px; top: 50%; transform: translate(50%, -50%) rotate(-90deg); }
.score2 { top: 4px; left: 50%; transform: translateX(-50%) rotate(180deg); }
.score3 { left: 9px; top: 50%; transform: translate(-50%, -50%) rotate(90deg); }

@media (max-width: 650px) {
    .table-plane .r1 { left: 75%; }
    .table-plane .r3 { left: 25%; }
}

/* Character cut-ins use the live call tiles over the action artwork. */
.effect-own {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: .6em;
    width: min(680px, 90cqw, 100cqh);
    aspect-ratio: 2.15;
    min-height: 0;
    padding: 4% 7%;

}
.effect-own .effect-avatar {
    mask-image: linear-gradient(to right, transparent, black 14%, black 86%, transparent),
                linear-gradient(to bottom, transparent, black 13%, black 76%, transparent);
    mask-composite: intersect;
    position: absolute;
    inset: 0 0 0 auto;
    height: 100%;
    width: auto;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    z-index: -1;
}
.effect-own .effect-copy small { border: 0; padding: 0; text-shadow: 0 1px 4px #171329; }
.effect-own .effect-copy strong {
    margin-top: .14em;
    font-size: clamp(46px,min(10cqw,17cqh),102px);
    transform: rotate(-6deg);
    text-shadow: 1px 3px var(--fx-ink), 0 5px 1px var(--fx-ink), 0 0 12px var(--fx);
}
.effect-own .effect-tiles img { width: clamp(23px,min(5.6cqw,9cqh),48px); }
.effect-own::after {
    content: '';
    position: absolute;
    z-index: -1;
    inset: 48% -6% 5% 5%;
    border-radius: 50%;
    border-bottom: 4px solid white;
    box-shadow: 0 4px 4px var(--fx), 0 9px 15px var(--fx);
    transform: rotate(-12deg);
}
.effect-own .effect-stick { transform: rotate(-7deg); }
.effect-riichi { --fx: #ff667c; }
#opponent-effects .effect-opponent {
    pointer-events: none;
    overflow: visible;
    background: transparent;
    box-shadow: none;
    border: 0;
}
.effect-opponent .effect-copy small { display: none; }
.effect-opponent .effect-copy strong { transform: rotate(-7deg); }
.effect-opponent .effect-avatar { grid-column: 2; grid-row: 1 / span 2; }
.effect-opponent .effect-tiles,.effect-opponent .effect-stick { grid-column: 1; }
@media (prefers-reduced-motion:no-preference) {
    .effect-own .effect-avatar { animation: portrait-arrive .48s cubic-bezier(.16,1,.3,1) both; }
    .effect-own::after { animation: effect-sweep .45s ease-out both; }
}
@keyframes portrait-arrive { from { opacity: .3; transform: translateX(12%) scale(1.08); } }

#settlement {
    width:min(1080px,96cqw); max-width:96cqw; max-height:94cqh; overflow:auto;
    padding:clamp(12px,2cqw,24px); color:#fff1e4; border-color:#a57699;
    background:radial-gradient(ellipse at top right,#553455,transparent 60%),linear-gradient(135deg,#19182d,#302138 75%,#412638);
    box-shadow:0 18px 80px #0e0b22bf;
}
#settlement::backdrop { background:#100d20bc; }
.result-title { display:flex; flex-wrap:wrap; gap:12px; align-items:center; margin:0 0 12px; font:700 clamp(19px,2.3cqw,30px) KaiTi,serif; }
.result-title small { color:#e9c8a7; font:500 clamp(11px,1.3cqw,16px) system-ui; }
.result-main { display:grid; grid-template-columns:35% minmax(0,1fr); border-block:1px solid #a37e8055; }
.result-hero { display:flex; flex-direction:column; justify-content:end; padding:20px; min-height:310px; background-size:cover; background-position:center top; }
.result-hero strong { font:bold italic clamp(36px,6cqw,78px)/1.15 KaiTi,serif; color:#fff0ac; text-shadow:0 3px #93401d,0 0 14px #ff9c30; }
.result-details { padding:14px; background:#1915298f; display:grid; gap:15px; align-content:space-between; }
.result-group h3,.result-draw h3 { margin:0 0 8px; font-size:16px; color:#f4cba8; }
.result-hand,.result-faces { display:flex; align-items:flex-start; gap:2px; }
.result-hand { gap:8px; flex-wrap:wrap; }
.result-faces { flex-wrap:wrap; }
.result-faces img,.result-faces i { width:clamp(19px,2.55cqw,33px); aspect-ratio:9/13; border-radius:3px; background:#fcf6e9; box-shadow:0 2px #b79465; }
.result-faces i { background:linear-gradient(135deg,#ffd28a,#ca8c38); }
.winning-tile { flex-direction:column; align-items:center; color:#ffe0a2; }
.winning-tile img { outline:2px solid #ffc260; }
.result-columns { display:grid; grid-template-columns:1.15fr 1fr; gap:16px; }
.result-yaku>div { display:flex; justify-content:space-between; gap:8px; border-bottom:1px solid #866c824f; padding:4px 0; }
.result-yaku b,.result-total { color:#ffda93; }
.result-indicators small { margin:4px 0; color:#decbda; }
.result-indicators .result-faces>* { width:clamp(15px,1.9cqw,24px); }
.result-total { display:flex; align-items:baseline; justify-content:end; flex-wrap:wrap; gap:18px; }
.result-total strong { font:bold italic clamp(26px,4cqw,52px) Georgia,serif; }
.result-scores { margin:14px 0; display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:8px; }
.result-player { padding:9px; display:grid; grid-template-columns:auto 1fr; align-items:center; gap:2px 8px; background:#211a2fe0; border:1px solid #7d6179; border-radius:9px; }
.result-player img { grid-row:span 3; width:clamp(30px,4.8cqw,58px); border-radius:50%; }
.result-player-name { display:flex; align-items:center; gap:4px; }
.result-player b { color:#ffda93; }
.result-player .gain { color:#80e9b6; }
.result-player .loss { color:#ff9697; }
.result-next { display:block; margin:auto; padding:8px 40px; background:#ffce81; color:#41212a; font-weight:bold; }
.rank-settlement { display:flex; justify-content:center; align-items:center; flex-wrap:wrap; gap:8px 16px; margin:0 auto 14px; color:#ffda93; }
.result-draw { padding:18px; background:#17142799; border-radius:8px; }
@media(max-width:700px) {
    .result-scores { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .result-hero { padding:8px; min-height:180px; }
    .result-columns { grid-template-columns:1fr; }
    .result-details { padding:8px; }
    .result-hand>.result-faces { flex-wrap:wrap; }
}

#actions .win-action { background:linear-gradient(#ffe3a8,#e9ae59); color:#432236; font-weight:800; border-color:#ffe1a4; }
.effect-own.illustrated-call .effect-avatar{width:100%;height:100%;object-fit:contain;mask-image:none}
.effect-own.illustrated-call .effect-copy{position:absolute;top:2%;left:4%}
.effect-own.illustrated-call .effect-copy strong{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.effect-own.illustrated-call .effect-tiles{position:absolute;bottom:2%;left:5%}

/* The win presentation shares one illustrated stage from the title to the standings. */
#settlement.win-settlement {
    width:100cqw; max-width:100cqw; height:100cqh; max-height:100cqh;
    margin:0; padding:0; border:0; border-radius:0;
    background:linear-gradient(90deg,#20173222,#211732c9 40%,#211830b8 82%,#311b3996),
               url(/assets/shop-garden.webp) center 47% / cover;
}
#settlement.win-settlement[open] {
    display:grid; grid-template-rows:auto minmax(min-content,1fr) auto auto;
}
.win-settlement .result-title {
    z-index:1; margin:0; padding:9px 2cqw; display:grid; grid-template-columns:1fr auto 1fr;
    background:linear-gradient(90deg,#21172899,#26203ad6); border-bottom:1px solid #edc5bf75;
    font-size:clamp(18px,2.15cqw,32px);
}
.win-settlement .result-title small,.result-winner {
    padding:5px 1.5cqw; border-radius:20px; background:#251b32cc;
    font:600 clamp(12px,1.35cqw,20px) system-ui; white-space:nowrap;
}
.win-settlement .result-title small { border:1px solid #dca873; color:#ffe0aa; box-shadow:0 0 12px #f1ad5044; }
.result-winner { justify-self:end; font-size:clamp(11px,1.1cqw,16px); }
.win-settlement .result-main { border:0; position:relative; }
.win-settlement .result-hero { isolation:isolate; position:relative; padding:4% 7%; min-height:270px; }
.result-hero::before {
    content:''; position:absolute; inset:-5% -9% 0 0; z-index:-1;
    background:var(--victory-art) center 22% / cover;
    mask-image:linear-gradient(to right,black 78%,transparent),linear-gradient(to bottom,black 82%,transparent);
    mask-composite:intersect;
}
.win-settlement .result-hero strong {
    width:max-content; transform:rotate(-7deg); font-size:clamp(52px,7.6cqw,118px);
    text-shadow:0 3px #9a3c19,0 0 9px #ff9e35,0 0 25px #ef6a21;
    border-bottom:3px solid #ffcf83; border-radius:0 0 55% 10%;
}
.win-settlement .result-hero b { text-shadow:0 1px 5px #120b1b; margin-top:8px; }
.win-settlement .result-details { z-index:0; margin:1.2cqh 1.5cqw 1cqh 0; padding:0; gap:0; background:linear-gradient(140deg,#201b33ad,#33204071); align-content:stretch; grid-template-rows:auto 1fr auto; }
.win-settlement .result-group { padding:clamp(9px,1.25cqw,21px); background:linear-gradient(115deg,#211c36e8,#27203bc9); border-bottom:1px solid #b38ca34f; }
.win-settlement .result-group h3::before { content:'✿'; color:#ffb4ce; margin-right:.55em; }
.win-settlement .result-group h3 { font-size:clamp(15px,1.55cqw,22px); }
.win-settlement .result-hand { align-items:start; gap:5px; }
.win-settlement .result-hand img { width:clamp(19px,3.22cqw,54px); }
.win-settlement .winning-tile { margin-left:auto; }
.win-settlement .result-columns { grid-template-columns:minmax(0,1.5fr) minmax(0,1fr); gap:1px; }
.win-settlement .result-yaku { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(140px,100%),1fr)); gap:5px 12px; }
.win-settlement .result-yaku>div { padding:4px 8px; background:#64456345; border-radius:5px; }
.win-settlement .result-indicators .result-faces>* { width:clamp(16px,2.1cqw,32px); }
.win-settlement .result-total { padding:4px 2cqw; background:linear-gradient(0deg,#9b466961,transparent); }
.win-settlement .result-total span { padding:5px 15px; border-block:1px solid #d1a06e; background:#372139bb; }
.win-settlement .result-total strong { font-size:clamp(40px,6cqw,90px); color:#ffdf95; text-shadow:0 3px #9e4523,0 0 18px #ef842c; }
.win-settlement .result-scores { padding:2cqh 5cqw 1cqh; margin:0; gap:2cqw; border-top:1px solid #d49a9d99; background:#21172966; }
.result-player { position:relative; }
.result-player::before { content:attr(data-rank); position:absolute; left:-4px; top:-12px; font:bold italic 26px Georgia,serif; color:#eee2fb; text-shadow:0 2px 5px #23152b; }
.result-player[data-rank="1"] { border-color:#ffcd78; box-shadow:inset 0 0 15px #e9a75233,0 0 12px #ffc05b66; }
.result-player[data-rank="1"]::before { color:#ffd577; }
.win-settlement .result-player { padding:9px 13px; background:linear-gradient(110deg,#443044e8,#241b32ed); }
.win-settlement .result-player img { width:clamp(32px,5.8cqw,83px); border:1px solid #cba5a2; }
.win-settlement .result-next { margin:1.5cqh auto 2.5cqh; border-radius:8px; padding:8px 5cqw; background:linear-gradient(#ffe0a4,#f0b65e); border:1px solid #ffebc3; }
@media(max-width:700px) {
    .win-settlement .result-title { grid-template-columns:1fr auto; }
    .win-settlement .result-title small { grid-row:2; grid-column:1/-1; justify-self:center; }
    .win-settlement .result-columns { grid-template-columns:1fr; }
    .win-settlement .result-hero { padding:8px; }
    .win-settlement .result-hero strong { font-size:clamp(32px,8cqw,55px); }
    .win-settlement .result-scores { gap:12px; }
    .win-settlement .result-details { align-content:start; }
}
#table-music { display: grid; place-items: center; flex: none; width: 34px; height: 34px; padding: 0; margin-left: auto; }
#table-music[aria-pressed="false"] .waves, #table-music[aria-pressed="true"] .mute { display: none; }

/* The right end of a rack follows its owner's seat orientation. */
.meld-rack {
    --w:min(2.65cqw, 3.9cqh);
    --h:calc(var(--w) * 1.23);
    position:absolute; display:flex; align-items:end; gap:calc(var(--w) * .18);
    transform-origin:100% 100%; transform-style:preserve-3d;
    transform:rotateX(26deg) rotateZ(var(--angle));
}
.rack-0 {
    --w:min(3.85cqw,6.5cqh);
    position:relative;
    margin-left:clamp(10px,1.9cqw,30px);
    transform-origin:left bottom;
    transform:perspective(950px) rotateX(39deg);
}
.rack-0 .meld-cell .table-tile { --tile-depth:calc(var(--w) * .46); }
.rack-0 .meld-cell + .meld-cell { margin-left:1px; }
.seat-rail .meld-rack {
    --w:clamp(8px,1.65cqw,26px);
    position:relative;
    align-self:flex-end;
    flex:none;
    margin-left:auto;
    transform:none;
}
.seat-rail .rack-2 {
    margin-left:0;
    margin-right:auto;
    transform-origin:center;
    transform:rotateZ(180deg);
}
.seat-rail .meld-cell .table-tile { --tile-depth:calc(var(--w) * .48); }
.open-set,.meld-cell { display:flex; align-items:end; transform-style:preserve-3d; }
.meld-cell { position:relative; width:var(--w); height:var(--h); }
.meld-cell::before {
    content:'';
    position:absolute;
    inset:5%;
    border-radius:15%;
    background:#080f207d;
    box-shadow:0 0 calc(var(--w) * .10) calc(var(--w) * .025) #080f2070;
    transform:translate3d(var(--shadow-x,.065em),var(--shadow-y,.14em),-1px);
    font-size:var(--w);
    pointer-events:none;
}
.rack-1 { --shadow-x:-.14em; --shadow-y:.065em; }
.rack-2 { --shadow-x:-.065em; --shadow-y:-.14em; }
.rack-3 { --shadow-x:.14em; --shadow-y:-.065em; }
.meld-cell.sideways { width:var(--h); height:var(--w); }
.meld-cell .table-tile { position:absolute; width:var(--w); height:var(--h); --tile-depth:calc(var(--w) * .24); }
.sideways .table-tile { left:0; bottom:0; transform-origin:0 100%; transform:translateX(var(--h)) rotate(-90deg); }
.sideways .added-kan { transform:translateX(var(--h)) translateZ(var(--tile-depth)) rotate(-90deg); }
.face-down .tile-face { background:linear-gradient(120deg,#edbf70,#ba843b); }
#player-row { position:absolute; left:9%; right:14%; bottom:3%; display:flex; align-items:flex-end; }
#player-row #hand { position:static; justify-content:flex-start; min-width:0; }
#player-row .drawn { margin-left:min(.8cqw,12px); }
#player-melds { margin-left:auto; flex:none; pointer-events:none; }
.seat.s0 { left:19%; top:auto; bottom:calc(4% + min(7.3cqw,12.3cqh)); transform:translateX(-50%); }
.seat.s2 { left:75%; top:1%; }
.seat.s1,.seat.s3 { top:36%; }
.seat.s1 { left:94%; }
.seat.s3 { left:6%; }
.seat-identity { position:relative;width:fit-content;margin:0 auto 2px; }
.seat-rank { position:absolute;right:-14%;bottom:0;width:48%;aspect-ratio:1;object-fit:contain;filter:drop-shadow(0 2px 3px #080816); }
.seat-rank.provisional { filter:saturate(.35) drop-shadow(0 2px 3px #080816); }
@media(max-width:650px) {
    .seat { width:18cqw; }
    .seat.s1 { left:91%; }
    .seat.s3 { left:9%; }
    .seat.s1,.seat.s3 { top:32%; }
    .seat .avatar { max-width:12cqw; height:auto; }
    .seat .badge { padding:2px 5px; }
    #player-row { left:2%; right:1%; bottom:5%; }
}

.battle-view {
    position:relative; overflow:hidden;
    container-type:size;
    height:calc(100svh - 56px);
    display:grid;
    place-items:end center;
    background:#302b50 url(/assets/battle-courtyard.webp) center / cover no-repeat;
}
/* Keep the garden framing tied to the available height on landscape screens. */
@media (orientation:landscape) {
    .battle-view { background-size:max(100%, calc((100svh - 56px) * 2.7)) auto; }
}
@media (orientation:portrait) {
    .battle-view { background-size:cover; }
    .battle-view main { width:100%; height:min(100cqh,150cqw); }
}

@media (orientation:portrait) {
    .concealed-perspective { top:auto; bottom:0; height:auto; aspect-ratio:1671/941; container-type:size; }
}

#fps-debug {
    position:relative;
    z-index:5;
    flex:none;
    min-width:6ch;
    padding:3px 5px;
    border-radius:4px;
    color:#b6f5ca;
    background:#121920;
    font:600 11px/1.2 monospace;
    pointer-events:none;
}

@media (prefers-reduced-motion:no-preference) {
    /* Move the illustrated call and its glow together as one painted layer. */
    .effect-own.illustrated-call:is(.effect-chi,.effect-pon,.effect-kan) {
        animation:portrait-arrive .48s cubic-bezier(.16,1,.3,1);
        will-change:transform,opacity;
    }
    .effect-own.illustrated-call:is(.effect-chi,.effect-pon,.effect-kan)::before,
    .effect-own.illustrated-call:is(.effect-chi,.effect-pon,.effect-kan)::after,
    .effect-own.illustrated-call:is(.effect-chi,.effect-pon,.effect-kan) .effect-avatar {
        animation:none;
    }
}
#settlement.ranked-final {
    width:min(1460px,80vw);max-width:96vw;max-height:94dvh;padding:clamp(15px,1.5vw,30px) clamp(18px,2.5vw,48px) clamp(12px,1vw,22px);
    border:2px solid #de9fc9;border-radius:22px;color:#fff1dc;
    background:radial-gradient(ellipse at 65% 85%,#57365299,transparent 65%),linear-gradient(125deg,#402b48,#31233b 53%,#49304c);
    box-shadow:0 18px 70px #10091ebf,inset 0 0 54px #aa69b01c;
}
.ranked-final .result-title{font:800 clamp(25px,2.5vw,47px) KaiTi,STKaiti,serif;letter-spacing:.06em;text-shadow:0 2px 3px #211124}
.ranked-final .result-scores{margin:1.4em 0 1em;gap:10px}
.ranked-final .result-player{padding:clamp(8px,.9vw,18px) clamp(10px,1.25vw,24px);column-gap:.65em;border-radius:13px;background:linear-gradient(125deg,#332339,#251c2c);font-size:clamp(13px,1.25vw,23px)}
.ranked-final .result-player img{width:clamp(40px,4.5vw,84px);aspect-ratio:1;object-fit:cover}
.ranked-final .result-player::before{font-size:clamp(24px,2.2vw,42px);top:-.3em}
.ranked-final .result-player-name{overflow:hidden;white-space:nowrap}
.rank-message{text-align:center;color:#ffdf99;font-size:clamp(16px,1.55vw,28px);font-weight:700;margin:.8em 0 .55em}
.rank-message button{margin-left:1em}
.rank-band{position:relative;display:grid;grid-template-columns:19% 21% minmax(0,1fr) 18%;align-items:center;border:2px solid #c98cae;border-radius:18px;padding:clamp(12px,1vw,22px);background:linear-gradient(90deg,#54364da6,#49344ed9 65%,#49304b88),linear-gradient(0deg,#30213466,#322138ef 70%),url(/assets/course-shrine.webp) right 62%/cover;box-shadow:inset 0 0 24px #eeaddb33,0 0 12px #c471a92a}
.rank-self,.rank-badge{display:grid;justify-items:center;align-content:center;text-align:center;line-height:1.2}
.rank-self,.rank-self+.rank-badge{border-right:1px solid #bf94b68a}
.rank-self img{width:clamp(62px,7.2vw,135px);border-radius:50%;border:3px double #efd1a9;aspect-ratio:1;object-fit:cover}
.rank-self b{border:1px solid #bd91aa;border-radius:18px;padding:.15em 1em;background:#482e47;color:#ffdfaf}
.rank-badge img{width:clamp(58px,7.1vw,134px);aspect-ratio:1;object-fit:contain}
.rank-badge b{font:700 clamp(21px,2.3vw,43px) KaiTi,serif;color:#ead4ff}
.rank-badge:last-child{position:relative}.rank-badge:last-child img{width:clamp(45px,5vw,100px)}.rank-badge:last-child b{color:#ffd99d;font-size:clamp(17px,1.65vw,32px)}
.rank-badge:last-child::before{content:'»';position:absolute;left:0;top:38%;font:bold 2em Georgia;color:#ffdfa2}
.rank-meter{padding:0 6%}.rank-band small{font-size:clamp(13px,1.3vw,25px);color:#ffe8ca}.rank-meter strong{display:block;color:#ffdb98;font-size:clamp(22px,2.2vw,42px);margin:.22em 0}.rank-meter strong span{margin-left:.55em}.rank-meter .gain{color:#98e38d}.rank-meter .loss{color:#ff9e9e}
.rank-track{position:relative;border:1px solid #cba0bc;border-radius:30px;background:#302336;overflow:hidden;text-align:center}.rank-track i{position:absolute;inset:2px auto 2px 1px;max-width:99.5%;border-radius:inherit;background:linear-gradient(90deg,#b889ef,#dce0ff)}.rank-track b{position:relative;font-size:clamp(12px,1.15vw,21px);color:white;text-shadow:0 1px 3px #211527,0 0 3px #211527}
.ranked-final .result-next{margin:1.1em auto 0;border-radius:40px;background:linear-gradient(110deg,#ffd289,#ffe0a0);color:#332033;padding:.55em 2.8em;font-size:clamp(16px,1.45vw,28px)}
@media(max-width:850px){#settlement.ranked-final{width:94vw}.ranked-final .result-scores{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.rank-band{grid-template-columns:18% 20% minmax(0,1fr) 18%}}
@media(max-width:540px){.rank-band{grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}.rank-meter{grid-row:2;grid-column:1/-1}.rank-band .rank-badge:last-child{grid-column:3;grid-row:1}.rank-badge:last-child::before{display:none}.ranked-final .result-player img{width:36px}}
.final-coins{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:.4em .8em;margin:14px auto;padding:10px 16px;border:1px solid #a47a52;border-radius:12px;background:linear-gradient(110deg,#48333b,#332737);color:#ffe0a2}
.final-coins img{width:28px;height:28px}.final-coins .coin-amount{color:#ffda80;font-size:1.6em}.final-coins small{color:#ead8c6}

/* Desktop keeps the single-row top bar; prevent #table-mode from ever wrapping vertically. */
.header-drawer{display:contents}
#table-mode{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
#menu-toggle,#menu-close,#menu-backdrop{display:none}

/* Mobile portrait & mobile landscape: full-bleed 100dvh stage + top-right floating capsule + right slide-out drawer. */
@media (max-width:650px),(max-height:540px) and (orientation:landscape){
    html,body{height:100%;overflow:hidden}
    .battle-view{
        width:100%;
        height:100svh;
        height:100dvh;
        background-size:cover;
        background-position:center;
    }
    header{
        position:fixed;
        top:max(8px,env(safe-area-inset-top));
        right:max(10px,env(safe-area-inset-right));
        left:auto;
        height:auto;
        padding:0;
        gap:8px;
        background:none;
        border:0;
        z-index:30;
        pointer-events:none;
    }
    header #table-music,header #menu-toggle{
        pointer-events:auto;
        display:inline-flex;
        align-items:center;
        justify-content:center;
        height:36px;
        margin-left:0;
        background:#21182ed9;
        border:1px solid #a687a8;
        box-shadow:0 4px 14px #0b071699;
        backdrop-filter:blur(8px);
        -webkit-backdrop-filter:blur(8px);
    }
    header #table-music{width:36px;border-radius:50%;padding:0}
    header #menu-toggle{
        gap:5px;
        padding:0 12px;
        border-radius:999px;
        border-color:#e5b97d;
        color:#ffe7be;
        font-size:13px;
        font-weight:600;
        line-height:1;
    }
    header #menu-toggle span{flex:none;color:inherit;font-size:inherit}
    header .header-drawer{
        position:fixed;
        top:0;
        right:0;
        bottom:0;
        width:min(268px,78vw);
        padding:max(14px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) 16px;
        display:flex;
        flex-direction:column;
        align-items:stretch;
        gap:10px;
        background:#1c1528f2;
        border-left:1px solid #98708f;
        box-shadow:-10px 0 32px #080612bf;
        backdrop-filter:blur(12px);
        -webkit-backdrop-filter:blur(12px);
        transform:translateX(100%);
        opacity:0;
        visibility:hidden;
        pointer-events:none;
        transition:transform .22s cubic-bezier(.2,.8,.2,1),opacity .2s ease,visibility .2s ease;
        z-index:32;
        overflow-y:auto;
        -webkit-overflow-scrolling:touch;
    }
    body.menu-open header .header-drawer{
        transform:translateX(0);
        opacity:1;
        visibility:visible;
        pointer-events:auto;
    }
    #menu-backdrop:not([hidden]){
        display:block;
        position:fixed;
        inset:0;
        z-index:29;
        background:#0d091985;
        backdrop-filter:blur(2px);
        -webkit-backdrop-filter:blur(2px);
    }
    header .header-drawer #menu-close{
        display:grid;
        place-items:center;
        position:absolute;
        top:max(10px,env(safe-area-inset-top));
        right:max(12px,env(safe-area-inset-right));
        width:32px;
        height:32px;
        padding:0;
        border-radius:50%;
        border:1px solid #8a6e92;
        background:#302541;
        color:#fff2ea;
        font-size:14px;
        line-height:1;
    }
    header .header-drawer strong{
        order:1;
        font-size:17px;
        padding-right:36px;
        line-height:1.3;
    }
    header .header-drawer #table-mode{
        display:block;
        order:2;
        flex:none;
        font-size:12px;
        color:#e3c7d8;
        padding-bottom:8px;
        border-bottom:1px solid #98708f4d;
    }
    header .header-drawer #fps-debug{
        order:3;
        align-self:flex-start;
        font-size:11px;
    }
    header .header-drawer label{
        order:4;
        display:flex;
        align-items:center;
        justify-content:space-between;
        gap:10px;
        padding:9px 12px;
        border-radius:10px;
        background:#ffffff0d;
        border:1px solid #ffffff14;
        font-size:14px;
        cursor:pointer;
    }
    header .header-drawer label input{
        order:2;
        width:18px;
        height:18px;
        accent-color:#f0b862;
    }
    header .header-drawer #rules,
    header .header-drawer a{
        order:5;
        display:flex;
        align-items:center;
        justify-content:center;
        width:100%;
        padding:10px 14px;
        border-radius:12px;
        font-size:14px;
        font-weight:600;
        text-align:center;
    }
    header .header-drawer #rules{margin-top:auto}
    header .header-drawer a{
        border-color:#c6879499;
        background:#442636;
        color:#ffdfe2;
    }
    #dora{
        top:max(2%,env(safe-area-inset-top));
        left:max(1.5%,env(safe-area-inset-left));
    }
    dialog{max-height:calc(100dvh - 16px);overflow:auto}
}

/* Mobile landscape fine-tuning: maximize felt visibility & touchable hand tiles above home indicator. */
@media (max-height:540px) and (orientation:landscape){
    /* Prevent center counter from covering opposite seat's first discard row (.r2). */
    .table-plane .counter{
        top:47.5%;
        padding:clamp(14px,4.2cqh,22px) clamp(18px,3cqw,34px);
    }
    .table-plane .counter strong{font-size:clamp(15px,4.6cqh,24px)}
    .table-plane .counter small{font-size:clamp(9px,2.6cqh,12px)}
    .table-plane .r2{bottom:69%}

    #player-row{
        left:max(6%,env(safe-area-inset-left));
        right:max(6%,env(safe-area-inset-right));
        bottom:max(3.5%,env(safe-area-inset-bottom));
    }
    #hand button{width:min(4.8cqw,8.2cqh)}
    .seat.s0{bottom:calc(4.5% + min(7.8cqw,13.5cqh))}
    .controls{bottom:18%}

    /* Keep win & draw settlement dialogs cleanly fitted in short landscape viewports. */
    #settlement.win-settlement{
        width:100vw;max-width:100vw;
        height:100svh;height:100dvh;max-height:100dvh;
        overflow:auto;
        padding-left:env(safe-area-inset-left);
        padding-right:env(safe-area-inset-right);
        padding-bottom:env(safe-area-inset-bottom);
    }
    #settlement.win-settlement[open]{grid-template-rows:auto minmax(0,1fr) auto auto}
    .win-settlement .result-title{padding:4px 12px;font-size:clamp(14px,3.8cqh,20px)}
    .win-settlement .result-title small,.win-settlement .result-winner{padding:2px 10px;font-size:clamp(10px,2.8cqh,13px)}
    .win-settlement .result-main{grid-template-columns:28% minmax(0,1fr);min-height:0}
    .win-settlement .result-hero{min-height:0;padding:6px 10px}
    .win-settlement .result-hero strong{font-size:clamp(28px,10cqh,48px)}
    .win-settlement .result-hero b{font-size:12px;margin-top:2px}
    .win-settlement .result-details{margin:4px 8px 4px 0;min-height:0;overflow:auto}
    .win-settlement .result-group{padding:5px 8px}
    .win-settlement .result-group h3{margin:0 0 4px;font-size:12px}
    .win-settlement .result-hand img,.win-settlement .result-faces img,.win-settlement .result-faces i{width:clamp(16px,2.5vw,24px)}
    .win-settlement .result-yaku{gap:3px 8px;font-size:12px}
    .win-settlement .result-yaku>div{padding:2px 6px}
    .win-settlement .result-indicators small{margin:2px 0;font-size:11px}
    .win-settlement .result-indicators .result-faces>*{width:clamp(14px,2vw,20px)}
    .win-settlement .result-total{padding:2px 10px;gap:10px}
    .win-settlement .result-total span{padding:2px 8px;font-size:12px}
    .win-settlement .result-total strong{font-size:clamp(22px,7cqh,36px)}
    .win-settlement .result-scores{padding:5px 12px;gap:8px}
    .win-settlement .result-player{padding:4px 8px;font-size:11px;gap:1px 6px}
    .win-settlement .result-player::before{font-size:16px;top:-8px;left:-2px}
    .win-settlement .result-player img{width:clamp(24px,7cqh,36px)}
    .win-settlement .result-next{margin:5px auto 6px;padding:5px 28px;font-size:13px}

    #settlement:not(.win-settlement){padding:10px 14px;max-height:calc(100dvh - 12px)}
    #settlement:not(.win-settlement) .result-title{margin:0 0 6px;font-size:16px}
    #settlement:not(.win-settlement) .result-draw{padding:10px;font-size:13px}
    #settlement:not(.win-settlement) .result-scores{margin:8px 0;gap:6px}
    #settlement:not(.win-settlement) .result-player{padding:5px 7px;font-size:12px}
    #settlement:not(.win-settlement) .result-next{padding:6px 26px;font-size:13px}
    #settlement.ranked-final{padding:10px 14px;width:min(96vw,860px)}
    .ranked-final .result-scores{margin:8px 0;gap:6px}
    .rank-band{padding:8px 10px}
    .rank-self img,.rank-badge img{width:clamp(36px,9cqh,56px)}
    .rank-meter strong{font-size:clamp(16px,5cqh,24px);margin:2px 0}
    .ranked-final .result-next{margin:8px auto 0;padding:6px 24px;font-size:14px}
}

/* Mobile two-step discard selection & confirm CTA */
#hand button.selected img{
    transform:translateY(-15px);
    filter:drop-shadow(0 0 6px #ffcf7d) drop-shadow(0 7px 3px #131c30);
}
#actions #discard-confirm{
    background:linear-gradient(#ffe3a8,#e9ae59);
    color:#432236;
    font-weight:800;
    border:1px solid #fff0c8;
    padding:6px 22px;
    box-shadow:0 3px 12px #0f0a1d99,0 0 10px #f5b95b66;
}
@media (prefers-reduced-motion:reduce){
    header .header-drawer{transition:none}
}

/* Mobile portrait: compact scenic top bar + full rectangular top-down table + all-upright 2D tiles & symmetric seats. */
@media (orientation:portrait){
    .battle-view{
        --hand-h:calc(min(28vw,118px) + 18px);
        --stage-top:max(68px,calc(env(safe-area-inset-top) + 58px));
        --stage-bottom:calc(var(--hand-h) + 92px + env(safe-area-inset-bottom));
        display:flex;
        align-items:stretch;
        justify-content:center;
        background-size:cover;
        background-position:center top;
    }
    .battle-view main{
        width:100%;
        height:100%;
        aspect-ratio:auto;
    }
    /* Pure top-down rectangular blue felt table with overhead lamp glow & gold-trimmed wood rail. */
    .felt{
        left:6px;
        right:6px;
        top:var(--stage-top);
        bottom:var(--stage-bottom);
        width:auto;
        height:auto;
        aspect-ratio:auto;
        transform:none;
        border:4px solid #a67838;
        border-top:5px solid #c2954e;
        border-bottom:7px solid #cf9e52;
        border-radius:14px;
        box-shadow:
            inset 0 0 34px #040a1cc7,
            inset 0 1px 0 #ffe8af44,
            inset 0 -1px 0 #ffe09633,
            0 8px 20px #060410b0;
        background:radial-gradient(circle at 50% 52%,#214a8e 0%,#173770 44%,#102754 80%,#0b1b3d 100%);
    }
    .felt::before{
        content:'';
        position:absolute;
        inset:8px;
        border:1px solid #96c8ff1c;
        border-radius:8px;
        pointer-events:none;
    }

    /* Flat top-down 2D stage (no 3D trapezoid distortion) so single-perspective 2D tiles stay crisp & unified. */
    .table-perspective,
    .concealed-perspective{
        top:var(--stage-top);
        bottom:var(--stage-bottom);
        left:6px;
        right:6px;
        width:auto;
        height:auto;
        aspect-ratio:auto;
        transform:none;
        perspective:none;
        container-type:size;
    }
    .table-plane{
        transform:none;
        transform-style:flat;
        --c:clamp(92px,min(28cqw,28cqh),130px);
        --tw:calc((var(--c) - 10px) / 6);
        --th:calc(var(--tw) * 1.32);
    }
    #rivers,#table-backs{transform-style:flat}
    /* Render upright DOM river tiles directly in portrait instead of the 3D perspective canvas. */
    .river-paint{display:none}
    #rivers.painted .river{opacity:1}

    /* Hide opponents' concealed tile backs in portrait; place all opponent melds cleanly beneath each avatar. */
    .concealed-perspective .backs{display:none}
    .seat-rail{min-width:0;transform-style:flat}
    .seat-rail .meld-rack{
        --w:clamp(14px,3.8cqw,18px);
        --h:calc(var(--w) * 1.32);
        margin-left:0;
        transform:none;
        transform-style:flat;
        gap:6px;
    }
    .seat-rail .rack-2{margin-right:0;transform:none}
    .seat-rail .open-set,
    .seat-rail .meld-cell,
    .seat-rail .meld-cell .table-tile{transform-style:flat}
    .seat-rail .meld-cell .table-tile :is(.tile-near,.tile-far,.tile-left,.tile-right,.tile-core,.tile-back){display:none}
    .seat-rail .meld-cell::before{display:none}
    .seat-rail .meld-cell{width:var(--w);height:var(--h)}
    .seat-rail .meld-cell .table-tile{width:var(--w);height:var(--h);transform:none}
    /* Keep called (.sideways) tiles upright 0deg facing player with subtle blue highlight instead of rotating 2D art. */
    .seat-rail .meld-cell.sideways{width:var(--w);height:var(--h)}
    .seat-rail .meld-cell.sideways .table-tile{left:0;bottom:0;transform:none}
    .seat-rail .meld-cell.sideways .added-kan{transform:translateY(-28%)}
    .seat-rail .meld-cell .table-tile .tile-face{
        transform:none;
        border-radius:3px;
        border:1px solid #c9c3b4;
        background:linear-gradient(180deg,#fdfcf9 0%,#efede4 85%,#dedad0 100%);
        box-shadow:0 -2px 0 #e09c34,0 -2.5px 0 #a36818,0 2px 3px #030a1a8c;
    }
    .seat-rail .meld-cell.sideways .table-tile .tile-face{
        border-color:#6ea0dc;
        background:linear-gradient(180deg,#e8f3ff 0%,#cfe3fa 80%,#b9d2f2 100%);
    }
    .seat-rail .meld-cell .face-down .tile-face{
        border-color:#ffd88a;
        background:linear-gradient(180deg,#f3b54a 0%,#d48824 85%,#a86412 100%);
    }
    .seat-rail .open-set{
        gap:1.5px;
        padding:4px 4px 3px;
        border-radius:6px;
        background:#08122a59;
        border:1px solid #9bc8ff24;
    }
    /* Top player melds: centered horizontally right below top avatar. */
    .rail-2{left:50%;top:28px;justify-content:center;transform:translateX(-50%)}
    /* Left & Right player melds: stacked vertically right below each side avatar card. */
    .rail-3{left:8px;top:96px;transform:none}
    .rail-1{right:8px;left:auto;top:96px;transform:none}
    .rail-3 .meld-rack,.rail-1 .meld-rack{flex-direction:column;align-items:center;gap:5px}
    main:has(.seat.s1 .riichi-marker) .rail-1{top:128px}
    main:has(.seat.s3 .riichi-marker) .rail-3{top:128px}

    /* Center obsidian compass flush with all 4 upright rivers. */
    .table-plane .counter{
        left:50%;
        top:55%;
        width:var(--c);
        height:var(--c);
        padding:12px 8px;
        display:flex;
        flex-direction:column;
        align-items:center;
        justify-content:center;
        gap:1px;
        border:2px solid #9bb9eb5e;
        border-radius:14px;
        background:radial-gradient(circle at 50% 42%,#232b42 0%,#121726 78%,#0a0d18 100%);
        box-shadow:0 6px 16px #00000099,inset 0 1px 0 #ffffff24,inset 0 0 12px #000000b3;
    }
    .table-plane .counter strong{font-size:clamp(15px,4.4cqw,22px);line-height:1.1;color:#fff}
    .table-plane .counter small{font-size:clamp(9px,2.5cqw,11px);color:#e6c67e}
    .table-plane .counter .table-score{display:none}
    #table-scores .wind-badge{font-size:clamp(9px,2.4cqw,11px)}

    /* All 4 discard rivers: uniform 0deg upright 2D tiles facing the player, flush with compass. */
    .river{
        --discard-gap:2px;
        width:auto;
        transform-style:flat;
    }
    .river .table-tile{
        width:var(--tw);
        height:var(--th);
        aspect-ratio:auto;
        transform:none !important;
        transform-style:flat;
    }
    .river .table-tile .tile-face{
        inset:0;
        border-radius:3px;
        border:1px solid #c9c3b4;
        background:linear-gradient(180deg,#fdfcf9 0%,#efede4 85%,#dedad0 100%);
        box-shadow:0 -2px 0 #e09c34,0 -2.5px 0 #a36818,0 2px 3px #030a1a8c;
    }
    .river .table-tile .tile-face img{width:100%;height:100%;object-fit:contain}
    .river .table-tile.claimed .tile-face{opacity:.48}
    .river .table-tile.declared .tile-face{
        border-color:#ff6b7d;
        box-shadow:0 -2px 0 #e09c34,0 0 8px #ff5a72b3,0 2px 3px #030a1a99;
    }
    .river .table-tile.declared .tile-face::after{box-shadow:none}
    .river .table-tile.call-target .tile-face{
        border-color:#ffcf7d;
        box-shadow:0 -2px 0 #e09c34,0 0 8px #ffac43cc,0 2px 3px #030a1a99;
    }

    /* Bottom river (自家): grows downward below compass */
    .table-plane .r0{
        left:50%;
        top:calc(55% + var(--c) / 2 + 8px);
        transform:translateX(-50%);
        display:grid;
        grid-template-columns:repeat(6,var(--tw));
        gap:4px 2px;
    }
    /* Top river (对家): grows upward above compass, all tiles 0deg upright facing player */
    .table-plane .r2{
        left:50%;
        top:auto;
        bottom:calc(45% + var(--c) / 2 + 8px);
        transform:translateX(-50%);
        display:flex;
        flex-wrap:wrap-reverse;
        flex-direction:row-reverse;
        width:calc(var(--tw) * 6 + 10px);
        gap:4px 2px;
    }
    /* Left river (上家): upright columns growing leftward from compass */
    .table-plane .r3{
        left:auto;
        right:calc(50% + var(--c) / 2 + 8px);
        top:55%;
        transform:translateY(-50%);
        display:grid;
        grid-auto-flow:column;
        grid-template-rows:repeat(6,var(--th));
        grid-template-columns:none;
        direction:rtl;
        gap:3px 3px;
    }
    /* Right river (下家): upright columns growing rightward from compass */
    .table-plane .r1{
        left:calc(50% + var(--c) / 2 + 8px);
        top:55%;
        transform:translateY(-50%);
        display:grid;
        grid-auto-flow:column;
        grid-template-rows:repeat(6,var(--th));
        grid-template-columns:none;
        gap:3px 3px;
    }

    /* Symmetrical 4-player avatar layout around the rectangular table. */
    .seat{width:auto;z-index:5}
    .seat .avatar{width:36px;max-width:36px;height:36px;border-color:#ecc77f}
    .seat .badge{
        padding:3px 9px;
        font-size:11px;
        white-space:nowrap;
        border-color:#e8c47cb8;
        background:linear-gradient(180deg,#161226eb,#0e0e1cf2);
    }
    .seat .badge .seat-points{justify-content:center;gap:4px;margin-top:1px}
    /* Top opponent (对家): centered horizontal pill straddling the top table border. */
    .seat.s2{
        left:50%;
        top:calc(var(--stage-top) - 21px);
        bottom:auto;
        transform:translateX(-50%);
        display:flex;
        flex-direction:row;
        align-items:center;
        gap:6px;
        padding:3px 10px 3px 4px;
        border-radius:999px;
        background:linear-gradient(180deg,#161226f0,#0e0e1cf5);
        border:1.5px solid #e8c47cc4;
        box-shadow:0 5px 14px #0000008c;
    }
    .seat.s2 .seat-identity{margin:0}
    .seat.s2 .badge{background:none;border:0;box-shadow:none;padding:0;text-align:left}
    .seat.s2 .badge .seat-points{justify-content:flex-start}
    .seat.s2 .opposite-hand{display:none}
    .seat.s2 .riichi-marker{margin:2px 0 6px;font-size:10px;padding:0 8px}

    /* Left (上家) & Right (下家): strictly symmetrical vertical cards in upper corners of table. */
    .seat.s3,
    .seat.s1{
        top:calc(var(--stage-top) + 10px);
        bottom:auto;
        width:clamp(74px,20vw,84px);
        transform:none;
        display:flex;
        flex-direction:column;
        align-items:center;
    }
    .seat.s3{left:14px}
    .seat.s1{right:14px;left:auto}
    .seat.s3 .seat-identity,
    .seat.s1 .seat-identity{margin:0 auto -12px;z-index:2}
    .seat.s3 .badge,
    .seat.s1 .badge{
        width:100%;
        padding:15px 4px 5px;
        border-radius:12px;
        font-size:10.5px;
    }
    .seat.s3 .riichi-marker,
    .seat.s1 .riichi-marker{
        display:block;
        margin:5px auto 9px;
        padding:0 8px;
        font-size:11px;
        width:fit-content;
    }

    /* Self player (自家): moved outside the table into the left side of the bottom status strip. */
    .seat.s0{
        left:10px;
        top:auto;
        bottom:calc(var(--hand-h) + 46px + env(safe-area-inset-bottom));
        transform:none;
        display:flex;
        flex-direction:row;
        align-items:center;
        gap:6px;
        padding:3px 11px 3px 4px;
        border-radius:999px;
        background:linear-gradient(180deg,#161226f0,#0e0e1cf5);
        border:1.5px solid #e8c47cc4;
        box-shadow:0 4px 12px #00000073;
    }
    .seat.s0 .seat-identity{margin:0}
    .seat.s0 .badge{background:none;border:0;box-shadow:none;padding:0;text-align:left}
    .seat.s0 .badge .seat-points{justify-content:flex-start}
    .seat.s0 .riichi-marker{margin:0 0 0 4px;font-size:10px;padding:0 7px}

    /* Tenpai pill sits cleanly on the right of the bottom status strip, opposite .seat.s0 (never overlaps melds). */
    #tenpai:not(:empty){
        position:fixed;
        right:10px;
        bottom:calc(var(--hand-h) + 46px + env(safe-area-inset-bottom));
        margin:0;
        padding:4px 9px;
        max-width:54vw;
        border-radius:12px;
        background:linear-gradient(180deg,#1b3b34,#112622);
        border:1.5px solid #7ee0bab8;
        box-shadow:0 4px 12px #00000066;
        z-index:7;
    }
    #tenpai strong{font-size:13px}
    #tenpai small{font-size:11px;margin:0 3px}
    #tenpai img{width:18px}

    /* Single-row action strip (status + 吃/碰/杠/立直托管/出牌) cleanly between status strip and hand tray. */
    .controls{
        left:10px;
        right:10px;
        width:auto;
        bottom:calc(var(--hand-h) + max(10px,env(safe-area-inset-bottom) + 2px));
        display:flex;
        flex-direction:row;
        flex-wrap:wrap;
        align-items:center;
        justify-content:center;
        gap:4px 8px;
        z-index:8;
    }
    .controls #status{
        font-size:12px;
        padding:4px 12px;
        border-radius:999px;
        background:#140e22cc;
        border:1px solid #ffd47873;
        color:#ffe39e;
    }
    #actions{gap:6px;flex-wrap:wrap;justify-content:center}
    #actions button{margin:0;padding:4px 13px;font-size:12.5px}
    #actions .call{padding:3px 9px;gap:5px}
    .call strong{font-size:16px}
    .combination img{width:15px}

    /* 7x2 large touch-friendly hand tray at the bottom. */
    #player-row{
        left:10px;
        right:10px;
        bottom:max(8px,env(safe-area-inset-bottom));
        display:flex;
        flex-direction:column;
        align-items:center;
        padding:8px 6px 6px;
        border-radius:14px;
        background:#120c1ec0;
        border:1px solid #c4a6e02b;
        z-index:4;
    }
    #player-row #hand{
        display:grid;
        grid-template-columns:repeat(7,minmax(0,1fr));
        gap:5px 4px;
        width:100%;
        max-width:390px;
        justify-items:center;
    }
    #hand button{width:100%;max-width:48px}
    #player-row .drawn{
        margin-left:0;
        outline:2px solid #ffcf7d;
        outline-offset:1px;
        border-radius:5px;
    }
    #hand button.selected img{
        transform:translateY(-10px);
        filter:drop-shadow(0 0 6px #ffcf7d) drop-shadow(0 5px 3px #131c30);
    }

    /* Own called melds (吃/碰/杠): upright 0deg 2D tiles cleanly on the bottom-right inside the table. */
    #player-melds{
        position:fixed;
        right:14px;
        bottom:calc(var(--stage-bottom) + 10px);
        margin-left:0;
        width:auto;
        z-index:4;
    }
    #player-melds .rack-0{
        --w:clamp(18px,4.8vw,22px);
        --h:calc(var(--w) * 1.32);
        margin-left:0;
        transform:none;
        transform-style:flat;
        gap:6px;
    }
    #player-melds .rack-0 .open-set{
        gap:2px;
        padding:4px 5px 3px;
        border-radius:7px;
        background:#08122a59;
        border:1px solid #9bc8ff24;
        transform-style:flat;
    }
    #player-melds .rack-0 .meld-cell,
    #player-melds .rack-0 .meld-cell .table-tile{
        width:var(--w);
        height:var(--h);
        transform:none;
        transform-style:flat;
    }
    #player-melds .rack-0 .meld-cell.sideways{width:var(--w);height:var(--h)}
    #player-melds .rack-0 .meld-cell.sideways .table-tile{left:0;bottom:0;transform:none}
    #player-melds .rack-0 .meld-cell.sideways .added-kan{transform:translateY(-28%)}
    #player-melds .rack-0 .meld-cell .table-tile :is(.tile-near,.tile-far,.tile-left,.tile-right,.tile-core,.tile-back){
        display:none;
    }
    #player-melds .rack-0 .meld-cell .table-tile .tile-face{
        transform:none;
        border-radius:3px;
        border:1px solid #c9c3b4;
        background:linear-gradient(180deg,#fdfcf9 0%,#efede4 85%,#dedad0 100%);
        box-shadow:0 -2px 0 #e09c34,0 -2.5px 0 #a36818,0 2px 4px #030a1a99;
    }
    #player-melds .rack-0 .meld-cell.sideways .table-tile .tile-face{
        border-color:#6ea0dc;
        background:linear-gradient(180deg,#e8f3ff 0%,#cfe3fa 80%,#b9d2f2 100%);
    }
    #player-melds .rack-0 .meld-cell .face-down .tile-face{
        border-color:#ffd88a;
        background:linear-gradient(180deg,#f3b54a 0%,#d48824 85%,#a86412 100%);
    }
    #player-melds .rack-0 .meld-cell::before{display:none}

    /* Portrait Win Settlement (.win-settlement): full-width character hero banner + single-row hand + compact 2x2 scores. */
    #settlement.win-settlement{
        width:100vw;max-width:100vw;
        height:100svh;height:100dvh;max-height:100dvh;
        overflow-y:auto;
        -webkit-overflow-scrolling:touch;
        padding:env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
        background:
            linear-gradient(180deg,#161024b8 0%,#1c132ce0 45%,#180f24f0 100%),
            url(/assets/shop-garden.webp) center/cover no-repeat;
    }
    #settlement.win-settlement[open]{
        display:flex;
        flex-direction:column;
    }
    .win-settlement .result-title{
        flex:none;
        display:flex;
        flex-wrap:wrap;
        align-items:center;
        justify-content:space-between;
        gap:6px;
        padding:10px 12px;
        font-size:18px;
        background:linear-gradient(90deg,#1c1328eb,#261c38eb);
        border-bottom:1px solid #edc5bf59;
    }
    .win-settlement .result-title small{
        grid-row:auto;
        grid-column:auto;
        padding:3px 9px;
        font-size:11px;
        border-color:#dca873b3;
    }
    .win-settlement .result-winner{
        padding:3px 9px;
        font-size:11.5px;
        margin-left:auto;
        display:inline-flex;
        align-items:center;
        gap:4px;
    }
    .win-settlement .result-main{
        display:flex;
        flex-direction:column;
        flex:none;
    }
    .win-settlement .result-hero{
        flex:none;
        height:clamp(155px,22dvh,212px);
        min-height:155px;
        margin:10px 12px 0;
        padding:12px 14px;
        border-radius:16px;
        border:1.5px solid #ecc3917a;
        overflow:hidden;
        justify-content:flex-end;
        align-items:flex-start;
        box-shadow:0 8px 24px #080512a6;
    }
    .win-settlement .result-hero::before{
        inset:0;
        background:var(--victory-art) center 16%/cover no-repeat;
        mask-image:none;
        -webkit-mask-image:none;
    }
    .win-settlement .result-hero::after{
        content:'';
        position:absolute;
        inset:0;
        z-index:-1;
        background:
            linear-gradient(180deg,#100a1c14 0%,#120c2040 48%,#120b1eeb 100%),
            linear-gradient(90deg,#120b1ea6 0%,transparent 52%,#120b1e73 100%);
    }
    .win-settlement .result-hero strong{
        font-size:clamp(34px,10vw,44px);
        transform:rotate(-5deg);
        transform-origin:left bottom;
    }
    .win-settlement .result-hero b{
        font-size:13px;
        margin-top:4px;
    }
    .win-settlement .result-details{
        margin:9px 12px 0;
        padding:0;
        display:flex;
        flex-direction:column;
        gap:8px;
        background:none;
    }
    .win-settlement .result-total{
        order:-1;
        display:flex;
        align-items:center;
        justify-content:space-between;
        padding:6px 12px;
        border-radius:12px;
        background:linear-gradient(115deg,#3c2142eb,#241834e8);
        border:1px solid #ebb87880;
    }
    .win-settlement .result-total span{
        padding:3px 10px;
        border:1px solid #ebb878b8;
        border-radius:999px;
        background:#2d1932d9;
        font-size:12px;
        font-weight:700;
    }
    .win-settlement .result-total strong{
        font-size:clamp(26px,7.5vw,34px);
    }
    .win-settlement .result-group{
        padding:9px 10px;
        border-radius:12px;
        border:1px solid #c498b852;
        background:linear-gradient(135deg,#1c162ee6,#241a34db);
    }
    .win-settlement .result-group h3{
        font-size:13px;
        margin:0 0 7px;
    }
    .win-settlement .result-hand{
        flex-wrap:nowrap;
        align-items:flex-end;
        justify-content:space-between;
        gap:4px;
    }
    .win-settlement .result-hand>.result-faces:not(.winning-tile){
        flex-wrap:nowrap;
        gap:1.5px;
        min-width:0;
    }
    .win-settlement .result-hand img{
        width:clamp(18px,5.6vw,26px);
        height:auto;
    }
    .win-settlement .winning-tile{
        flex:none;
        margin-left:auto;
        padding-left:5px;
        border-left:1px dashed #ffd08059;
    }
    .win-settlement .winning-tile small{font-size:10px}
    .win-settlement .result-columns{
        display:grid;
        grid-template-columns:1.12fr 1fr;
        gap:8px;
        background:none;
    }
    .win-settlement .result-yaku{
        grid-template-columns:1fr;
        gap:5px;
    }
    .win-settlement .result-yaku>div{
        padding:4px 8px;
        font-size:12.5px;
    }
    .win-settlement .result-indicators small{
        font-size:11px;
        margin:3px 0;
    }
    .win-settlement .result-indicators .result-faces{gap:2px}
    .win-settlement .result-indicators .result-faces>*{
        width:clamp(18px,4.9vw,24px);
    }
    .win-settlement .result-scores{
        margin:10px 12px 0;
        padding:0;
        border-top:0;
        background:none;
        display:grid;
        grid-template-columns:1fr 1fr;
        gap:9px;
    }
    .win-settlement .result-player{
        padding:8px 9px;
        border-radius:11px;
        gap:2px 8px;
        font-size:12px;
    }
    .win-settlement .result-player img{
        width:38px;
        height:38px;
        object-fit:cover;
    }
    .win-settlement .result-player::before{
        font-size:20px;
        left:-4px;
        top:-10px;
    }
    .win-settlement .result-next{
        margin:auto auto 16px;
        margin-top:12px;
        width:72%;
        max-width:300px;
        padding:10px 0;
        border-radius:999px;
        font-size:15px;
    }

    /* Portrait Ranked Final Settlement (#settlement.ranked-final): Hero Rank Card -> Coins -> 4-Row Standings. */
    #settlement.ranked-final{
        width:100vw;max-width:100vw;
        height:100svh;height:100dvh;max-height:100dvh;
        margin:0;
        border:0;
        border-radius:0;
        padding:max(14px,env(safe-area-inset-top)) 14px max(18px,env(safe-area-inset-bottom));
        overflow-y:auto;
        -webkit-overflow-scrolling:touch;
        background:
            radial-gradient(ellipse at 70% 15%,#783e766b,transparent 58%),
            radial-gradient(ellipse at 20% 85%,#5c326059,transparent 60%),
            linear-gradient(155deg,#2d1d38 0%,#1d1428 52%,#2b1a34 100%);
    }
    #settlement.ranked-final[open]{
        display:flex;
        flex-direction:column;
    }
    .ranked-final .result-title{
        order:1;
        margin:0;
        padding-bottom:10px;
        border-bottom:1px solid #de9fc947;
        font-size:24px;
    }
    .ranked-final .rank-summary{
        order:2;
        margin-top:10px;
    }
    .ranked-final .rank-message{
        margin:0 0 8px;
        font-size:12.5px;
        text-align:left;
        color:#ffdf99;
    }
    .ranked-final .rank-band{
        display:grid;
        grid-template-columns:82px 1fr 1fr;
        align-items:center;
        gap:10px 6px;
        padding:14px 12px;
        border-radius:16px;
        border:1.5px solid #d698beb8;
        background:
            linear-gradient(180deg,#402644c7 0%,#24162eeb 72%),
            url(/assets/course-shrine.webp) center 35%/cover no-repeat;
    }
    .ranked-final .rank-self{
        border-right:0;
        grid-column:1;
        grid-row:1;
    }
    .ranked-final .rank-self img{width:58px;height:58px}
    .ranked-final .rank-self b{font-size:11px;padding:2px 8px;margin-top:4px}
    .ranked-final .rank-self+.rank-badge{
        border-right:0;
        grid-column:2;
        grid-row:1;
    }
    .ranked-final .rank-badge img{width:52px;height:52px}
    .ranked-final .rank-badge b{font-size:16px}
    .ranked-final .rank-badge:last-child{
        grid-column:3;
        grid-row:1;
    }
    .ranked-final .rank-badge:last-child img{width:46px;height:46px}
    .ranked-final .rank-badge:last-child b{font-size:14px}
    .ranked-final .rank-badge:last-child::before{
        display:block;
        left:-8px;
        top:34%;
        font-size:22px;
    }
    .ranked-final .rank-meter{
        grid-column:1/-1;
        grid-row:2;
        padding:10px 0 0;
        border-top:1px solid #daaacc38;
    }
    .ranked-final .rank-band small{font-size:11.5px}
    .ranked-final .rank-meter strong{
        font-size:24px;
        margin:2px 0 6px;
    }
    .ranked-final .rank-track{height:22px;display:flex;align-items:center;justify-content:center}
    .ranked-final .rank-track b{font-size:12px}
    .ranked-final .final-coins{
        order:3;
        width:100%;
        margin:10px 0 0;
        padding:10px 14px;
        border-radius:13px;
        justify-content:space-between;
    }
    .ranked-final .final-coins img{width:24px;height:24px}
    .ranked-final .final-coins .coin-amount{font-size:20px}
    .ranked-final .result-scores{
        order:4;
        margin:12px 0 0;
        display:flex;
        flex-direction:column;
        gap:8px;
    }
    .ranked-final .result-player{
        display:grid;
        grid-template-columns:24px 38px 1fr auto;
        grid-template-rows:auto auto;
        align-items:center;
        gap:1px 10px;
        padding:8px 12px;
        border-radius:12px;
        font-size:13px;
    }
    .ranked-final .result-player::before{
        position:static;
        grid-column:1;
        grid-row:1/span 2;
        text-align:center;
        font-size:20px;
    }
    .ranked-final .result-player img{
        grid-column:2;
        grid-row:1/span 2;
        width:38px;
        height:38px;
    }
    .ranked-final .result-player-name{
        grid-column:3;
        grid-row:1/span 2;
        font-weight:700;
        font-size:14px;
    }
    .ranked-final .result-player b{
        grid-column:4;
        grid-row:1;
        text-align:right;
        font-size:14.5px;
    }
    .ranked-final .result-player small{
        grid-column:4;
        grid-row:2;
        text-align:right;
        font-size:11.5px;
        font-weight:700;
    }
    .ranked-final .result-next{
        order:5;
        margin:auto auto 0;
        margin-top:14px;
        width:82%;
        max-width:320px;
        padding:11px 0;
        font-size:15.5px;
    }

    /* Portrait Draw / Casual Final Settlement Dialog */
    #settlement:not(.win-settlement):not(.ranked-final){
        width:94vw;
        max-width:94vw;
        padding:16px 14px;
    }
    #settlement:not(.win-settlement):not(.ranked-final) .result-scores{
        grid-template-columns:1fr 1fr;
        gap:8px;
    }
    #settlement:not(.win-settlement):not(.ranked-final) .result-next{
        width:72%;
        border-radius:999px;
        padding:10px 0;
    }
}

/* Sakura glowing loading overlay when transitioning from settlement to next hand. */
#continue-loading:not([hidden]){
    position:fixed;
    inset:0;
    z-index:40;
    display:grid;
    place-items:center;
    padding:16px;
    background:#0a0714bd;
    backdrop-filter:blur(6px);
    -webkit-backdrop-filter:blur(6px);
}
.continue-loading-card{
    position:relative;
    isolation:isolate;
    overflow:hidden;
    width:min(440px,88vw);
    min-height:190px;
    padding:32px 24px;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:16px;
    text-align:center;
    border:2px solid #c385f6;
    border-radius:clamp(16px,2vw,26px);
    background:radial-gradient(ellipse at 50% 85%,#44285f,#281d3d 80%);
    box-shadow:0 0 18px #af60e96e,0 18px 64px #090514aa;
}
.continue-loading-card::before,
.continue-loading-card::after{
    content:'';
    position:absolute;
    z-index:-1;
    pointer-events:none;
    background:url('/assets/profile-petals.webp') left bottom/cover;
}
.continue-loading-card::before{
    top:0;left:0;width:34%;height:46%;
    transform:scaleY(-1);
    mask-image:linear-gradient(135deg,#000 20%,transparent 85%);
    opacity:.9;
}
.continue-loading-card::after{
    bottom:0;right:0;width:30%;height:40%;
    transform:scaleX(-1);
    mask-image:linear-gradient(130deg,transparent 6%,#000 85%);
}
.continue-loading-orb{
    position:relative;
    width:62px;height:62px;
    display:grid;place-items:center;
    border-radius:50%;
    background:radial-gradient(circle,#4a2c6b,#241738);
    border:2px solid #c992ff88;
    box-shadow:0 0 22px #a45df066;
}
.continue-loading-orb::before{
    content:'';
    position:absolute;
    inset:-6px;
    border-radius:50%;
    border:2px solid transparent;
    border-top-color:#ffe197;
    border-right-color:#c98eff;
    animation:continue-spin 1s linear infinite;
}
.continue-loading-orb span{
    font:800 28px/1 SimSun,serif;
    color:#ffe6b0;
    text-shadow:0 0 10px #f0b15a99;
}
.continue-loading-card h2{
    margin:0;
    font-size:clamp(20px,5vw,28px);
    line-height:1.25;
    background:linear-gradient(105deg,#f4e6ff 40%,#ffe197 60%);
    color:transparent;
    background-clip:text;
}
@keyframes continue-spin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion:reduce){.continue-loading-orb::before{animation:none}}
