:root {
    --ink: #132019;
    --muted: #66746c;
    --paper: #f3f1e8;
    --panel: #fffdf6;
    --line: #d9d7cd;
    --field: #287348;
    --field-dark: #1c5e39;
    --accent: #f2c94c;
    --danger: #c54b4b;
    --success: #1e8b50;
    --shadow: 0 18px 45px rgba(20, 32, 25, .15);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    background:
        radial-gradient(circle at top left, rgba(242, 201, 76, .22), transparent 30rem),
        var(--paper);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1160px;
    margin: 0 auto;
    padding: 24px 22px 12px;
}

.eyebrow,
.kicker {
    margin: 0;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .14em;
}

h1 {
    margin: 2px 0 0;
    font-size: clamp(2rem, 7vw, 4rem);
    line-height: .9;
    letter-spacing: -.07em;
}

h1 strong {
    color: var(--field);
}

.icon-button,
.modal-close {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
}

.icon-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    font-weight: 900;
}

.page-shell {
    max-width: 1160px;
    margin: 0 auto;
    padding: 18px 22px 50px;
}

.intro {
    text-align: center;
}

.intro h2 {
    margin: 5px 0 2px;
    font-size: clamp(1.8rem, 4vw, 3rem);
}

.intro > p:last-of-type {
    margin-top: 4px;
    color: var(--muted);
}

.progress-row {
    display: flex;
    justify-content: center;
    gap: 36px;
    margin: 18px 0 22px;
}

.progress-row div {
    display: grid;
}

.progress-row strong {
    font-size: 1.25rem;
}

.progress-row span {
    color: var(--muted);
    font-size: .78rem;
}

.field-wrap {
    overflow-x: auto;
    padding: 8px 0 22px;
}

.field {
    position: relative;
    width: min(100%, 760px);
    min-width: 670px;
    min-height: 1040px;
    margin: 0 auto;
    overflow: hidden;
    border: 7px solid rgba(255,255,255,.9);
    border-radius: 50% / 12%;
    background:
        repeating-linear-gradient(
            90deg,
            rgba(255,255,255,.025) 0,
            rgba(255,255,255,.025) 45px,
            rgba(0,0,0,.02) 45px,
            rgba(0,0,0,.02) 90px
        ),
        linear-gradient(var(--field), var(--field-dark));
    box-shadow: var(--shadow);
}

.field::before,
.field::after {
    content: "";
    position: absolute;
    z-index: 0;
    left: 50%;
    width: 68%;
    height: 240px;
    transform: translateX(-50%);
    border: 2px solid rgba(255,255,255,.38);
    border-radius: 50%;
}

.field::before {
    top: -120px;
}

.field::after {
    bottom: -120px;
}

.centre-square {
    position: absolute;
    z-index: 0;
    top: 50%;
    left: 50%;
    width: 250px;
    height: 250px;
    transform: translate(-50%, -50%) rotate(45deg);
    border: 2px solid rgba(255,255,255,.28);
}

.centre-circle {
    position: absolute;
    z-index: 0;
    top: 50%;
    left: 50%;
    width: 110px;
    height: 110px;
    transform: translate(-50%, -50%);
    border: 2px solid rgba(255,255,255,.32);
    border-radius: 50%;
}

.goal-square {
    position: absolute;
    z-index: 0;
    left: 50%;
    width: 180px;
    height: 90px;
    transform: translateX(-50%);
    border: 2px solid rgba(255,255,255,.32);
}

.goal-square.top {
    top: -2px;
    border-top: 0;
}

.goal-square.bottom {
    bottom: -2px;
    border-bottom: 0;
}

.lineup-grid {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-content: space-around;
    gap: 31px 20px;
    min-height: 1040px;
    padding: 54px 54px;
}

.position-card {
    min-height: 105px;
    padding: 12px 9px;
    border: 2px solid rgba(255,255,255,.8);
    border-radius: 17px;
    background: rgba(255,255,255,.92);
    color: var(--ink);
    box-shadow: 0 8px 20px rgba(0,0,0,.13);
    transition: transform .15s ease, box-shadow .15s ease;
}

.position-card:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 12px 26px rgba(0,0,0,.18);
}

.position-card.solved {
    border-color: var(--accent);
    background: #fff7c9;
    cursor: default;
}

.position-label,
.remaining {
    display: block;
}

