:root {
    --color-error: #ffb4ae;
    --color-error-bg: #2b191c;
    --color-error-border: #87464a;
    --bg: #111318;
    --panel: #1c2027;
    --panel-raised: #2a303a;
    --panel-inset: #161a21;
    --line: #37414e;
    --text: #f1f4f8;
    --muted: #a9b3c2;
    --card-title: #d4dce7;
    --accent: #00a4ff;
    --accent-hover: #31b5ff;
    --accent-text: #73caff;
    --accent-contrast: #071724;
    --accent-soft: rgb(0 164 255 / 12%);
    --page-glow: #182b3b;
    --topbar-bg: rgb(17 19 24 / 94%);
    --cover-w: 85px;
    --cover-h: 128px;
    --title-gap: 5px;
    --title-h: 20px;
    --card-font: 16px;
    --card-h: calc(var(--cover-h) + var(--title-gap) + var(--title-h));
    --games-pad: 8px;
    --page-gutter: 18px;
    --section-space: 18px;
    --layer-board-controls: 4;
    --tier-label-width: 86px;
    --tier-label-font-size: 34px;
    --row-min-h: calc(var(--card-h) + var(--games-pad) * 2);
    color-scheme: dark;
}

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

html,
body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(1200px 500px at 10% -10%, var(--page-glow) 0%, var(--bg) 55%);
    color: var(--text);
    font-family: Manrope, ui-sans-serif, system-ui, sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* Page */
.page--home,
.page--share {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.site-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding: var(--section-space) var(--page-gutter) 22px;
    text-align: center;
}

.site-footer__text {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    letter-spacing: 0.01em;
}

.site-footer__link {
    color: var(--accent-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.site-footer__link:hover {
    color: var(--text);
}

.page--editor {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

.page--editor:fullscreen,
:fullscreen.page--editor {
    width: 100%;
    height: 100%;
    max-height: none;
    overflow: hidden;
}

.page--editor #editor-root {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.page--editor #editor-root > .workspace {
    flex: 1 1 auto;
    min-height: 0;
}

/* Button */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}

.button--primary {
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 800;
}

.button--primary:hover {
    background: var(--accent-hover);
}

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

/* Page actions */
.page-actions__icon {
    display: none;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.dialog__url {
    width: 100%;
    min-width: 0;
    padding: 12px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    font: inherit;
}

.share-status {
    position: fixed;
    z-index: 50;
    bottom: calc(var(--page-actions-height, 0px) + 12px);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 0;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
    text-align: center;
}

/* Lang switcher */
.lang {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-right: 8px;
}

.lang--topbar {
    margin-left: auto;
    margin-right: 0;
}

.lang__toggle {
    display: none;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
}

.lang__toggle:hover,
.lang--open > .lang__toggle {
    background: var(--panel-raised);
}

.lang__options {
    display: flex;
    align-items: center;
    gap: 2px;
}

.lang__link {
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
    padding: 5px 6px;
    border-radius: 8px;
    opacity: 0.42;
    filter: grayscale(0.2);
}

.lang__link:hover,
.lang__link--active {
    opacity: 1;
    filter: none;
    background: var(--panel-raised);
}

.notices {
    position: fixed;
    z-index: 40;
    right: 16px;
    bottom: calc(16px + var(--page-actions-height, 0px));
    max-height: calc(100dvh - var(--page-actions-height, 0px) - 32px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(520px, calc(100vw - 32px));
}

.lang-prompt {
    display: grid;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

html.is-cookies-dismissed #cookies-notice,
html.is-lang-prompt-dismissed #lang-prompt {
    display: none;
}

.lang-prompt__text {
    margin: 0;
    color: var(--text);
    font-size: 14px;
    line-height: 1.4;
}

.lang-prompt__actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
}

.lang-prompt__actions .button {
    white-space: nowrap;
}

/* Hero */
.hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: min(960px, 100%);
    margin: 0 auto;
    padding: 48px var(--page-gutter) 64px;
}

.hero__title {
    font-family: Syne, sans-serif;
    font-size: clamp(40px, 8vw, 84px);
    line-height: 0.95;
    margin: 12px 0 18px;
}

.hero__lead,
.hero__hint {
    color: var(--muted);
    max-width: 58ch;
}

.hero__hint {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
    margin: 20px 0 14px;
}

.hero__example-line {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
}

.hero__example {
    display: inline;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent-text);
    font: inherit;
    text-decoration: underline dotted;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    cursor: pointer;
    word-break: break-all;
    text-align: left;
}

