body {
    background-color: #008080;
    font-family: monospace;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    cursor: default;
    user-select: none;
}

img {
    -webkit-user-drag: none;
    user-drag: none;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

.pixel-grid-bg {
    background-image: 
        linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px);
    background-size: 64px 64px;
    background-position: 0 0;
}

.crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 9999;
}

.center-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#jumpscare {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    z-index: 10000;
}

    #jumpscare img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

.menu-bar {
    background: #c0c0c0;
    padding: 2px;
    border-bottom: 2px solid #808080;
}

.menu-item {
    display: inline-block;
    padding: 2px 8px;
    cursor: pointer;
    position: relative;
    color: #000000;
}

    .menu-item:hover {
        background: #000080;
        color: #ffffff;
    }

.dropdown {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    background: #c0c0c0;
    border: 2px outset #ffffff;
    width: 150px;
    z-index: 200;
    box-shadow: 3px 3px 0 #000000;
}

    .dropdown div {
        padding: 5px 10px;
        color: #000000;
    }

        .dropdown div:hover {
            background: #000080;
            color: #ffffff;
        }

table {
    width: 100%;
    background: #ffffff;
    border-collapse: collapse;
}

th {
    background: #000080;
    color: #ffffff;
    border: 1px solid #000000;
    padding: 5px;
    font-size: 12px;
    position: sticky;
    top: 0;
}

td {
    border: 1px solid #808080;
    padding: 5px;
    font-size: 12px;
    cursor: pointer;
    color: #000000;
}

tr:hover {
    background: #000080;
    color: #ffffff;
}

tr.secret-row {
    background: #ff0000 !important;
    color: #ffffff !important;
    font-weight: bold;
}

    tr.secret-row:hover {
        background: #cc0000 !important;
        color: #ffffff !important;
    }

tr.special-row {
    background: #ffffff;
    color: #000000;
}

    tr.special-row:hover {
        background: #000080;
        color: #ffffff;
    }

tr.data-error-row {
    opacity: 0.6;
    background: #e0e0e0;
}

    tr.data-error-row:hover {
        background: #808080;
        color: #ffffff;
    }

.glitch-text {
    color: #ff0000;
    font-weight: bold;
    animation: text-shake 0.1s infinite;
}

@keyframes text-shake {
    0% {
        transform: translate(1px, 0);
    }

    50% {
        transform: translate(-1px, 0);
    }

    100% {
        transform: translate(0, 0);
    }
}

.blink {
    animation: blink-anim 0.5s infinite;
}

@keyframes blink-anim {
    0%, 49% {
        opacity: 1;
    }

    50%, 100% {
        opacity: 0;
    }
}

.earthquake {
    animation: screen-shake 0.05s infinite;
}

@keyframes screen-shake {
    0% {
        transform: translate(-50%, -50%) translate(5px, 5px) rotate(1deg);
    }

    25% {
        transform: translate(-50%, -50%) translate(-5px, -5px) rotate(-1deg);
    }

    50% {
        transform: translate(-50%, -50%) translate(-5px, 5px) rotate(0deg);
    }

    75% {
        transform: translate(-50%, -50%) translate(5px, -5px) rotate(1deg);
    }

    100% {
        transform: translate(-50%, -50%) translate(0, 0);
    }
}

.side-btn {
    display: block;
    width: 100%;
    margin-bottom: 5px;
    text-align: left;
    padding: 5px;
    background: #c0c0c0;
    border: 2px outset #ffffff;
    cursor: pointer;
}

    .side-btn:hover {
        background: #000080;
        color: #ffffff;
    }

    .side-btn:active {
        border-style: inset;
    }

    .side-btn.active-btn {
        font-weight: bold;
        background: #000080;
        color: #ffffff;
    }

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #c0c0c0;
    border-top-color: #000080;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

body {
    opacity: 0;
    animation: fade-in 0.5s ease-out 0.3s forwards;
}

@keyframes fade-in {
    to {
        opacity: 1;
    }
}

button {
    background: #c0c0c0;
    border: 2px outset #ffffff;
    padding: 5px 15px;
    font-family: monospace;
    cursor: pointer;
}

    button:hover {
        background: #e0e0e0;
    }

    button:active {
        border-style: inset;
    }

.sidebar-portrait {
    width: 100%;
    max-height: 120px;
    object-fit: cover;
    border: 2px inset #808080;
    margin-bottom: 10px;
    filter: grayscale(30%) contrast(110%);
}

