:root {
    --bg: #0a0a0a;
    --fg-dim: #444;
    --fg: #e6e6e6;
    --accent: #ffd166;
    --highlight-bg: rgba(255, 209, 102, 0.1);
}

* {
    box-sizing: border-box;
}
html,
body {
    height: 100%;
}
/* Use dynamic viewport height on modern iOS to avoid showing browser UI */
#app {
    height: 100%;
}
@supports (height: 100dvh) {
    #app {
        height: 100dvh;
    }
}
@supports (-webkit-touch-callout: none) {
    /* Older iOS Safari fallback */
    html,
    body {
        height: -webkit-fill-available;
    }
    #app {
        height: -webkit-fill-available;
    }
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family:
        ui-sans-serif,
        system-ui,
        -apple-system,
        Segoe UI,
        Roboto,
        "Helvetica Neue",
        Arial,
        "Noto Sans",
        "Apple Color Emoji",
        "Segoe UI Emoji";
    overflow: hidden; /* hide page scroll */
    overscroll-behavior: none; /* prevent rubber-banding that can reveal bars */
}

#playpause-btn {
    position: fixed;
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 20;
    background: rgba(255, 255, 255, 0.08);
    color: var(--fg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    backdrop-filter: blur(4px);
    cursor: pointer;
}

#playpause-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

#orientation-hint {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    color: var(--fg);
    font-size: 1.25rem;
    z-index: 10;
}

/* Show hint when in portrait */
@media (orientation: portrait) {
    #orientation-hint {
        display: flex;
    }
}

#ribbon {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    overflow: hidden; /* our horizontal scroller lives inside */
}

#track {
    position: absolute;
    will-change: transform;
    white-space: nowrap;
    user-select: none;
    pointer-events: none;
    filter: blur(0.3px);
}

.phrase {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 1.25rem;
    color: var(--fg-dim);
    letter-spacing: 0.02em;
    opacity: 0.55; /* nearly unreadable while fast */
    font-size: clamp(32px, 7vh, 64px);
    line-height: 1.15;
    transform-origin: center center;
    transition: transform 180ms ease;
}

.phrase .line {
    display: block;
}

.phrase .uk {
    font-weight: 600;
    font-size: 33%;
}
.phrase .en {
    opacity: 0.9;
}

.sep {
    opacity: 0.35;
    margin: 0 0.75rem;
}

.highlight {
    color: var(--card-fg, var(--fg));
    opacity: 1;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
    background: var(--card-bg, var(--highlight-bg));
    border-radius: 6px;
    padding: 0.2rem 0.45rem;
    position: relative; /* enable z-index and ::before */
    z-index: 5;
    /* Blur what's behind the card area */
    -webkit-backdrop-filter: blur(8px) saturate(0.9);
    backdrop-filter: blur(8px) saturate(0.9);
}

.highlight::before {
    content: "";
    position: absolute;
    inset: -0.35rem -0.75rem; /* enlarge the glass area */
    background: var(--card-bg, var(--highlight-bg));
    border-radius: 10px;
    -webkit-backdrop-filter: blur(8px) saturate(0.9);
    backdrop-filter: blur(8px) saturate(0.9);
    z-index: -1; /* place underneath the text */
    pointer-events: none;
}

.phrase.zoomed {
    transform: scale(var(--zoom-scale, 1.28));
}

#center-line {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(-0.5px);
}

/* History button (bottom-left) */
#history-secret {
    position: fixed;
    left: calc(env(safe-area-inset-left, 0px) + 12px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 21;
    background: rgba(255, 255, 255, 0.08);
    color: var(--fg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    backdrop-filter: blur(4px);
    cursor: pointer;
}

#history-secret:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* --- History overlay (shown on device shake) --- */
#history-overlay {
    position: fixed;
    inset: 0;
    display: none; /* toggled to flex when active */
    align-items: center;
    justify-content: center;
    z-index: 50;
    background: rgba(0, 0, 0, 0.75);
    -webkit-backdrop-filter: blur(8px) saturate(0.9);
    backdrop-filter: blur(8px) saturate(0.9);
    /* Keep overlay content within safe areas */
    padding: calc(env(safe-area-inset-top, 0px)) calc(env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px))
        calc(env(safe-area-inset-left, 0px));
}

#history-overlay.active {
    display: flex;
}

.history-panel {
    width: min(92vw, 1000px);
    height: min(86vh, 720px);
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* On touch/mobile screens, make the panel fill the screen safely */
@media (pointer: coarse) {
    .history-panel {
        width: calc(100vw - (env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px)));
        height: calc(100dvh - (env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)));
        max-width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }
}

/* optional header removed to keep overlay minimal by default */

.history-body {
    flex: 1;
    overflow: auto;
}

#history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(14px, 1.9vh, 16px);
}

#history-table thead th {
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.06);
    color: var(--fg);
    text-align: left;
    padding: 8px 10px;
    z-index: 1;
}

#history-table tbody td {
    padding: 8px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    word-break: break-word;
}

#history-close {
    appearance: none;
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.08);
    color: var(--fg);
    padding: 12px 14px;
    font-size: 14px;
    cursor: pointer;
}

#history-close:hover {
    background: rgba(255, 255, 255, 0.14);
}
