/* Snakkehjulet – styles. Mobile first; two-column layout on wide/landscape screens. */

:root {
    color-scheme: light dark;

    --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", "Segoe UI",
        system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;

    --bg: #fff4e8;
    --blob-1: #ffd9c2;
    --blob-2: #e9dcff;
    --surface: #ffffff;
    --surface-2: #fff9f2;
    --border: #f0dccb;
    --text: #2b2135;
    --muted: #6e5f78;
    --focus: #6741d9;
    --shadow: 0 10px 30px -12px rgb(91 52 22 / 0.35);

    --rim: #2b2135;
    --peg: #ffe9a8;
    --seg-ink: #241a2f;
    --pointer: #e8335a;
    --pointer-dot: #fff4e8;
    --hub-1: #fff8ee;
    --hub-2: #ffd8a8;

    --btn-1: #ff6a3d;
    --btn-2: #e8336d;
    --btn-ink: #ffffff;

    /* Wheel segment colours – all light enough for dark label text. */
    --seg-0: #ffd43b;
    --seg-1: #9b7cfa;
    --seg-2: #ff8fab;
    --seg-3: #4dabf7;
    --seg-4: #ff922b;
    --seg-5: #22c3d6;
    --seg-6: #ff6b6b;
    --seg-7: #5ccf6e;

    --gutter: 16px;
    --card-h: clamp(8.75rem, 23dvh, 12.5rem);
    --q-max: clamp(1.35rem, 0.9rem + 2.6vw, 2.1rem);
    --wheel-max: 560px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1d1626;
        --blob-1: #3a2140;
        --blob-2: #1f2a4a;
        --surface: #2a2136;
        --surface-2: #322840;
        --border: #43365a;
        --text: #f7eefb;
        --muted: #bfb0cc;
        --focus: #b197fc;
        --shadow: 0 12px 34px -14px rgb(0 0 0 / 0.7);

        --rim: #120d18;
        --peg: #ffe08a;
        --pointer: #ff5c7c;
        --pointer-dot: #1d1626;
        --hub-1: #3b3049;
        --hub-2: #1d1626;

        --btn-1: #ff7a4d;
        --btn-2: #e8336d;

        /* Slightly muted so the wheel glows instead of glaring on dark. */
        --seg-0: #f5c83b;
        --seg-1: #a184f5;
        --seg-2: #f28aa8;
        --seg-3: #56a8ec;
        --seg-4: #f5943a;
        --seg-5: #2ebfd1;
        --seg-6: #f27373;
        --seg-7: #5fc471;
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(circle at 8% -5%, var(--blob-1), transparent 42%),
        radial-gradient(circle at 105% 95%, var(--blob-2), transparent 48%),
        var(--bg);
    line-height: 1.4;
    -webkit-tap-highlight-color: transparent;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ---------- Header / footer ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem 1rem;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0.6rem var(--gutter) 0.4rem;
}

/* ---------- Mode switch (normal / kids) ---------- */

.mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    margin-left: auto;
    padding: 0.25rem 0.85rem 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
}

.mode-switch__track {
    position: relative;
    flex: none;
    width: 42px;
    height: 26px;
    border-radius: 999px;
    background: var(--border);
    transition: background-color 0.2s ease;
}

.mode-switch__thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
    transition: transform 0.2s ease;
}

.mode-switch[aria-pressed="true"] .mode-switch__track {
    background: var(--seg-7);
}

.mode-switch[aria-pressed="true"] .mode-switch__thumb {
    transform: translateX(16px);
}

.mode-switch[aria-disabled="true"] {
    opacity: 0.6;
    cursor: progress;
}

/* Kids mode: a cooler, greener background so you can tell at a glance. */
.is-kids {
    --blob-1: #c9f2d0;
    --blob-2: #cfe6ff;
}

