/* WordPerfect 5.1 Color Scheme */
:root {
    --wp-blue: #0000AA;
    --wp-light-blue: #5555FF;
    --wp-white: #FFFFFF;
    --wp-cyan: #55FFFF;
    --wp-yellow: #FFFF55;
    --wp-black: #000000;
    --wp-gray: #AAAAAA;
    --wp-dark-gray: #555555;
}

/* Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Use a classic DOS-style font */
@font-face {
    font-family: 'DOS VGA';
    src: url('../fonts/PerfectDOSVGA437Win.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

body {
    font-family: 'DOS VGA', 'Consolas', 'Courier New', monospace;
    font-size: 16px;
    line-height: 1.2;
    background-color: var(--wp-blue);
    color: var(--wp-white);
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: default;
}


/* DOS Prompt Screen */
#dos-prompt {
    position: fixed;
    inset: 0;
    z-index: 10001;
    background-color: #000;
    padding: 24px;
}

#dos-prompt.hidden {
    display: none;
}

.dos-date,
.dos-time {
    color: #AAA;
    font-size: 16px;
}

.dos-line {
    color: #AAA;
    font-size: 16px;
}

.dos-typed {
    color: #CCC;
}

.dos-cursor {
    animation: blink-cursor 0.8s step-end infinite;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Splash Screen */
#splash-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background-color: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

#splash-screen.hidden {
    display: none;
}

.splash-box {
    border: 2px solid #AAA;
    padding: 24px 48px;
    text-align: center;
    margin-bottom: 48px;
}

.splash-title {
    color: #DDD;
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 8px;
}

.splash-subtitle {
    color: #AAA;
    font-size: 16px;
}

.splash-continue {
    color: #AAA;
    font-size: 14px;
}

.splash-yes,
.splash-no {
    font-weight: bold;
    color: #DDD;
    text-decoration: underline;
}

.splash-hidden {
    visibility: hidden;
}

/* Color Test Screen */
#color-test {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background-color: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

#color-test.hidden {
    display: none;
}

.color-test-box {
    border: 1px solid #AAA;
    padding: 24px 32px;
    text-align: center;
    max-width: 55ch;
}

.color-test-text {
    color: #AAA;
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 24px;
}

.color-test-blocks {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 24px;
}

.color-block {
    width: 48px;
    height: 24px;
}

.color-block-red { background-color: #AA0000; }
.color-block-green { background-color: #00AA00; }
.color-block-blue { background-color: #0000AA; }

.color-test-prompt {
    color: #AAA;
    font-size: 16px;
}

.color-test-prompt-y,
.color-test-prompt-n {
    text-decoration: underline;
}

/* Optional CRT Effect */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1) 0px,
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 9999;
}

/* Menu Bar */
#menu-bar {
    display: flex;
    background-color: var(--wp-black);
    color: var(--wp-white);
    padding: 2px 0;
    border-bottom: 1px solid var(--wp-gray);
}

#menu-bar.hidden {
    display: none;
}

.menu-item {
    position: relative;
    padding: 2px 16px;
    cursor: pointer;
}

.menu-item:hover,
.menu-item.active {
    background-color: var(--wp-light-blue);
    color: var(--wp-white);
}

.menu-title::first-letter {
    color: var(--wp-yellow);
}

.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--wp-black);
    border: 1px solid var(--wp-gray);
    min-width: 200px;
    z-index: 100;
}

.menu-item.active .menu-dropdown {
    display: block;
}

.menu-option {
    padding: 4px 16px;
    cursor: pointer;
    white-space: nowrap;
}

.menu-option:hover,
.menu-option.focused {
    background-color: var(--wp-light-blue);
}

/* Document Container */
#document-container {
    flex: 1;
    overflow: auto;
    padding: 16px 24px;
    background-color: var(--wp-blue);
    display: flex;
    justify-content: center;
}

#document {
    width: 100%;
    max-width: calc(80ch + 36px);
    min-height: 100%;
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    caret-color: var(--wp-white);
    font-size: 16px;
    line-height: 1.4;
    padding-bottom: 0;
    -webkit-text-size-adjust: 100%;
}

#document > div:not(.wp-box):not(.wp-ascii):not(.wp-nowrap) {
    font-size: inherit;
    line-height: inherit;
}

#document::after {
    content: '';
    display: block;
    height: 1.2em;
}

/* Block Cursor Effect (when not focused, simulated) */
#document:focus {
    animation: blink-caret 1s step-end infinite;
}

@keyframes blink-caret {
    0%, 100% { caret-color: var(--wp-white); }
    50% { caret-color: transparent; }
}

/* ASCII art and decorative lines - prevent wrapping */
.wp-ascii {
    white-space: pre;
    overflow-x: auto;
    scrollbar-width: none;
    font-size: min(16px, 1.9vw);
}

.wp-ascii::-webkit-scrollbar {
    display: none;
}

.wp-nowrap {
    white-space: pre;
    display: block;
    overflow-x: hidden;
    font-size: min(16px, 1.9vw);
}

