/*
 * PINBALL - paper, glass and a lit playfield.
 *
 * The page is warm paper so the cabinet reads as an object on a table; the
 * playfield is the only dark thing on it. Each table's card carries its own
 * --accent and --ink from config/tables.php, so the menu, the HUD and the
 * board all take their colour from the table that is open.
 */

.pinball-page {
    --pb-paper: #f5efe4;
    --pb-paper-soft: #fbf7ef;
    --pb-paper-deep: #ece3d3;
    --pb-ink: #191724;
    --pb-ink-soft: #3a3747;
    --pb-muted: #6b6678;
    --pb-line: rgba(25, 23, 36, 0.13);
    --pb-line-soft: rgba(25, 23, 36, 0.07);
    --pb-night: #0f1724;
    --pb-night-soft: #182337;
    --pb-blue: #1d4ed8;
    --pb-blue-soft: #dbe6ff;
    --pb-good: #0f766e;
    --pb-shadow: 0 18px 40px rgba(30, 25, 20, 0.12);
    --pb-accent: #22d3ee;
    --pb-table-ink: #03202a;
    --pb-font: "Inter", "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    margin: 0;
    color: var(--pb-ink);
    background:
        radial-gradient(900px 520px at 8% -8%, rgba(34, 211, 238, 0.14), transparent 62%),
        radial-gradient(760px 480px at 96% 0%, rgba(251, 146, 60, 0.12), transparent 60%),
        linear-gradient(180deg, #f7f2e8 0%, #f1e9da 60%, #e9dfcd 100%);
    font-family: var(--pb-font);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

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

.pinball-page .skip-link {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 200;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--pb-night);
    color: #fdf9f1;
    font: 600 0.8rem/1.2 var(--pb-font);
    text-decoration: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    transform: translateY(-220%);
}

.pinball-page .skip-link:focus {
    transform: translateY(0);
}

.pb {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 64px;
}

/* ---------- the top of the page ---------- */

.pb-hero {
    max-width: 640px;
    margin: 0 0 26px;
}

.pb-hero__kicker {
    margin: 0 0 6px;
    color: var(--pb-muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.pb-hero__title {
    margin: 0;
    font-size: clamp(2.2rem, 5vw, 3.1rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.02;
}

.pb-hero__tag {
    margin: 10px 0 0;
    color: var(--pb-ink-soft);
    font-size: 1.02rem;
}

/* ---------- the cards ---------- */

.pb-menu__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px 20px;
    margin-bottom: 14px;
}

.pb-menu__head h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.pb-menu__head p {
    margin: 0;
    color: var(--pb-muted);
    font-size: 0.85rem;
}

.pb-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(214px, 1fr));
    gap: 16px;
}

/* The shelf and the two panels share one row: the cards on the left, the keys and
   the board on the right, level with the top of the first card. */
.pb-menu__body {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 16px;
}

.pb-menu__body .pb-cards {
    flex: 1 1 320px;
    min-width: 0;
}

.pb-card {
    display: flex;
    /* A card is a table's poster, not a page. One table on the shelf would
       otherwise stretch its art the width of the column. */
    max-width: 340px;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--pb-line);
    border-radius: 18px;
    background: var(--pb-paper-soft);
    color: var(--pb-ink);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(30, 25, 20, 0.06);
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.pb-card:hover,
.pb-card:focus-visible {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 16px 34px rgba(30, 25, 20, 0.14);
}

.pb-card:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.pb-card__art {
    display: block;
    position: relative;
    aspect-ratio: 480 / 776;
    overflow: hidden;
    background: var(--accent);
}

.pb-card__art img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pb-card__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    padding: 13px 16px 12px;
}

.pb-card__name {
    font-size: 1.04rem;
    font-weight: 750;
    letter-spacing: -0.01em;
    line-height: 1.25;
}

.pb-card__tag {
    color: var(--pb-muted);
    font-size: 0.84rem;
}