@media (prefers-color-scheme: dark) {
    .is-kids {
        --blob-1: #1f3d2c;
        --blob-2: #1c3352;
    }
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.brand__mark {
    width: 1.6em;
    height: 1.6em;
}

.brand__rim {
    fill: var(--rim);
}

.brand__hub {
    fill: var(--hub-1);
}

.topbar__tagline {
    display: none;
    margin: 0;
    color: var(--muted);
    font-weight: 600;
}

.footer {
    padding: 0.25rem var(--gutter) 0.75rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
}

.footer p {
    margin: 0;
}

.noscript {
    margin: 0 var(--gutter) 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: var(--surface);
    text-align: center;
    font-weight: 600;
}

/* ---------- Stage layout ---------- */

.stage {
    flex: 1;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "card"
        "wheel"
        "controls";
    gap: 0.9rem;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 var(--gutter) 0.5rem;
}

/* ---------- Question card ---------- */

.card {
    grid-area: card;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    height: var(--card-h);
    padding: 0.85rem 1.1rem 1rem;
    border-radius: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    width: 100%;
    max-width: 40rem;
    justify-self: center;
}

.card__category {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    padding: 0.15rem 0.7rem 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--seg-ink);
    font-size: 0.9rem;
    font-weight: 800;
    flex: none;
    transition: background-color 0.3s ease;
}

.card:not([data-seg]) .card__category {
    color: var(--text);
}

.card[data-seg="0"] .card__category { background: var(--seg-0); }
.card[data-seg="1"] .card__category { background: var(--seg-1); }
.card[data-seg="2"] .card__category { background: var(--seg-2); }
.card[data-seg="3"] .card__category { background: var(--seg-3); }
.card[data-seg="4"] .card__category { background: var(--seg-4); }
.card[data-seg="5"] .card__category { background: var(--seg-5); }
.card[data-seg="6"] .card__category { background: var(--seg-6); }
.card[data-seg="7"] .card__category { background: var(--seg-7); }

.card__question {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    margin: 0;
    font-size: var(--q-max);
    font-weight: 800;
    line-height: 1.18;
    letter-spacing: -0.01em;
    text-wrap: balance;
    overflow-wrap: break-word;
    hyphens: manual;
}

.card.is-waiting .card__question {
    opacity: 0.35;
    transition: opacity 0.25s ease;
}

.card.is-revealed .card__question,
.card.is-revealed .card__category {
    animation: reveal 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.card.is-revealed .card__category {
    animation-duration: 0.4s;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ---------- Wheel ---------- */

.wheel-area {
    grid-area: wheel;
    container-type: size;
    min-height: 240px;
    display: grid;
    place-items: center;
}

.wheel {
    position: relative;
    /* Leave room for the pointer that sticks out above the wheel. */
    width: min(100cqw, 92cqh, var(--wheel-max));
    aspect-ratio: 1;
    margin-top: 4%;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
}

.wheel.is-dragging {
    cursor: grabbing;
}

.wheel.is-spinning {
    cursor: default;
}

/* Static circular clip: a rotated square would otherwise widen the page. */
.wheel__disc {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: var(--shadow), 0 0 0 4px var(--surface);
}

.wheel__rotor {
    position: absolute;
    inset: 0;
    will-change: transform;
}

.wheel__svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.wheel__rim {
    fill: var(--rim);
}

.wheel__peg {
    fill: var(--peg);
}

.seg-0 { --c: var(--seg-0); }
.seg-1 { --c: var(--seg-1); }
.seg-2 { --c: var(--seg-2); }
.seg-3 { --c: var(--seg-3); }
.seg-4 { --c: var(--seg-4); }
.seg-5 { --c: var(--seg-5); }
.seg-6 { --c: var(--seg-6); }
.seg-7 { --c: var(--seg-7); }

.seg__slice,
.brand__mark path {
    fill: var(--c);
}

.seg__slice {
    stroke: var(--rim);
    stroke-width: 1.2;
    stroke-linejoin: round;
}

.seg {
    transition: filter 0.45s ease;
}

.seg__label {
    fill: var(--seg-ink);
    font-family: var(--font);
    font-weight: 800;
    letter-spacing: 0.02em;
    text-anchor: middle;
    dominant-baseline: central;
}

.seg__icon {
    font-size: 15px;
    text-anchor: middle;
    dominant-baseline: central;
}

.wheel.has-result .seg:not(.is-winner) {
    filter: saturate(0.35) brightness(1.08);
}

@media (prefers-color-scheme: dark) {
    .wheel.has-result .seg:not(.is-winner) {
        filter: saturate(0.4) brightness(0.72);
    }
}

.wheel__hub {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 19%;
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, var(--hub-1), var(--hub-2));
    border: 4px solid var(--rim);
    box-shadow: 0 3px 10px rgb(0 0 0 / 0.25);
    pointer-events: none;
}

.wheel__pointer {
    position: absolute;
    top: -7%;
    left: 50%;
    width: 11%;
    margin-left: -5.5%;
    transform-origin: 50% 32%;
    filter: drop-shadow(0 3px 3px rgb(0 0 0 / 0.3));
    pointer-events: none;
}

.wheel__pointer path {
    fill: var(--pointer);
    stroke: var(--rim);
    stroke-width: 2.5;
    stroke-linejoin: round;
}

.wheel__pointer circle {
    fill: var(--pointer-dot);
}

/* ---------- Controls ---------- */

.controls {
    grid-area: controls;
    display: grid;
    grid-template-columns: 56px minmax(0, 22rem) 56px;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
}

.spin-btn {
    min-height: 64px;
    padding: 0.5rem 1.5rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--btn-1), var(--btn-2));
    color: var(--btn-ink);
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 8px 20px -8px var(--btn-2), inset 0 -4px 0 rgb(0 0 0 / 0.15);
    transition: transform 0.12s ease, filter 0.2s ease;
    touch-action: manipulation;
}