/* ================================================================
   RESPONSIVE - Mobile (768px and below)
   ================================================================ */

@media screen and (max-width: 768px) {
    
    /* === Basic body === */
    body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
    }

    /* === center-screen override (비-모달 페이지 기본값) === */
    .center-screen {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        margin: 10px auto;
        max-width: 95vw;
        width: 95vw !important;
        box-sizing: border-box;
    }

    /* === main.html, secret.html - 모바일에서 창 세로 중앙 정렬 === */
    body:has(#main-dashboard),
    body:has(#secret-window) {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
    }

    body:has(#main-dashboard) .center-screen,
    body:has(#secret-window) .center-screen {
        margin-top: 0;
        margin-bottom: 0;
    }

    /* === 모달 창들은 모바일에서도 fixed + 정중앙 유지 === */
    /* (흔들림 애니메이션이 translate(-50%,-50%) 기반이라 반드시 고정 필요) */
    #notice-popup,
    #login-window,
    #lockout-window,
    #loading-window {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        margin: 0 !important;
    }

    /* === 98.css window fix === */
    .window {
        max-width: 95vw;
        box-sizing: border-box;
    }

    .window-body {
        overflow-x: hidden;
    }

    /* === index.html - notice popup === */
    #notice-popup {
        width: 95vw !important;
    }

    #notice-popup .title-bar-text {
        font-size: 10px;
    }

    #notice-body,
    #notice-content {
        text-align: center !important;
        justify-content: center !important;
    }

    #notice-content {
        flex-direction: column !important;
        align-items: center !important;
    }

    #notice-text {
        text-align: center !important;
    }

    #notice-text p {
        text-align: center !important;
    }

    /* === index.html - login === */
    #login-window {
        width: 95vw !important;
    }

    #login-window .field-row-stacked {
        width: 100% !important;
    }

    #login-window input[type="text"],
    #login-window input[type="password"] {
        width: 100%;
        box-sizing: border-box;
    }

    /* === index.html - lockout === */
    #lockout-window {
        width: 95vw !important;
    }

    #lockout-timer {
        font-size: 36px !important;
    }

    /* === main.html - dashboard === */
    #main-dashboard {
        width: 95vw !important;
        height: auto !important;
        min-height: auto;
    }

    /* Main layout: sidebar + content to vertical */
    /* :last-of-type 대신 :nth-child(3) 사용 - 실제 flex window-body가 3번째 자식 */
    #main-dashboard > .window-body:nth-child(3) {
        flex-direction: column !important;
        height: auto !important;
        padding: 5px !important;
        gap: 5px !important;
    }

    /* Sidebar: horizontal wrap */
    #main-dashboard > .window-body:nth-child(3) > .sunken-panel {
        width: 100% !important;
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 5px;
        padding: 5px !important;
        align-items: center;
    }

    .sidebar-portrait {
        width: 50px !important;
        max-height: 50px !important;
    }

    .side-btn {
        width: auto;
        flex: 1;
        min-width: 70px;
        font-size: 10px;
        padding: 3px 5px;
        margin-bottom: 0;
    }

    /* Hide sidebar bottom panel on mobile */
    #main-dashboard > .window-body:nth-child(3) > .sunken-panel > div[style*="margin-top: auto"] {
        display: none;
    }

    /* Hide sidebar decorations */
    #main-dashboard > .window-body:nth-child(3) > .sunken-panel > div[style*="text-align:center; margin: 5px"],
    #main-dashboard > .window-body:nth-child(3) > .sunken-panel > div[style*="margin-top: 10px,"],
    #main-dashboard > .window-body:nth-child(3) > .sunken-panel > div[style*="text-align:center; margin-top:5px"] {
        display: none;
    }

    /* Table area */
    #main-dashboard > .window-body:nth-child(3) > div:last-child {
        min-height: 300px;
    }

    /* Table horizontal scroll */
    #main-dashboard table {
        font-size: 10px;
        min-width: 500px;
    }

    #main-dashboard > .window-body:nth-child(3) > div:last-child > div:first-child {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    th, td {
        padding: 3px;
        font-size: 10px;
    }

    /* Title bar text truncation */
    .title-bar-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: calc(100% - 60px);
    }

    /* === main.html - modals === */
    #detail-modal,
    #error-404,
    #help-modal,
    #secret-input-modal {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 85vh;
        overflow-y: auto;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        margin: 0;
    }

    #help-modal {
        max-height: 80vh !important;
    }

    #help-modal .window-body {
        max-height: 70vh !important;
        overflow-y: auto;
    }

    #secret-input-modal .field-row-stacked {
        width: 100% !important;
    }

    #secret-input-modal input {
        width: 100%;
        box-sizing: border-box;
    }

    /* === loading.html === */
    #loading-window {
        width: 90vw !important;
    }

    /* === secret.html === */
    #secret-window {
        width: 95vw !important;
        max-width: 95vw !important;
    }

    .credential-box {
        font-size: 9px;
    }

    .credential-box p {
        word-break: break-all;
        font-size: 9px !important;
    }

    /* === deepweb.html === */
    #hand-container {
        width: 70vw !important;
        height: 70vw !important;
        max-width: 280px;
        max-height: 280px;
    }

    #main-image {
        max-width: 100% !important;
        max-height: 100% !important;
    }

    #upload-zone {
        width: 70vw !important;
        max-width: 200px;
    }

    #back-btn {
        top: 10px;
        left: 10px;
        padding: 8px 12px;
        font-size: 12px;
    }

    /* === ending.html === */
    .document {
        padding: 15px !important;
        margin: 0 auto;
        max-width: 95vw !important;
    }

    .training-ascii {
        font-size: 6px !important;
        line-height: 1.1 !important;
        overflow-x: auto;
    }

    .training-stats {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .training-body {
        padding: 15px 10px !important;
    }

    .steam-btn {
        padding: 10px 20px !important;
        font-size: 12px !important;
    }

    .info-table td {
        padding: 4px;
        font-size: 11px;
    }

    .info-table td:first-child {
        width: 70px;
    }

    .last-words-section input {
        font-size: 14px;
    }

    .content li {
        font-size: 11px;
    }

    /* === gallery.html === */
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .gallery-container {
        padding: 10px;
        max-width: 100%;
    }

    .gallery-header h1 {
        font-size: 18px !important;
    }

    .gallery-item img {
        height: 120px !important;
    }

    .modal img {
        max-width: 95% !important;
        max-height: 60vh !important;
    }

    /* === Marquee text === */
    marquee {
        font-size: 9px;
    }

    /* === Easter egg modal === */
    #easter-modal {
        padding: 10px;
    }

    #easter-modal img {
        max-width: 95% !important;
        max-height: 70vh !important;
    }

    /* === Image overflow prevention === */
    img {
        max-width: 100%;
        height: auto;
    }

    /* === Corner deco hidden on mobile === */
    .corner-deco {
        display: none !important;
    }

    /* === Maintenance code field === */
    #maintenance-code {
        width: 100%;
        box-sizing: border-box;
    }

    /* === Status bar text === */
    .status-bar {
        flex-wrap: wrap;
    }

    .status-bar-field {
        font-size: 9px !important;
    }

    /* === Notice content flex wrap === */
    #notice-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    #notice-content img[width="32"] {
        margin-bottom: 5px;
    }
}