.hero__example:hover {
    color: var(--text);
}

.hero__example-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    color: var(--muted);
    border-radius: 8px;
    text-decoration: none;
}

.hero__example-open svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hero__example-open:hover {
    color: var(--text);
    background: var(--panel-raised);
}

.hero__example-open:focus-visible {
    outline: 2px solid var(--accent-text);
    outline-offset: 2px;
}

/* Steam form */
.steam-form {
    display: flex;
    gap: 8px;
    width: 100%;
    margin: 28px 0 10px;
}

.steam-form__field {
    flex: 1;
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 14px;
    padding: 14px 16px;
    font: inherit;
}

/* Own key */
.own-key {
    margin: 4px 0 12px;
    color: var(--muted);
    font-size: 14px;
}

.own-key__summary {
    cursor: pointer;
    color: var(--text);
    font-weight: 600;
}

.own-key__get {
    margin: 8px 0 0;
}

.own-key__get-link {
    color: var(--accent-text);
    overflow-wrap: anywhere;
}

.own-key__get-link:hover {
    text-decoration: underline;
}

.own-key__hint {
    margin: 8px 0;
}

.own-key__field {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 14px;
    padding: 12px 16px;
    font: inherit;
}

/* Featured */
.featured {
    margin-top: 48px;
    width: 100%;
}

.featured__head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.featured__title {
    font-family: Syne, sans-serif;
    font-size: 22px;
    margin: 0;
    flex: 1;
}

/* Dialog */
.dialog {
    width: min(440px, 92vw);
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    color: var(--text);
    padding: 22px 22px 18px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.dialog::backdrop {
    background: rgba(0, 0, 0, 0.62);
}

.dialog__title {
    font-family: Syne, sans-serif;
    font-size: 24px;
    margin: 0 0 16px;
}

.dialog__hint {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.4;
}

.dialog__option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 12px 0;
    color: var(--text);
    font-size: 15px;
    line-height: 1.35;
    cursor: pointer;
}

.dialog__option-input {
    margin: 3px 0 0;
    accent-color: var(--accent-text);
    flex-shrink: 0;
}

.dialog__option-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dialog__option-label {
    font-weight: 700;
}

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

.dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* Workspace */
.library-limit-banner {
    flex-shrink: 0;
    margin: 0;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: 13px;
    line-height: 1.4;
}

.workspace {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.board-panel,
.pool-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.board-panel {
    position: relative;
}

.board-panel__scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.board {
    overflow: visible;
    padding: var(--section-space) var(--page-gutter) 4px;
    flex: 0 0 auto;
}

.pool-panel {
    border-left: 1px solid var(--line);
    background: var(--panel-inset);
}

.pool-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 10px var(--page-gutter);
    flex-shrink: 0;
}

.pool-toolbar__filter {
    min-width: 240px;
    flex: 1;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 14px;
    padding: 14px 16px;
    font: inherit;
}

.sorts {
    display: flex;
    gap: 6px;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
}

.sorts__button {
    background: var(--panel-raised);
    color: var(--text);
}

.tier-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
    padding: 2px var(--page-gutter) 12px;
    flex-shrink: 0;
    color: var(--muted);
    font-size: 13px;
}

.tier-controls__button {
    min-width: 72px;
    font-weight: 800;
    background: var(--panel-raised);
    color: var(--text);
}

.tier-controls__button:disabled {
    opacity: 0.35;
    cursor: default;
}

.pool {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 0 var(--page-gutter) var(--section-space);
    flex: 1;
    align-content: flex-start;
    background: transparent;
    min-height: 0;
    margin: 0;
    overflow: auto;
}

.pool--virtual {
    display: block;
    position: relative;
    gap: 0;
}

.pool--flow {
    display: block;
}

.pool__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, var(--cover-w));
    gap: 8px 10px;
    align-items: start;
}

.pool__virtual-space {
    position: relative;
    width: 100%;
}

.pool__virtual-space .game-card {
    will-change: transform;
}

