:root {
    color-scheme: light dark;
    --bg: #f4f1ea;
    --bg-alt: #ffffff;
    --surface: #fdf8f1;
    --surface-strong: #fff6e6;
    --text: #1b1b1b;
    --text-muted: #4a4a4a;
    --accent: #ff4d2d;
    --accent-strong: #f8371a;
    --accent-soft: rgba(255, 77, 45, 0.15);
    --border: rgba(0, 0, 0, 0.12);
    --shadow: 0 20px 40px rgba(18, 18, 18, 0.12);
    --radius: 16px;
    --font-body: "Bahnschrift", "Trebuchet MS", "Calibri", sans-serif;
    --font-display: "Cascadia Mono", "Consolas", "Courier New", monospace;
}

html[data-theme="dark"] {
    --bg: #0e1116;
    --bg-alt: #141924;
    --surface: #171c26;
    --surface-strong: #1f2532;
    --text: #f5f4f1;
    --text-muted: #b8b3aa;
    --accent: #ff7348;
    --accent-strong: #ff4c26;
    --accent-soft: rgba(255, 115, 72, 0.2);
    --border: rgba(255, 255, 255, 0.12);
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --bg: #0e1116;
        --bg-alt: #141924;
        --surface: #171c26;
        --surface-strong: #1f2532;
        --text: #f5f4f1;
        --text-muted: #b8b3aa;
        --accent: #ff7348;
        --accent-strong: #ff4c26;
        --accent-soft: rgba(255, 115, 72, 0.2);
        --border: rgba(255, 255, 255, 0.12);
        --shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-body);
    background-color: #07080b;
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='0.25'/></svg>");
    background-size: 320px 320px;
    background-repeat: repeat;
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

body[data-texture="2"] {
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='2' stitchTiles='stitch'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='0.22'/></svg>");
    background-size: 420px 420px;
}

body[data-texture="3"] {
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.6' numOctaves='4' stitchTiles='stitch'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='0.3'/></svg>");
    background-size: 360px 360px;
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 40px;
}

.hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 20px 24px;
    border-radius: var(--radius);
    background: linear-gradient(120deg, var(--surface-strong), var(--surface));
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    align-items: center;
    gap: 20px;
}

.brand-mark {
    font-family: var(--font-display);
    font-size: 2.5rem;
    letter-spacing: 0.2rem;
    padding: 10px 16px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 10px 20px rgba(255, 77, 45, 0.35);
}

.hero h1 {
    margin: 0;
    font-size: 2rem;
}

.hero p {
    margin: 6px 0 0;
    color: var(--text-muted);
}

.hero-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

button {
    border: 1px solid var(--border);
    background: var(--bg-alt);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.reset-btn {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-top: 28px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card.calculator {
    min-height: 70vh;
}

.card-header h2 {
    margin: 0 0 6px;
}

.card-header p {
    margin: 0 0 16px;
    color: var(--text-muted);
}

.errors {
    min-height: 24px;
    color: var(--accent-strong);
    font-weight: 600;
}

.ratio-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 12px 16px;
    align-items: center;
    margin-top: 16px;
}

.ratio-cell {
    display: grid;
    gap: 14px;
}

.ratio-divider {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--accent);
}

label {
    display: grid;
    gap: 6px;
    font-size: 0.95rem;
}

input[type="text"],
select,
textarea {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.flash {
    animation: flash 0.8s ease;
}

@keyframes flash {
    0% { background: rgba(255, 77, 45, 0.25); }
    100% { background: var(--bg-alt); }
}

.options {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle input {
    accent-color: var(--accent);
}

.select span {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.ratio-output {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-top: 18px;
    align-items: center;
}

.ratio-output .label {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.ratio-output .value {
    font-size: 1.6rem;
    margin: 4px 0 0;
    font-family: var(--font-display);
}

.standard-match {
    margin: 8px 0 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.standard-tags {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.standard-sensors {
    margin: 8px 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: var(--text);
}

.tag.streaming {
    border-color: rgba(88, 201, 255, 0.5);
    color: #9fe3ff;
}

.tag.imax {
    border-color: rgba(255, 210, 98, 0.6);
    color: #ffd77a;
}

.tag.anamorphic {
    border-color: rgba(255, 110, 180, 0.5);
    color: #ff9fd3;
}

.tag.theatrical {
    border-color: rgba(160, 255, 150, 0.5);
    color: #b8ffae;
}

.tag.legacy {
    border-color: rgba(255, 140, 70, 0.5);
    color: #ffb186;
}

#visual-ratio {
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
    min-height: 220px;
    min-width: 400px;
    overflow: hidden;
    position: relative;
}

#visual-ratio img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0;
}

#visual-ratio.has-sample img {
    opacity: 1;
}

.preview-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.preview-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.55);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
    z-index: 2;
}

.preview-line.vertical {
    width: 2px;
    height: 100%;
    right: 0;
    bottom: 0;
}

.preview-line.horizontal {
    height: 2px;
    width: 100%;
    bottom: 0;
    left: 0;
}

.preview-label {
    position: absolute;
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 4px 8px;
    border-radius: 999px;
    backdrop-filter: blur(6px);
    z-index: 3;
}

.preview-shell {
    position: relative;
    display: inline-block;
}

.preview-label.outside.width {
    right: 0;
    top: calc(100% + 10px);
}

.preview-label.outside.height {
    left: calc(100% + 10px);
    top: 10px;
    transform: rotate(90deg);
    transform-origin: left top;
}

.sample {
    margin-top: 18px;
    display: grid;
    gap: 12px;
}

.sample-options {
    display: grid;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: var(--bg-alt);
}

.segmented {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.segmented label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--surface-strong);
}

.hidden {
    display: none;
}

.footer {
    margin-top: 30px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.noscript {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 12px 16px;
    border-radius: 999px;
}

@media (max-width: 720px) {
    .hero {
        flex-direction: column;
        align-items: flex-start;
    }

    .ratio-grid {
        grid-template-columns: 1fr;
    }

    .ratio-divider {
        text-align: center;
    }
}

@media (max-width: 520px) {
    #visual-ratio {
        min-width: 100%;
    }
}

/* Contextual prompts */

.prompt-parent {
    position: relative;
}

.prompt {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translate(12px, -50%);
    background: var(--surface-strong);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 0.85rem;
    width: 190px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    z-index: 5;
}

.prompt::after {
    content: "";
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 12px;
    height: 12px;
    background: var(--surface-strong);
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.prompt.show {
    opacity: 1;
    transform: translate(0, -50%);
    pointer-events: auto;
}
