/* ----------------------------------------------------------------
   System 7 bitmap fonts (self-hosted from system.css)
   Chicago_12 → ChiKareGo2 (recreation by Giles Booth)
   Geneva_9   → FindersKeepers (recreation by Giles Booth)
   ---------------------------------------------------------------- */
@font-face {
    font-family: Chicago_12;
    src: url('fonts/ChiKareGo2.woff2') format('woff2'),
        url('fonts/ChiKareGo2.woff') format('woff');
    font-display: swap;
}

@font-face {
    font-family: Geneva_9;
    src: url('fonts/FindersKeepers.woff2') format('woff2'),
        url('fonts/FindersKeepers.woff') format('woff');
    font-display: swap;
}

/* h1 keeps 1.4em, .book-link-h1 matches book text size */
/* Book reader links match THKS tab links */
.book-reader-content a {
    color: #268bd2;
    text-decoration: none;
    font-weight: bold;
    background-color: #268bd2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: opacity 0.2s;
}

.book-reader-content a:hover {
    opacity: 0.7;
}

@media (prefers-color-scheme: dark) {
    .book-reader-content a {
        color: #3294c2;
        background-color: #3294c2;
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
    }
}

body.force-dark .book-reader-content a {
    color: #3294c2;
    background-color: #3294c2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
}

body.force-dark h1,
body.force-dark .book-link-h1 {
    background-color: #3294c2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
    color: #3294c2;
}

/* Responsive tab overflow classes */
.tabs.tight-tabs .tab {
    padding: 4px 8px !important;
    font-size: 1em !important;
}

.tabs.tighter-tabs .tab {
    padding: 4px 4px !important;
    font-size: 0.9em !important;
}

.tabs.tiny-tabs .tab {
    padding: 4px 2px !important;
    font-size: 0.9em !important;
}

/* BOOK Tab Styles */
.book-list-container {
    height: 100%;
    overflow-y: auto;
    background: var(--bg-base);
    border: 2px solid var(--border-color);
    box-shadow: 2px 2px 0 var(--border-color);
    padding: 0;
    margin: 0;
    scrollbar-width: thin;
    scrollbar-color: #586e75 var(--bg-surface);
    /* Allow native vertical panning on touch devices (preserve momentum) */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.book-percent-read {
    float: right;
    text-align: right;
    min-width: 3em;
    font-weight: normal;
    color: inherit;
    vertical-align: middle;
}

/* Blocky, square-ended, dithered scrollbars (global + per-component fallback)
   - WebKit (Chrome / Safari / Edge): custom thumb with repeating dither and square end caps
   - Firefox: fallback using scrollbar-color and scrollbar-width
*/
/* Firefox fallback for all scrollable elements */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) var(--bg-surface);
}

/* WebKit-based browsers (Chrome / Safari / Edge) */
*::-webkit-scrollbar {
    width: 18px;
    height: 18px;
    background: var(--bg-surface);
}

*::-webkit-scrollbar-thumb {
    /* dithered diagonal pattern using the two theme colors */
    background: repeating-linear-gradient(135deg, var(--scroll-thumb) 0 4px, var(--scroll-thumb-alt) 4px 8px);
    border: 2px solid var(--border-color);
    border-radius: 0;
    /* square end caps */
    min-height: 32px;
    box-shadow: none;
}

*::-webkit-scrollbar-track {
    background: var(--bg-surface);
    border-radius: 0;
}

*::-webkit-scrollbar-corner {
    background: var(--bg-surface);
}

/* Keep the component-specific rule for .book-list-container so it remains explicit */
.book-list-container::-webkit-scrollbar {
    width: 18px;
    background: var(--bg-surface);
}

.book-list-container::-webkit-scrollbar-thumb {
    background: repeating-linear-gradient(135deg, var(--scroll-thumb) 0 4px, var(--scroll-thumb-alt) 4px 8px);
    border: 2px solid var(--border-color);
    border-radius: 0;
    min-height: 32px;
}

.book-list-container::-webkit-scrollbar-track {
    background: var(--bg-surface);
}

.book-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.book-list-item {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    padding: 5px 18px 5px 32px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    background: none;
    color: var(--text-primary);
    transition: background 0.15s, color 0.15s;
    outline: none;
    position: relative;
    user-select: none;
}

.book-list-item:last-child {
    border-bottom: none;
}

.book-list-item:focus-visible {
    outline: 3px solid #268bd2;
    background: var(--bg-surface);
}

.book-list-item:hover {
    background: var(--bg-surface);
}

.book-list-item .offline-indicator {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9em;
    color: #35b1a8;
}

.book-list-item.read {
    text-decoration: line-through;
    color: #93a1a1;
    font-weight: normal;
}

.book-list-item.started {
    font-weight: bold;
}

.book-list-item.unread {
    font-weight: normal;
}

.book-title {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
}

.book-author,
.book-author-name {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
}

