@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

/* Dark-only palette, safe-area values, and reusable game design tokens. */
:root {
    --bg: hsl(0, 0%, 7%);
    --fg: hsl(0, 0%, 98%);
    --mut: hsl(0, 0%, 76%);
    --card: hsl(240, 2%, 12%);
    --line: hsl(0, 0%, 22%);
    --mus: hsl(0, 43%, 51%);
    --act: hsl(45, 100%, 72%);
    --ok: hsl(145, 55%, 55%);
    --skin: hsl(25, 45%, 72%);
    --skin2: hsl(25, 35%, 58%);
    --short: hsl(45, 54%, 58%);
    --floor: hsl(240, 1%, 17%);
    --ff-poppins: 'Poppins', sans-serif;
    color-scheme: dark;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px)
}

/* Use border-box sizing so layout dimensions include padding and borders. */
* {
    box-sizing: border-box
}

/* Set the game canvas, foreground text, and typeface for the full document. */
html,
body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--ff-poppins)
}

/* Center the game and constrain its maximum width. */
main {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: clamp(12px, 2vw, 24px)
}

/* Arrange the game title and instructions. */
.page-header {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 16px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line)
}

.page-header .sub { margin-bottom: 0 }

.level-label { margin: 0; color: var(--act); font-size: 13px; font-weight: 600 }

/* Split the movement simulation from its written guide. */
.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr);
    gap: 14px;
    align-items: stretch
}

.game-column {
    min-width: 0;
    display: flex;
    flex-direction: column
}

.game-column .stage { flex: 1 0 auto }
.game-column .keys { flex: 0 0 auto }
.game-column #info { flex: 0 0 auto }

/* Make the movement guide a scrollable dark card beside the game. */
.overview {
    min-width: 0;
    height: 100%;
    overflow: auto;
    padding: 16px 18px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--fg);
    font-size: 14px;
    line-height: 1.5
}

.overview h2 { margin: 0 0 8px; font-size: 19px; line-height: 1.25 }
.overview p { margin: 8px 0 }
.overview ol { padding-left: 22px; margin: 6px 0 12px }
.overview li { padding-left: 2px; margin: 0 0 8px }
.overview a { color: var(--fg); font-weight: 650 }

/* Override the shared display face with a clean system UI face on game headings. */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Poppins', system-ui, sans-serif
}

h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -.3px;
    margin: 0 0 4px
}

h1::after {
    content: '';
    display: block;
    width: 34px;
    height: 3px;
    margin-top: 5px;
    border-radius: 3px;
    background: var(--act)
}

p.sub {
    margin: 0 0 12px;
    color: var(--mut);
    font-size: 14px
}

/* Give buttons shared dark surfaces and visible borders. */
button {
    font: inherit;
    font-size: 14px;
    color: var(--fg);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer
}

/* Frame the canvas with a plain dark surface. */
.stage {
    position: relative;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden
}

/* Scale the drawing surface to the width of the game column. */
canvas {
    display: block;
    width: 100%;
    height: auto
}

/* Pin timers and goal information above the canvas. */
.hud {
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 14px;
    pointer-events: none
}

.hud b {
    font-variant-numeric: tabular-nums;
    font-size: 22px
}

.goal {
    color: var(--mut)
}

/* Cover the stage with the results panel after a movement ends. */
#ov {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--card) 88%, transparent);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center
}

#ov .m {
    font-size: 64px;
    line-height: 1
}

#ov .row {
    display: flex;
    gap: 8px;
    margin-top: 10px
}

/* Wrap muscle key controls beneath the stage. */
.keys {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px
}

/* Style each muscle control as a clickable key card. */
.key {
    flex: 1 1 120px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 8px 10px;
    position: relative;
    overflow: hidden;
    user-select: none;
    touch-action: none;
    cursor: pointer
}

.key .cap {
    display: inline-block;
    min-width: 26px;
    text-align: center;
    font-weight: 700;
    border: 1px solid var(--fg);
    border-radius: 6px;
    padding: 1px 6px;
    margin-right: 6px
}

.key small {
    display: block;
    color: var(--mut);
    margin-top: 2px
}

.key i {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    background: var(--act);
    width: 0
}

/* Separate medal records from the key controls. */
.medals {
    margin-top: 12px;
    color: var(--mut);
    font-size: 13px
}

/* Keep the title and instructions aligned on smaller screens. */
@media (max-width: 760px) {
    .page-header { gap: 10px }
}

/* Stack the game and guide into one column on narrow screens. */
@media (max-width: 680px) {
    .workspace { grid-template-columns: minmax(0, 1fr); gap: 12px }
    .overview { height: auto; overflow: visible }
}