:root {
    --bg: #14141f;
    --panel: #1e1e2e;
    --text: #e6e6f0;
    --muted: #8a8aa3;
    --accent: #ff9e3d;
    --accent-2: #5ec2ff;
    --error: #ff6b81;
}

body {
    font-family: system-ui, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--accent-2);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1 {
    color: var(--accent);
}

main {
    padding: 1.5rem 2rem;
    max-width: 1100px;
    margin: 0 auto;
}

.topbar {
    display: flex;
    gap: 1.5rem;
    align-items: baseline;
    padding: 0.75rem 2rem;
    background: var(--panel);
}

.topbar a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    touch-action: manipulation;
}

.topbar .brand {
    font-weight: 800;
    font-size: 1.4rem;
    color: var(--accent);
    letter-spacing: 0.05em;
}

/* Account control: right of the site links, with its sign-in dialog
   dropping down from it. */
.account {
    position: relative;
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.account-name {
    font-weight: 700;
}

.account-button {
    font: inherit;
    font-weight: 700;
    min-height: 44px;
    padding: 0.4rem 0.9rem;
    border: 2px solid var(--accent);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    touch-action: manipulation;
}

.account-button:disabled {
    opacity: 0.45;
    cursor: wait;
}

.account-primary {
    background: var(--accent);
    color: var(--bg);
}

@media (hover: hover) {
    .account-button:not(:disabled):hover {
        background: var(--accent);
        color: var(--bg);
    }
}

.account-dialog {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    z-index: 10;
    width: min(22rem, calc(100vw - 2rem));
    padding: 1rem;
    background: var(--panel);
    border: 2px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 18px 60px #0006;
}

.account-dialog label {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
}

.account-dialog input {
    box-sizing: border-box;
    width: 100%;
    min-height: 44px;
    margin: 0.35rem 0 0.75rem;
    padding: 0.4rem 0.6rem;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--muted);
    border-radius: 6px;
}

.account-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.account-reason {
    margin: 0 0 0.75rem;
    font-weight: 700;
}

.account-error {
    color: var(--error);
}

.account-status {
    color: var(--accent-2);
    font-size: 0.85rem;
}

.account-help,
.account-notice {
    color: var(--muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.account-notice {
    flex-basis: 100%;
    margin: 0;
    text-align: right;
}

.muted {
    color: var(--muted);
}

.error {
    color: var(--error);
}

.n-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(3.5rem, 1fr));
    gap: 0.5rem;
    max-width: 40rem;
}

.n-button,
.button {
    display: inline-block;
    padding: 0.6rem 0.9rem;
    text-align: center;
    background: var(--panel);
    border: 2px solid var(--accent);
    border-radius: 6px;
    color: var(--text);
    font-weight: 700;
    min-height: 44px;
    line-height: 1.6;
    touch-action: manipulation;
}

@media (hover: hover) {
    .n-button:hover,
    .button:hover {
        background: var(--accent);
        color: var(--bg);
        text-decoration: none;
    }
}

table {
    border-collapse: collapse;
    margin-top: 1rem;
    width: 100%;
}

/* Wide leaderboard tables scroll sideways on narrow screens. */
.leaderboard {
    overflow-x: auto;
}

th,
td {
    padding: 0.4rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--panel);
    font-variant-numeric: tabular-nums;
}

th {
    color: var(--muted);
    font-weight: 600;
}

.long-expr {
    cursor: help;
}

/* A name typed before accounts, so not a verified username. */
.legacy {
    color: var(--muted);
    cursor: help;
}

.badge.legacy-badge {
    background: var(--muted);
}

.badge {
    margin-left: 0.5rem;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    background: var(--accent-2);
    color: var(--bg);
}

svg.arrangement {
    width: min(90vw, 480px);
    height: auto;
    display: block;
    margin: 1rem 0;
}

svg.arrangement .container {
    fill: var(--panel);
    stroke: var(--muted);
    stroke-width: 0.02;
}