/* Book reader container */
.book-reader-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-base);
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
    overflow: hidden;
    /* System 7 double-border */
    border: 2px solid var(--border-color);
    box-shadow:
        inset 0 0 0 1px var(--bg-surface),
        inset 0 0 0 3px var(--border-color);
}

.book-reader-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    /* System 7 horizontal stripe title bar */
    background-color: var(--bg-surface);
    background-image: linear-gradient(var(--border-color) 50%, transparent 50%);
    background-size: 100% 3px;
    background-position: top left;
    background-clip: content-box;
    border-bottom: 2px solid var(--border-color);
    padding: 6px 12px;
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 0.9em;
    font-weight: bold;
    letter-spacing: 1px;
    min-height: 28px;
}

.book-reader-close {
    cursor: pointer;
    font-size: 1.1em;
    background-color: var(--bg-surface);
    border: 2px solid var(--border-color);
    color: #dc322f;
    font-weight: bold;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    user-select: none;
    z-index: 1;
    transition: background-color 0.1s;
}

.book-reader-close:hover {
    background-color: var(--border-color);
    color: var(--bg-base);
}

.book-reader-close:active {
    background-color: #dc322f;
    color: var(--bg-surface);
}

.book-reader-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 18px 24px 18px;
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 1.1em;
    /* Use a dedicated --book-text variable so we can increase contrast in
       light mode without changing the global --text-primary for other UI. */
    color: var(--book-text, var(--text-primary));
    background: var(--bg-base);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.7;
    user-select: text;
    -webkit-user-select: text;
    outline: none;
    /* Allow native vertical panning on touch devices (preserve momentum) */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.book-reader-content:focus-visible {
    outline: 3px solid #268bd2;
}

/* ASCII spinner */
.book-spinner {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 1.2em;
    color: #268bd2;
    text-align: center;
    margin: 48px 0 0 0;
    letter-spacing: 2px;
    animation: book-spinner-anim 1s steps(4) infinite;
    user-select: none;
}

@keyframes book-spinner-anim {
    0% {
        opacity: 1;
    }

    25% {
        opacity: 0.7;
    }

    50% {
        opacity: 0.5;
    }

    75% {
        opacity: 0.7;
    }

    100% {
        opacity: 1;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* Disable all mobile gestures globally */
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Allow text selection and native touch-callout inside the Book reader only.
   This overrides the global "user-select: none" reset but keeps interaction
   blocked for the rest of the UI. The rule targets the book reader container
   (present only when a book is open) so selection is enabled only while
   reading. */
.book-reader-container,
.book-reader-container * {
    -webkit-user-select: text !important;
    user-select: text !important;
    -webkit-touch-callout: default !important;
    touch-action: auto !important;
}

/* Solarized Light (default) */
:root {
    --bg-base: #fdf6e3;
    --bg-surface: #eee8d5;
    --text-primary: #586e75;
    --text-secondary: #93a1a1;
    --border-color: #93a1a1;
    /* scrollbar colors used for dithered thumb pattern */
    --scroll-thumb: #586e75;
    --scroll-thumb-alt: #eee8d5;
}

/* Book-specific text override: increase contrast for book body in light mode
   without altering global --text-primary used elsewhere. Defaults to the
   global value so dark mode preserves existing styling. */
:root {
    --book-text: var(--text-primary);
}

@media (prefers-color-scheme: light) {

    /* Stronger, darker book text for better legibility on light backgrounds */
    :root {
        --book-text: #073642;
        /* Solarized base02 - high contrast on light bg */
    }
}

@media (prefers-color-scheme: dark) {

    /* Ensure book text in dark mode stays the intended lighter shade */
    :root {
        --book-text: var(--text-primary);
    }
}

body.force-light {
    --book-text: #073642;
}

body.force-dark {
    --book-text: var(--text-primary);
}

/* Solarized Dark */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-base: #002b36;
        --bg-surface: #073642;
        --text-primary: #839496;
        --text-secondary: #586e75;
        --border-color: #586e75;
        /* dark theme scrollbar variants */
        --scroll-thumb: #839496;
        --scroll-thumb-alt: #073642;
    }
}

body {
    /* Subtle dither outside the main window: 1-in-4 dot pattern over bg-base */
    background-color: var(--bg-base);
    background-image: radial-gradient(circle, var(--text-secondary) 1px, transparent 1px);
    background-size: 6px 6px;
    color: var(--text-primary);
    font-family: 'Courier New', 'Courier', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    /* Disable mobile gestures */
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-overflow-scrolling: auto;
    position: fixed;
    width: 100%;
    height: 100%;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
}

/* Mobile devices: position at top instead of center to avoid Safari toolbar issues */
@media (pointer: coarse) and (hover: none) {
    body {
        align-items: flex-start;
        padding-top: 20px;
    }
}

