/*
 * Lemmings - the page around the landscape.
 *
 * Two halves: the menu and the results are quiet cards on a dark page, and the
 * play screen is the landscape itself taking almost the whole viewport. The
 * palette is the game's own: navy sky, warm dirt, and the crowd's red cap.
 */

:root {
    --bg: #0e1421;
    --panel: #16203a;
    --panel-2: #1c2a49;
    --line: #27385c;
    --text: #e8eefb;
    --muted: #93a4c4;
    --accent: #ffd166;
    --accent-2: #4cc9f0;
    --cap: #e63946;
    --cap-deep: #a81f2c;
    --good: #57cc99;
    --warn: #ff8f5a;
    --radius: 14px;
    --shadow: 0 18px 40px rgba(4, 8, 16, 0.55);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    color: var(--text);
    background:
        radial-gradient(900px 460px at 8% -12%, rgba(76, 201, 240, 0.14), transparent 62%),
        radial-gradient(820px 420px at 100% 0%, rgba(230, 57, 70, 0.12), transparent 58%),
        var(--bg);
    font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.lems {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ------------------------------- top bar ------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(14, 20, 33, 0.88);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1120px;
    margin: 0 auto;
    padding: 12px 20px;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-weight: 700;
    letter-spacing: 0.01em;
}

/* The crowd's red cap, seen from the side. */
.topbar__mark {
    position: relative;
    width: 22px;
    height: 16px;
    border-radius: 11px 11px 4px 4px;
    background: linear-gradient(180deg, var(--cap), var(--cap-deep));
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.14) inset;
}

.topbar__mark::after {
    content: "";
    position: absolute;
    right: -5px;
    bottom: 0;
    width: 8px;
    height: 4px;
    border-radius: 0 3px 3px 0;
    background: var(--cap-deep);
}

.topbar__sub {
    color: var(--muted);
    font-weight: 500;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topbar__home {
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
}

.topbar__home:hover,
.topbar__home:focus-visible {
    color: var(--text);
    border-color: var(--accent-2);
}

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

.main {
    flex: 1;
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 22px 20px 8px;
}

.screen[hidden] {
    display: none;
}

.screen--play {
    max-width: 1180px;
    margin: 0 auto;
}

/* The verdict sits in the middle of the page - there is nothing else to read
   once the level is over. `:not([hidden])` keeps the higher specificity from
   resurrecting a screen the app has just put away. */
.screen[data-screen="result"]:not([hidden]) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 56vh;
    padding-bottom: 5vh;
}

.lede {
    max-width: 62ch;
    margin: 0 auto 22px;
    color: var(--muted);
    font-size: 17px;
    text-align: center;
}

.screen__title {
    margin: 8px 0 6px;
    font-size: clamp(22px, 3.4vw, 30px);
    text-align: center;
}

.screen__blurb {
    margin: 0 auto 14px;
    max-width: 56ch;
    color: var(--muted);
    text-align: center;
}

.hint {
    color: var(--muted);
    font-size: 13px;
}

.hint--center {
    text-align: center;
    margin: 14px 0 0;
}

/* --------------------------- the level menu ---------------------------- */

.ranks {
    display: grid;
    gap: 20px;
    margin-top: 6px;
}

.rank__title {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin: 0 0 8px;
    font-size: 13px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
}

.rank__count {
    font-size: 12px;
    letter-spacing: 0.04em;
    color: var(--accent);
    text-transform: none;
}

