:root {
    --app-viewport-width: 100vw;
    --app-viewport-height: 100dvh;
    --stage-width: 720px;
    --stage-height: 1280px;
    --stage-scale: 1;
    --stage-x: 0px;
    --stage-y: 0px;
    --screen-top: calc((var(--stage-height) - 1280px) / 2);
    --screen-left: calc((var(--stage-width) - 720px) / 2);
    --player: #3a78bf;
    --player-light: #8bc4ff;
    --enemy: #bc4747;
    --enemy-light: #ff9891;
    --gold: #f0cc69;
    --gold-button-art: url("../assets/ui/sylvan-line-start-gold-button-v01.webp");
    --green-button-art: url("../assets/ui/sylvan-line-start-green-button-v01.webp");
    --cream: #fff3c7;
    --success: #5ebc65;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-user-select: none;
    user-select: none;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    position: fixed;
    inset: 0;
    width: var(--app-viewport-width);
    height: var(--app-viewport-height);
    overflow: hidden;
    touch-action: none;
    color: var(--cream);
    background: #10271d;
    font-family: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
    -webkit-font-smoothing: none;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font: inherit;
}

#app-shell {
    position: relative;
    width: var(--app-viewport-width);
    height: var(--app-viewport-height);
    overflow: hidden;
    background: #10271d;
}

#game-stage {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--stage-width);
    height: var(--stage-height);
    overflow: hidden;
    transform: translate3d(var(--stage-x), var(--stage-y), 0) scale(var(--stage-scale));
    transform-origin: 0 0;
}

#game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: var(--stage-width);
    height: var(--stage-height);
    overflow: hidden;
    background: #102b2b;
    image-rendering: pixelated;
}

#scene-canvas {
    position: absolute;
    z-index: 0;
    left: 0;
    top: 0;
    display: block;
    width: var(--stage-width);
    height: var(--stage-height);
    pointer-events: none;
    image-rendering: auto;
}

#game-container :is(#settings-button, #camera-toggle, #match-logo, #player-bar, #card-zone, #info-panel, #game-area) {
    transition: opacity 0.6s ease-out, visibility 0s;
}

#game-container.is-entering :is(#settings-button, #camera-toggle, #match-logo, #player-bar, #card-zone, #info-panel, #game-area) {
    visibility: hidden;
    opacity: 0;
    transition: none;
}

.overlay-screen {
    position: absolute;
    z-index: 500;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--cream);
    background: rgba(8, 27, 19, 0.76);
}

.overlay-screen[hidden] {
    display: none;
}

#start-screen {
    background: #0c2c21 url("../assets/backgrounds/sylvan-line-start-sanctuary-v01.webp") center / cover no-repeat;
}

.icon-button {
    position: absolute;
    z-index: 610;
    top: 12px;
    display: grid;
    width: 86px;
    height: 86px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: var(--gold);
    background: transparent;
    cursor: pointer;
    filter: drop-shadow(0 3px 2px #061209) drop-shadow(0 0 8px #0612099e);
}

.icon-button[hidden] {
    display: none;
}

.icon-button svg {
    width: 48px;
    height: 48px;
}

.icon-button:active {
    transform: translateY(2px);
}

#settings-button {
    right: 20px;
}

.start-heading {
    position: absolute;
    inset: 60px 34px auto;
    display: grid;
    justify-items: center;
    gap: 13px;
    text-align: center;
}

.start-heading h1 img {
    display: block;
    width: 600px;
    height: 300px;
    filter: drop-shadow(0 8px 10px #071a12b3);
}

.start-rule {
    position: relative;
    width: 454px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #edbd5a 14% 47.5%, transparent 47.5% 52.5%, #edbd5a 52.5% 86%, transparent);
    box-shadow: 0 2px 4px #071a12;
}

.start-rule::after {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 13px;
    height: 13px;
    content: "";
    background: linear-gradient(135deg, #ffe694, #b77025);
    box-shadow: 2px 2px 3px #071a12;
    transform: translate(-50%, -50%) rotate(45deg);
}

.start-heading p {
    color: var(--cream);
    font: 700 39px/1.15 Georgia, serif;
    text-shadow: 0 3px 5px #071a12;
}

#streak-panel {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: grid;
    width: 560px;
    justify-items: center;
    text-align: center;
    white-space: nowrap;
}

#streak-panel[hidden] {
    display: none;
}