.container {
    position: relative;
    width: min(600px, 100%, calc((100vh - 40px) * 2 / 3));
    aspect-ratio: 2 / 3;
    max-height: 600px;
    max-width: 400px;
    background-color: var(--bg-surface);
    display: flex;
    flex-direction: column;
    /* System 7 double-border: outer 2px → 1px gap → inner 2px → 4px drop shadow */
    border: 2px solid var(--border-color);
    box-shadow:
        0 0 0 1px var(--bg-surface),
        0 0 0 3px var(--border-color),
        6px 6px 0 1px var(--border-color);
    outline: none;
}

main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.menu-bar {
    /* System 7 title-bar horizontal stripe pattern */
    background-color: var(--bg-surface);
    background-image: linear-gradient(var(--border-color) 50%, transparent 50%);
    background-size: 100% 3px;
    background-position: top left;
    background-clip: content-box;
    color: var(--text-primary);
    padding: 6px 8px;
    border-bottom: 2px solid var(--border-color);
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 1px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    overflow: hidden;
    min-height: 28px;
}

/* The center title text sits in a 'chip' — solid background behind the title
   so it pops out of the stripes exactly as in System 7 */
.menu-bar>span:nth-child(2) {
    flex: 0 1 auto;
    /* shrink to text width, don't grow */
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--bg-surface);
    padding: 0 8px;
    position: relative;
    z-index: 1;
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 0.9em;
    letter-spacing: 1px;
    border: 2px solid var(--border-color);
    /* Centre the chip within the flex row */
    margin: 0 auto;
}

/* System 7-style window chrome box buttons */
.theme-toggle {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.85em;
    line-height: 1;
    padding: 2px 0 0 0;
    flex-shrink: 0;
    transition: background-color 0.1s;
    font-family: inherit;
    position: relative;
    z-index: 1;
}

.theme-toggle:active {
    background-color: var(--text-primary);
    color: var(--bg-base);
}

.mute-toggle {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.75em;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    transition: background-color 0.1s;
    font-family: inherit;
    position: relative;
    z-index: 1;
}

.mute-toggle:active {
    background-color: var(--text-primary);
    color: var(--bg-base);
}

.reset-app {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.85em;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    transition: background-color 0.1s;
    font-family: inherit;
    position: relative;
    z-index: 1;
}

.reset-app:active {
    background-color: var(--text-primary);
    color: var(--bg-base);
}

.menu-bar-left {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    z-index: 1;
}

.menu-bar-right {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    z-index: 1;
}

.menu-bar-right>span:last-child {
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

/* Thin separator line between title bar and tabs */
.separator {
    height: 0;
    border-top: 2px solid var(--border-color);
    flex-shrink: 0;
}

/* Force dark mode when class is applied */
body.force-dark {
    --bg-base: #002b36;
    --bg-surface: #073642;
    --text-primary: #839496;
    --text-secondary: #586e75;
    --border-color: #586e75;
}

/* Force light mode when class is applied */
body.force-light {
    --bg-base: #fdf6e3;
    --bg-surface: #eee8d5;
    --text-primary: #586e75;
    --text-secondary: #93a1a1;
    --border-color: #93a1a1;
}

.tabs {
    display: flex;
    background-color: var(--border-color);
    border-bottom: 2px solid var(--border-color);
}

.tab {
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.85em;
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    background-color: var(--border-color);
    color: var(--bg-base);
    border-right: 1px solid var(--text-secondary);
    font-weight: bold;
    letter-spacing: 0;
    transition: background-color 0.15s;
    user-select: none;
    white-space: nowrap;
    flex: 1 1 0;
    text-align: center;
    /* 3D bevel on inactive tabs */
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.2),
        inset -1px -1px 0 rgba(0, 0, 0, 0.15);
}

.tab:hover {
    background-color: var(--text-primary);
}

.tab.active {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    /* Remove bottom border so active tab appears lifted into content area */
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.2),
        inset -1px 0 0 rgba(0, 0, 0, 0.1),
        0 2px 0 var(--bg-surface);
}

.tab-content {
    display: none;
}

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

.content {
    flex: 1;
    padding: 24px;
    overflow: hidden;
    line-height: 1.6;
}

#home-content.active {
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-family: Chicago_12, 'Courier New', Courier, monospace;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    background-color: var(--bg-surface);
}

#bonk-content {
    padding: 0;
    overflow: hidden;
    position: relative;
}

#blok-content {
    padding: 0;
    overflow: hidden;
    position: relative;
}

#draw-content {
    padding: 0;
    overflow: hidden;
    position: relative;
}

#note-content {
    padding: 0;
    overflow: hidden;
}

#calc-content.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

#drawCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    background-color: var(--bg-surface);
}

#blokCanvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    background-color: var(--bg-surface);
}

.ascii-art {
    color: #dc322f;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.7em;
    line-height: 1.2;
    margin-bottom: 16px;
    white-space: pre;
    text-align: left;
    transition: text-shadow 0.3s ease;
    cursor: pointer;
    user-select: none;
}