.pb-card__best {
    margin-top: 8px;
    color: var(--pb-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.pb-card__best b {
    color: var(--pb-ink);
    font-size: 0.9rem;
    letter-spacing: 0;
}

.pb-card__go {
    align-self: flex-start;
    margin-top: 10px;
    padding: 4px 12px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 26%, transparent);
    color: var(--pb-ink);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.pb-menu__hint {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 22px;
    margin: 18px 0 0;
    color: var(--pb-muted);
    font-size: 0.8rem;
}

.pb-menu__hint kbd,
.pb-keys kbd {
    display: inline-block;
    min-width: 1.5em;
    padding: 1px 6px;
    border: 1px solid var(--pb-line);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--pb-paper);
    color: var(--pb-ink-soft);
    font: 600 0.74rem/1.4 var(--pb-font);
    text-align: center;
}


/* ---------- the table that is open ---------- */

.pb-game {
    --accent: var(--pb-accent);
}

.pb-back,
.pb-sound {
    padding: 8px 14px;
    border: 1px solid var(--pb-line);
    border-radius: 999px;
    background: var(--pb-paper-soft);
    color: var(--pb-ink);
    font: 600 0.82rem/1 var(--pb-font);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.pb-back:hover,
.pb-sound:hover {
    border-color: var(--accent);
    background: #fffdf8;
}

.pb-back:focus-visible,
.pb-sound:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.pb-sound {
    margin-left: auto;
}

.pb-sound[aria-pressed="false"] {
    color: var(--pb-muted);
    text-decoration: line-through;
}

.pb-hud {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr 1.2fr;
    gap: 1px;
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px solid var(--pb-line);
    border-radius: 16px;
    background: var(--pb-line);
}

.pb-hud__cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: 10px 14px;
    background: var(--pb-paper-soft);
}

.pb-hud__cell--wide {
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--accent) 22%, var(--pb-paper-soft)), var(--pb-paper-soft));
}

