:root {
    --sky-top: #b9d3ea;
    --sky-bottom: #f3e7d6;
    --bg: #eef1f4;
    --panel: rgba(255, 255, 255, 0.72);
    --panel-border: rgba(255, 255, 255, 0.9);
    --text: #1f2a36;
    --muted: #5d6b7a;
    --accent: #d9682f;
    --water: #2c8fc0;
    --shadow: 0 10px 30px rgba(31, 42, 54, 0.14);
    --radius: 14px;
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color-scheme: light;
}

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

html {
    background: var(--bg);
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.6 var(--font);
    -webkit-font-smoothing: antialiased;
}

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

h1,
h2,
h3 {
    line-height: 1.2;
}

kbd {
    display: inline-block;
    min-width: 1.5em;
    padding: 0 0.35em;
    border: 1px solid rgba(31, 42, 54, 0.18);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.7);
    font: 600 0.8em/1.6 ui-monospace, 'Cascadia Mono', Consolas, monospace;
    text-align: center;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

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

/* --- Top bar ---------------------------------------------------------------- */

.topbar {
    position: absolute;
    inset: 0 0 auto;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 800;
    font-size: 18px;
    text-decoration: none;
}

.brand-mark {
    width: 30px;
    height: 30px;
}

.brand-tld {
    color: var(--water);
}

.topbar-nav a {
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.topbar-nav a:hover {
    color: var(--text);
}

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

.stage {
    position: relative;
    height: 100vh;
    height: 100svh;
    min-height: 560px;
    overflow: hidden;
    background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom) 75%);
}

/* Overcast sky while it rains (a gradient cannot be transitioned, an overlay's opacity can). */
.stage::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, #6f7c88, #b9bcbf 75%);
    opacity: 0;
    transition: opacity 1.5s ease;
}

.stage.is-raining::before {
    opacity: 1;
}

.stage-viewport {
    position: absolute;
    inset: 0;
    cursor: crosshair;
}

[data-tool='hammer'] .stage-viewport {
    cursor: pointer;
}

.stage-gl {
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.is-ready .stage-gl {
    opacity: 1;
}

.hud {
    position: absolute;
    z-index: 5;
}

/* Tool bar: a column on the left */
.hud-tools {
    top: 64px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 150px;
    max-height: calc(100% - 80px);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    scrollbar-width: thin;
}

.tool {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font: 600 14px/1 var(--font);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tool:hover {
    background: rgba(31, 42, 54, 0.07);
}

.tool[aria-pressed='true'] {
    background: var(--text);
    color: #fff;
}

.tool kbd {
    border-color: currentColor;
    background: transparent;
    opacity: 0.55;
}

.tool-water[aria-pressed='true'],
.tool-spring[aria-pressed='true'],
.tool-sponge[aria-pressed='true'] {
    background: var(--water);
}

.tool-dig[aria-pressed='true'],
.tool-raise[aria-pressed='true'],
.tool-push[aria-pressed='true'] {
    background: var(--accent);
}

.tool-clay[aria-pressed='true'] {
    background: #a84f31;
}

.tool-rock[aria-pressed='true'] {
    background: #5c6168;
}

.tool-lava[aria-pressed='true'] {
    background: #e8590c;
}

.tool-objects[aria-pressed='true'] {
    background: #f2b705;
    color: #1f2a36;
}

select {
    width: 100%;
    padding: 7px 8px;
    border: 1px solid rgba(31, 42, 54, 0.18);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    font: 600 13px/1.2 var(--font);
}

/* Settings panel */
.hud-panel {
    top: 70px;
    right: 24px;
    width: 260px;
    max-height: calc(100% - 170px);
    overflow-y: auto;
    padding: 16px 18px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

.control {
    display: grid;
    gap: 4px;
    margin-bottom: 12px;
}

.control label {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.control output {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

input[type='range'] {
    width: 100%;
    accent-color: var(--accent);
}

.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0;
    font-weight: 600;
    cursor: pointer;
}

.switch input {
    width: 18px;
    height: 18px;
    accent-color: var(--water);
}

.panel-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 6px;
}

.panel-title {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.btn {
    padding: 9px 10px;
    border: 1px solid rgba(31, 42, 54, 0.14);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.85);
    color: var(--text);
    font: 600 13px/1.2 var(--font);
    cursor: pointer;
}

.btn:hover:not(:disabled) {
    border-color: var(--text);
}

.btn:disabled {
    color: var(--muted);
    cursor: default;
    opacity: 0.7;
}

.panel-hint {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.7;
}

.btn-panel {
    display: none;
}

.toast {
    position: absolute;
    top: 76px;
    left: 50%;
    z-index: 6;
    margin: 0;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--text);
    color: #fff;
    font-weight: 600;
    transform: translate(-50%, -6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

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

.stage-fallback {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: grid;
    place-items: center;
    padding: 24px;
    text-align: center;
}

.stage-fallback[hidden] {
    display: none;
}

.stage-fallback p {
    max-width: 420px;
    padding: 20px;
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.is-fallback .hud-tools,
.is-fallback .hud-panel,
.is-fallback .btn-panel {
    display: none;
}

@media (max-width: 899px) {
    .topbar { padding: 12px 16px; }

    /* On a phone the tools go back to the bottom, in one row that scrolls sideways */
    .hud-tools {
        top: auto;
        right: 12px;
        bottom: 12px;
        left: 12px;
        flex-direction: row;
        width: auto;
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }

    .tool {
        flex: 0 0 auto;
        padding: 12px 14px;
        font-size: 13px;
    }

    .tool kbd { display: none; }

    .btn-panel {
        display: block;
        top: 58px;
        right: 16px;
        box-shadow: var(--shadow);
    }

    .hud-panel {
        top: 104px;
        right: 12px;
        left: 12px;
        width: auto;
        max-height: 50svh;
        display: none;
    }

    .is-panel-open .hud-panel { display: block; }
    .hint-keys { display: none; }
}

/* --- About -------------------------------------------------------------------------- */

.about {
    max-width: 1100px;
    margin: 0 auto;
    padding: 80px 24px 56px;
}

.about > h2 {
    margin: 0 0 32px;
    font-size: clamp(24px, 3vw, 32px);
}

.about-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    gap: 28px 44px;
}

.about h3 {
    margin: 0 0 8px;
    font-size: 17px;
}

.about p {
    margin: 0;
    color: #3d4a58;
}

/* --- Text pages (legal) --------------------------------------------------------------- */

.page-head {
    max-width: 820px;
    margin: 0 auto;
    padding: 110px 24px 8px;
}

.page-head h1 {
    margin: 0 0 8px;
    font-size: clamp(26px, 4vw, 38px);
}

.content {
    max-width: 820px;
    margin: 0 auto;
    padding: 0 24px 64px;
}

.content-section h2 {
    margin: 32px 0 10px;
    font-size: 19px;
}

.content-section ul { padding-left: 20px; }

mark.todo {
    padding: 0 4px;
    background: #ffe36e;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
