* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --base-font-size: calc(1.2vw);
    --min-font-size: 16px;
    --dialog-font-size: calc(1.125 * max(var(--base-font-size), var(--min-font-size)));
    --name-font-size: max(var(--base-font-size), var(--min-font-size));
    --mono-font-size: calc(0.875 * max(var(--base-font-size), var(--min-font-size)));
    --small-font-size: calc(0.75 * max(var(--base-font-size), var(--min-font-size)));
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: #1a1a1a;
    color: white;
    overflow: hidden;
    font-size: var(--base-font-size);
}

#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.title-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.title-background object {
    pointer-events: none;
    object-fit: cover;
}

.title-content {
    text-align: center;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.title-content h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    color: #fff;
    text-shadow: 0 0 20px rgba(52, 152, 219, 0.8);
}

.button-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.title-button {
    background-color: rgba(52, 152, 219, 0.9);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 200px;
    margin: 0 auto;
    backdrop-filter: blur(4px);
}

.title-button:hover:not(:disabled) {
    background-color: rgba(41, 128, 185, 0.9);
}

.title-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#game-container {
    display: none;
    width: 100vw;
    height: 100vh;
    position: relative;
}

#scene-info {
    visibility: hidden;
    position: absolute;
    top: 20px;
    right: 20px;
    background-color: rgba(0, 0, 0, 0.75);
    padding: 10px;
    border-radius: 4px;
    font-size: var(--mono-font-size);
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#main-window {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#background {
    width: 100%;
    height: 100%;
    padding: 20px;
    border-radius: 8px;
    position: relative;
    transition: background-color 1000ms ease;
    overflow: hidden;
    opacity: 65%;
}

.background-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    background-color: transparent;
    transition: opacity 1000ms ease, background-color 0ms linear 1000ms;
    pointer-events: none;
}

.background-overlay.active {
    opacity: 1;
    transition: opacity 1000ms ease, background-color 0ms linear;
}

#background-text {
    font-family: monospace;
    font-size: var(--mono-font-size);
    margin: 0;
    position: relative;
    z-index: 1;
}

#background-text::after {
    content: '▋';
    position: absolute;
    right: -0.5em;
    animation: cursor-blink 1s infinite;
}

@keyframes cursor-blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

#character-sprite {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 256px;
    height: 384px;
    background-color: #374151;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 1;
    animation: fadeIn 300ms ease-in forwards;
    transition: width 0.3s ease, height 0.3s ease;

    text-align: center;
    justify-content: flex-start;
    gap: 10px;
}

#character-name {
    font-weight: bold;
    margin: 0;
    font-size: var(--name-font-size);
    color: white;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    backdrop-filter: blur(2px);
}

#character-appearance {
    margin: 0;
    font-size: calc(0.85 * var(--name-font-size));
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
    max-height: calc(100% - 50px);
    overflow-y: auto;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    backdrop-filter: blur(2px);
}

#character-sprite p:first-child {
    margin-bottom: 10px;
}

#sfx-toast {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    animation: fadeIn 300ms ease-out forwards;
    z-index: 10;
    max-width: 90%;
    width: auto;
}

.sfx-content {
    background-color: rgba(0, 0, 0, 0.75);
    border: 1px solid #2563eb;
    border-radius: 4px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sfx-icon {
    flex-shrink: 0;
    width: calc(var(--name-font-size) * 1.2);
    height: calc(var(--name-font-size) * 1.2);
    border-radius: 50%;
    background-color: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--small-font-size);
}

#sfx-text {
    font-size: var(--mono-font-size);
    margin: 0;
    color: white;
}

/* Dialog panel container */
#dialog-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
}

#dialog-box {
    width: 100%;
    background-color: rgba(31, 41, 55, 0.95);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    padding: 20px;
    position: relative;
    cursor: pointer;
    margin-top: 40px;
    padding-bottom: 80px;
    transition: height 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#name-box {
    position: absolute;
    top: -40px;
    left: 20px;
    background-color: #2563eb;
    padding: 5px 20px;
    border-radius: 4px;
    z-index: 1;
}

#name-text {
    font-weight: bold;
    margin: 0;
    font-size: var(--name-font-size);
    color: white;
}

#dialog-text {
    font-size: var(--dialog-font-size);
    margin: 0;
    line-height: 1.5;
    overflow-wrap: break-word;
    word-break: break-word;
}

#nav-buttons {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 20px;
    z-index: 2;
}

.nav-button {
    background-color: #2563eb;
    padding: 10px 20px;
    border-radius: 4px;
    border: none;
    color: white;
    font-family: inherit;
    font-size: var(--name-font-size);
    cursor: pointer;
    transition: opacity 300ms;
}

.nav-button:disabled {
    opacity: 0.5;
    cursor: default;
}

.nav-button:focus {
    outline: none;
}

.nav-button:not(:disabled):hover {
    background-color: #1d4ed8;
}

.help-button {
    position: absolute !important;
    bottom: 20px !important;
    left: 20px !important;
    z-index: 2;
}

/* Scene transition overlay */
#scene-transition {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    transition: opacity 2s ease;
}

#scene-transition.active {
    opacity: 1;
}

/* Ensure other elements can fade properly */
#main-window,
#dialog-container,
#scene-info {
    transition: opacity 2s ease;
}