svg.arrangement .square {
    stroke: var(--bg);
    stroke-width: 0.02;
}

/* Play screen */

.packing-game {
    --ink: #e9edf5;
    --pg-muted: #a1adc2;
    --pg-accent: #c7f36b;
    color: var(--ink);
    max-width: 1250px;
    margin: auto;
    padding: 24px 12px;
}

.packing-game * {
    box-sizing: border-box;
}

.pg-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.pg-eyebrow {
    color: var(--pg-accent);
    text-transform: uppercase;
    letter-spacing: 0.17em;
    font-size: 11px;
    font-weight: 800;
}

.packing-game h1 {
    color: var(--ink);
    font-size: clamp(32px, 5vw, 58px);
    letter-spacing: -0.055em;
    margin: 8px 0;
}

.pg-sub {
    color: var(--pg-muted);
    font-size: 14px;
}

.pg-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 22px;
    margin-top: 24px;
}

.pg-board {
    position: relative;
    background: #121823;
    border: 1px solid #303c50;
    border-radius: 22px;
    padding: 16px;
    box-shadow: 0 18px 60px #0003;
}

.pg-board canvas {
    width: 100%;
    aspect-ratio: 1;
    display: block;
    touch-action: none;
    outline: none;
    border-radius: 12px;
}

.pg-board canvas:focus-visible {
    outline: 2px solid var(--pg-accent);
}

.pg-board-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--pg-muted);
    font-size: 13px;
    padding: 12px 4px 0;
}

.pg-panel {
    background: #1c2432;
    border: 1px solid #303c50;
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 14px;
}

.pg-panel h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--pg-muted);
    margin: 0 0 18px;
}

.pg-stat {
    font-size: 30px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.04em;
}

.pg-stat small {
    font-size: 12px;
    color: var(--pg-muted);
    letter-spacing: 0;
}

.pg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 15px 0;
    font-size: 13px;
}

.packing-game input[type="range"] {
    width: 100%;
    height: 32px;
    accent-color: var(--pg-accent);
    touch-action: manipulation;
}

.packing-game input[type="checkbox"] {
    accent-color: var(--pg-accent);
    width: 24px;
    height: 24px;
}

.packing-game button,
.packing-game input[type="text"],
.packing-game input[type="number"] {
    font: inherit;
    border: 1px solid #445067;
    border-radius: 9px;
    background: #273348;
    color: var(--ink);
    padding: 10px 14px;
    min-height: 44px;
    touch-action: manipulation;
}

.packing-game button {
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
}

@media (hover: hover) {
    .packing-game button:hover {
        background: #35455e;
    }
}

.pg-turn {
    display: inline-flex;
    gap: 8px;
}

.packing-game .pg-turn button {
    min-width: 44px;
    font-size: 20px;
    line-height: 1;
}

/* Mouse hints by default; touch devices get touch instructions instead. */
.pg-hint-touch {
    display: none;
}

@media (pointer: coarse) {
    .pg-hint-mouse {
        display: none;
    }

    .pg-hint-touch {
        display: inline;
    }

    /* Native range thumbs are too small to grab with a finger; the thumb can
       only be resized once the native appearance is replaced. */
    .packing-game input[type="range"] {
        -webkit-appearance: none;
        appearance: none;
        height: 44px;
        background: transparent;
    }

    .packing-game input[type="range"]::-webkit-slider-runnable-track {
        height: 6px;
        border-radius: 3px;
        background: #344159;
    }

    .packing-game input[type="range"]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 28px;
        height: 28px;
        margin-top: -11px;
        border-radius: 50%;
        border: 2px solid #17200d;
        background: var(--pg-accent);
    }

    .packing-game input[type="range"]::-moz-range-track {
        height: 6px;
        border-radius: 3px;
        background: #344159;
    }

    .packing-game input[type="range"]::-moz-range-thumb {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        border: 2px solid #17200d;
        background: var(--pg-accent);
    }
}

.packing-game button:disabled {
    opacity: 0.45;
    cursor: wait;
}

