body {
    color: #e8f0f0;
}

#pinball-wrapper {
    width: min(96vw, 1120px);
    margin: 18px auto 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.pinball-panel {
    width: min(92vw, 600px);
    box-sizing: border-box;
    padding: 14px 18px;
    text-align: center;
    background: rgba(16, 35, 52, 0.9);
    border: 2px solid #126364;
    border-radius: 12px;
    box-shadow: 0 0 18px rgba(8, 15, 24, 0.4);
}

.pinball-stat {
    margin: 6px 0;
    font-size: 1.02em;
}

.pinball-stat.blue {
    color: #7ddfdf;
    font-weight: 700;
}

.level-track {
    height: 7px;
    margin-top: 11px;
    overflow: hidden;
    background: rgba(125, 223, 223, 0.13);
    border-radius: 999px;
}

.level-track span {
    display: block;
    width: 3.33%;
    height: 100%;
    background: #7ddfdf;
    border-radius: inherit;
    transition: width 0.3s ease;
}

#pinball-board-shell {
    --port-band: clamp(34px, 7vw, 48px);
    --board-gap: clamp(2px, 0.65vw, 6px);
    --board-padding: clamp(5px, 1.3vw, 10px);
    --grid-border: 2px;
    position: relative;
    display: grid;
    grid-template-columns: var(--port-band) minmax(0, 1fr) var(--port-band);
    grid-template-rows: var(--port-band) minmax(0, 1fr) var(--port-band);
    width: min(94vw, 650px);
    aspect-ratio: 1 / 1;
    padding: 8px;
    box-sizing: border-box;
    background: rgba(16, 35, 52, 0.94);
    border: 2px solid #126364;
    border-radius: 16px;
    box-shadow: 0 0 24px rgba(8, 15, 24, 0.48);
    user-select: none;
}

#top-ports {
    grid-column: 2;
    grid-row: 1;
    padding-inline: calc(var(--board-padding) + var(--grid-border));
    column-gap: var(--board-gap);
}

#bottom-ports {
    grid-column: 2;
    grid-row: 3;
    padding-inline: calc(var(--board-padding) + var(--grid-border));
    column-gap: var(--board-gap);
}

#left-ports {
    grid-column: 1;
    grid-row: 2;
    padding-block: calc(var(--board-padding) + var(--grid-border));
    row-gap: var(--board-gap);
}

#right-ports {
    grid-column: 3;
    grid-row: 2;
    padding-block: calc(var(--board-padding) + var(--grid-border));
    row-gap: var(--board-gap);
}

.port-row,
.port-column {
    position: relative;
    z-index: 6;
    display: grid;
    align-items: center;
    justify-items: center;
    box-sizing: border-box;
}

.port-column {
    grid-auto-flow: row;
}

.port-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.port-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: clamp(18px, 62%, 31px);
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 2px solid #1f2d3a;
    border-radius: 50%;
    background: #7c8286;
    color: #102334;
    font-family: 'Futura', sans-serif;
    font-size: clamp(0.72rem, 2.3vw, 1rem);
    font-weight: 900;
    cursor: pointer;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2), 0 2px 5px rgba(0, 0, 0, 0.32);
    transition: transform 0.14s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.port-button:not(:disabled):hover {
    transform: scale(1.12);
    background: #a7b0b5;
}

.port-button:disabled {
    cursor: default;
}

.port-button.launch {
    background: #7ddfdf;
    border-color: #e8ffff;
    box-shadow: 0 0 0 4px rgba(125, 223, 223, 0.17), 0 0 15px rgba(125, 223, 223, 0.78);
}

.port-button.predicted {
    background: #f0c96a;
    border-color: #fff0bb;
    box-shadow: 0 0 0 4px rgba(240, 201, 106, 0.16), 0 0 14px rgba(240, 201, 106, 0.62);
}

.port-button.correct-exit {
    background: #bfeecf;
    border-color: #effff4;
    box-shadow: 0 0 0 4px rgba(191, 238, 207, 0.18), 0 0 15px rgba(191, 238, 207, 0.7);
}

.port-button.wrong-exit {
    background: #e96b6b;
    border-color: #ffd1d1;
    box-shadow: 0 0 0 4px rgba(233, 107, 107, 0.18), 0 0 15px rgba(233, 107, 107, 0.66);
}

#pinball-grid {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    z-index: 2;
    display: grid;
    gap: var(--board-gap);
    padding: var(--board-padding);
    box-sizing: border-box;
    background:
        radial-gradient(circle at center, rgba(125, 223, 223, 0.09) 0 2px, transparent 2.6px) 0 0 / 18px 18px,
        #0c1d2b;
    border: var(--grid-border) solid #1b5862;
    border-radius: 10px;
    overflow: hidden;
}

.pinball-cell {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: rgba(40, 63, 78, 0.72);
    border: 1px solid rgba(125, 223, 223, 0.16);
    border-radius: clamp(3px, 0.9vw, 7px);
}