#streak-title {
    display: flex;
    width: 100%;
    height: 64px;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--gold);
    font: 700 38px/1 Georgia, serif;
    letter-spacing: 2px;
    text-transform: uppercase;
    background: linear-gradient(90deg, transparent, #071a12a6 22% 78%, transparent);
    text-shadow: 0 -1px #fff2af, 0 3px #9b591c, 0 5px 8px #071a12;
}

#streak-title::before,
#streak-title::after {
    width: 70px;
    height: 2px;
    content: "";
    background: #edbd5a;
    box-shadow: 0 2px 4px #071a12;
}

#streak-title::before {
    background: linear-gradient(90deg, transparent, #edbd5a);
}

#streak-title::after {
    background: linear-gradient(90deg, #edbd5a, transparent);
}

#streak-count {
    color: #ffce56;
    font-family: "Times New Roman", serif;
    font-size: 60px;
    letter-spacing: 0;
}

#streak-rows {
    display: grid;
    width: 100%;
    list-style: none;
}

#streak-rows li {
    position: relative;
    display: flex;
    height: 70px;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--cream);
    background: linear-gradient(90deg, transparent, #071a12a6 22% 78%, transparent);
    font: 700 25px/1 Georgia, serif;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-shadow: 0 2px 4px #071a12;
}

#streak-rows b {
    color: #ffce56;
    font-size: 29px;
    text-shadow: 0 -1px #fff2af, 0 2px #9b591c, 0 4px 6px #071a12;
}

#streak-rows .start-rule {
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
}

.start-actions {
    position: absolute;
    bottom: 160px;
    display: grid;
    width: 386px;
}

#start-enter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 179px;
    cursor: pointer;
    border: 0;
    color: var(--cream);
    background: none;
    font: 700 37px/44px Georgia, serif;
    letter-spacing: 2px;
    text-shadow: 0 3px 5px #071a12, 0 0 18px #071a12;
    animation: enter-prompt 1.6s ease-in-out infinite;
}

#start-enter:focus-visible {
    outline: 3px solid var(--cream);
    outline-offset: -12px;
}

#start-enter[hidden],
#start-entry[hidden] {
    display: none;
}

@keyframes enter-prompt {
    50% { opacity: 0.45; }
}

.start-btn {
    display: grid;
    height: 82px;
    place-items: center;
    cursor: pointer;
    border: 0;
    border-radius: 12px;
    color: #10291d;
    background: var(--gold-button-art) center / 100% 74px no-repeat;
    filter: drop-shadow(0 5px 3px #071a12ad);
    font: 700 37px/1 Georgia, serif;
    letter-spacing: 0.5px;
}

.btn-green {
    color: var(--cream);
    background-image: var(--green-button-art);
    text-shadow: 0 2px 2px #092317;
}

.start-btn:focus-visible,
.action-btn:focus-visible,
.icon-button:focus-visible {
    outline: 3px solid var(--cream);
    outline-offset: 2px;
}

.start-btn:active {
    transform: translateY(3px);
    filter: drop-shadow(0 2px 2px #071a12ad);
}

#match-screen {
    z-index: 600;
    background:
        linear-gradient(#06140dd9 0, #06140d8c 26%, transparent 42%, transparent 66%, #06140d80 100%),
        #10271d url("../assets/backgrounds/sylvan-line-woodland-clearing-v03.webp") center / cover no-repeat;
    image-rendering: auto;
}

#match-screen > *,
.match-plaque {
    position: absolute;
}

#match-heading,
#match-countdown,
#match-ready,
#match-vs {
    left: 0;
    right: 0;
    font-family: Georgia, serif;
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
}

#match-heading {
    top: calc(var(--screen-top) + 112px);
    color: #ffd76a;
    font-size: 50px;
    line-height: 56px;
    letter-spacing: 3px;
    text-shadow: 3px 3px 0 #5a3410, 0 8px 18px #000c;
}

#match-message {
    top: calc(var(--screen-top) + 186px);
    left: calc(var(--screen-left) + 40px);
    right: calc(var(--screen-left) + 40px);
    font: 700 30px/36px Georgia, serif;
    text-align: center;
    text-shadow: 0 3px 5px #071a12;
    white-space: pre-line;
}

#match-screen[data-state="error"] #match-message {
    color: var(--enemy-light);
}