/* ================================================================
   RESPONSIVE - Small mobile (480px and below)
   ================================================================ */

@media screen and (max-width: 480px) {

    .center-screen {
        width: 100vw !important;
        max-width: 100vw;
        margin: 5px auto;
    }

    /* Sidebar buttons smaller */
    .side-btn {
        font-size: 9px;
        min-width: 55px;
        padding: 2px 3px;
    }

    .sidebar-portrait {
        width: 40px !important;
        max-height: 40px !important;
    }

    /* Table even smaller */
    th, td {
        padding: 2px;
        font-size: 9px;
    }

    /* Ending tweaks */
    .document {
        padding: 10px !important;
    }

    .training-ascii {
        font-size: 4.5px !important;
    }

    .training-title {
        font-size: 14px !important;
    }

    /* Lockout timer */
    #lockout-timer {
        font-size: 28px !important;
    }

    /* Lockout image */
    #lockout-window img {
        max-width: 80px;
    }

    /* Gallery 1-column */
    .gallery-grid {
        grid-template-columns: 1fr !important;
    }

    .gallery-item img {
        height: 100px !important;
    }

    /* Deepweb */
    #hand-container {
        width: 80vw !important;
        height: 80vw !important;
    }

    #offering-text {
        font-size: 12px !important;
    }

    #status-text {
        font-size: 11px !important;
    }

    .finger-slot {
        width: 25px !important;
        height: 25px !important;
        font-size: 9px !important;
    }

    /* Secret page cred text */
    .credential-box p {
        font-size: 8px !important;
    }
}