/* WP-style fieldset boxes */
.wp-box {
    border: 1px solid var(--wp-gray);
    padding: 12px 16px;
    margin: 12px 0;
}

.wp-box-title {
    color: var(--wp-cyan);
    padding: 0 8px;
    font-weight: normal;
    font-size: inherit;
}

/* Links in document */
#document a {
    color: var(--wp-cyan);
    text-decoration: underline;
}

#document a:hover {
    color: var(--wp-yellow);
}

/* Selection styling */
#document::selection,
#document *::selection {
    background-color: var(--wp-light-blue);
    color: var(--wp-white);
}

/* Reveal Codes Panel */
#reveal-codes {
    flex: 0 0 30%;
    background-color: var(--wp-black);
    border-top: 2px solid var(--wp-cyan);
    overflow: auto;
    padding: 8px;
}

#reveal-codes.hidden {
    display: none;
}

#reveal-codes-content {
    color: var(--wp-cyan);
    font-size: 14px;
    white-space: pre-wrap;
}

/* Status Bar */
#status-bar {
    display: flex;
    justify-content: flex-end;
    gap: 24px;
    padding: 4px 16px;
    background-color: var(--wp-blue);
    color: var(--wp-white);
    border-top: 1px solid var(--wp-light-blue);
    font-size: 14px;
}

/* Function Key Bar */
#function-bar {
    display: flex;
    justify-content: space-around;
    background-color: var(--wp-black);
    padding: 4px 0;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--wp-gray);
}

.fkey {
    color: var(--wp-white);
    font-size: 14px;
    padding: 2px 8px;
    cursor: pointer;
    transition: background-color 0.1s;
}

.fkey:hover {
    background-color: var(--wp-dark-gray);
}

.fkey:active {
    background-color: var(--wp-light-blue);
}

.fkey-disabled {
    opacity: 0.3;
    pointer-events: none;
}

.mobile-menu-option.fkey-disabled {
    opacity: 1;
    color: var(--wp-gray);
}

.reveal-label-short { display: none; }
@media (max-width: 600px) {
    .reveal-label-full { display: none; }
    .reveal-label-short { display: inline; }
}

.fkey-num {
    color: var(--wp-cyan);
    margin-right: 4px;
}

.cmd-symbol {
    font-size: 1.15em;
    vertical-align: bottom;
    line-height: 1;
}

/* DOS-style buttons (mobile dialogs) */
.wp-btn {
    background: var(--wp-black);
    color: var(--wp-cyan);
    border: 1px solid var(--wp-cyan);
    font-family: inherit;
    font-size: 14px;
    padding: 6px 16px;
    cursor: pointer;
}

.wp-btn:active {
    background: var(--wp-light-blue);
    color: var(--wp-white);
}

.dialog-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
}

/* Desktop: show text footer, hide buttons */
.dialog-footer-mobile { display: none; }
.dialog-footer-desktop { display: block; }

@media (max-width: 768px) {
    .dialog-footer-mobile { display: flex; }
    .dialog-footer-desktop { display: none !important; }
}

/* Modal Overlay */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#modal-overlay.hidden {
    display: none;
}

#modal-content {
    background-color: var(--wp-black);
    border: 2px solid var(--wp-cyan);
    padding: 16px 24px;
    max-width: min(80%, 40ch);
    box-shadow: 4px 4px 0 var(--wp-dark-gray);
}

#modal-title {
    color: var(--wp-yellow);
    font-size: 18px;
    margin-bottom: 16px;
    text-align: center;
    border-bottom: 1px solid var(--wp-cyan);
    padding-bottom: 8px;
}

#modal-body {
    color: var(--wp-white);
    margin-bottom: 16px;
    line-height: 1.6;
    white-space: pre-wrap;
    font-size: 16px;
}

#modal-footer {
    color: var(--wp-gray);
    text-align: center;
    font-size: 12px;
}

/* Search Dialog */
#search-dialog {
    position: fixed;
    top: 50%;
    left: 16px;
    right: 16px;
    transform: translateY(-50%);
    z-index: 1000;
    max-width: 400px;
    margin: 0 auto;
}

#search-dialog.hidden {
    display: none;
}

.dialog-content {
    background-color: var(--wp-black);
    border: 2px solid var(--wp-cyan);
    padding: 16px;
    width: 100%;
}

.dialog-title {
    color: var(--wp-cyan);
    margin-bottom: 12px;
}

.dialog-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.dialog-row label {
    color: var(--wp-white);
}

.dialog-row input {
    flex: 1;
    background-color: var(--wp-blue);
    border: 1px solid var(--wp-cyan);
    color: var(--wp-white);
    padding: 4px 8px;
    font-family: inherit;
    font-size: 16px;
    outline: none;
}

.dialog-footer {
    color: var(--wp-gray);
    font-size: 12px;
}

/* Guestbook Sign Dialog */
#guestbook-sign {
    position: fixed;
    top: 50%;
    left: 16px;
    right: 16px;
    transform: translateY(-50%);
    z-index: 1000;
    max-width: 400px;
    margin: 0 auto;
}