.pinball-cell::after {
    content: '';
    position: absolute;
    inset: 47%;
    border-radius: 50%;
    background: rgba(201, 235, 235, 0.2);
}

.wall {
    --wall-angle: 45deg;
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 2;
    width: 74%;
    height: clamp(4px, 1.2vw, 9px);
    border-radius: 999px;
    background: #f5f7f7;
    box-shadow: 0 0 0 2px rgba(16, 35, 52, 0.35), 0 0 9px rgba(245, 247, 247, 0.45);
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--wall-angle)) scale(0.72);
    transition: opacity 0.24s ease, transform 0.24s ease;
}

.wall.slash {
    --wall-angle: -45deg;
}

.wall.backslash {
    --wall-angle: 45deg;
}

.wall.visible {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--wall-angle)) scale(1);
}

.wall.feedback {
    box-shadow: 0 0 0 2px rgba(16, 35, 52, 0.35), 0 0 12px rgba(125, 223, 223, 0.72);
}

#trajectory-layer {
    position: absolute;
    inset: 0;
    z-index: 4;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

#trajectory-guide {
    fill: none;
    stroke: none;
}

#trajectory-path {
    fill: none;
    stroke: #bfe6ea;
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 8 10;
    opacity: 0;
    filter: drop-shadow(0 0 3px rgba(125, 223, 223, 0.7));
}

#trail-mask-path {
    fill: none;
    stroke: #fff;
    stroke-width: 12;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#pinball-dot {
    fill: #f7ffff;
    stroke: #7ddfdf;
    stroke-width: 3;
    opacity: 0;
    filter: drop-shadow(0 0 7px rgba(125, 223, 223, 0.95));
}

#status-line {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 7px;
    color: #cfe3e6;
    line-height: 1.3;
}

.pinball-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 18px;
    margin: 11px 0 13px;
    color: #b7cdd1;
    font-size: 0.82em;
}

.pinball-legend span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.legend-port {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 1px solid #e8ffff;
}

.legend-port.launch {
    background: #7ddfdf;
}

.legend-port.choice {
    background: #f0c96a;
}

.pinball-button {
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    background: #7ddfdf;
    color: #102334;
    font-family: 'Futura', sans-serif;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, background-color 0.25s;
}

.pinball-button:hover {
    transform: scale(1.02);
    background: #a7eded;
}

#controls-panel {
    width: min(94vw, 660px);
    text-align: left;
}

.control-row {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
    color: #e8f0f0;
    font-size: 0.95em;
}

.control-row label {
    font-weight: 700;
}

.control-row input[type="range"] {
    width: 100%;
    accent-color: #7ddfdf;
}

.control-value {
    text-align: right;
    color: #bfe6ea;
    font-size: 0.95em;
}

#results-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(8, 15, 24, 0.8);
}

#results-card {
    width: min(92vw, 470px);
    padding: 19px;
    box-sizing: border-box;
    color: #eee;
    text-align: center;
    background: #102334;
    border: 2px solid #126364;
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(8, 15, 24, 0.72);
}

#results-text {
    margin: 10px 0 14px;
    padding: 11px;
    white-space: pre-wrap;
    text-align: left;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.results-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.results-actions button {
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-family: 'Futura', sans-serif;
    cursor: pointer;
}

#copy-share {
    color: #102334;
    font-weight: 700;
    background: #7ddfdf;
}

#close-results {
    color: #e8f0f0;
    background: #2e4b61;
}

@media (min-width: 1040px) {
    body:not([data-mode="custom"]) #pinball-wrapper {
        display: grid;
        grid-template-columns: minmax(260px, 300px) minmax(0, 650px);
        grid-template-areas:
            "level level"
            "status board";
        justify-content: center;
        column-gap: 150px;
        row-gap: 16px;
        align-items: center;
    }

    body[data-mode="custom"] #pinball-wrapper {
        display: grid;
        grid-template-columns: minmax(260px, 300px) minmax(0, 650px);
        grid-template-areas:
            "level level"
            "controls controls"
            "status board";
        justify-content: center;
        column-gap: 150px;
        row-gap: 16px;
        align-items: center;
    }

    #level-panel {
        grid-area: level;
        width: 100%;
    }

    #controls-panel {
        grid-area: controls;
        width: 100%;
    }

    #status-panel {
        grid-area: status;
        width: 100%;
    }

    #pinball-board-shell {
        grid-area: board;
        width: min(62vw, 650px);
    }
}

@media (max-width: 680px) {
    .control-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .control-value {
        text-align: left;
    }

    #pinball-board-shell {
        width: min(96vw, 650px);
        padding: 5px;
        border-radius: 12px;
    }

    #trajectory-path {
        stroke-width: 3;
    }

    #pinball-dot {
        r: 5;
    }
}

@media (prefers-reduced-motion: reduce) {
    .wall,
    .port-button,
    .level-track span {
        transition-duration: 0.01ms;
    }
}