.position-label {
    color: var(--muted);
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.player-name {
    display: grid;
    place-items: center;
    min-height: 43px;
    margin: 3px 0;
    font-size: .9rem;
}

.unknown {
    font-size: 1.7rem;
}

.remaining {
    color: var(--muted);
    font-size: .66rem;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
}

.button {
    padding: 12px 17px;
    border: 0;
    border-radius: 12px;
    background: var(--ink);
    color: white;
    font-weight: 800;
}

.button.secondary {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
}

.modal {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(11, 19, 14, .68);
}

.hidden {
    display: none !important;
}

.modal-card {
    position: relative;
    width: min(100%, 520px);
    max-height: 88vh;
    overflow-y: auto;
    padding: 27px;
    border-radius: 22px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.modal-card h2 {
    margin: 4px 0;
}

.modal-card > p:not(.kicker) {
    color: var(--muted);
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.35rem;
}

.search-label {
    display: block;
    margin: 22px 0 7px;
    font-size: .8rem;
    font-weight: 800;
}

.search-input {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    background: white;
}

.search-input:focus {
    border-color: var(--field);
    box-shadow: 0 0 0 3px rgba(40,115,72,.13);
}

.search-results {
    display: grid;
    gap: 7px;
    margin-top: 9px;
}

.search-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: white;
    text-align: left;
}

.search-result:hover {
    border-color: var(--field);
}

.search-result span {
    color: var(--muted);
    font-size: .75rem;
    text-align: right;
}

.previous-guesses {
    margin-top: 22px;
}

.previous-guesses h3 {
    margin-bottom: 8px;
    font-size: .9rem;
}

.attempt {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 11px;
    border-radius: 9px;
    margin-bottom: 6px;
    background: #f4e7e7;
}

.attempt.correct {
    background: #dff2e7;
}

.attempt small,
.muted {
    color: var(--muted);
}

.toast {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    min-width: min(90vw, 300px);
    padding: 13px 17px;
    border-radius: 12px;
    background: var(--ink);
    color: white;
    text-align: center;
    box-shadow: var(--shadow);
}

@media (max-width: 720px) {

    .site-header {
        padding: 14px 14px 6px;
    }

    h1 {
        font-size: 2.4rem;
    }

    .page-shell {
        padding: 10px 10px 30px;
    }

    .intro h2 {
        font-size: 1.55rem;
    }

    .intro > p:last-of-type {
        margin: 4px auto 0;
        max-width: 320px;
        font-size: 0.86rem;
    }

    .progress-row {
        gap: 18px;
        margin: 14px 0;
    }

    .progress-row strong {
        font-size: 1.05rem;
    }

    .progress-row span {
        font-size: 0.7rem;
    }

    /*
     * Prevent horizontal scrolling.
     */
    .field-wrap {
        overflow: visible;
        padding: 4px 0 12px;
    }

    /*
     * Scale the entire field to the available phone width.
     */
    .field {
        width: 100%;
        min-width: 0;
        min-height: 0;
        aspect-ratio: 0.68;
        border-width: 4px;
        border-radius: 46% / 10%;
    }

    .field::before,
    .field::after {
        width: 76%;
        height: 24%;
    }

    .field::before {
        top: -12%;
    }

    .field::after {
        bottom: -12%;
    }

    .centre-square {
        width: 31%;
        height: 21%;
    }

    .centre-circle {
        width: 16%;
        height: 11%;
    }

    .goal-square {
        width: 27%;
        height: 8%;
    }

    /*
     * Six rows of three players.
     */
    .lineup-grid {
        min-height: 0;
        height: 100%;
        padding: 5.5% 4%;
        gap: 2.2% 2.4%;

        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: repeat(6, minmax(0, 1fr));

        align-content: stretch;
    }

    .position-card {
        min-width: 0;
        min-height: 0;
        height: 100%;

        padding: 5px 3px;
        border-width: 1px;
        border-radius: 10px;

        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
        touch-action: manipulation;
    }

    /*
     * Hover effects can remain stuck on touch devices,
     * so remove the desktop movement.
     */
    .position-card:hover:not(:disabled) {
        transform: none;
    }

    .position-card:active:not(:disabled) {
        transform: scale(0.97);
    }

    .position-label {
        font-size: clamp(0.48rem, 1.8vw, 0.62rem);
        line-height: 1.05;
        letter-spacing: 0;
    }

    .player-name {
        min-height: 0;
        height: 48%;

        margin: 2px 0;

        font-size: clamp(0.58rem, 2.15vw, 0.76rem);
        line-height: 1.05;

        overflow-wrap: anywhere;
    }

    .unknown {
        font-size: 1.25rem;
    }

    .remaining {
        font-size: clamp(0.46rem, 1.65vw, 0.58rem);
        line-height: 1.05;
    }

    /*
     * Keep reset/reveal controls reachable.
     */
    .controls {
        position: sticky;
        bottom: 0;
        z-index: 5;

        gap: 8px;
        margin: 0 -10px;
        padding: 10px;

        background: linear-gradient(
            to top,
            var(--paper) 72%,
            transparent
        );
    }

    .button {
        flex: 1;
        min-height: 46px;

        padding: 11px 10px;
        border-radius: 11px;

        font-size: 0.9rem;
    }

    /*
     * Show modals as a bottom sheet on phones.
     */
    .modal {
        align-items: end;
        padding: 0;
    }

    .modal-card {
        width: 100%;
        max-height: 88dvh;

        padding:
            22px
            16px
            calc(18px + env(safe-area-inset-bottom));

        border-radius: 22px 22px 0 0;
        overscroll-behavior: contain;
    }

    .modal-close {
        top: 12px;
        right: 12px;

        width: 40px;
        height: 40px;
    }

    /*
     * 16px prevents automatic zoom on iPhone inputs.
     */
    .search-input {
        min-height: 48px;
        font-size: 16px;
    }

    .search-result {
        min-height: 50px;
        padding: 12px;
    }

    .search-result strong {
        font-size: 0.92rem;
    }

    .search-result span {
        max-width: 40%;
        font-size: 0.7rem;
    }

    .toast {
        bottom: calc(18px + env(safe-area-inset-bottom));
        width: calc(100% - 24px);
    }
}

@media (max-width: 390px) {

    .site-header {
        padding-top: 10px;
    }

    h1 {
        font-size: 2.1rem;
    }

    .page-shell {
        padding-left: 7px;
        padding-right: 7px;
    }

    .field {
        aspect-ratio: 0.64;
    }

    .lineup-grid {
        padding-left: 3%;
        padding-right: 3%;
        gap: 1.7% 1.7%;
    }

    .position-label {
        font-size: 0.46rem;
    }

    .player-name {
        font-size: 0.56rem;
    }

    .remaining {
        font-size: 0.43rem;
    }

    .controls {
        margin-left: -7px;
        margin-right: -7px;
    }
}