.spin-btn:hover {
    filter: brightness(1.06);
}

.spin-btn:active {
    transform: translateY(2px) scale(0.98);
}

.spin-btn[aria-disabled="true"] {
    cursor: progress;
    filter: saturate(0.6);
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.12s ease, opacity 0.2s ease, background-color 0.2s ease;
    touch-action: manipulation;
}

.icon-btn:active {
    transform: scale(0.94);
}

.icon-btn svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-btn__fill {
    fill: currentColor;
}

.icon-btn[aria-pressed="true"] {
    background: var(--seg-0);
    color: var(--seg-ink);
    border-color: transparent;
}

#sound-toggle[aria-pressed="false"] .sound-on,
#sound-toggle[aria-pressed="true"] .sound-off {
    display: none;
}

.icon-btn[aria-disabled="true"] {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(6.5rem + env(safe-area-inset-bottom));
    transform: translate(-50%, 12px);
    max-width: calc(100% - 2 * var(--gutter));
    padding: 0.6rem 1.1rem;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast:empty {
    padding: 0;
}

/* ---------- Larger screens ---------- */

@media (min-width: 600px) {
    .topbar__tagline {
        display: block;
    }

    .card {
        padding: 1.1rem 1.5rem 1.25rem;
    }
}

/* Wide or landscape: wheel on the left, question and controls on the right. */
@media (min-width: 640px) and (min-aspect-ratio: 5/4) {
    :root {
        --card-h: clamp(10rem, 34dvh, 17rem);
        --q-max: clamp(1.4rem, 0.6rem + 2vw, 2.6rem);
    }

    .stage {
        grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 1fr);
        grid-template-rows: 1fr auto auto 1fr;
        grid-template-areas:
            "wheel ."
            "wheel card"
            "wheel controls"
            "wheel .";
        column-gap: clamp(1.5rem, 4vw, 4rem);
        row-gap: 1.25rem;
        align-items: center;
        padding-top: 0.5rem;
    }

    .wheel-area {
        min-height: 0;
        height: 100%;
    }

    .card {
        max-width: none;
    }

    .controls {
        grid-template-columns: 56px minmax(0, 1fr) 56px;
    }

    .toast {
        bottom: 2rem;
    }
}

/* Very short landscape screens (phones on their side): tighten everything. */
@media (max-height: 480px) and (min-aspect-ratio: 5/4) {
    .topbar {
        padding-block: 0.4rem 0.2rem;
    }

    .topbar__tagline,
    .footer {
        display: none;
    }

    :root {
        --card-h: clamp(7rem, 42dvh, 11rem);
        --q-max: clamp(1.1rem, 4.5dvh + 0.4rem, 1.6rem);
    }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    .card.is-revealed .card__question,
    .card.is-revealed .card__category {
        animation: fade 0.3s ease both;
    }

    .spin-btn,
    .icon-btn,
    .seg,
    .toast,
    .mode-switch__track,
    .mode-switch__thumb {
        transition: none;
    }

    @keyframes fade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}
