:root {
    --mac-w-px: 512;
    --mac-h-px: 342;
    --mac-width: calc(var(--mac-w-px) * 1px);
    --mac-height: calc(var(--mac-h-px) * 1px);
    --surface-0: rgba(255, 255, 255, 0.9);
    --surface-1: rgba(246, 246, 248, 0.8);
    --surface-2: rgba(226, 226, 230, 0.55);
    --border-soft: rgba(120, 120, 125, 0.25);
    --border-strong: rgba(90, 90, 95, 0.35);
    --shadow-soft: 0 10px 28px rgba(30, 30, 40, 0.18);
    --shadow-strong: 0 18px 40px rgba(22, 22, 30, 0.24);
    --text-title: hsl(39deg 10.41% 43.77%);
    --text-primary: hsl(39deg 10.41% 43.77%);
    --text-secondary: hsl(39deg 10.41% 43.77%);
    --accent-muted: rgba(160, 160, 165, 0.35);
    --tint-highlight: rgba(190, 190, 200, 0.5);
    --timelapse-active-bg: rgba(255, 214, 214, 0.7);
    --timelapse-active-border: rgba(255, 175, 175, 0.7);
    --timelapse-active-text: #8f1a1a;
}

body {
    margin: 0;
    min-height: 99vh;
    font-family: 'IBM Plex Mono', 'SFMono-Regular', Menlo, Monaco, 'Courier New', monospace;
    background: radial-gradient(140% 140% at 50% 0%, hsl(39deg 38.44% 88.05%) 0%, hsl(39deg 49.41% 88.42%) 45%, hsl(39deg 26.79% 78.21%) 100%);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

.wrapper {
    max-width: min(1080px, 92vw);
    margin: clamp(6px, 2vw, 12px);
    padding: 0 clamp(12px, 4vw, 24px);
    display: flex;
    justify-self: center;
    flex-direction: column;
    gap: clamp(20px, 4vw, 32px);
}

h1 {
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    font-weight: 500;
    margin: 0;
    color: var(--text-title);
    text-align: center;
    letter-spacing: 0.06em;
}

.emulator-container {
    /* background: rgba(255, 255, 255, 0.85); */
    /* border: 1px solid var(--border-soft); */
    /* border-radius: 22px; */
    /* padding: clamp(18px, 4vw, 28px); */
    /* box-shadow: var(--shadow-soft); */
    position: relative;
    overflow: visible;
}

/* Fullscreen container stays centered with black background */
.emulator-container:fullscreen,
.emulator-container:-webkit-full-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    padding: 0;
    border: none;
    position: relative;
    /* anchor moirÃ© overlay */
}

.iframe-wrapper {
    --frame-scale: 1;
    position: relative;
    width: min(100%, var(--mac-width));
    height: calc(var(--frame-scale) * var(--mac-height));
    margin: 0 auto clamp(16px, 3vw, 26px);
    overflow: visible;
}

/* In fullscreen, the wrapper fills and centers its child */
.emulator-container:fullscreen .iframe-wrapper,
.emulator-container:-webkit-full-screen .iframe-wrapper {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    box-shadow: none;
}

.iframe-wrapper iframe {
    border: none;
    border-radius: 5px;
    width: var(--mac-width);
    height: var(--mac-height);
    box-sizing: border-box;
    box-shadow: 0 0 0 12px #050507, 0 16px 32px rgba(30, 30, 40, 0.16);
    background: linear-gradient(160deg, #181a1f, #0f1014);
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scale(var(--frame-scale));
    transform-origin: top center;
}

.emulator-container:fullscreen .iframe-wrapper iframe,
.emulator-container:-webkit-full-screen .iframe-wrapper iframe {
    position: relative;
    top: 0;
    left: 0;
    width: var(--mac-width);
    height: var(--mac-height);
    transform: none;
    transform-origin: center center;
    border: none;
    border-radius: 0;
    box-shadow: none;
    /* avoids any shift */
}

.controls {
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 3.5vw, 20px);
    margin-bottom: clamp(14px, 4vw, 24px);
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: clamp(12px, 2.8vw, 18px);
    justify-content: center;
}

.primary-actions button {
    flex: 0 0 auto;
    min-width: 136px;
}

.secondary-actions {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(12px, 2.8vw, 18px);
    align-items: stretch;
    justify-content: center;
}

.secondary-actions>* {
    flex: 1 1 220px;
    max-width: fit-content;
    width: fit-content;
}

.secondary-actions .real-size-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    font-size: 13px;
    box-sizing: border-box;
}