#match-countdown,
#match-ready {
    color: #fff3c4;
    text-shadow: 6px 6px 0 #5a3410, 0 0 36px #ffcf5ab3;
}

#match-countdown {
    top: calc(var(--screen-top) + 285px);
    font-size: 170px;
    line-height: 170px;
}

#match-ready {
    top: calc(var(--screen-top) + 332px);
    font-size: 76px;
    line-height: 76px;
    letter-spacing: 4px;
    animation: explode-vs 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

#match-screen:not([data-state="searching"]) #match-countdown,
#match-screen:not([data-state="found"]) #match-ready,
#match-screen[data-state="found"] #cancel-match-btn {
    display: none;
}

.match-seat {
    top: calc(var(--screen-top) + 448px);
    width: 384px;
    height: 384px;
}

.player-seat {
    left: calc(var(--screen-left) - 7px);
    animation: fly-left 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.rival-seat {
    left: calc(var(--screen-left) + 343px);
    animation: fly-right 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.match-seat .piece-sprite {
    width: 384px;
    height: 384px;
    filter: drop-shadow(0 8px 4px #04180e99);
}

.rival-seat .piece-sprite {
    transform: scaleX(-1);
}

#match-screen:not([data-state="found"]) .rival-seat .piece-sprite {
    filter: brightness(0) opacity(0.78);
}

#match-screen[data-state="found"] .rival-seat .piece-sprite {
    animation: knight-idle 1s steps(7) infinite, rival-reveal 0.5s ease-out;
}

.match-plaque {
    top: 318px;
    left: 47px;
    width: 290px;
    height: 48px;
    padding: 0 18px;
    overflow: hidden;
    color: #f6e7b0;
    background: url("../assets/ui/sylvan-line-hud-deck-plaque-v01.webp") center / 100% 100% no-repeat;
    font-size: 26px;
    font-weight: 700;
    line-height: 48px;
    letter-spacing: 1px;
    text-align: center;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

#match-screen[data-state="found"] #match-rival-name {
    animation: explode-vs 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

#match-vs {
    top: calc(var(--screen-top) + 580px);
    color: var(--gold);
    font-size: 110px;
    font-style: italic;
    line-height: 120px;
    text-shadow: 6px 6px 0 #723a32, 0 12px 24px rgba(0, 0, 0, 0.75);
    animation: explode-vs 0.6s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

#cancel-match-btn {
    bottom: 34px;
    left: calc(50% - 193px);
    width: 386px;
}

@keyframes rival-reveal {
    from { filter: brightness(0) opacity(0.78); }
    40% { filter: brightness(3) drop-shadow(0 0 24px #fff3c4); }
}

@keyframes fly-left {
    from { transform: translateX(-280px); opacity: 0; }
}

@keyframes fly-right {
    from { transform: translateX(280px); opacity: 0; }
}

@keyframes explode-vs {
    from { transform: scale(0); opacity: 0; }
    55% { transform: scale(1.22); }
}

#match-logo {
    position: absolute;
    z-index: 5;
    top: calc(var(--screen-top) + 108px);
    left: 0;
    right: 0;
    display: none;
    color: #ffce56;
    font: 700 42px/1 Georgia, serif;
    letter-spacing: 3px;
    text-align: center;
    text-shadow: 0 -1px #fff2af, 0 2px #9b591c, 0 4px #4e301b, 0 6px 12px #071a12, 0 0 24px #ffce5666;
    pointer-events: none;
}

#game-container.in-match #match-logo { display: block; }

#card-zone {
    position: absolute;
    z-index: 5;
    top: calc(var(--screen-top) + 162px);
    right: calc(var(--screen-left) + 38px);
    left: calc(var(--screen-left) + 38px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1fr);
    align-items: start;
}

.deck-area {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    perspective: 1000px;
}

.deck-label {
    width: 184px;
    height: 36px;
    padding: 0 12px;
    overflow: hidden;
    background: url("../assets/ui/sylvan-line-hud-deck-plaque-v01.webp") center / 100% 100% no-repeat;
    font: 700 19px/36px Georgia, serif;
    text-align: center;
    text-overflow: ellipsis;
    text-shadow: 0 2px 4px #111714;
    text-transform: uppercase;
    white-space: nowrap;
}

.player-label { color: var(--player-light); }
.rival-label { color: var(--enemy-light); }

.card-container {
    position: relative;
    flex: none;
    width: 160px;
    height: 200px;
    transform: translateZ(0);
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.deck-area.is-active {
    --card-glow: #ffd96d;
}

.card-container.is-flipped {
    transform: translateZ(0) rotateY(180deg);
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-front {
    transform: rotateY(180deg);
}

.card-container[data-piece="tower"] {
    --card-background: url("../assets/ui/sylvan-line-tower-card-background-v01.webp");
}

.card-container[data-piece="knight"] {
    --card-background: url("../assets/ui/sylvan-line-knight-card-background-v01.webp");
}

.card-container[data-piece="mage"] {
    --card-background: url("../assets/ui/sylvan-line-mage-card-background-v01.webp");
}

.card-back::before,
.card-front::before,
.card-front::after {
    position: absolute;
    content: "";
    pointer-events: none;
}

.card-front::before {
    inset: 15% 4.5% 3.5%;
    border-radius: 0 0 9% 9%;
    background: var(--card-background, none) center 82% / cover no-repeat;
}

.card-back::before,
.card-front::after {
    inset: -2.4% -4% -3.8%;
    background-position: center;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    filter: drop-shadow(0 0 2px var(--card-glow, transparent)) drop-shadow(0 0 6px var(--card-glow, transparent)) drop-shadow(0 5px 5px #03120ec2);
}

.card-back::before {
    background-image: url("../assets/ui/sylvan-line-draw-card-back-v01.webp");
}

.card-front::after {
    background-image: url("../assets/ui/sylvan-line-draw-card-frame-v01.webp");
}

.res-icon {
    position: absolute;
    inset: 0;
    overflow: clip;
}

.res-name {
    position: absolute;
    z-index: 1;
    top: 4.4%;
    right: 8%;
    left: 8%;
    display: grid;
    height: 12.3%;
    place-items: center;
    color: #fff1cb;
    font: 700 24px/1 Georgia, serif;
    letter-spacing: 0.4px;
    text-shadow: 0 2px #041a10;
    text-transform: uppercase;
}

.res-dir {
    position: absolute;
    z-index: 1;
    right: 10%;
    bottom: 8.5%;
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border: 2px solid #e3bf77;
    border-radius: 8px;
    color: #fff0bf;
    background: #10261f;
    font: 800 20px/1 system-ui, sans-serif;
}

.res-dir:empty { display: none; }

#turn-core {
    display: flex;
    height: 238px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#announcer-text {
    width: 100%;
    padding-bottom: 12px;
    border-bottom: 2px solid #d5b66b;
    color: var(--cream);
    font: 700 22px/1.2 Georgia, serif;
    text-align: center;
    text-shadow: 0 2px 2px #0c2719, 0 0 10px #0c2719, 0 0 16px #0c2719;
    text-transform: uppercase;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.25s;
}

#announcer-text.show { opacity: 1; }

#timer-box {
    display: flex;
    height: 76px;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s;
}

#timer-box.show { opacity: 1; }

#timer-num {
    min-width: 112px;
    color: var(--gold);
    font: 700 76px/1 Georgia, serif;
    font-variant-numeric: lining-nums tabular-nums;
    text-align: center;
    text-shadow: 0 4px 3px #0c2719, 0 0 12px #143322, 0 0 22px #143322;
}

#timer-num.timer-danger {
    color: #ff9487;
    transform: scale(1.08);
}