.ascii-art.glow {
    animation: ascii-glow 0.5s ease-out;
}

@keyframes ascii-glow {
    0% {
        text-shadow: 0 0 2px #dc322f, 0 0 4px #dc322f;
    }

    50% {
        text-shadow: 0 0 4px #dc322f, 0 0 8px #dc322f;
    }

    100% {
        text-shadow: none;
    }
}

@media (prefers-color-scheme: dark) {
    .ascii-art {
        color: #db5b26;
    }

    @keyframes ascii-glow {
        0% {
            text-shadow: 0 0 2px #db5b26, 0 0 4px #db5b26;
        }

        50% {
            text-shadow: 0 0 4px #db5b26, 0 0 8px #db5b26;
        }

        100% {
            text-shadow: none;
        }
    }
}

body.force-dark .ascii-art {
    color: #db5b26;
}

body.force-dark .ascii-art.glow {
    animation: ascii-glow-dark 2s ease-out;
}

@keyframes ascii-glow-dark {
    0% {
        text-shadow: 0 0 2px #db5b26, 0 0 4px #db5b26;
    }

    50% {
        text-shadow: 0 0 4px #db5b26, 0 0 8px #db5b26;
    }

    100% {
        text-shadow: none;
    }
}

.ascii-art.glow-active {
    animation: ascii-glow-pulse 2s ease-in-out infinite;
}

@keyframes ascii-glow-pulse {
    0%, 100% {
        text-shadow: 0 0 2px #dc322f, 0 0 4px #dc322f;
    }

    50% {
        text-shadow: 0 0 6px #dc322f, 0 0 12px #dc322f, 0 0 20px #dc322f;
    }
}

@media (prefers-color-scheme: dark) {
    @keyframes ascii-glow-pulse {
        0%, 100% {
            text-shadow: 0 0 2px #db5b26, 0 0 4px #db5b26;
        }

        50% {
            text-shadow: 0 0 6px #db5b26, 0 0 12px #db5b26, 0 0 20px #db5b26;
        }
    }
}

body.force-dark .ascii-art.glow-active {
    animation: ascii-glow-pulse-dark 2s ease-in-out infinite;
}

@keyframes ascii-glow-pulse-dark {
    0%, 100% {
        text-shadow: 0 0 2px #db5b26, 0 0 4px #db5b26;
    }

    50% {
        text-shadow: 0 0 6px #db5b26, 0 0 12px #db5b26, 0 0 20px #db5b26;
    }
}

h1 {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 1.4em;
    margin-bottom: 16px;
    letter-spacing: 1px;
    background-color: #1e7bb2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: #1e7bb2;
}

@media (prefers-color-scheme: dark) {
    h1 {
        background-color: #3294c2;
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
        color: #3294c2;
    }
}

body.force-dark h1 {
    background-color: #3294c2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
    color: #3294c2;
}

p {
    margin-bottom: 16px;
    text-align: left;
    font-weight: 500;
}

.highlight {
    font-weight: bold;
    background-color: #dc322f;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: #dc322f;
}

@media (prefers-color-scheme: dark) {
    .highlight {
        background-color: #db5b26;
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
        color: #db5b26;
    }
}

body.force-dark .highlight {
    background-color: #db5b26;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
    color: #db5b26;
}

.cursor {
    animation: blink 1s infinite;
    background-color: var(--text-primary);
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--text-primary);
}

@media (prefers-color-scheme: dark) {
    .cursor {
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
    }
}

body.force-dark .cursor {
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

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

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .cursor {
        animation: none;
        opacity: 1;
    }

    .clock-colon {
        animation: none;
        opacity: 1;
    }
}

/* Focus indicators for accessibility */
.tab:focus {
    /* Hide the native focus ring when the tab receives focus programmatically or via mouse.
       Keep :focus-visible below so keyboard users still see a clear outline. */
    outline: none;
}

.tab:focus-visible,
.calc-btn:focus-visible,
.note-key:focus-visible,
.theme-toggle:focus-visible,
.mute-toggle:focus-visible,
.reset-app:focus-visible,
.speed-step:focus-visible,
.download-icon:focus-visible,
.book-list-item:focus-visible,
.book-reader-close:focus-visible,
.footer-text:focus-visible {
    outline: 3px solid #268bd2;
    outline-offset: 2px;
}

/* Accessibility behavior: keep all action target outlines and high contrast on keyboard focus */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 3px solid #268bd2;
    outline-offset: 2px;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #268bd2;
    color: var(--bg-base);
    padding: 8px 16px;
    text-decoration: none;
    font-weight: bold;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Visually hidden but accessible to screen readers */
.visually-hidden {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Instruction popup styles */
.instruction-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-surface);
    max-width: 400px;
    width: 80%;
    z-index: 50;
    text-align: center;
    display: flex;
    flex-direction: column;
    /* System 7 double-border */
    border: 2px solid var(--border-color);
    box-shadow:
        0 0 0 1px var(--bg-surface),
        0 0 0 3px var(--border-color),
        6px 6px 0 1px var(--border-color);
}