.dialog__message {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

/* Share credit */
.share-credit {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: var(--section-space) var(--page-gutter) 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.35;
}

.share-credit__avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.share-credit__text {
    margin: 0;
}

.share-credit__link {
    color: var(--text);
    font-weight: 800;
    text-decoration: none;
}

.share-credit__link:hover {
    color: var(--accent-text);
    text-decoration: underline;
}

@media (min-width: 960px) {
    .tier-controls {
        position: absolute;
        top: calc(var(--section-space) + 6px);
        right: calc(var(--page-gutter) + 6px);
        z-index: var(--layer-board-controls);
        gap: 4px;
        padding: 0;
    }

    .tier-controls__button {
        min-width: 56px;
        min-height: 30px;
        padding: 6px 10px;
        border-radius: 9px;
        font-size: 12px;
        line-height: 1.2;
    }
}

@media (max-width: 959px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .pool-panel {
        border-left: none;
        border-top: 1px solid var(--line);
    }

    /* Single-column editor: page scroll, not a locked 70/30 split */
    .page--editor:not(:fullscreen) {
        height: auto;
        min-height: 100dvh;
        max-height: none;
        overflow-x: hidden;
        overflow-y: visible;
        width: 100%;
        max-width: 100vw;
    }

    .page--editor:not(:fullscreen) #editor-root {
        flex: 1 0 auto;
    }

    .page--editor:not(:fullscreen) .workspace {
        flex: none;
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 0;
        width: 100%;
        max-width: 100%;
    }

    .page--editor:not(:fullscreen) .board-panel,
    .page--editor:not(:fullscreen) .pool-panel {
        flex: none;
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .page--editor:not(:fullscreen) .board-panel__scroll,
    .page--editor:not(:fullscreen) .pool {
        overflow: visible;
    }

    /* Fullscreen keeps locked panels + internal scroll even on narrow viewports */
    .page--editor:fullscreen .workspace,
    :fullscreen.page--editor .workspace {
        flex: 1 1 auto;
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        height: auto;
    }

    .page--editor:fullscreen .board-panel,
    .page--editor:fullscreen .pool-panel,
    :fullscreen.page--editor .board-panel,
    :fullscreen.page--editor .pool-panel {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .page--editor:fullscreen .board-panel__scroll,
    .page--editor:fullscreen .pool,
    :fullscreen.page--editor .board-panel__scroll,
    :fullscreen.page--editor .pool {
        overflow: auto;
    }
}

@media (max-width: 720px) {
    :root {
        --page-gutter: 10px;
        --section-space: 12px;
        --tier-label-width: 40px;
        --tier-label-font-size: 24px;
    }

    .page--share,
    .page--editor {
        padding-bottom: var(--page-actions-height, 84px);
    }

    .page-actions {
        position: fixed;
        z-index: 30;
        inset: auto 0 0;
        display: grid;
        gap: 6px;
        padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        border-top: 1px solid var(--line);
        background: var(--bg);
    }

    .page-actions--viewer {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .page-actions--editor {
        grid-template-columns: minmax(0, 1fr);
    }

    .page-actions__button {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        width: 100%;
        min-width: 0;
        min-height: 56px;
        padding: 8px 4px;
        font-size: 12px;
        line-height: 1.3;
        white-space: normal;
        overflow-wrap: anywhere;
        text-align: center;
    }

    .page-actions__icon {
        display: block;
    }

    .hero {
        justify-content: flex-start;
        padding: 16px var(--page-gutter) 24px;
    }

    .hero__title {
        margin: 0 0 12px;
    }

    .hero__lead {
        margin: 0 0 16px;
    }

    .steam-form {
        margin-top: 0;
    }

    .lang-prompt__actions {
        flex-wrap: wrap;
    }

    .lang-prompt__actions .button {
        white-space: normal;
    }

    .steam-form,
    .pool-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .lang__toggle {
        display: grid;
    }

    .lang__options {
        display: none;
        position: absolute;
        top: calc(100% + 6px);
        right: 0;
        z-index: 20;
        min-width: 52px;
        max-height: calc(100dvh - var(--page-actions-height, 0px) - 80px);
        overflow-y: auto;
        padding: 6px;
        flex-direction: column;
        gap: 2px;
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 12px;
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    }

    .lang--open > .lang__options {
        display: flex;
    }

    .lang__link {
        display: grid;
        place-items: center;
        width: 40px;
        height: 36px;
        padding: 0;
    }

    .page--editor .tier-controls {
        padding: 2px var(--page-gutter) 10px;
    }

    .page--editor .pool-toolbar {
        padding: 8px var(--page-gutter);
    }

    .page--editor .pool-toolbar__filter {
        min-width: 0;
        width: 100%;
    }

    .page--editor .pool {
        padding: 0 var(--page-gutter) var(--section-space);
    }
}