#game-area {
    position: absolute;
    z-index: 4;
    inset: 0;
    pointer-events: none;
}

#board {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.board-cell {
    position: absolute;
    border: 0;
    outline: none;
    background: transparent;
    cursor: pointer;
    pointer-events: auto;
}

.board-cell:active {
    background: #f8db9a44;
}

#render-notice {
    position: absolute;
    z-index: 600;
    top: 114px;
    left: calc(var(--screen-left) + 54px);
    right: calc(var(--screen-left) + 54px);
    padding: 18px 26px;
    border: 2px solid #c59e61;
    background: #102e29;
    color: #fff1cb;
    font: 700 24px/1.4 system-ui, sans-serif;
    text-align: center;
    pointer-events: none;
}

.piece-sprite {
    display: block;
    flex: none;
    background-position: 0 0;
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

.sprite-tower {
    background-position: center;
    background-size: contain;
}

.sprite-tower.player { background-image: url("../assets/characters/sylvan-line-player-tower-v01.png"); }
.sprite-tower.rival { background-image: url("../assets/characters/sylvan-line-enemy-tower-v01.png"); }

.sprite-knight {
    background-size: 800% 100%;
    animation: knight-idle 1s steps(7) infinite;
}

.sprite-knight.player { background-image: url("../assets/characters/sylvan-line-player-knight-idle-v01.png"); }
.sprite-knight.rival { background-image: url("../assets/characters/sylvan-line-enemy-knight-idle-v01.png"); }

.sprite-mage {
    background-size: 600% 100%;
    animation: mage-idle 1.1s steps(5) infinite;
}

.sprite-mage.player { background-image: url("../assets/characters/sylvan-line-player-mage-idle-v01.png"); }
.sprite-mage.rival { background-image: url("../assets/characters/sylvan-line-enemy-mage-idle-v01.png"); }

@keyframes knight-idle {
    to { background-position: 100% 0; }
}

@keyframes mage-idle {
    to { background-position: 100% 0; }
}

.res-icon .piece-sprite {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 3px 2px #0a10235c);
}

.res-icon :is(.sprite-knight, .sprite-mage).rival {
    transform: translate(-50%, -50%) scaleX(-1);
}

.res-icon .sprite-tower {
    width: 90px;
    height: 180px;
}

.res-icon .sprite-knight {
    width: 260px;
    height: 260px;
}

.res-icon .sprite-mage {
    width: 333px;
    height: 333px;
}

#skill-effects {
    position: absolute;
    z-index: 20;
    inset: 0;
    pointer-events: none;
}