.instruction-popup-title {
    /* System 7 horizontal stripe title bar — matches .menu-bar */
    background-color: var(--bg-surface);
    background-image: linear-gradient(var(--border-color) 50%, transparent 50%);
    background-size: 100% 3px;
    background-position: top left;
    background-clip: content-box;
    color: var(--text-primary);
    padding: 6px 12px;
    border-bottom: 2px solid var(--border-color);
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 1px;
    text-align: center;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Title chip — solid background behind the text so it reads against the stripes */
.instruction-popup-title>span {
    background: var(--bg-surface);
    padding: 3px 8px;
    position: relative;
    z-index: 1;
    border: 2px solid var(--border-color);
    line-height: 1;
}

.instruction-popup-content {
    padding: 12px;
    font-family: Chicago_12, 'Courier New', Courier, monospace;
}

.instruction-popup-content p {
    margin-bottom: 12px;
    text-align: center;
    line-height: 1.6;
}

.instruction-popup button {
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    font-size: 1em;
    font-weight: bold;
    padding: 10px 28px;
    border: 2px solid var(--border-color);
    background-color: #859900;
    background-image:
        linear-gradient(45deg, rgba(0, 0, 0, 0.12) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.12) 75%),
        linear-gradient(45deg, rgba(0, 0, 0, 0.12) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.12) 75%);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
    color: var(--bg-base);
    cursor: pointer;
    /* 3D bevel */
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.25),
        inset -1px -1px 0 rgba(0, 0, 0, 0.3),
        2px 2px 0 var(--border-color);
    margin-top: 16px;
    letter-spacing: 1px;
    transition: background-color 0.1s;
}

.instruction-popup button:active {
    box-shadow:
        inset -1px -1px 0 rgba(255, 255, 255, 0.25),
        inset 1px 1px 0 rgba(0, 0, 0, 0.3),
        0 0 0 var(--border-color);
    transform: translate(2px, 2px);
}

.instruction-popup button:hover {
    background-color: #719e07;
}

.instruction-popup button:active {
    box-shadow: 0px 0px 0px var(--border-color);
    transform: translate(2px, 2px);
}

/* Clock popup styles */
.clock-popup {
    max-width: 400px;
    width: 80%;
    z-index: 1000;
    /* Use fixed positioning so the popup sits above the full-screen overlay
       and remains centered regardless of scroll or parent stacking contexts. */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.clock-popup-content {
    padding: 12px 12px 12px 12px;
}

/* Overlay for blocking interactions when clock is open */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Single-layer dot stipple — ~20% coverage, genuinely see-through */
    background-color: transparent;
    background-image: radial-gradient(circle, var(--text-secondary) 1px, transparent 1px);
    background-size: 4px 4px;
    z-index: 999;
    display: none;
}

#ascii-clock-display {
    font-family: 'Courier New', 'Courier', monospace;
    font-size: 0.7em;
    line-height: 1.1;
    white-space: pre;
    text-align: center;
    margin-bottom: 12px;
    user-select: none;
    background-color: var(--text-primary);
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--text-primary);
}

/* Allow colored spans in clock to override the dithering */
#ascii-clock-display span[style*="color"] {
    background: none !important;
    -webkit-background-clip: initial !important;
    background-clip: initial !important;
    -webkit-text-fill-color: initial !important;
}

@media (prefers-color-scheme: dark) {
    #ascii-clock-display {
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
    }
}

body.force-dark #ascii-clock-display {
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
}

#clock-date-display {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 1em;
    font-weight: bold;
    text-align: center;
    margin-bottom: 12px;
    letter-spacing: 1px;
    background-color: var(--text-primary);
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--text-primary);
}

@media (prefers-color-scheme: dark) {
    #clock-date-display {
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
    }
}

body.force-dark #clock-date-display {
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
}

#clock-digital-display {
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 0.9em;
    font-weight: 700;
    text-align: center;
    margin-bottom: 12px;
    letter-spacing: 2px;
    color: var(--text-primary);
}

#clock-home-btn {
    margin-top: 0;
}

.footer {
    border-top: 2px solid var(--border-color);
    padding: 6px 10px;
    /* System 7 horizontal stripe like the title bar, using border-color */
    background-color: var(--bg-surface);
    background-image: linear-gradient(var(--border-color) 50%, transparent 50%);
    background-size: 100% 3px;
    background-position: top left;
    background-clip: content-box;
    color: var(--text-primary);
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-size: 0.85em;
    font-weight: 500;
    text-align: left;
    letter-spacing: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.footer-text {
    cursor: pointer;
    font-weight: bold;
    user-select: none;
    background: var(--bg-surface);
    padding: 3px 4px;
    position: relative;
    z-index: 1;
    white-space: nowrap;
    line-height: 1;
    border: 2px solid var(--border-color);
}

/* Credits tab styles */
#thks-content {
    overflow: hidden;
}

