:root {
    --bg: #050508;
    --panel: #0d0d14;
    --line: #1f1f2e;
    --text: #e8e8f0;
    --muted: #7a7a92;
    --red: #ff2a2a;
    --blue: #2a5bff;
    --yellow: #ffd21f;
    --glow-red: 0 0 18px rgba(255, 42, 42, .55);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    background:
        radial-gradient(ellipse at 50% -10%, #1a1030 0%, transparent 60%),
        var(--bg);
    color: var(--text);
    font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    text-align: center;
    padding: 0 16px;
}

/* CRT-scanlinet koko sivun päällä */
.crt {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: repeating-linear-gradient(to bottom, rgba(255,255,255,.025) 0 1px, transparent 1px 3px);
    mix-blend-mode: overlay;
}

/* ---------- Logo ---------- */
.top { flex: none; padding: clamp(8px, 2vh, 20px) 0 0; }

.logo {
    position: relative;
    margin: 0;
    font-family: Impact, "Anton", "Arial Black", sans-serif;
    font-size: clamp(36px, min(11vw, 9vh), 88px);
    letter-spacing: 2px;
    line-height: 1;
    color: var(--blue);
    text-shadow: 0 0 24px rgba(42, 91, 255, .6);
    user-select: none;
}
.logo::before, .logo::after {
    content: attr(data-text);
    position: absolute;
    inset: 0;
    opacity: .8;
}
.logo::before { color: var(--red); animation: glitch 3.2s infinite steps(1); }
.logo::after  { color: #22e1ff; animation: glitch 2.7s infinite reverse steps(1); mix-blend-mode: screen; }

@keyframes glitch {
    0%, 88%, 100% { transform: none; clip-path: inset(0 0 0 0); opacity: 0; }
    89% { transform: translate(-4px, 1px); clip-path: inset(10% 0 55% 0); opacity: .8; }
    92% { transform: translate(4px, -2px); clip-path: inset(60% 0 8% 0);  opacity: .8; }
    95% { transform: translate(-2px, 2px); clip-path: inset(35% 0 35% 0); opacity: .8; }
}

.tagline {
    margin: clamp(4px, 1vh, 10px) 0 0;
    color: var(--muted);
    font-size: 14px;
    letter-spacing: .5px;
}
.tagline span { color: var(--yellow); font-weight: bold; }

/* ---------- Soitin ---------- */
/* Sivu täyttää tasan näytön korkeuden: soitin saa kaiken jäljelle jäävän tilan (4:3) */
main {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    padding-top: clamp(8px, 1.6vh, 16px);
}
.stage-wrap {
    flex: 1;
    min-height: 0;
    container-type: size;
    display: flex;
    justify-content: center;
    align-items: center;
}
.stage {
    position: relative;
    width: min(100cqw, 100cqh * 4 / 3);
    aspect-ratio: 4 / 3;
    background: #000;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 0 1px #000, 0 20px 60px rgba(0,0,0,.6), 0 0 80px rgba(42, 91, 255, .12);
}
.stage:fullscreen { border: 0; border-radius: 0; }

.screen, .screen > * {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.screen video { object-fit: contain; background: #000; }

.start {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    background: radial-gradient(circle, rgba(20,20,40,.75), rgba(0,0,0,.92));
    color: var(--text);
    font: inherit;
    font-size: 22px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    cursor: pointer;
    z-index: 2;
}
.start small { font-size: 12px; font-weight: normal; letter-spacing: 1px; text-transform: none; color: var(--muted); }
.start-icon {
    display: grid;
    place-items: center;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: var(--red);
    box-shadow: var(--glow-red);
    font-size: 34px;
    padding-left: 6px;
    transition: transform .15s;
}
.start:hover .start-icon { transform: scale(1.08); }
.start[hidden] { display: none; }

.loading::after {
    content: "loading…";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--muted);
    font-size: 14px;
    letter-spacing: 2px;
}

/* ---------- Napit ---------- */
.bar {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 10px;
    margin: clamp(8px, 1.8vh, 18px) 0 clamp(6px, 1vh, 10px);
}

.btn {
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(2px); }

.btn.random {
    min-width: 220px;
    padding: clamp(8px, 1.6vh, 16px) 30px;
    background: var(--red);
    color: #fff;
    font-family: Impact, "Arial Black", sans-serif;
    font-size: clamp(24px, 4vh, 34px);
    letter-spacing: 3px;
    box-shadow: 0 5px 0 #8f0000, var(--glow-red);
}
.btn.random:hover { background: #ff4545; }
.btn.random:active { box-shadow: 0 2px 0 #8f0000, var(--glow-red); }

.btn.ghost {
    width: 58px;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 18px;
}
.btn.ghost:hover:not(:disabled) { border-color: var(--blue); color: #fff; }
.btn:disabled { opacity: .35; cursor: default; }

.meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 14px;
}
.tag {
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 210, 31, .1);
    color: var(--yellow);
    font-weight: bold;
    font-variant-numeric: tabular-nums;
}
.link {
    border: 0;
    background: none;
    padding: 0;
    color: var(--muted);
    font: inherit;
    text-decoration: underline dotted;
    cursor: pointer;
}
.link:hover { color: #fff; }

.keys { margin: clamp(4px, 1.2vh, 12px) 0 0; color: #4a4a60; font-size: 12px; }
kbd {
    display: inline-block;
    min-width: 20px;
    padding: 1px 5px;
    margin: 0 1px;
    border: 1px solid #2a2a3c;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #101018;
    color: #9a9ab0;
    font: 11px ui-monospace, Consolas, monospace;
}

/* ---------- Footer ---------- */
footer { flex: none; padding: clamp(6px, 1.4vh, 14px) 0; color: #3c3c52; font-size: 12px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 20px);
    padding: 10px 18px;
    border-radius: 8px;
    background: #fff;
    color: #000;
    font-size: 14px;
    font-weight: bold;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Puhelimella sivu saa vierittyä normaalisti */
@media (max-width: 600px) {
    body { height: auto; min-height: 100dvh; overflow: auto; }
    main { flex: none; }
    .stage-wrap { flex: none; container-type: normal; display: block; }
    .stage { width: 100%; }
    footer { margin-top: auto; }
}

@media (max-width: 520px) {
    .btn.random { min-width: 0; flex: 1; font-size: 28px; padding: 14px 10px; }
    .keys { display: none; }
}