.skill-dialogue {
    position: absolute;
    display: grid;
    width: 198px;
    aspect-ratio: 5 / 2;
    place-items: center;
    isolation: isolate;
    padding: 0 18px 5px;
    color: #3c2819;
    font: 700 22px/1.08 Georgia, serif;
    text-align: center;
    transform: translateY(-95.5%);
}

.skill-dialogue::before {
    position: absolute;
    z-index: -1;
    inset: 0;
    background: url("../assets/ui/sylvan-line-dialogue-vellum-02-v01.webp") center / contain no-repeat;
    filter: drop-shadow(0 2px 2px #17261584);
    opacity: 0.85;
    content: "";
}

.skill-dialogue.is-mirrored::before {
    transform: scaleX(-1);
}

.skill-dialogue span {
    max-width: 150px;
}

#game-container.in-match::before,
#game-container.in-match::after {
    position: absolute;
    z-index: 3;
    right: 0;
    left: 0;
    content: "";
    pointer-events: none;
}

#game-container.in-match::before {
    top: 0;
    height: 150px;
    background: linear-gradient(#06120cd9, transparent);
}

#game-container.in-match::after {
    bottom: 0;
    height: 280px;
    background: linear-gradient(transparent, #06120cb3 55%, #06120ce6);
}

#info-panel {
    position: absolute;
    z-index: 4;
    left: calc(var(--screen-left) + 30px);
    right: calc(var(--screen-left) + 30px);
    bottom: 46px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
    color: var(--cream);
    text-shadow: 0 2px 3px #061209, 0 0 8px #061209;
}

.info-item {
    display: grid;
    gap: 4px;
    text-align: center;
}

.info-portrait {
    position: relative;
    height: 88px;
    overflow: clip;
}

.info-portrait .piece-sprite {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    animation: none;
    filter: drop-shadow(0 3px 2px #04180e);
}

.info-portrait .sprite-tower {
    bottom: -12px;
    width: 60px;
    height: 120px;
}

.info-portrait .sprite-knight {
    bottom: -53px;
    width: 185px;
    height: 185px;
}

.info-portrait .sprite-mage {
    bottom: -70px;
    width: 230px;
    height: 230px;
}

.info-item b {
    font: 700 26px/1.1 Georgia, serif;
    text-transform: uppercase;
}

.info-item b span { color: var(--gold); }

.info-item small {
    font: 600 20px/1.15 system-ui, sans-serif;
}

#match-outcome:not([hidden]) {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(8, 22, 17, 0.52);
}