#thks-content.active {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.thks-header {
    /* System 7 horizontal stripe — matches .menu-bar and popup titles */
    background-color: var(--bg-surface);
    background-image: linear-gradient(var(--border-color) 50%, transparent 50%);
    background-size: 100% 3px;
    background-position: top left;
    background-clip: content-box;
    padding: 6px 16px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    font-family: Chicago_12, 'Courier New', Courier, monospace;
    font-weight: bold;
    letter-spacing: 1px;
    text-align: center;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thks-content-area {
    /* Match the `.content` formatting: let the outer `.content` container
        provide the 24px padding, keep this area unpadded so text lines up.
        Also ensure list spacing matches paragraph spacing in HOME. */
    padding: 0;
    overflow-y: auto;
    max-height: 60vh;
    min-height: 200px;
    -webkit-overflow-scrolling: touch;
    outline: none;
    scroll-behavior: smooth;
    /* visually match book list scroll area */
    border-radius: 4px;
    box-shadow: none;
    /* Hide scrollbars on Webkit */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-surface);
    font-family: Chicago_12, 'Courier New', Courier, monospace;
}

.thks-content-area::-webkit-scrollbar {
    width: 8px;
    background: var(--bg-surface);
}

.thks-content-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.thks-content-area a {
    color: #268bd2;
    text-decoration: none;
    font-weight: bold;
    background-color: #268bd2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

@media (prefers-color-scheme: dark) {
    .thks-content-area a {
        color: #3294c2;
        background-color: #3294c2;
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
    }
}

body.force-dark .thks-content-area a {
    color: #3294c2;
    background-color: #3294c2;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
}

.thks-content-area a:hover {
    opacity: 0.7;
}

.thks-content-area ul {
    list-style-type: none;
    /* Remove the small top gap so lists align with surrounding content */
    margin: 0 0 16px 0;
    padding: 0;
}

.thks-content-area li {
    /* Match paragraph spacing in `.content` (16px bottom) so the
       credits read like normal paragraphs in HOME */
    margin-bottom: 16px;
    padding-left: 0;
}

.thks-content-area li:before {
    /* Hide default bullets and any pseudo-element markers so list items are not indented */
    display: none;
}

.clock {
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    font-weight: bold;
    padding: 3px 4px;
    background: var(--bg-surface);
    color: var(--text-primary);
    letter-spacing: 1px;
    user-select: none;
    cursor: pointer;
    border: 2px solid var(--border-color);
    line-height: 1;
}

.clock-colon {
    animation: blink 1s infinite;
}

.divider {
    color: var(--text-secondary);
    margin-top: -6px;
    margin-bottom: 10px;
}

/* Calculator styles */
.calculator {
    max-width: 380px;
    max-height: 600px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* System 7 double-border */
    border: 2px solid var(--border-color);
    padding: 8px;
    box-shadow:
        0 0 0 1px var(--bg-surface),
        0 0 0 3px var(--border-color);
}

.calc-display {
    background-color: #073642;
    border: 3px solid var(--border-color);
    padding: 8px 12px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

body.force-light .calc-display {
    background-color: #93a1a1;
}

@media (prefers-color-scheme: light) {
    body:not(.force-dark) .calc-display {
        background-color: #93a1a1;
    }
}

.calc-equation {
    display: none;
}

.calc-result {
    font-size: 0.6em;
    font-weight: bold;
    text-align: right;
    font-family: 'Courier New', Courier, monospace;
    line-height: 1.1;
    white-space: pre;
    overflow: hidden;
    color: #cb4b16;
    text-shadow: 0 0 6px rgba(210, 110, 38, 0.4);
    letter-spacing: 0.05em;
}

@media (prefers-color-scheme: dark) {
    .calc-result {
        color: #2aa198;
        text-shadow: 0 0 8px rgba(42, 161, 152, 0.6);
    }
}

body.force-light .calc-result {
    color: #cb4b16;
    text-shadow: 0 0 6px rgba(210, 78, 38, 0.4);
}

body.force-dark .calc-result {
    color: #2aa198;
    text-shadow: 0 0 8px rgba(42, 161, 152, 0.6);
}

.calc-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.calc-btn {
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    font-size: 1.3em;
    font-weight: bold;
    padding: 16px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-surface);
    background-image:
        linear-gradient(45deg, rgba(0, 0, 0, 0.12) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.12) 75%),
        linear-gradient(45deg, rgba(0, 0, 0, 0.12) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.12) 75%);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.1s;
    /* 3D bevel: light top-left, dark bottom-right */
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.35),
        inset -1px -1px 0 rgba(0, 0, 0, 0.25),
        2px 2px 0 var(--border-color);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.calc-btn:hover {
    background-color: var(--bg-base);
}

