html,
body {
    min-height: 100%;
}

body.win98-shell {
    margin: 0;
    color: var(--win98-text);
    font-family: var(--win98-font);
    background: linear-gradient(180deg, var(--win98-wallpaper-top), var(--win98-wallpaper-bottom));
}

html.win98-embed-root,
body.win98-embed {
    height: 100%;
}

body.win98-embed {
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
    box-sizing: border-box;
    color: var(--win98-text);
    font-family: var(--win98-font);
    background: #c0c0c0;
    display: flex;
    flex-direction: column;
}

body.win98-embed > .win98-explorer {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
}

body.win98-embed > *:only-child:not(.win98-explorer) {
    flex: 1 1 auto;
    min-height: 0;
}

body.win98-embed > *:only-child.win98-game-app,
body.win98-embed > *:only-child.win98-calculator {
    flex: 0 0 auto;
    min-height: 0;
}

/*
 * Embed pages use the iframe width as the viewport — often under 900px while the shell
 * window is still “desktop-sized”. Global Explorer mobile rules hide the Folders pane;
 * restore the classic two-pane layout inside iframes.
 */
@media (max-width: 900px) {
    body.win98-embed {
        overflow-x: auto;
    }

    body.win98-embed .win98-explorer {
        min-width: 560px;
    }

    body.win98-embed .win98-explorer__split {
        grid-template-columns: 200px minmax(0, 1fr);
    }

    body.win98-embed .win98-explorer__sidebar {
        display: flex;
    }

    body.win98-embed .win98-explorer__menubar {
        flex-wrap: nowrap;
        overflow-x: auto;
    }
}

body.win98-embed .win98-embed-fallback {
    color: var(--win98-text);
    background: var(--win98-surface);
    border: 2px solid;
    border-color: #fff var(--win98-surface-dark) var(--win98-surface-dark) #fff;
    margin: 8px;
}

.win98-desktop-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.win98-desktop-shell::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.16) 12%, transparent 13%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 28%);
    background-size: 4px 4px, 100% 100%;
    opacity: 0.35;
}

.win98-desktop {
    position: relative;
    flex: 1;
    overflow: hidden;
    padding: 24px 24px calc(var(--win98-taskbar-height) + var(--win98-safe-bottom) + 32px);
}

.win98-desktop__icons {
    display: grid;
    gap: 14px;
    width: min(112px, 100%);
    position: relative;
    z-index: 1;
}

.win98-desktop-icon {
    display: grid;
    gap: 6px;
    justify-items: center;
    padding: 4px;
    color: #fff;
    text-decoration: none;
    text-align: center;
    font-size: 13px;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
}

.win98-desktop-icon:hover {
    background: rgba(0, 0, 128, 0.35);
}

.win98-desktop-icon:focus {
    outline: none;
}

.win98-desktop-icon:focus-visible {
    background: rgba(0, 0, 128, 0.35);
    outline: 2px dotted #fff;
    outline-offset: 2px;
}

.win98-desktop-icon__glyph,
.win98-window__title-icon,
.win98-start-menu__icon {
    display: inline-block;
    vertical-align: middle;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
}

.win98-desktop-icon__glyph {
    width: 32px;
    height: 32px;
    position: relative;
}

.win98-desktop-icon[data-shortcut="true"] .win98-desktop-icon__glyph::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 14px;
    height: 14px;
    background-image: var(--win98-icon-shortcut);
    background-repeat: no-repeat;
    background-position: bottom left;
    background-size: contain;
    image-rendering: pixelated;
    z-index: 2;
}