#match-outcome[data-outcome="victory"] {
    --outcome-icon: url("../assets/ui/sylvan-line-result-victory-icon-v01.webp");
    --outcome-title: url("../assets/ui/sylvan-line-result-victory-title-v01.webp");
}

#match-outcome[data-outcome="defeat"] {
    --outcome-icon: url("../assets/ui/sylvan-line-result-defeat-icon-v01.webp");
    --outcome-title: url("../assets/ui/sylvan-line-result-defeat-title-v01.webp");
}

#match-outcome[data-outcome="draw"] {
    --outcome-icon: url("../assets/ui/sylvan-line-result-draw-icon-v01.webp");
    --outcome-title: url("../assets/ui/sylvan-line-result-draw-title-v01.webp");
}

.match-outcome-content {
    display: grid;
    width: 600px;
    justify-items: center;
    gap: 14px;
    text-align: center;
}

.match-outcome-icon {
    width: 258px;
    height: 184px;
    background: var(--outcome-icon) center / contain no-repeat;
    filter: drop-shadow(0 7px 6px #0b1c15);
}

#match-result {
    width: 100%;
    height: 94px;
    background: var(--outcome-title) center / contain no-repeat;
    filter: drop-shadow(0 6px 6px #0b1c15);
    outline: 0;
}

#match-result-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}

.match-actions {
    display: flex;
    width: 530px;
    gap: 20px;
    margin-top: 10px;
}

#match-result-detail {
    color: #fff3d4;
    font: 700 27px/1.25 system-ui, sans-serif;
    text-shadow: 0 2px 3px #0b1c15, 0 0 10px #0b1c15;
}

#match-result-reward {
    color: var(--gold);
    font: 700 27px/1.25 Georgia, serif;
    font-variant-numeric: lining-nums tabular-nums;
    text-shadow: 0 2px 3px #0b1c15, 0 0 10px #0b1c15;
}

#match-result-reward:empty {
    display: none;
}

.action-btn {
    display: grid;
    flex: 1;
    min-width: 0;
    height: 82px;
    place-items: center;
    cursor: pointer;
    border: 0;
    border-radius: 8px;
    color: var(--cream);
    background: var(--green-button-art) center / 100% 65px no-repeat;
    font: 700 27px/1 Georgia, serif;
    text-transform: uppercase;
}

.replay-btn {
    color: #10291d;
    background-image: var(--gold-button-art);
}

.action-btn:active { transform: translateY(3px); }
.action-btn:focus-visible { outline: 3px solid #fff3d4; }

#match-notice {
    position: absolute;
    z-index: 21;
    bottom: 204px;
    left: 50%;
    width: max-content;
    max-width: calc(100% - 36px);
    padding: 6px 18px;
    overflow: hidden;
    border-radius: 7px;
    color: var(--gold);
    background: rgba(12, 32, 22, 0.94);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.38);
    font: 700 21px/1.2 system-ui, sans-serif;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
    transform: translateX(-50%);
    transition: opacity 0.25s;
}

#match-opening {
    position: absolute;
    z-index: 21;
    top: 50%;
    left: 50%;
    width: 602px;
    height: 122px;
    color: transparent;
    background: url("../assets/ui/sylvan-line-game-start-title-v01.webp") center / contain no-repeat;
    filter: drop-shadow(0 6px 6px #0b1c15);
    pointer-events: none;
    transform: translate(-50%, -50%);
    animation: match-opening-word var(--opening-duration, 2s) ease-out both;
}

@keyframes match-opening-word {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(1.45); }
    16% { opacity: 1; transform: translate(-50%, -50%) scale(0.94); }
    26% { transform: translate(-50%, -50%) scale(1); }
    78% { opacity: 1; transform: translate(-50%, -50%) scale(1.02); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.08); }
}

#match-notice:empty {
    opacity: 0;
}

#match-notice.announcement-only {
    clip-path: inset(50%);
}

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

#camera-toggle {
    right: 114px;
    display: none;
    z-index: 21;
}

#game-container.in-match #camera-toggle { display: grid; }

#player-bar {
    position: absolute;
    z-index: 21;
    left: 24px;
    right: 214px;
    top: 12px;
    display: none;
    height: 86px;
    align-items: center;
    gap: 12px;
    color: var(--cream);
    text-shadow: 0 2px 3px #061209, 0 0 8px #061209;
}

#game-container.in-match #player-bar { display: flex; }

