:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    background: #000000;
    overscroll-behavior: none;
    overflow: hidden;
    touch-action: none;
}

body {
    color: rgba(255, 255, 255, 0.87);
    font-family: "Courier New", Courier, monospace;
    box-sizing: border-box;
}

#app {
    box-sizing: border-box;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

#game-container {
    display: flex;
    justify-content: center;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

#game-container,
#game-container canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
}

.mobile-rotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483646;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    background: #050302;
    color: #f4deb0;
    font-family: Georgia, "Times New Roman", serif;
    text-align: center;
    padding: 32px;
    padding-top: calc(var(--safe-top) + 32px);
    padding-bottom: calc(var(--safe-bottom) + 32px);
}

html[data-mobile="true"][data-orientation="portrait"] .mobile-rotate-overlay {
    display: flex;
}

.mobile-rotate-overlay__icon {
    width: 96px;
    height: 96px;
    color: #f4deb0;
    animation: mobile-rotate-spin 2.4s ease-in-out infinite;
}

@keyframes mobile-rotate-spin {
    0%, 25% { transform: rotate(0deg); }
    50%, 75% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}

.mobile-rotate-overlay__title {
    font-size: 24px;
    letter-spacing: 1px;
    margin: 0;
}

.mobile-rotate-overlay__hint {
    font-size: 14px;
    opacity: 0.75;
    max-width: 320px;
    line-height: 1.5;
    margin: 0;
}

.mobile-fullscreen-toggle {
    position: fixed;
    top: max(8px, var(--safe-top));
    right: max(8px, var(--safe-right));
    z-index: 2147483645;
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(244, 222, 176, 0.55);
    border-radius: 6px;
    color: #f4deb0;
    font: 20px/1 Georgia, "Times New Roman", serif;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    touch-action: manipulation;
}

html[data-mobile="true"][data-fullscreen-supported="true"][data-fullscreen="false"][data-orientation="landscape"] .mobile-fullscreen-toggle {
    display: flex;
}

.mobile-fullscreen-toggle:active {
    background: rgba(244, 222, 176, 0.2);
}

#text-ui {
    width: min(1100px, 96vw);
    height: min(calc(100dvh - var(--safe-top) - var(--safe-bottom) - 24px), 900px);
    background: #0b0b0b;
    color: #e6e6e6;
    border: 2px solid #2b2b2b;
    padding: 12px;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: 10px;
    box-shadow: 0 0 0 2px #101010 inset;
}

#text-ui-header {
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-bottom: 1px solid #333;
    padding-bottom: 6px;
}

#text-ui-output {
    background: #060606;
    padding: 10px;
    margin: 0;
    overflow: auto;
    border: 1px solid #1c1c1c;
    white-space: pre-wrap;
}

#text-ui-prompt {
    background: #111;
    border: 1px solid #272727;
    padding: 8px;
}

#text-ui-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
}

#text-ui-actions button {
    background: #151515;
    color: #e0e0e0;
    border: 1px solid #333;
    padding: 8px;
    cursor: pointer;
    text-align: left;
}

#text-ui-controls {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

#text-ui-input {
    background: #050505;
    color: #f1f1f1;
    border: 1px solid #3a3a3a;
    padding: 10px;
    font-size: 16px;
}

#text-ui-submit {
    background: #1f1f1f;
    color: #f1f1f1;
    border: 1px solid #4a4a4a;
    padding: 10px 16px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#text-ui-quick {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

#text-ui-quick button {
    background: #151515;
    color: #cfcfcf;
    border: 1px solid #333;
    padding: 8px;
    cursor: pointer;
}
