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

:root {
    --bg: #0b0d12;
    --panel: #161a23;
    --text: #e9ecf2;
    --muted: #8a93a6;
    --accent: #7c5cff;
    --ok: #33d17a;
    --warn: #f6c343;
    --danger: #ff5c5c;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

a { color: var(--accent); }

h1, h2 { margin: 0 0 .5em; line-height: 1.2; }

.back {
    color: var(--muted);
    text-decoration: none;
    font-size: .95rem;
}

.btn-start {
    display: block;
    width: 100%;
    max-width: 22rem;
    margin: 1.5rem auto 0;
    padding: 1rem 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}
.btn-start:active { transform: scale(.98); }

.error {
    max-width: 30rem;
    margin: 1rem auto 0;
    padding: .9rem 1rem;
    color: #fff;
    background: rgba(255, 92, 92, .15);
    border: 1px solid var(--danger);
    border-radius: .75rem;
}

/* ===== Startseite ===== */
.home {
    max-width: 44rem;
    margin: 0 auto;
    padding: max(2rem, env(safe-area-inset-top)) 1.25rem 3rem;
}
.home h1 { font-size: 2.4rem; }
.lead { color: var(--muted); font-size: 1.1rem; }

.stage-links {
    display: grid;
    gap: 1rem;
    margin: 2rem 0;
}
@media (min-width: 40rem) {
    .stage-links { grid-template-columns: 1fr 1fr; }
}
.card {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding: 1.25rem;
    color: var(--text);
    text-decoration: none;
    background: var(--panel);
    border: 1px solid #262c3a;
    border-radius: 1rem;
}
.card:active, .card:hover { border-color: var(--accent); }
.card-step { color: var(--accent); font-weight: 700; text-transform: uppercase; font-size: .8rem; letter-spacing: .08em; }
.card-title { font-size: 1.3rem; font-weight: 600; }
.card-text { color: var(--muted); }

.cheatsheet, .hints {
    margin-top: 2rem;
    padding: 1.25rem;
    background: var(--panel);
    border-radius: 1rem;
}
.hints ul { padding-left: 1.2rem; margin: 0; }
.hints li { margin: .4rem 0; color: var(--muted); }

.legend {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
    display: grid;
    gap: .5rem;
}
.legend li { display: flex; align-items: center; gap: .75rem; }
.legend-num { font-weight: 700; width: 1.2rem; text-align: center; }
.table-wrap { overflow-x: auto; margin-top: 1rem; }
.mapping { border-collapse: collapse; font-size: .85rem; white-space: nowrap; }
.mapping th, .mapping td { padding: .45rem .6rem; text-align: left; border-bottom: 1px solid #262c3a; }
.mapping th { color: var(--muted); font-weight: 600; }
.mapping .swatch { display: inline-block; vertical-align: middle; width: 1.6rem; height: .9rem; margin-right: .3rem; }
.tip { color: var(--muted); margin-top: 1rem; }

.swatch {
    width: 2.2rem;
    height: 1.2rem;
    border-radius: .3rem;
    background: var(--c);
    box-shadow: 0 0 10px var(--c);
}

/* ===== Stufe 1 ===== */
.stage1 {
    max-width: 32rem;
    margin: 0 auto;
    padding: max(1rem, env(safe-area-inset-top)) 1.25rem 2rem;
}
.topbar { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.25rem; }
.topbar h1 { font-size: 1.4rem; }

.readings {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .75rem;
}
.reading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem .5rem;
    background: var(--panel);
    border-radius: 1rem;
}
.reading-label { color: var(--muted); font-size: .85rem; text-align: center; }
.reading-label small { display: block; font-size: .7rem; }
.reading-value {
    margin-top: .35rem;
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.zbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .8rem;
    color: var(--muted);
}
.zbar-track {
    position: relative;
    flex: 1;
    height: .6rem;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--danger), #444 50%, var(--ok));
}
.zbar-marker {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    background: #fff;
    transform: translate(-50%, -50%);
    transition: left .08s linear;
}