/* Hide elements during transition */
.transitioning #main-window,
.transitioning #dialog-container,
.transitioning #scene-info {
    opacity: 0;
}

#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.help-modal-content {
    background-color: #1f2937;
    border-radius: 8px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.help-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.help-modal-title {
    font-size: 1.5rem;
    color: white;
    font-weight: bold;
}

#close-help-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0.5rem;
}

#close-help-btn:hover {
    color: white;
}

#controls-list {
    list-style: none;
    padding: 0;
}

#controls-list li {
    color: #d1d5db;
    margin-bottom: 1rem;
    line-height: 1.5;
    font-size: 1rem;
}

#controls-list li strong {
    color: #60a5fa;
    display: inline-block;
    margin-right: 0.5rem;
}

.hidden {
    display: none !important;
}

#long-press-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background-color: rgba(31, 41, 55, 0.98);
    border-radius: 8px;
    padding: 1rem;
    z-index: 3000;
    min-width: 200px;
    max-width: 90%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
}

#long-press-menu.active {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.long-press-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: white;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-size: var(--name-font-size);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.long-press-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.long-press-menu-item:active {
    background-color: rgba(255, 255, 255, 0.2);
}

.long-press-menu-item+.long-press-menu-item {
    margin-top: 0.5rem;
}

.long-press-progress {
    position: fixed;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 2999;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.long-press-progress.active {
    opacity: 1;
}

.long-press-progress svg {
    transform: rotate(-90deg);
}

.long-press-progress circle {
    stroke: #2563eb;
    stroke-width: 4;
    fill: none;
    stroke-dasharray: 251.2;
    stroke-dashoffset: 251.2;
    transition: stroke-dashoffset 1s linear;
}

.long-press-progress.active circle {
    stroke-dashoffset: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.hidden {
    display: none !important;
}

#confirmation-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

#confirmation-modal.hidden {
    display: none;
}

.confirmation-modal-content {
    background-color: #1f2937;
    border-radius: 8px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.confirmation-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.confirmation-modal-title {
    font-size: 1.5rem;
    color: white;
    font-weight: bold;
    margin: 0;
}

.close-modal-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0.5rem;
}

.close-modal-btn:hover {
    color: white;
}

#confirmation-message {
    color: #d1d5db;
    margin-bottom: 2rem;
    line-height: 1.5;
    font-size: 1rem;
}

.confirmation-button-container {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.modal-button {
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.modal-button.confirm {
    background-color: #2563eb;
    color: white;
}

.modal-button.confirm:hover {
    background-color: #1d4ed8;
}

.modal-button.cancel {
    background-color: #4b5563;
    color: white;
}

.modal-button.cancel:hover {
    background-color: #374151;
}

.last-updated {
    position: absolute;
    bottom: 20px;
    left: 20px;
    color: rgba(255, 255, 255, 0.7);
    font-size: var(--small-font-size);
    z-index: 1;
}

@media (min-width: 769px) {

    #long-press-menu,
    .long-press-progress {
        display: none;
    }
}

@media (max-width: 768px) {
    .last-updated {
        bottom: 10px;
        left: 10px;
        font-size: calc(0.8 * var(--small-font-size));
    }
    
    .title-content h1 {
        font-size: 2rem;
    }

    .title-button {
        width: 160px;
        padding: 0.8rem 1.6rem;
        font-size: 1rem;
    }

    #dialog-container {
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }

    #dialog-box {
        padding-bottom: 20px !important;
    }

    #nav-buttons {
        display: none !important;
    }
    
    .help-button {
        display: none !important;
    }

    #character-sprite {
        width: 192px;
        height: 288px;
    }

    #character-appearance {
        font-size: calc(0.8 * var(--name-font-size));
    }
}

/* Portrait mode styles */
@media (orientation: portrait) {
    .title-background object {
        height: 100%;
    }

    #character-sprite {
        width: 60vw;
        /* Increased from 30vw */
        height: 90vw;
        /* Increased from 45vw */
        max-width: 400px;
        /* Increased from 256px */
        max-height: 600px;
        /* Increased from 384px */
        bottom: 20vh;
        /* Position higher up in portrait mode */
    }

    #character-appearance {
        max-height: calc(100% - 60px);
    }

    /* Adjust dialog container to avoid overlap */
    #dialog-container {
        padding: 15px;
        padding-bottom: env(safe-area-inset-bottom, 15px);
        /* Safari support */
    }

    /* Make dialog box background more opaque in portrait mode */
    #dialog-box {
        background-color: rgba(31, 41, 55, 0.98);
    }

    /* Ensure dialog text remains readable over character sprite */
    #dialog-text {
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }
}

/* Additional media query for tall but narrow screens */
@media (orientation: portrait) and (min-height: 800px) {
    #character-sprite {
        bottom: 25vh;
        /* Position even higher on taller screens */
    }
}

/* Handle smaller portrait screens */
@media (orientation: portrait) and (max-width: 480px) {
    #character-sprite {
        width: 75vw;
        /* Even larger on small screens */
        height: 112.5vw;
        bottom: 15vh;
    }
}

/* Very small screens */
@media (orientation: portrait) and (max-width: 320px) {
    #character-sprite {
        width: 85vw;
        height: 127.5vw;
        bottom: 12vh;
    }
}