#guestbook-sign.hidden {
    display: none;
}

/* Guestbook Viewer */
#guestbook-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--wp-blue);
    z-index: 500;
    display: flex;
    flex-direction: column;
    padding: 16px;
}

#guestbook-viewer.hidden {
    display: none;
}

.guestbook-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.guestbook-title {
    color: var(--wp-yellow);
    text-align: center;
    margin-bottom: 16px;
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    font-size: min(18px, 4.5vw);
}

#guestbook-entries {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--wp-cyan);
    padding: 8px;
    background-color: var(--wp-black);
}

.guestbook-entry {
    padding: 4px 8px;
    color: var(--wp-white);
    cursor: pointer;
}

.guestbook-entry.selected {
    background-color: var(--wp-light-blue);
}

.guestbook-entry-date {
    color: var(--wp-cyan);
}

.guestbook-entry.selected .guestbook-entry-date {
    color: var(--wp-white);
}

.guestbook-entry-name {
    color: var(--wp-white);
}

.guestbook-footer {
    color: var(--wp-gray);
    text-align: center;
    margin-top: 16px;
    font-size: 12px;
}

.guestbook-empty {
    color: var(--wp-gray);
    text-align: center;
    padding: 32px;
}

/* Guestbook entry banner */
#guestbook-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--wp-black);
    color: var(--wp-cyan);
    text-align: center;
    padding: 4px 16px;
    font-size: 14px;
    z-index: 200;
    border-bottom: 1px solid var(--wp-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.guestbook-back-btn {
    background: none;
    border: none;
    color: var(--wp-white);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
}

/* Mobile Toolbar (hidden on desktop) */
#mobile-toolbar {
    display: none;
}

#mobile-menu {
    display: none;
}

@media (max-width: 768px) {
    #mobile-toolbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: var(--wp-black);
        padding: 8px 12px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--wp-gray);
    }

    #mobile-hamburger {
        background: none;
        border: 1px solid var(--wp-gray);
        color: var(--wp-white);
        font-family: inherit;
        font-size: 18px;
        padding: 4px 10px;
        cursor: pointer;
        line-height: 1;
    }

    #mobile-hamburger:active {
        background: var(--wp-light-blue);
    }

    #mobile-toolbar-right {
        display: flex;
        gap: 8px;
    }

    #mobile-edit-btn,
    #mobile-save-btn {
        background: none;
        border: 1px solid var(--wp-cyan);
        color: var(--wp-cyan);
        font-family: inherit;
        font-size: 13px;
        padding: 4px 14px;
        cursor: pointer;
    }

    #mobile-edit-btn:active,
    #mobile-save-btn:active {
        background: var(--wp-light-blue);
        color: var(--wp-white);
    }

    #mobile-save-btn.hidden {
        display: none;
    }

    #mobile-menu {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: var(--wp-black);
        border-top: 1px solid var(--wp-gray);
        z-index: 500;
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }

    #mobile-menu:not(.hidden) {
        display: block;
    }

    .mobile-menu-option {
        padding: 12px 20px;
        color: var(--wp-white);
        border-bottom: 1px solid #222;
        cursor: pointer;
        font-size: 15px;
    }

    .mobile-menu-option:active {
        background-color: var(--wp-light-blue);
    }

    #function-bar,
    #status-bar,
    #menu-bar {
        display: none !important;
    }
}

/* Responsive adjustments */

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    #modal-content {
        min-width: 350px;
    }

}

/* Small tablet / large phone */
@media (min-width: 481px) and (max-width: 767px) {
    body {
        font-size: 14px;
        max-width: 100vw;
        -webkit-text-size-adjust: 100%;
    }

    #document {
        max-width: 100%;
        font-size: 16px;
        overflow-x: hidden;
    }

    #document-container {
        padding: 8px 12px;
    }

    .fkey {
        font-size: 12px;
        padding: 4px 6px;
    }

    .fkey-num {
        display: block;
        margin-right: 0;
        margin-bottom: 2px;
    }

    #status-bar {
        font-size: 12px;
        gap: 16px;
    }

    #modal-content {
        min-width: 90%;
        max-width: 95%;
    }

    .menu-item {
        padding: 4px 12px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    body {
        font-size: 12px;
        max-width: 100vw;
        -webkit-text-size-adjust: 100%;
    }

    #document {
        max-width: 100%;
        font-size: 16px;
        line-height: 1.4;
        overflow-x: hidden;
        min-height: auto;
    }

    #document::after {
        height: 0;
    }

    #document-container {
        padding: 8px;
    }

    #modal-content {
        min-width: 95%;
        max-width: 98%;
        padding: 12px 16px;
    }

    #modal-title {
        font-size: 16px;
    }

    .dialog-content {
        padding: 12px;
    }

    #reveal-codes {
        height: 25%;
        font-size: 12px;
    }

    .guestbook-title {
        font-size: 14px;
    }
}
