:root {
    color-scheme: dark;
    font-family: Arial, Helvetica, sans-serif;
    background: #000;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

html,
body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
}

body {
    position: fixed;
    inset: 0;
    background: #000;
}

button {
    min-height: 44px;
    border: 0;
    font: inherit;
    touch-action: manipulation;
    cursor: pointer;
}

button:focus-visible {
    outline: 2px solid #f1ca70;
    outline-offset: 3px;
}

#app {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--app-width, 100%);
    height: var(--app-height, 100dvh);
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow: hidden;
    isolation: isolate;
    transform: translate(var(--app-left, 0), var(--app-top, 0));
    background:
        radial-gradient(circle at 50% 38%, rgba(102, 82, 37, .22), transparent 35%),
        linear-gradient(#12100b, #020202 72%);
}

#app::before {
    position: absolute;
    z-index: 0;
    inset: 0;
    background: #000 url('assets/loading-background.png?build=20260902180943837') center top / auto 100% no-repeat;
    content: '';
}

#game-canvas,
#ui-canvas {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

#ui-canvas {
    display: none;
}

#login-flame-canvas {
    position: absolute;
    z-index: 2;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#login-flame-canvas[hidden] {
    display: none;
}

#performance-diagnostics {
    position: absolute;
    z-index: 8;
    top: 4px;
    left: 4px;
    max-width: calc(100% - 8px);
    max-height: calc(100% - 8px);
    margin: 0;
    padding: 4px 6px;
    overflow: hidden;
    color: #fff2a8;
    background: rgba(0, 0, 0, .76);
    font: 16px/1.45 monospace;
    white-space: pre;
    pointer-events: none;
}

#app:not([data-state="login"]):not([data-state="playing"]) #game-canvas,
#app:not([data-state="login"]):not([data-state="playing"]) #ui-canvas {
    visibility: hidden;
}

html[data-input="touch"] #game-canvas {
    cursor: none;
}

html[data-input="pen"] #game-canvas {
    cursor: none;
}

#loading {
    position: absolute;
    z-index: 3;
    top: auto;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: 50%;
    width: min(88vw, 520px);
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    text-shadow: 0 2px 3px #000;
}

#status {
    color: #eee7d7;
    font-size: clamp(14px, 3.5vw, 18px);
    line-height: 1.45;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

#error-details {
    width: min(88vw, 620px);
    max-height: min(30vh, 220px);
    margin: 10px auto 0;
    padding: 9px 11px;
    overflow: auto;
    border: 1px solid rgba(255, 177, 168, .42);
    border-radius: 6px;
    background: rgba(0, 0, 0, .68);
    color: #f4ddd8;
    font: 12px/1.4 monospace;
    text-align: left;
    text-shadow: none;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    pointer-events: auto;
    user-select: text;
    -webkit-user-select: text;
}

#cache-progress {
    width: min(86vw, 520px);
    margin: 8px auto 0;
}

.progress-track {
    position: relative;
    height: 32px;
    overflow: hidden;
    background: transparent;
}

#cache-progress-value {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 2%;
    background: rgba(0, 0, 0, .78);
    transition: left .12s linear;
}

#loading-progress-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    line-height: 32px;
    text-shadow: 1px 1px 0 #000;
    white-space: nowrap;
}

#cache-progress-text {
    min-height: 18px;
    margin-top: 4px;
    color: #d8d1c1;
    font-size: 13px;
}

#retry-button,
#copy-error-button {
    width: min(250px, 80vw);
    margin: 20px auto 0;
    pointer-events: auto;
}

#copy-error-button {
    margin-top: 8px;
}

#app[data-state="login"] #loading,
#app[data-state="playing"] #loading {
    display: none;
}

#app[data-state="playing"]::before,
#app[data-state="login"]::before {
    opacity: 0;
}

.game-login {
    position: absolute;
    z-index: 4;
    top: 50%;
    left: 50%;
    width: min(92vw, 360px);
    transform: translate(-50%, -50%);
}

.game-login form {
    display: flex;
    flex-direction: column;
    gap: 13px;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    padding: 22px;
    border: 1px solid rgba(216, 172, 73, .65);
    border-radius: 14px;
    color: #eee7d7;
    background: rgba(12, 11, 8, .92);
    box-shadow: 0 14px 44px rgba(0, 0, 0, .65);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.game-login h1 {
    margin: 0;
    color: #f1ca70;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 25px;
    text-align: center;
}

.game-login p {
    min-height: 20px;
    margin: 0;
    color: #d8d1c1;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    white-space: pre-line;
}

.game-login label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #e8ddc5;
    font-size: 13px;
    text-align: left;
}