.secondary-actions .real-size-topline span {
    font-size: 13px;
}

.secondary-actions .moire-toggle {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 13px;
    box-sizing: border-box;
}

.secondary-actions .moire-toggle span {
    font-size: 13px;
}

.secondary-actions .calibrate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    /* max-width: none; */
}

/* Controls hidden in fullscreen */
.emulator-container:fullscreen .controls,
.emulator-container:-webkit-full-screen .controls {
    display: none;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 0.045em;
    font-family: 'IBM Plex Mono', 'SFMono-Regular', Menlo, Monaco, 'Courier New', monospace;
    border: 2px solid #1f1f1f;
    border-radius: 4px;
    background-color: #f2f1ec;
    color: var(--text-primary) box-shadow: 0 0 0 1px #ffffff inset;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.12s ease;
}

button:not(.linklike):hover {
    background-color: #e6e4db;
}

button:not(.linklike):active {
    background-color: #dcd9cf;
    box-shadow: 0 0 0 1px #c9c6bc inset;
    transform: translate(1px, 1px);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
    background-color: #f5f4ef;
    color: rgba(26, 26, 26, 0.6);
}

button.timelapse-active {
    background-color: #ffe4de;
    border-color: #7a1b1b;
    box-shadow: 0 0 0 1px #ffe2dc inset;
    color: #611111;
}

button.timelapse-active:hover {
    background-color: #ffd8d2;
}

button.timelapse-active:active {
    background-color: #ffcdc4;
    box-shadow: 0 0 0 1px #f2b5ad inset;
}

.status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    margin-top: clamp(12px, 3vw, 20px);
}

.emulator-container:fullscreen .status,
.emulator-container:-webkit-full-screen .status {
    display: none;
}

.info {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-top: clamp(12px, 4vw, 20px);
}

.info a {
    color: #3d6dda;
    text-decoration: none;
    font-weight: 500;
}

.info a:hover {
    text-decoration: underline;
}

/* --- Minimal styles for real-size toggle + calibration --- */
.real-size-wrap,
.moire-toggle {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px 14px;
    border-radius: 16px;
    background: linear-gradient(155deg, rgba(255, 255, 255, 0.75), rgba(236, 236, 240, 0.5));
    border: 1px solid rgba(170, 170, 180, 0.32);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.real-size-topline {
    display: flex;
    align-items: center;
    gap: 10px;
}

.moire-toggle {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.real-size-wrap input:disabled+span,
.moire-toggle input:disabled+span {
    color: rgba(120, 120, 128, 0.6);
}

.hint {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    opacity: 0.85;
    margin: 2px 0 0 0;
}

button.linklike {
    border-style: dashed;
    background-color: #eceae2;
    color: var(--text-primary)
        /* max-width: fit-content; */
        text-decoration: none;
}

button.linklike:hover {
    background-color: #e2dfd5;
}

button.linklike:active {
    background-color: #d7d4ca;
    box-shadow: 0 0 0 1px #c9c6bc inset;
    transform: translate(1px, 1px);
}

/* --- Calibration modal --- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 26, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000
}

.modal.open {
    display: flex
}

.modal-card {
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.93), rgba(236, 236, 240, 0.85));
    border-radius: 20px;
    width: min(700px, 92vw);
    padding: clamp(20px, 4vw, 32px);
    box-shadow: var(--shadow-strong);
    border: 1px solid rgba(180, 180, 190, 0.28);
}

.modal-card h2 {
    margin: 0 0 8px 0;
    font-weight: 500;
    font-size: 20px;
    color: var(--text-primary);
}

.modal-card p {
    margin: 8px 0;
    color: var(--text-secondary);
    line-height: 1.6;
}

.calibration-area {
    border: 1px dashed rgba(150, 150, 160, 0.35);
    border-radius: 16px;
    padding: 18px;
    margin-top: 16px;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.6), rgba(240, 240, 244, 0.5));
}

.card-outline {
    outline: 2px solid rgba(80, 80, 90, 0.6);
    border-radius: 8px;
    box-sizing: content-box;
    margin: 14px auto;
}

.range-row {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-top: 6px;
    flex-wrap: wrap
}

.range-row input[type=range] {
    flex: 1
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px
}

/* --- Anti-moirÃ© overlay (fullscreen only) --- */
.moire-overlay {
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 16px;
    gap: 10px;
    background: linear-gradient(155deg, rgba(70, 70, 80, 0.72), rgba(30, 30, 38, 0.65));
    color: #f5f5f8;
    padding: 10px 16px;
    border-radius: 18px;
    align-items: center;
    box-shadow: 0 14px 30px rgba(15, 15, 20, 0.45);
    z-index: 2;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(180, 180, 190, 0.18);
}

.emulator-container:fullscreen .moire-overlay[aria-hidden="false"],
.emulator-container:-webkit-full-screen .moire-overlay[aria-hidden="false"] {
    display: flex;
}

.moire-label {
    font-size: 12px;
    opacity: 0.9;
}

#moireRange {
    width: min(40vw, 420px);
}

.moire-readout {
    font-size: 12px;
    min-width: 160px;
    text-align: right;
    opacity: 0.9;
}

/* --- Visible tick marks for moirÃ© slider --- */
.moire-slider {
    position: relative;
    display: inline-block;
    width: min(40vw, 420px);
}

.moire-slider input[type="range"] {
    width: 100%;
    display: block;
}

.moire-ticks {
    pointer-events: none;
    position: absolute;
    left: 0;
    right: 0;
    /* Align ticks along the track */
    top: 50%;
    transform: translateY(-50%);
    height: 20px;
}

.moire-ticks .tick {
    position: absolute;
    bottom: 2px;
    width: 2px;
    background: #ffffff;
    height: 8px;
    transform: translateX(-50%);
    opacity: 0.9;
    box-shadow: 0 0 2px rgba(0, 0, 0, .4);
}

.moire-ticks .tick.real {
    height: 12px;
    background: #d9d9df;
    /* highlight real-size */
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
}

.moire-ticks .tick.real::after {
    content: 'Real-size';
    position: absolute;
    left: 50%;
    transform: translate(-50%, -120%);
    white-space: nowrap;
    font-size: 10px;
    color: #f2f2f4;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.65);
    opacity: 0.95;
}

/* --- Timelapse status --- */
.timelapse-status {
    display: inline-block;
    min-width: 140px;
    font-size: 12px;
    color: #444;
    padding-left: 6px;
}

details#diagPanel {
    margin-top: clamp(16px, 4vw, 26px);
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.78), rgba(236, 236, 242, 0.58));
    border-radius: 20px;
    border: 1px solid rgba(170, 170, 180, 0.35);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
    padding: clamp(10px, 3vw, 16px);
}