.calc-btn:active {
    /* reverse bevel on press */
    box-shadow:
        inset -1px -1px 0 rgba(255, 255, 255, 0.35),
        inset 1px 1px 0 rgba(0, 0, 0, 0.25),
        0 0 0 var(--border-color);
    transform: translate(2px, 2px);
}

.calc-operator {
    background-color: #268bd2;
    color: var(--bg-base);
}

.calc-operator:hover {
    background-color: #1e7bb2;
}

.calc-equals {
    background-color: #859900;
    color: var(--bg-base);
}

.calc-equals:hover {
    background-color: #719e07;
}

.calc-clear {
    background-color: #dc322f;
    color: var(--bg-base);
}

.calc-clear:hover {
    background-color: #cc221f;
}

.calc-wide {
    grid-column: span 2;
}

.calc-tall {
    grid-row: span 2;
}

/* Note styles */
.note-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
}

.note-text-area {
    flex: 1;
    background-color: var(--bg-base);
    padding: 16px;
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    font-size: 1.6em;
    font-weight: bold;
    overflow-wrap: break-word;
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-y: auto;
    box-shadow: inset 2px 2px 4px rgba(0, 0, 0, 0.1);
    line-height: 1.4;
    user-select: none;
    -webkit-user-select: none;
    text-align: left;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    position: relative;
}

.note-text-area>div {
    background-color: var(--text-primary);
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 4px);
    background-size: 4px 4px;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--text-primary);
}

@media (prefers-color-scheme: dark) {
    .note-text-area>div {
        background-image:
            repeating-linear-gradient(0deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px),
            repeating-linear-gradient(90deg,
                transparent,
                transparent 2px,
                rgba(0, 0, 0, 0.08) 2px,
                rgba(0, 0, 0, 0.08) 4px);
    }
}

body.force-dark .note-text-area>div {
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
}

#noteText {
    word-break: break-word;
}

.note-keyboard {
    height: 35%;
    background-color: var(--text-secondary);
    padding: 6px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-top: 3px solid var(--border-color);
}

.note-keyboard-row {
    display: flex;
    gap: 2px;
    justify-content: space-between;
    flex: 1;
}

.note-key {
    flex: 1 1 auto;
    min-width: 0;
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    font-size: 0.9em;
    font-weight: bold;
    border: 2px solid var(--border-color);
    background-color: var(--bg-surface);
    background-image:
        linear-gradient(45deg, rgba(0, 0, 0, 0.12) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.12) 75%),
        linear-gradient(45deg, rgba(0, 0, 0, 0.12) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.12) 75%);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.1s;
    /* 3D bevel */
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.35),
        inset -1px -1px 0 rgba(0, 0, 0, 0.25);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.note-key:hover {
    background-color: var(--bg-base);
}

.note-key:active {
    box-shadow:
        inset -1px -1px 0 rgba(255, 255, 255, 0.35),
        inset 1px 1px 0 rgba(0, 0, 0, 0.25);
    background-color: var(--text-secondary);
}

.note-key.space {
    flex: 8;
}

.note-key.backspace {
    background-color: #dc322f;
    color: var(--bg-base);
    flex: 2;
    font-size: 1.1em;
}

.note-key.backspace:hover {
    background-color: #cc221f;
}

.note-key.shift {
    background-color: #2aa198;
    color: var(--bg-base);
    flex: 2;
}

.note-key.shift:hover {
    background-color: #239992;
}

.note-key.shift.active {
    background-color: #859900;
}

.note-key.shift.active:hover {
    background-color: #719e07;
}

/* Download icon styles */
.download-icon {
    position: absolute;
    bottom: 0.4rem;
    right: 0.6rem;
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: opacity 0.2s;
    z-index: 10;
    line-height: 1;
}

.download-icon:hover {
    opacity: 0.7;
}

.download-icon:active {
    opacity: 0.5;
}

/* Media queries for short displays - prioritize home page content */
@media (max-height: 700px) {
    .content {
        padding: 16px;
    }

    /* Reduce padding further for THKS tab on short screens */
    #thks-content.content {
        padding: 12px;
    }

    .ascii-art {
        font-size: 0.6em;
        margin-bottom: 12px;
    }

}

@media (max-height: 600px) {
    .content {
        padding: 12px;
    }

    /* Further reduce padding for THKS tab on very short screens */
    #thks-content.content {
        padding: 8px;
    }

    .ascii-art {
        font-size: 0.55em;
        margin-bottom: 8px;
        line-height: 1.1;
    }


    .divider {
        margin-top: -4px;
        margin-bottom: 6px;
    }
}