.pb-hud__label {
    color: var(--pb-muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.pb-hud__value {
    overflow: hidden;
    font-size: 1.22rem;
    font-weight: 780;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- playfield ---------- */

.pb-body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 18px;
}

/* The stage sits tight around the playfield, so the side panels ride next to it
   instead of being pushed to the far edge of a wide column. */
.pb-play {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.pb-stage {
    position: relative;
    display: flex;
    justify-content: center;
    padding: 12px;
    border-radius: 22px;
    background:
        radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.18), transparent 60%),
        linear-gradient(180deg, #24314a 0%, #131c2c 60%, #0b1220 100%);
    box-shadow: 0 22px 46px rgba(15, 23, 36, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

#pb-canvas {
    display: block;
    width: auto;
    /* The board keeps clear of the bar, the numbers, the padding and the row under
       it, so the whole machine is on screen without a scrollbar. */
    height: min(760px, calc(100dvh - 210px));
    aspect-ratio: 480 / 776;
    max-width: 100%;
    border-radius: 14px;
    background: #04121f;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12), 0 10px 26px rgba(0, 0, 0, 0.4);
    touch-action: none;
}

#pb-canvas:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

.pb-status {
    margin: 12px 0 0;
    min-height: 1.4em;
    color: var(--pb-ink-soft);
    font-size: 0.86rem;
}

.pb-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    padding: 16px;
    overflow: auto;
    border-radius: 22px;
    background: rgba(7, 11, 19, 0.72);
    backdrop-filter: blur(7px);
}

.pb-overlay[hidden] {
    display: none;
}

.pb-overlay__panel {
    width: min(340px, 100%);
    padding: 24px 22px 20px;
    border-radius: 20px;
    background: var(--pb-paper-soft);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    text-align: center;
}

.pb-overlay__kicker {
    margin: 0;
    color: var(--pb-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.pb-overlay__title {
    margin: 4px 0 8px;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.pb-overlay__score {
    margin: 0;
    font-size: 2.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.pb-overlay__score span {
    color: var(--accent);
    -webkit-text-stroke: 0.5px rgba(0, 0, 0, 0.25);
}

.pb-overlay__line {
    margin: 8px 0 16px;
    color: var(--pb-ink-soft);
    font-size: 0.88rem;
}

.pb-save {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin: 0 0 14px;
    text-align: left;
}

.pb-save[hidden] {
    display: none;
}

.pb-save label {
    color: var(--pb-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.pb-save input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--pb-line);
    border-radius: 10px;
    background: #fffdf8;
    color: var(--pb-ink);
    font: 600 0.95rem/1.3 var(--pb-font);
}

.pb-save input:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 1px;
}

.pb-save button,
.pb-primary {
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: var(--pb-blue);
    color: #f8fafc;
    font: 700 0.88rem/1.2 var(--pb-font);
    cursor: pointer;
    transition: filter 0.15s ease;
}

.pb-save button:hover,
.pb-primary:hover {
    filter: brightness(1.1);
}

.pb-save button:disabled {
    opacity: 0.6;
    cursor: progress;
}

.pb-overlay__actions {
    display: flex;
    gap: 8px;
}

.pb-overlay__actions .pb-primary {
    flex: 1;
}

.pb-quiet {
    padding: 10px 14px;
    border: 1px solid var(--pb-line);
    border-radius: 11px;
    background: transparent;
    color: var(--pb-ink);
    font: 650 0.86rem/1.2 var(--pb-font);
    cursor: pointer;
}

.pb-overlay__actions button:focus-visible,
.pb-save button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.pb-overlay__note {
    margin: 12px 0 0;
    color: var(--pb-muted);
    font-size: 0.8rem;
}

.pb-overlay__note[hidden] {
    display: none;
}

/* ---------- the side panels ---------- */

.pb-side {
    display: flex;
    flex: 0 0 316px;
    flex-direction: column;
    gap: 12px;
}

.pb-panel {
    padding: 14px 16px;
    border: 1px solid var(--pb-line);
    border-radius: 16px;
    background: var(--pb-paper-soft);
}

.pb-panel__title {
    margin: 0 0 8px;
    color: var(--pb-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.pb-keys {
    display: grid;
    gap: 7px;
    margin: 0;
}

.pb-keys > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.pb-keys dt {
    color: var(--pb-ink-soft);
    font-size: 0.84rem;
}

.pb-keys dd {
    margin: 0;
    text-align: right;
    color: var(--pb-muted);
    font-size: 0.78rem;
}

/* ---------- the board for the open table ---------- */

.pb-board {
    display: grid;
    gap: 1px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pb-board li {
    display: grid;
    grid-template-columns: 1.5rem minmax(0, 1fr) auto;
    gap: 8px;
    align-items: baseline;
    padding: 5px 0;
    border-bottom: 1px dashed var(--pb-line-soft);
    font-size: 0.86rem;
}

.pb-board li:last-child {
    border-bottom: 0;
}

.pb-board__rank {
    color: var(--pb-muted);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.pb-board__name {
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pb-board__tick {
    margin-left: 5px;
    color: var(--pb-good);
    font-size: 0.74rem;
}

.pb-board__score {
    font-weight: 760;
    font-variant-numeric: tabular-nums;
}

.pb-board__empty {
    margin: 4px 0 0;
    color: var(--pb-muted);
    font-size: 0.82rem;
}

.pb-board__empty[hidden] {
    display: none;
}

/* ---------- touch pads ---------- */

.pb-touch {
    display: none;
    grid-template-columns: 1fr 1.15fr 1fr;
    gap: 10px;
    margin-top: 14px;
}

.pb-touch__pad {
    padding: 18px 8px;
    border: 1px solid var(--pb-line);
    border-radius: 14px;
    background: var(--pb-paper-soft);
    color: var(--pb-ink);
    font: 700 0.82rem/1.2 var(--pb-font);
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pb-touch__pad--plunger {
    background: var(--pb-night);
    color: #f8fafc;
}

.pb-touch__pad.is-down {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--pb-ink);
}

/* ---------- the two notes under the cabinet ---------- */

.pb-foot {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 30px;
}

.pb-foot__card {
    padding: 16px 18px;
    border: 1px solid var(--pb-line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--pb-paper-soft) 72%, transparent);
}

.pb-foot__card h2 {
    margin: 0 0 6px;
    font-size: 0.98rem;
    font-weight: 750;
}

.pb-foot__card p {
    margin: 0;
    color: var(--pb-ink-soft);
    font-size: 0.88rem;
}

/* ---------- the machine fills the window ---------- */

/* A table open turns the page into the machine: the navigation, the numbers, then
   the board, and nothing else. The hero, the two notes and the side panels are menu
   furniture, so they leave the flow. The HUD stays: it is where the score is written,
   and the board itself does not print it. */

.pinball-page.is-playing {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.pinball-page.is-playing .pb {
    display: flex;
    width: 100%;
    /* No ceiling: the board's height rule measures the window, so
       a column narrower than the window would keep the machine small on a big
       screen. It takes the room it has and only shrinks when the window does. */
    max-width: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    /* The bar is 39px and its logo hangs past it, so the numbers start below the
       mark rather than under it. */
    padding: 34px 16px 8px;
}

.pinball-page.is-playing .pb-hero,
.pinball-page.is-playing .pb-foot {
    display: none;
}

.pinball-page.is-playing .pb-game {
    display: flex;
    flex: 1;
    min-height: 0;
    align-items: center;
    flex-direction: column;
}

/* The numbers, the way out and the pads are one column the width of a cabinet, so
   the machine has one edge whether it is drawn tall or wide. The row is a strip
   rather than a block: a label beside its number, the way a score bar reads. */
.pinball-page.is-playing .pb-hud {
    width: min(100%, 480px);
    margin-bottom: 10px;
}

.pinball-page.is-playing .pb-hud__cell {
    flex-direction: row;
    align-items: baseline;
    gap: 7px;
    padding: 6px 10px;
}

.pinball-page.is-playing .pb-hud__label {
    font-size: 0.6rem;
    line-height: 1.2;
    letter-spacing: 0.06em;
}

.pinball-page.is-playing .pb-hud__value {
    font-size: 1rem;
    line-height: 1.4;
}

/* Hidden, not gone: the table's name is the heading a screen reader reaches first,
   and the score and ball above the cabinet are the only place a player reads them. */
.pb-only {
    position: absolute;
    width: 1px;
    height: 1px;
    min-height: 0;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.pinball-page.is-playing .pb-body {
    flex: 1;
    min-height: 0;
    align-items: stretch;
}

/* The cabinet is tight around the board: the stage is as wide as the board plus
   its padding, and the auto margins keep it in the middle of whatever is left.
   The column itself takes every pixel the panels leave, so the board's width rule
   measures the room it really has - a column that shrank to fit its own canvas
   would freeze the board at the size it opened at. */
.pinball-page.is-playing .pb-play {
    min-height: 0;
    flex: 1 1 auto;
    align-items: center;
    justify-content: flex-start;
}

.pinball-page.is-playing .pb-stage {
    flex: 0 0 auto;
    margin: 0;
}

/* The way out and the sound sit on the machine's own top corners, so neither needs
   a row. They fade until they are pointed at, which keeps them out of the play. */
.pinball-page.is-playing .pb-back,
.pinball-page.is-playing .pb-sound {
    position: absolute;
    top: 18px;
    z-index: 4;
    padding: 5px 11px;
    border-color: rgba(255, 255, 255, 0.24);
    background: rgba(9, 15, 30, 0.55);
    color: #e8f0fb;
    font-size: 0.72rem;
    backdrop-filter: blur(6px);
    opacity: 0.62;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}

.pinball-page.is-playing .pb-back {
    left: 18px;
}

.pinball-page.is-playing .pb-sound {
    right: 18px;
    margin-left: 0;
}

.pinball-page.is-playing .pb-back:hover,
.pinball-page.is-playing .pb-back:focus-visible,
.pinball-page.is-playing .pb-sound:hover,
.pinball-page.is-playing .pb-sound:focus-visible {
    border-color: var(--accent);
    background: rgba(9, 15, 30, 0.8);
    color: #f8fbff;
    opacity: 1;
}

/* The three pads are the machine's only other row, and only on a screen without a
   pointer to hover: a thumb needs them and nothing else can put them there. */
.pinball-page.is-playing .pb-touch {
    width: min(100%, 420px);
    margin: 12px auto 0;
}

@media (min-width: 901px) and (hover: hover) {
    /* The board was measured to fit and the pads are hidden for a mouse, so there is
       nothing below it to scroll to. A wide touch screen keeps its scrollbar: there
       the pads sit under the board and clipping them would put the flippers out of
       reach. */
    .pinball-page.is-playing {
        overflow: hidden;
    }
}

@media (max-width: 900px) {
    /* The panels live on the menu, above the machine, so the open table has the
       whole width and is only as tall as the screen. */
    .pinball-page.is-playing .pb {
        flex: 0 0 auto;
    }

    .pinball-page.is-playing .pb-body {
        flex: 0 0 auto;
        align-items: center;
    }
}

/* ---------- narrow screens ---------- */

@media (hover: none), (max-width: 860px) {
    .pb-touch {
        display: grid;
    }
}

@media (max-width: 900px) {
    .pb-body {
        flex-direction: column;
        align-items: center;
    }

    .pb-menu__body {
        flex-direction: column;
        align-items: stretch;
    }

    .pb-side {
        width: 100%;
        max-width: 560px;
        flex-basis: auto;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }

    .pb-menu__body .pb-side {
        max-width: none;
    }

    #pb-canvas {
        width: min(100%, 420px);
        height: auto;
    }
}

@media (max-width: 640px) {
    .pb {
        width: calc(100% - 20px);
        padding-top: 18px;
    }

    .pb-hud {
        grid-template-columns: 1fr 1fr;
    }

    .pb-hud__cell--wide {
        grid-column: 1 / -1;
    }

    /* While a table is open the row is a strip, and the strip fits a small screen in
       two rows of two - the score does not get a row to itself. */
    .pinball-page.is-playing .pb-hud__cell--wide {
        grid-column: auto;
    }

    .pb-sound {
        margin-left: 0;
    }

    .pb-stage {
        padding: 8px;
        border-radius: 18px;
    }

    #pb-canvas {
        width: 100%;
        border-radius: 12px;
    }

    .pb-overlay {
        border-radius: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pinball-page *,
    .pinball-page *::before,
    .pinball-page *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