.win98-window__title-icon,
.win98-start-menu__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.win98-desktop-icon[data-icon-type="folder"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-folder,
.win98-start-menu__icon.is-folder { background-image: var(--win98-icon-folder); }

.win98-desktop-icon[data-icon-type="folder-open"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-folder-open,
.win98-start-menu__icon.is-folder-open { background-image: var(--win98-icon-folder-open); }

.win98-desktop-icon[data-icon-type="document"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-document,
.win98-start-menu__icon.is-document { background-image: var(--win98-icon-document); }

.win98-desktop-icon[data-icon-type="mail"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-mail,
.win98-start-menu__icon.is-mail { background-image: var(--win98-icon-mail); }

.win98-desktop-icon[data-icon-type="briefcase"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-briefcase,
.win98-start-menu__icon.is-briefcase { background-image: var(--win98-icon-briefcase); }

.win98-desktop-icon[data-icon-type="computer"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-computer,
.win98-start-menu__icon.is-computer { background-image: var(--win98-icon-computer); }

.win98-desktop-icon[data-icon-type="documents"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-documents,
.win98-start-menu__icon.is-documents { background-image: var(--win98-icon-documents); }

.win98-desktop-icon[data-icon-type="calculator"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-calculator,
.win98-start-menu__icon.is-calculator { background-image: var(--win98-icon-calculator); }

.win98-desktop-icon[data-icon-type="games"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-games,
.win98-start-menu__icon.is-games { background-image: var(--win98-icon-games); }

.win98-desktop-icon[data-icon-type="categories"] .win98-desktop-icon__glyph,
.win98-window__title-icon.is-categories,
.win98-start-menu__icon.is-categories { background-image: var(--win98-icon-categories); }

.win98-window__title-icon.is-error,
.win98-start-menu__icon.is-error { background-image: var(--win98-icon-error); }

.win98-window__title-icon.is-search,
.win98-start-menu__icon.is-search { background-image: var(--win98-icon-search); }

.win98-window {
    position: absolute;
    top: 44px;
    left: 150px;
    width: min(860px, calc(100vw - 220px));
    height: min(560px, calc(100vh - 120px));
    min-width: 360px;
    min-height: 240px;
    display: flex;
    flex-direction: column;
    background: var(--win98-surface);
    border: 2px solid;
    border-color: #fff var(--win98-surface-dark) var(--win98-surface-dark) #fff;
    box-shadow: var(--win98-shadow);
    z-index: 2;
}

.win98-window.is-fixed-size:not(.is-maximized) {
    height: auto;
    min-height: 0;
}

.win98-window.is-maximized {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
    height: calc(100% - var(--win98-taskbar-height) - var(--win98-safe-bottom) - 24px);
}

.win98-window.is-template-calculator {
    width: 286px;
    min-width: 0;
    min-height: 0;
}

.win98-window.is-template-minesweeper {
    width: 236px;
    min-width: 0;
    min-height: 0;
}

.win98-window.is-template-tic-tac-toe {
    width: 236px;
    min-width: 0;
    min-height: 0;
}

.win98-window.is-template-snake {
    width: 366px;
    min-width: 0;
    min-height: 0;
}

.win98-window.is-template-breakout {
    width: 396px;
    min-width: 0;
    min-height: 0;
}

.win98-window.is-template-freecell {
    width: 742px;
    min-width: 0;
    min-height: 0;
}

.win98-window.is-template-games {
    width: min(760px, calc(100vw - 220px));
}

.win98-window.is-minimized,
.win98-window.is-closed {
    display: none;
}

.win98-window__titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 3px 3px;
    color: var(--win98-title-text);
    background: linear-gradient(90deg, var(--win98-title-start), var(--win98-title-end));
    cursor: move;
    user-select: none;
}

.win98-window:not(.is-focused) .win98-window__titlebar {
    color: #424242;
    text-shadow: 1px 1px 0 #e8e8e8;
    background: linear-gradient(90deg, var(--win98-title-inactive-start), var(--win98-title-inactive-end));
    cursor: default;
}

.win98-window:not(.is-focused) .win98-window__titlebar .win98-window__title {
    opacity: 0.95;
}

.win98-window:not(.is-focused) .win98-window__controls button:not(:disabled) {
    opacity: 0.92;
}

.win98-window__title {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
}

.win98-window__controls {
    display: grid;
    grid-auto-flow: column;
    gap: 2px;
}

.win98-window__controls button,
.win98-taskbar__start,
.win98-taskbar__window {
    min-width: 18px;
    padding: 2px 6px;
    border: 2px solid;
    border-color: #fff var(--win98-surface-dark) var(--win98-surface-dark) #fff;
    background: var(--win98-surface);
    color: var(--win98-text);
    font: inherit;
}

.win98-window__controls button {
    width: 18px;
    height: 16px;
    padding: 0;
    line-height: 1;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.win98-window__controls button:disabled {
    color: #808080;
    text-shadow: 1px 1px 0 #fff;
}

.win98-window__controls button:active,
.win98-taskbar__start:active,
.win98-taskbar__window:active,
.win98-taskbar__window.is-active {
    border-color: var(--win98-surface-dark) #fff #fff var(--win98-surface-dark);
}

.win98-window__controls button:focus-visible,
.win98-taskbar__start:focus-visible,
.win98-taskbar__window:focus-visible {
    outline: 2px dotted #000;
    outline-offset: 2px;
    z-index: 1;
}

.win98-window__body {
    flex: 1;
    overflow: auto;
    padding: 0;
    background: #f5f5f5;
}

.win98-window.is-template-shell-iframe .win98-window__body {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.win98-window.is-template-shell-iframe .win98-window__body iframe[data-shell-embed] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #f5f5f5;
}

.win98-window.is-template-shell-iframe.is-fixed-size .win98-window__body {
    flex: 0 0 auto;
    overflow: visible;
}

.win98-window.is-template-shell-iframe.is-fixed-size .win98-window__body iframe[data-shell-embed] {
    position: relative;
    inset: auto;
    width: 100%;
    height: 240px;
    vertical-align: top;
}

.win98-window.is-template-minesweeper .win98-window__body iframe[data-shell-embed] {
    height: 270px;
}

.win98-window.is-template-tic-tac-toe .win98-window__body iframe[data-shell-embed] {
    height: 220px;
}

.win98-window.is-template-snake .win98-window__body iframe[data-shell-embed] {
    height: 354px;
}

.win98-window.is-template-breakout .win98-window__body iframe[data-shell-embed] {
    height: 344px;
}

.win98-window.is-template-freecell .win98-window__body iframe[data-shell-embed] {
    height: 548px;
}

.win98-window:not(.is-focused) .win98-window__body {
    opacity: 0.97;
}

.win98-window__resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    z-index: 5;
    cursor: nwse-resize;
    touch-action: none;
    background:
        linear-gradient(135deg, transparent 0 45%, #666 45% 55%, transparent 55% 100%),
        linear-gradient(135deg, transparent 0 68%, #999 68% 78%, transparent 78% 100%);
}

.win98-start-menu {
    position: fixed;
    left: 2px;
    bottom: calc(var(--win98-taskbar-height) + var(--win98-safe-bottom) - 2px);
    z-index: 70;
    width: min(280px, calc(100vw - 12px));
    display: grid;
    grid-template-columns: 34px 1fr;
    background: var(--win98-surface);
    border: 2px solid;
    border-color: #fff var(--win98-surface-dark) var(--win98-surface-dark) #fff;
    box-shadow: var(--win98-shadow);
}

.win98-start-menu[hidden] {
    display: none;
}

.win98-start-menu__sidebar {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 8px 0 10px;
    background: linear-gradient(180deg, #0d2f88 0%, #7a7a7a 100%);
}

.win98-start-menu__sidebar span {
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    line-height: 1;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}

.win98-start-menu__content {
    padding: 8px 6px 6px;
}

.win98-start-menu__group + .win98-start-menu__group {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--win98-surface-dark);
}

.win98-start-menu__heading {
    margin: 0 0 4px;
    padding: 0 6px;
    font-size: 11px;
    text-transform: uppercase;
}

.win98-start-menu__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.win98-start-menu__list a {
    display: grid;
    grid-template-columns: 18px 1fr;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    color: var(--win98-text);
    text-decoration: none;
    font-size: 12px;
}

.win98-start-menu__list a:hover:not(:focus-visible) {
    color: #fff;
    background: #000080;
}

.win98-start-menu__list a:focus {
    outline: none;
}

.win98-start-menu__list a:focus-visible {
    color: #fff;
    background: #000080;
    outline: 2px dotted #fff;
    outline-offset: -2px;
}

.win98-taskbar__start {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
}

.win98-taskbar__start-logo {
    width: 16px;
    height: 16px;
    display: inline-block;
    background-image: var(--win98-icon-start);
    background-repeat: no-repeat;
    background-size: contain;
    image-rendering: pixelated;
}

.win98-taskbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: calc(var(--win98-taskbar-height) + var(--win98-safe-bottom));
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px calc(5px + var(--win98-safe-bottom));
    background: var(--win98-surface);
    border-top: 2px solid #fff;
}

.win98-taskbar__windows {
    flex: 1;
    display: flex;
    gap: 6px;
    min-width: 0;
}

.win98-taskbar__window {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    font-size: 12px;
}

.win98-window.is-template-post .win98-window__body {
    background: #c0c0c0;
}

.win98-window.is-template-post .win98-window__titlebar {
    background: linear-gradient(90deg, #003c74 0%, #1084d0 100%);
}

.win98-window.is-template-outlook .win98-window__body {
    background: #c0c0c0;
}

.win98-window.is-template-outlook .win98-window__titlebar {
    background: linear-gradient(90deg, #003c74 0%, #1084d0 100%);
}

.win98-window.is-template-post:not(.is-focused) .win98-window__titlebar,
.win98-window.is-template-outlook:not(.is-focused) .win98-window__titlebar {
    background: linear-gradient(90deg, var(--win98-title-inactive-start), var(--win98-title-inactive-end));
    color: #424242;
    text-shadow: 1px 1px 0 #e8e8e8;
}

.win98-taskbar__clock {
    min-width: 72px;
    padding: 4px 8px;
    text-align: center;
    border: 2px solid;
    border-color: var(--win98-surface-dark) #fff #fff var(--win98-surface-dark);
    background: #d4d0c8;
    font-size: 12px;
}

.win98-context-menu {
    position: fixed;
    z-index: 1000;
    min-width: 190px;
    padding: 2px;
    color: #111;
    background: #c0c0c0;
    border: 2px solid;
    border-color: #fff #404040 #404040 #fff;
    box-shadow: 1px 1px 0 #000;
    font: 12px/1.2 var(--win98-font);
}

.win98-context-menu[hidden] {
    display: none;
}

.win98-context-menu__item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 18px;
    width: 100%;
    min-height: 22px;
    padding: 3px 18px 3px 20px;
    border: 0;
    color: #111;
    background: transparent;
    font: inherit;
    text-align: left;
    white-space: nowrap;
}


.win98-context-menu__item:not(.is-disabled):focus {
    outline: none;
}

.win98-context-menu__item:not(.is-disabled):focus-visible {
    color: #fff;
    background: #000080;
    outline: 2px dotted #fff;
    outline-offset: -2px;
}

.win98-context-menu__item:not(.is-disabled):hover:not(:focus-visible) {
    color: #fff;
    background: #000080;
}

.win98-context-menu__item.is-bold {
    font-weight: 700;
}

.win98-context-menu__item.is-disabled {
    color: #808080;
    text-shadow: 1px 1px 0 #fff;
}

.win98-context-menu__shortcut,
.win98-context-menu__arrow {
    justify-self: end;
}

.win98-context-menu__sep {
    height: 1px;
    margin: 3px 2px;
    background: #808080;
    border-bottom: 1px solid #fff;
}

@media (max-width: 900px) {
    .win98-desktop {
        padding: 18px 12px 72px;
        overflow: auto;
    }

    .win98-desktop__icons {
        width: auto;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-bottom: 16px;
    }

    .win98-start-menu {
        width: min(300px, calc(100vw - 12px));
    }

    .win98-window,
    .win98-window.is-maximized {
        position: relative;
        top: auto;
        left: auto;
        width: 100%;
        min-width: 0;
        height: auto;
        margin-top: 12px;
    }

    .win98-window__titlebar {
        cursor: default;
    }

    .win98-window__resize-handle {
        display: none;
    }

    .win98-taskbar__window {
        max-width: 160px;
    }

    .win98-start-menu {
        width: min(300px, calc(100vw - 12px));
    }
}

@media (max-width: 640px) {
    body.win98-shell {
        overflow: hidden;
    }

    .win98-desktop-shell {
        min-height: 100dvh;
        height: 100dvh;
        overflow: hidden;
    }

    .win98-desktop {
        padding: 12px 12px calc(var(--win98-taskbar-height) + var(--win98-safe-bottom) + 16px);
        overflow: hidden;
    }

    .win98-window,
    .win98-window.is-maximized {
        position: fixed !important;
        left: var(--win98-window-mobile-margin) !important;
        right: var(--win98-window-mobile-margin) !important;
        top: var(--win98-window-mobile-margin) !important;
        bottom: calc(var(--win98-taskbar-height) + 2 * var(--win98-safe-bottom) + 10px + var(--win98-window-mobile-margin)) !important;
        width: auto !important;
        height: auto !important;
        max-width: none;
        max-height: none;
        min-width: 0;
        min-height: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 50;
    }

    .win98-window.is-template-calculator,
    .win98-window.is-template-minesweeper,
    .win98-window.is-template-tic-tac-toe,
    .win98-window.is-template-snake,
    .win98-window.is-template-breakout,
    .win98-window.is-template-freecell {
        max-width: calc(100vw - 2 * var(--win98-window-mobile-margin));
    }

    .win98-window.is-minimized,
    .win98-window.is-closed {
        display: none !important;
    }

    .win98-window__titlebar {
        flex: 0 0 auto;
        cursor: default;
    }

    .win98-window__body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .win98-window.is-template-shell-iframe .win98-window__body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .win98-window__resize-handle {
        display: none;
    }

    .win98-desktop__icons {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 18px 12px;
        width: auto;
        max-width: 100%;
        padding: 4px 4px 12px;
        margin: 0;
    }

    .win98-desktop-icon {
        min-width: 0;
        max-width: 100%;
        padding: 6px 4px;
        align-content: start;
        gap: 4px;
    }

    .win98-desktop-icon__label {
        max-width: 100%;
        margin: 0 auto;
        line-height: 1.2;
        overflow-wrap: anywhere;
        word-break: normal;
        text-wrap: balance;
    }
}