.game-login [hidden] {
    display: none;
}

.game-login input {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid rgba(238, 231, 215, .35);
    border-radius: 8px;
    color: #fff;
    font: 16px Arial, Helvetica, sans-serif;
    background: rgba(0, 0, 0, .68);
}

.game-login input:focus {
    border-color: #d8ac49;
    outline: 2px solid rgba(216, 172, 73, .24);
}

.auth-mode-switch {
    min-height: 32px;
    padding: 3px 6px;
    border: 0;
    color: #f1ca70;
    font-size: 14px;
    background: transparent;
}

.auth-mode-switch span {
    text-decoration: underline;
}

.auth-mode-switch:hover,
.auth-mode-switch:focus-visible {
    color: #ffe29c;
}

.auth-mode-switch:disabled {
    color: rgba(241, 202, 112, .45);
}

#app[data-state="error"] #status {
    color: #ffb1a8;
}

#shell-controls {
    position: absolute;
    z-index: 5;
    top: calc(1px + env(safe-area-inset-top));
    right: calc(1px + env(safe-area-inset-right));
    display: flex;
    gap: 8px;
}

.shell-control {
    display: inline-flex;
    min-width: 48px;
    height: 48px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 13px;
    border: 1px solid rgba(231, 201, 132, .45);
    border-radius: 10px;
    color: #f4ead2;
    background: rgba(7, 7, 7, .78);
    box-shadow: 0 2px 12px rgba(0, 0, 0, .34);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.shell-control:hover {
    background: rgba(44, 36, 20, .88);
}

.shell-control svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

#fullscreen-control {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    color: rgba(244, 234, 210, .62);
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

#fullscreen-control:hover,
#fullscreen-control:focus-visible {
    color: #f4ead2;
    background: rgba(0, 0, 0, .38);
}

#fullscreen-control svg {
    width: 18px;
    height: 18px;
}

.shell-control .exit-fullscreen {
    display: none;
}

.shell-control[data-active="true"] .enter-fullscreen {
    display: none;
}

.shell-control[data-active="true"] .exit-fullscreen {
    display: block;
}

#mobile-controls {
    position: absolute;
    z-index: 6;
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    gap: 4px;
    transform: scale(var(--mobile-control-scale, 1));
    transform-origin: top left;
}

.mobile-overlay-button {
    width: 55px;
    min-width: 55px;
    height: 38px;
    min-height: 38px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: transparent;
    line-height: 0;
}

.mobile-overlay-button img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
}

#mobile-hotkeys {
    position: absolute;
    z-index: 6;
    /* --mobile-bottom-reserve is the portrait chat block height in CSS px
       (0 in landscape, or when the chat is collapsed), so the hotkey stack
       sits above the chat instead of behind it. */
    bottom: calc(8px + env(safe-area-inset-bottom) + var(--mobile-bottom-reserve, 0px));
    left: calc(8px + env(safe-area-inset-left));
    width: 55px;
    height: 41px;
    transform: scale(var(--mobile-control-scale, 1));
    transform-origin: bottom left;
}

#mobile-hotkeys[data-expanded="true"] {
    height: 152px;
}

.mobile-hotkeys-folded,
.mobile-hotkeys-expanded {
    position: absolute;
    inset: 0;
    display: block;
    width: 55px;
    height: auto;
    pointer-events: none;
}

.mobile-hotkeys-expanded,
#mobile-hotkeys[data-expanded="true"] .mobile-hotkeys-folded {
    display: none;
}

#mobile-hotkeys[data-expanded="true"] .mobile-hotkeys-expanded {
    display: block;
}

.mobile-hotkey-hit {
    position: absolute;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
}

.mobile-hotkey-toggle {
    inset: 0;
}

#mobile-hotkeys[data-expanded="true"] .mobile-hotkey-toggle {
    top: 121px;
    right: 0;
    bottom: 0;
    left: 0;
}

.mobile-hotkey-run,
.mobile-hotkey-drop,
.mobile-hotkey-mark {
    display: none;
    left: 8px;
    width: 39px;
    height: 37px;
}

#mobile-hotkeys[data-expanded="true"] .mobile-hotkey-run,
#mobile-hotkeys[data-expanded="true"] .mobile-hotkey-drop,
#mobile-hotkeys[data-expanded="true"] .mobile-hotkey-mark {
    display: block;
}

.mobile-hotkey-run {
    top: 10px;
}