.player-avatar {
    position: relative;
    flex: none;
    width: 76px;
    height: 76px;
    overflow: hidden;
    border: 3px solid var(--gold);
    border-radius: 50%;
    background: radial-gradient(circle at 50% 35%, #7fb4ea, #2d5f97 70%);
    box-shadow: 0 3px 8px #061209;
}

.player-avatar .piece-sprite {
    position: absolute;
    left: 50%;
    bottom: -44px;
    width: 150px;
    height: 150px;
    animation: none;
    transform: translateX(-50%);
}

#player-name {
    min-width: 0;
    overflow: hidden;
    font: 700 28px/1 system-ui, sans-serif;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.coin-icon {
    flex: none;
    width: 30px;
    height: 30px;
    margin-left: 6px;
    filter: drop-shadow(0 2px 2px #061209);
}

#player-balance {
    flex: none;
    color: var(--gold);
    font: 700 30px/1 Georgia, serif;
    font-variant-numeric: lining-nums tabular-nums;
}

#settings-dialog:not([hidden]) {
    position: absolute;
    z-index: 700;
    inset: 0;
    display: grid;
    place-items: center;
    background: #050e0ab3;
}

.settings-card {
    display: grid;
    width: 560px;
    gap: 18px;
    padding: 26px 30px 32px;
    border-radius: 24px;
    color: var(--cream);
    background: linear-gradient(#173226f5, #0d2018f5);
    box-shadow: 0 0 0 1px #f0cc6955, 0 18px 40px #000000b3;
}

.settings-head {
    display: grid;
    grid-template-columns: 56px 1fr 56px;
    align-items: center;
}

#settings-title {
    grid-column: 2;
    color: var(--gold);
    font: 700 40px/1 Georgia, serif;
    text-align: center;
}

.settings-round {
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    color: var(--cream);
    background: #ffffff14;
    cursor: pointer;
    font: 700 28px/1 system-ui, sans-serif;
}

#settings-back { grid-column: 1; grid-row: 1; }
#settings-close { grid-column: 3; grid-row: 1; }

.settings-view:not([hidden]) {
    display: grid;
    gap: 14px;
}

.settings-row {
    display: flex;
    height: 82px;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px;
    border: 0;
    border-radius: 16px;
    color: var(--cream);
    background: #ffffff0f;
    cursor: pointer;
    font: 700 30px/1 Georgia, serif;
}

.settings-row[hidden] { display: none; }

.switch {
    position: relative;
    width: 84px;
    height: 44px;
    border-radius: 22px;
    background: #ffffff2e;
    transition: background 0.2s;
}

.switch::after {
    position: absolute;
    top: 5px;
    left: 5px;
    width: 34px;
    height: 34px;
    content: "";
    border-radius: 50%;
    background: var(--cream);
    transition: transform 0.2s;
}

[aria-checked="true"] .switch { background: var(--success); }
[aria-checked="true"] .switch::after { transform: translateX(40px); }

.settings-arrow {
    color: var(--gold);
    font-size: 44px;
}

.rules-list {
    display: grid;
    gap: 14px;
    margin: 0;
    padding: 0 4px 0 28px;
    font: 500 24px/1.4 system-ui, sans-serif;
}

.rules-list b { color: var(--gold); }

.leave-text {
    margin: 10px 0;
    font: 700 30px/1.35 system-ui, sans-serif;
    text-align: center;
}

.leave-actions {
    display: flex;
    gap: 20px;
}

#nexus-message:not([hidden]) {
    position: absolute;
    z-index: 800;
    inset: 0;
    display: grid;
    place-items: center;
    background: #050e0ab3;
}

#nexus-message-text {
    margin: 10px 0 0;
    font: 700 28px/1.4 system-ui, sans-serif;
    text-align: center;
}

#nexus-message-code {
    margin: 0 0 6px;
    color: #fff3d4b3;
    font: 600 22px/1 system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

#nexus-message .action-btn {
    text-decoration: none;
    text-transform: none;
}

#nexus-message .action-btn[hidden] { display: none; }

.settings-round:focus-visible,
.settings-row:focus-visible {
    outline: 3px solid var(--cream);
    outline-offset: 2px;
}

#round-strip:not([hidden]) {
    position: absolute;
    z-index: 21;
    right: 0;
    bottom: 10px;
    left: 0;
    color: #fff3c7cc;
    font: 600 18px/1 system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
    text-align: center;
    text-shadow: 0 1px 2px #061209, 0 0 6px #061209;
    pointer-events: none;
}