.packing-game .pg-primary {
    background: var(--pg-accent);
    color: #17200d;
    border-color: var(--pg-accent);
}

.pg-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pg-force-actions {
    margin-top: 18px;
}

/* The Squeeze slider beside Settle: held, it presses the band in; let go,
   the box springs back out. */
.pg-squeeze .pg-row {
    margin: 12px 0 0;
    font-weight: 700;
}

.pg-squeeze output {
    font-variant-numeric: tabular-nums;
}

.pg-squeeze .pg-help {
    margin: 0 0 12px;
}

.pg-wide {
    width: 100%;
}

.pg-help {
    font-size: 12px;
    line-height: 1.65;
    color: var(--pg-muted);
}

.pg-status {
    font-size: 12px;
    line-height: 1.6;
    min-height: 42px;
    color: var(--pg-accent);
}

.pg-invalid {
    color: #ff9c9c;
}

/* A Share that finally failed: an alert that stands out from status text. */
.pg-share-error {
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid #ff9c9c;
    border-radius: 9px;
    background: #3a1f27;
    color: #ffd6d6;
    font-size: 13px;
}

/* Share or Submit waiting on a sign-in, or dropped because none came. */
.pg-sign-in {
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid var(--pg-accent);
    border-radius: 9px;
    background: #26301b;
    color: var(--ink);
    font-size: 13px;
}

.pg-field {
    width: 100%;
    margin: 8px 0;
}

.packing-game a {
    color: var(--pg-accent);
}

.pg-meter {
    height: 5px;
    background: #344159;
    border-radius: 4px;
    margin: 12px 0;
    overflow: hidden;
}

.pg-meter span {
    display: block;
    height: 100%;
    background: var(--pg-accent);
}

.pg-count {
    width: 75px;
}

/* Benchmark bubble: side as a percentage of the literature reference */

.pg-benchmark {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 8px 18px 8px 14px;
    margin: 12px 0;
    border-radius: 999px;
    background: #1c2432;
    border: 1px solid #303c50;
    box-shadow: 0 8px 30px #0004;
    color: #e9edf5;
}

.pg-benchmark-pct {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
}

.pg-benchmark-text {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.pg-benchmark-text strong {
    font-size: 13px;
}

.pg-benchmark-text small {
    font-size: 11px;
    color: var(--muted);
}

.pg-benchmark.is-near .pg-benchmark-pct {
    color: #5ec2ff;
}

.pg-benchmark.is-match {
    border-color: #c7f36b;
}

.pg-benchmark.is-match .pg-benchmark-pct {
    color: #c7f36b;
}

.pg-benchmark.is-record {
    border-color: #ffcf4d;
    box-shadow: 0 0 0 2px #ffcf4d55, 0 8px 30px #0004;
}

.pg-benchmark.is-record .pg-benchmark-pct {
    color: #ffcf4d;
}

.pg-benchmark.is-suspect {
    border-color: #ff9c9c;
}

.pg-benchmark.is-suspect .pg-benchmark-pct {
    color: #ff9c9c;
}

.pg-benchmark.is-missing .pg-benchmark-pct {
    color: var(--muted);
}

.pg-details {
    margin-top: 16px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--pg-muted);
}

/* Everything beyond drag and Settle, collapsed by default. */
.pg-advanced summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--pg-muted);
    min-height: 44px;
    display: flex;
    align-items: center;
}

.pg-advanced[open] summary {
    margin-bottom: 8px;
}

/* Up to iPad portrait: full-width board, panels below in two columns. */
@media (max-width: 900px) {
    .pg-layout {
        grid-template-columns: 1fr;
    }

    .pg-sidebar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .pg-panel {
        margin: 0;
    }

    .pg-submit {
        grid-column: 1 / -1;
    }
}

@media (max-width: 480px) {
    .pg-sidebar {
        display: block;
    }

    .pg-panel {
        margin-bottom: 12px;
    }

    .pg-board {
        padding: 7px;
    }

    .packing-game {
        padding: 12px 4px;
    }
}