.mobile-hotkey-drop {
    top: 47px;
}

.mobile-hotkey-mark {
    top: 84px;
}

.mobile-hotkey-active {
    position: absolute;
    z-index: 1;
    left: 8px;
    width: 39px;
    height: 37px;
    pointer-events: none;
}

#mobile-keyboard-input {
    position: absolute;
    z-index: 7;
    bottom: 0;
    left: 50%;
    width: 2px;
    height: 2px;
    padding: 0;
    border: 0;
    opacity: .01;
    pointer-events: none;
    resize: none;
}

html:not([data-input="touch"]) #mobile-controls,
html:not([data-input="touch"]) #mobile-hotkeys {
    display: none;
}

.shell-overlay {
    position: absolute;
    z-index: 10;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(20px + env(safe-area-inset-top))
             calc(20px + env(safe-area-inset-right))
             calc(20px + env(safe-area-inset-bottom))
             calc(20px + env(safe-area-inset-left));
    background: rgba(0, 0, 0, .68);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.shell-card {
    width: min(100%, 480px);
    max-height: 100%;
    overflow: auto;
    padding: clamp(22px, 5vw, 34px);
    border: 1px solid rgba(216, 172, 73, .58);
    border-radius: 18px;
    color: #eee7d7;
    text-align: center;
    background: linear-gradient(145deg, rgba(30, 26, 18, .98), rgba(7, 7, 7, .98));
    box-shadow: 0 16px 55px rgba(0, 0, 0, .65);
}

.shell-card h1 {
    margin: 0 0 12px;
    color: #f1ca70;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(23px, 5vw, 31px);
}

.shell-card p {
    margin: 0 auto 16px;
    max-width: 390px;
    color: #d8d1c1;
    font-size: 15px;
    line-height: 1.45;
}

.shell-card .instructions {
    color: #f5e7c7;
    font-weight: 700;
}

.shell-mark {
    display: grid;
    width: 58px;
    height: 66px;
    margin: 0 auto 16px;
    place-items: center;
    border: 2px solid #a9b4c7;
    border-radius: 28% 28% 43% 43%;
    color: #fff;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 38px;
    background: #303949;
    box-shadow: inset 0 0 0 3px #151a22, 0 5px 15px rgba(0, 0, 0, .42);
}

.shell-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 22px;
}

.primary-action,
.secondary-action {
    width: 100%;
    padding: 11px 18px;
    border-radius: 10px;
    font-weight: 700;
}

.primary-action {
    color: #171004;
    background: linear-gradient(#f0cd77, #c59131);
}

.secondary-action {
    border: 1px solid rgba(238, 231, 215, .34);
    color: #eee7d7;
    background: rgba(255, 255, 255, .07);
}

#orientation-hint {
    z-index: 9;
    display: none;
}

.compact-card {
    width: min(100%, 390px);
}

.rotate-device {
    margin-bottom: 6px;
    color: #d8ac49;
    font-size: 52px;
    line-height: 1;
}

.orientation-preference {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    margin: 3px 0 15px;
    color: #eee7d7;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.orientation-preference input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #d8ac49;
}

#version {
    display: none;
    position: absolute;
    z-index: 4;
    right: calc(var(--startup-side-gutter, 0px) + 10px + env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    color: rgba(255, 255, 255, .82);
    font-size: 13px;
    pointer-events: none;
    text-shadow: 0 1px 2px #000;
}

#app[data-state="loading"] #version,
#app[data-state="downloading"] #version,
#app[data-state="error"] #version,
#app[data-state="login"] #version,
#login-panel:not([hidden]) ~ #version {
    display: block;
}

@media (orientation: portrait) and (max-width: 900px) {
    html[data-mobile-device="true"] #app:not([data-install-prompt="visible"]):not([data-orientation-dismissed="true"]) #orientation-hint {
        display: flex;
    }
}

@media (max-width: 620px) {
    .shell-control {
        width: 48px;
        padding: 0;
    }

    .shell-control span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
}

@media (max-height: 470px) and (orientation: landscape) {
    .shell-overlay {
        align-items: flex-start;
        padding-top: calc(10px + env(safe-area-inset-top));
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .shell-card {
        padding: 16px 22px;
    }

    .shell-mark {
        display: none;
    }

    .shell-card h1 {
        margin-bottom: 7px;
        font-size: 23px;
    }

    .shell-card p {
        margin-bottom: 8px;
        font-size: 14px;
    }

    .shell-actions {
        flex-direction: row;
        margin-top: 12px;
    }
}