#game-container:not(.in-match) #round-strip { display: none; }

:root.landscape {
    --side-column: calc((var(--stage-width) - 670px) / 2);
    --painting-edge: calc((var(--stage-width) - var(--painting-width) * var(--painting-scale, 1)) / 2);
    --lower-center: calc((var(--stage-height) + 335px) / 2);
    --screen-top: calc((var(--stage-height) - 720px) / 2);
    --screen-left: 0px;
}

:root.landscape .start-heading {
    inset: calc(var(--screen-top) + 20px) 0 auto;
}

:root.landscape #streak-panel {
    top: calc(var(--screen-top) + 396px);
    left: calc(50% - 520px);
    width: 1040px;
    transform: none;
}

:root.landscape #streak-rows {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    background: linear-gradient(90deg, transparent, #071a12a6 12% 88%, transparent);
}

:root.landscape #streak-rows li {
    height: 84px;
    flex-direction: column;
    gap: 6px;
    background: none;
}

:root.landscape #streak-rows .start-rule {
    display: none;
}

:root.landscape .start-actions {
    top: calc(var(--screen-top) + 572px);
    bottom: auto;
    left: calc(50% - 193px);
}

:root.landscape #start-enter {
    align-items: flex-start;
    padding: calc(var(--screen-top) + 591px) 0 0;
}

:root.landscape #match-heading { top: calc(var(--screen-top) + 30px); }
:root.landscape #match-message { top: calc(var(--screen-top) + 92px); }
:root.landscape #match-countdown { top: calc(var(--screen-top) + 166px); }
:root.landscape #match-ready { top: calc(var(--screen-top) + 213px); }
:root.landscape #match-vs { top: calc(var(--screen-top) + 336px); }
:root.landscape .match-seat { top: calc(var(--screen-top) + 204px); }
:root.landscape .player-seat { left: calc(50% - 522px); }
:root.landscape .rival-seat { left: calc(50% + 138px); }

:root.landscape #match-logo { top: 34px; }
:root.landscape #player-bar { right: auto; }

:root.landscape #card-zone {
    inset: 0;
    display: block;
    pointer-events: none;
}

:root.landscape .deck-area,
:root.landscape #turn-core,
:root.landscape #info-panel {
    position: absolute;
    width: var(--side-column);
}

:root.landscape .deck-area { top: 118px; }
:root.landscape #player-deck { left: 0; }
:root.landscape #rival-deck { right: 0; }

:root.landscape #turn-core {
    top: calc(var(--lower-center) - 64px);
    right: 0;
    height: 128px;
}

:root.landscape #announcer-text {
    width: 200px;
}

:root.landscape #info-panel {
    top: calc(var(--lower-center) - 138px);
    right: auto;
    bottom: auto;
    left: 0;
    grid-template-columns: max-content;
    justify-content: center;
    gap: 8px;
}

:root.landscape .info-item {
    grid-template-columns: 100px max-content;
    grid-template-rows: 1fr 1fr;
    column-gap: 10px;
    row-gap: 4px;
    text-align: left;
}

:root.landscape .info-portrait {
    grid-row: 1 / 3;
}

:root.landscape .info-item b { align-self: end; }
:root.landscape .info-item small { align-self: start; }

:root.landscape #game-container.in-match::after {
    top: 0;
    height: auto;
    background:
        linear-gradient(90deg, #000 var(--painting-edge), transparent calc(var(--painting-edge) + 160px), transparent calc(100% - var(--painting-edge) - 160px), #000 calc(100% - var(--painting-edge))),
        linear-gradient(90deg, #06120cc7, #06120c66 calc(var(--side-column) * 0.8), transparent var(--side-column), transparent calc(100% - var(--side-column)), #06120c66 calc(100% - var(--side-column) * 0.8), #06120cc7);
}

:root.landscape #match-notice { bottom: 46px; }

:root.landscape .settings-card:has(#settings-rules:not([hidden])) {
    width: 1080px;
}

:root.landscape .rules-list {
    display: block;
    columns: 2;
    column-gap: 44px;
}

:root.landscape .rules-list li {
    margin-bottom: 14px;
    break-inside: avoid;
}