.levels {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.level {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 6px;
    width: 100%;
    padding: 14px 16px;
    text-align: left;
    color: inherit;
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 120ms ease, transform 120ms ease;
}

.level:hover,
.level:focus-visible {
    border-color: var(--accent-2);
    transform: translateY(-2px);
}

.level__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.level__number {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.level__name {
    font-size: 17px;
    font-weight: 700;
}

.level__hint {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.level__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.level__stars {
    letter-spacing: 2px;
    color: var(--accent);
}

.level__stars .off {
    color: #3d4d70;
}

.level--done .level__number::after {
    content: " \2713";
    color: var(--good);
}

/* ------------------------------ playhead ------------------------------- */

.playhead {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 16px;
    margin: 0 0 8px;
}

.playhead__level {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.playhead__rank {
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #16203a;
    background: var(--accent);
    border-radius: 999px;
}

.playhead__hint {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

/* ------------------------------- stage -------------------------------- */

.stage {
    position: relative;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: #0a1020;
    box-shadow: var(--shadow);
    overflow: hidden;
}

#board {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1600 / 448;
    max-height: calc(100vh - 340px);
    object-fit: contain;
    touch-action: manipulation;
    cursor: crosshair;
}


/* The banner over the landscape: "Crowd saved", "Everyone is jam". */
.banner {
    position: absolute;
    inset: auto 0 0;
    display: grid;
    gap: 2px;
    padding: 18px 20px 20px;
    text-align: center;
    background: linear-gradient(180deg, transparent, rgba(8, 12, 22, 0.86) 42%);
    pointer-events: none;
}

.banner__title {
    margin: 0;
    font-size: clamp(20px, 3vw, 30px);
    font-weight: 800;
    letter-spacing: 0.01em;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.banner__line {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

/* -------------------------------- hud --------------------------------- */

.hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 18px;
    margin: 12px 0 0;
}

.stats {
    display: flex;
    gap: 8px;
    margin: 0;
}

.stats__item {
    min-width: 74px;
    padding: 6px 12px;
    text-align: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.stats dt {
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

.stats dd {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stats__item--good dd {
    color: var(--good);
}

.stats__item--bad dd {
    color: var(--warn);
}

.rate {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.rate__button {
    width: 34px;
    height: 34px;
    font-size: 19px;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
}

.rate__button:hover,
.rate__button:focus-visible {
    border-color: var(--accent-2);
}

.rate__value {
    display: grid;
    place-items: center;
    min-width: 56px;
    margin: 0;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rate__unit {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.button {
    padding: 9px 16px;
    font: inherit;
    font-weight: 600;
    color: #101a2e;
    background: linear-gradient(180deg, #ffe08a, var(--accent));
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 10px;
    cursor: pointer;
}

.button:hover,
.button:focus-visible {
    filter: brightness(1.06);
}

.button--ghost {
    color: var(--text);
    background: var(--panel);
    border-color: var(--line);
}

.button--warn {
    color: #2a0f08;
    background: linear-gradient(180deg, #ffb08a, var(--warn));
}

.button--on {
    border-color: var(--accent-2);
    color: var(--accent-2);
}


/* ------------------------------- skills ------------------------------- */

.skills {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
    margin: 12px 0 0;
}

.skill {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 8px 4px 7px;
    font: inherit;
    color: var(--text);
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 120ms ease, transform 80ms ease;
}

.skill:hover,
.skill:focus-visible {
    border-color: var(--accent-2);
}

.skill[aria-pressed="true"] {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.28), 0 8px 18px rgba(0, 0, 0, 0.35);
    background: linear-gradient(180deg, #24345a, #1b2743);
}

.skill:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.skill__glyph {
    width: 26px;
    height: 26px;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.skill__name {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-align: center;
    color: var(--muted);
}

.skill[aria-pressed="true"] .skill__name {
    color: var(--text);
}

.skill__count {
    position: absolute;
    top: -7px;
    right: -6px;
    min-width: 22px;
    padding: 1px 5px;
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #101a2e;
    background: var(--accent);
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.skill:disabled .skill__count {
    background: #4a5b80;
    color: #c3cfe6;
}

.skill__key {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 9px;
    color: #6a7ba1;
}

/* ------------------------------- result ------------------------------- */

.stars {
    margin: 0 auto 18px;
    font-size: 34px;
    letter-spacing: 8px;
    text-align: center;
    color: var(--accent);
}

.stars .off {
    color: #33405f;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.foot {
    padding: 18px 20px 26px;
    color: #6a7ba1;
    font-size: 12px;
    text-align: center;
}

.foot p {
    margin: 0;
}

.foot__stamp {
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
}

/* ---------------------------- small screens --------------------------- */

@media (max-width: 980px) {
    .skills {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    #board {
        max-height: none;
    }
}

@media (max-width: 720px) {
    .main {
        padding: 16px 12px 8px;
    }

    .stats {
        flex-wrap: wrap;
        justify-content: center;
    }

    .hud {
        justify-content: center;
    }

    .topbar__sub {
        display: none;
    }

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

@media (max-width: 460px) {
    .skills {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .skill__name {
        font-size: 10px;
    }

    .stats__item {
        min-width: 62px;
        padding: 5px 8px;
    }

    .stats dd {
        font-size: 15px;
    }

    #controls-hint {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .level,
    .skill {
        transition: none;
    }
}