@media (max-height: 500px) {
    .menu-bar {
        padding: 6px 10px;
        font-size: 0.95em;
    }

    .tabs {
        font-size: 0.95em;
    }

    .tab {
        padding: 6px 12px;
    }

    .content {
        padding: 8px 12px;
    }

    /* Minimal padding for THKS tab on extra short screens */
    #thks-content.content {
        padding: 6px 8px;
    }

    .ascii-art {
        font-size: 0.5em;
        margin-bottom: 6px;
        line-height: 1.05;
    }


    .divider {
        margin-top: -4px;
        margin-bottom: 4px;
    }

    .footer {
        padding: 6px 10px;
        font-size: 0.85em;
    }
}

@media (max-height: 450px) {
    .menu-bar {
        padding: 4px 8px;
        font-size: 0.9em;
    }

    .tabs {
        font-size: 0.9em;
    }

    .tab {
        padding: 4px 10px;
    }

    .content {
        padding: 6px 10px;
    }

    /* Ultra-minimal padding for THKS tab on extremely short screens */
    #thks-content.content {
        padding: 4px 6px;
    }

    .ascii-art {
        font-size: 0.45em;
        margin-bottom: 4px;
        line-height: 1.0;
    }


    .divider {
        margin-top: -3px;
        margin-bottom: 3px;
    }

    .footer {
        padding: 4px 8px;
        font-size: 0.8em;
    }
}

@media (max-width: 640px) {
    body {
        padding: 10px;
    }

    .container {
        width: min(100%, calc((100vh - 20px) * 2 / 3));
    }

    .ascii-art {
        font-size: 0.5em;
    }


    .content {
        padding: 16px;
    }

    #calc-content.active {
        padding: 24px 16px;
    }

    .tab {
        padding: 8px 12px;
        letter-spacing: 0.5px;
        font-size: 0.95em;
    }

    .calc-btn {
        padding: 12px;
        font-size: 1.3em;
    }

    .calc-result {
        font-size: 0.5em;
    }

    .note-key {
        font-size: 0.9em;
        min-width: 0;
    }

    .note-text-area {
        font-size: 1.4em;
    }
}

/* Mobile touch devices: use dynamic viewport and top alignment */
@media (max-width: 640px) and (pointer: coarse) and (hover: none) {
    body {
        align-items: flex-start;
        padding-top: 10px;
    }

    .container {
        width: min(100%, calc((100dvh - 20px) * 2 / 3));
    }
}

/* Combined media queries for short AND narrow screens */
@media (max-width: 640px) and (max-height: 600px) {
    .content {
        padding: 10px;
    }

    .ascii-art {
        font-size: 0.45em;
        margin-bottom: 6px;
    }

}

@media (max-width: 640px) and (max-height: 500px) {
    .menu-bar {
        padding: 5px 8px;
    }

    .tab {
        padding: 5px 10px;
    }

    .content {
        padding: 8px;
    }

    .ascii-art {
        font-size: 0.4em;
        margin-bottom: 4px;
        line-height: 1.05;
    }


    .footer {
        padding: 5px 8px;
    }
}

@media (max-width: 400px) {
    .tab {
        padding: 8px 10px;
        letter-spacing: 0.3px;
        font-size: 0.9em;
    }
}

@media (max-width: 350px) {
    .tab {
        padding: 8px 8px;
        letter-spacing: 0px;
        font-size: 0.85em;
    }
}

/* Very short screens - reduce calculator button padding further */
@media (max-height: 600px) {
    .calc-btn {
        padding: 10px;
        font-size: 1.2em;
    }

    .calc-display {
        padding: 6px 10px;
    }

    .calc-result {
        font-size: 0.5em;
    }
}

/* Extra short screens - minimal padding */
@media (max-height: 500px) {
    .calc-btn {
        padding: 6px;
        font-size: 1em;
    }

    .calc-display {
        padding: 4px 8px;
    }

    .calc-result {
        font-size: 0.45em;
    }
}

/* Small screens - adjust speed slider */
@media (max-width: 400px) {
    .blok-speed-slider {
        font-size: 12px;
        gap: 3px;
    }

    .blok-speed-slider .speed-step {
        padding: 1px 4px;
        min-width: 20px;
    }
}

/* Blok speed slider styles */
.blok-speed-slider {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    font-size: 14px;
    font-weight: bold;
    user-select: none;
    z-index: 10;
}

.blok-speed-slider .speed-label {
    color: var(--text-primary);
}

.blok-speed-slider .speed-step {
    cursor: pointer;
    padding: 2px 6px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    transition: background-color 0.1s;
    min-width: 24px;
    text-align: center;
    font-family: Chicago_12, 'Courier New', 'Courier', monospace;
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.3),
        inset -1px -1px 0 rgba(0, 0, 0, 0.2);
}

.blok-speed-slider .speed-step:hover {
    background-color: var(--bg-base);
}

.blok-speed-slider .speed-step.active {
    background-color: #268bd2;
    color: var(--bg-base);
    border-color: #268bd2;
    box-shadow:
        inset -1px -1px 0 rgba(255, 255, 255, 0.2),
        inset 1px 1px 0 rgba(0, 0, 0, 0.25);
}