.message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .4rem;
    margin-top: 1.5rem;
    padding: 2rem 1rem;
    text-align: center;
    background: var(--panel);
    border: 2px solid transparent;
    border-radius: 1.25rem;
    transition: border-color .2s, background .2s;
}
.message-icon { font-size: 3rem; }
.message-text { font-size: 1.4rem; font-weight: 700; }
.message-sub { color: var(--muted); min-height: 1.2em; }
.message[data-state="up"]       { border-color: var(--ok);   background: rgba(51, 209, 122, .1); }
.message[data-state="vertical"] { border-color: var(--warn); background: rgba(246, 195, 67, .1); }
.message[data-state="tilted"]   { border-color: #3b4254; }

/* Vollflächig weiß leuchtend, wenn das Display nach unten zeigt */
.facedown-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: #c8c8c8;
    font-size: 1.2rem;
    font-weight: 600;
}
.facedown-overlay[hidden] { display: none; }
body.is-facedown { background: #fff; }

/* ===== Stufe 2 ===== */
.page-stage2 { background: #000; }
.page-stage2 { overflow: hidden; overscroll-behavior: none; }

.stage2 {
    position: fixed;
    inset: 0;
    background: #000;
    user-select: none;
    -webkit-user-select: none;
}

.intro {
    overflow-y: auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100%;
    padding: 2rem 1.5rem;
    text-align: center;
}
.intro .back { position: absolute; top: max(1rem, env(safe-area-inset-top)); left: 1.25rem; }
.intro h1 { font-size: 2.2rem; }
.intro p { color: var(--muted); font-size: 1.1rem; line-height: 1.5; }

.options {
    display: grid;
    gap: .8rem;
    width: 100%;
    max-width: 24rem;
    margin: 1.2rem auto 0;
    text-align: left;
}
.option { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.option select {
    width: 100%;
    padding: .7rem .8rem;
    font-size: 1rem;
    color: var(--text);
    background: var(--panel);
    border: 1px solid #2c3242;
    border-radius: .6rem;
}
.preview-buttons { display: flex; gap: .4rem; }
.preview-buttons button {
    flex: 1;
    padding: .55rem 0;
    font-size: 1rem;
    color: var(--text);
    background: var(--panel);
    border: 1px solid #2c3242;
    border-radius: .6rem;
}

.waiting {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
    color: #555;
    font-size: 1.1rem;
}

[hidden] { display: none !important; }

/* Spur am rechten Rand mit N gleich großen Positionen */
.beacon-track {
    --n: 6;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24vw;
    max-width: 9rem;
}
.beacon {
    --slot: 0;
    --c: #fff;
    position: absolute;
    right: 0;
    left: 0;
    top: calc(100% / var(--n) * var(--slot));
    height: calc(100% / var(--n));
    background-color: var(--c);
    transform: scaleY(.86); /* kleiner Abstand zwischen den Positionen */
    box-shadow: 0 0 40px 10px var(--c);
    border-radius: 6px 0 0 6px;
}

.debug {
    position: absolute;
    left: .5rem;
    bottom: max(.5rem, env(safe-area-inset-bottom));
    z-index: 60;
    padding: .3rem .5rem;
    font: 12px/1.3 ui-monospace, monospace;
    color: #8f8;
    background: rgba(0, 0, 0, .7);
    border-radius: .3rem;
}

/* ===== Simulator (?sim=1) ===== */
.simulator {
    position: fixed;
    left: .5rem;
    top: .5rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: .3rem;
    padding: .6rem .8rem;
    font-size: .8rem;
    color: #fff;
    background: rgba(30, 30, 40, .9);
    border: 1px solid #444;
    border-radius: .5rem;
}
.simulator label { display: flex; align-items: center; gap: .4rem; }
.simulator output { width: 2.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.sim-presets { display: flex; gap: .3rem; }
.sim-presets button { font-size: .75rem; padding: .2rem .4rem; }