details#diagPanel>summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 15px;
    list-style: none;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.9), rgba(240, 240, 244, 0.7));
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid rgba(180, 180, 190, 0.35);
    box-shadow: 0 6px 16px rgba(30, 30, 40, 0.15);
}

details#diagPanel[open]>summary {
    margin-bottom: clamp(12px, 3vw, 18px);
}

details#diagPanel pre {
    border-radius: 16px;
    background: linear-gradient(160deg, rgba(28, 30, 36, 0.92), rgba(38, 40, 46, 0.85));
    border: 1px solid rgba(80, 80, 90, 0.35);
    padding: clamp(12px, 3vw, 18px);
    color: #f1f2f8;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

details#diagPanel button {
    justify-self: start;
}

@media (max-width: 900px) {
    .wrapper {
        padding: 0 clamp(16px, 6vw, 24px);
    }

    .emulator-container {
        /* border-radius: 20px; */
        /* padding: clamp(18px, 6vw, 28px); */
    }

    .primary-actions button {
        flex: 1 1 45%;
        min-width: 0;
    }

    .controls-row {
        justify-content: flex-start;
    }

    .secondary-actions {
        gap: clamp(10px, 4vw, 16px);
        justify-content: flex-start;
    }

    .secondary-actions>* {
        flex: 1 1 220px;
        max-width: none;
    }
}

@media (max-width: 640px) {
    body {
        background: radial-gradient(140% 140% at 50% 0%, hsl(39deg 26.79% 78.21%) 0%, hsl(39deg 49.41% 88.42%) 45%, hsl(39deg 38.44% 88.05%) 100%);
    }

    .wrapper {
        max-width: 94vw;
        padding: 0 clamp(14px, 7vw, 22px);
    }

    .controls {
        gap: 12px;
    }

    .controls-row {
        gap: 12px;
        justify-content: flex-start;
    }

    .secondary-actions {
        justify-content: flex-start;
    }

    .secondary-actions>* {
        flex: 1 1 100%;
        max-width: 100%;
    }

    .primary-actions button {
        flex: 1 1 100%;
        min-width: 0;
    }

    button {
        padding: 10px 14px;
        font-size: 13px;
    }

    .info {
        padding: clamp(12px, 4vw, 20px);
        border-radius: 16px;
    }

    .status {
        font-size: 14px;
    }
}