@import url('https://fonts.googleapis.com/css2?family=Google+Sans:ital,opsz,wght@0,17..18,400..700;1,17..18,400..700&display=swap');

:root {
    --primary-color: #C1121F;
    --secondary-color: #780000;
    --accent-color: #669BBC;
    --background-color: #FDF0D5;
    --text-color: #003049;
}

body {
    background-color: var(--background-color);
}

h1 {
    font-family: "Google Sans", sans-serif;
    text-align: center;
    color: var(--primary-color);
}

p {
    font-family: "Google Sans", sans-serif;
    text-align: center;
    color: var(--text-color);
}

.intro-img {
    float: left;
    width: 50%;
    margin: 0 1em 0.1em 0;
}
.introduction-container::after { 
    content: "";
    display: block;
    clear: both;
}

.map {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    padding: 0 16px;
}

.map iframe {
    width: 100%;
    max-width: 600px;           /* full 600px on desktop, shrinks on phones */
    height: auto;
    aspect-ratio: 4 / 3;        /* keeps the original 600x450 proportions */
    border-radius: 12px;
    border: 2px solid var(--secondary-color);
    box-shadow: 0 4px 12px rgba(0, 48, 73, 0.15);
}

.events {
    display: flex;
    flex-wrap: wrap;            /* cards drop to a new row when space runs out */
    justify-content: center;
    gap: 24px;
    max-width: 1000px;
    margin: 32px auto;
    padding: 0 16px;
}

.event-card {
    position: relative;
    flex: 0 1 300px;            /* 300px wide, but allowed to shrink on narrow screens */
    aspect-ratio: 1;            /* the flyers are square */
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--secondary-color);
    box-shadow: 0 4px 12px rgba(0, 48, 73, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.event-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 48, 73, 0.25);
}

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

.event-card-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 40px 16px 14px;
    background: linear-gradient(transparent, rgba(120, 0, 0, 0.9)); /* --secondary-color */
    font-family: "Google Sans", sans-serif;
}

.event-card-overlay h3,
.event-card-overlay p {
    margin: 0;
    text-align: left;
    color: var(--background-color);
}

.event-card-overlay h3 {
    font-size: 20px;
}

.event-card-overlay p {
    font-size: 14px;
    opacity: 0.9;
}

.results-container {
    display: grid;
    justify-content: center;
    grid-template-columns: repeat(auto-fit, minmax(100px, 200px));
}

.results-container a {
    color: var(--primary-color);
}

.center {
    text-align: center;
}

.link-button {
    font: inherit;
    color: var(--primary-color);
    background: none;
    border: none;
    padding: 0;
    text-decoration: underline;
    cursor: pointer;
}

.link-button:hover {
    color: var(--secondary-color);
}

.popup {
    width: min(400px, calc(100% - 32px));
    padding: 0;                 /* padding lives on .popup-content so backdrop clicks are detectable */
    border: 2px solid var(--secondary-color);
    border-radius: 12px;
    background-color: var(--background-color);
    box-shadow: 0 8px 20px rgba(0, 48, 73, 0.25);
}

.popup::backdrop {
    background-color: rgba(0, 48, 73, 0.5);
}

.popup-content {
    padding: 20px 24px;
    font-family: "Google Sans", sans-serif;
}

.popup h2 {
    margin-top: 0;
    text-align: center;
    color: var(--primary-color);
}

.button {
    display: inline-block;
    font-family: "Google Sans", sans-serif;
    font-size: 16px;
    color: var(--background-color);
    background-color: var(--primary-color);
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    text-decoration: none;
    cursor: pointer;
}

.button:hover:not(:disabled) {
    background-color: var(--secondary-color);
}

.button:disabled {
    opacity: 0.6;
    cursor: default;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 320px;
    margin: 20px auto;
    font-family: "Google Sans", sans-serif;
    color: var(--text-color);
}

.auth-form input {
    font-family: inherit;
    font-size: 16px;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--accent-color);
    border-radius: 6px;
}

.auth-form .button {
    margin-top: 8px;
}

.button.secondary {
    color: var(--primary-color);
    background-color: transparent;
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

.button.secondary:hover:not(:disabled) {
    color: var(--background-color);
    background-color: var(--primary-color);
}

[hidden] {
    display: none !important;
}

.auth-panel {
    max-width: 420px;
    margin: 20px auto;
    font-family: "Google Sans", sans-serif;
    color: var(--text-color);
    text-align: center;
}

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

.auth-panel .hint {
    font-size: 14px;
}

.form-message.error {
    color: var(--primary-color);
}

.auth-form .hint {
    margin: 0 0 8px;
    font-size: 14px;
    text-align: left;
}

/* Small note at the bottom of a form, below the submit button */
.auth-form .hint.footnote {
    margin: 8px 0 0;
    font-size: 13px;
    text-align: center;
    opacity: 0.8;
}

.button.small {
    font-size: 14px;
    padding: 6px 12px;
}

/* Admin page (tournament import) */
.admin {
    max-width: 760px;
    margin: 0 auto 40px;
    padding: 0 16px;
    font-family: "Google Sans", sans-serif;
    color: var(--text-color);
}

.admin h2 {
    margin: 32px 0 8px;
    font-size: 22px;
    color: var(--primary-color);
}

.admin p {
    text-align: left;
}

.admin .hint {
    font-size: 14px;
}

.admin input,
.admin select {
    font-family: inherit;
    font-size: 16px;
    padding: 8px;
    border: 1px solid var(--accent-color);
    border-radius: 6px;
    background-color: #fff;
    color: var(--text-color);
    max-width: 100%;
    box-sizing: border-box;
}

.admin .file-label {
    display: block;
    margin-bottom: 6px;
}

.admin-fields {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 360px;
    margin: 20px 0;
}

.admin-fields input,
.admin-fields select {
    margin-bottom: 8px;
}

.admin-warnings {
    color: var(--primary-color);
    padding-left: 20px;
}

.table-scroll {
    overflow-x: auto;           /* wide tables scroll inside the page on phones */
    margin: 12px 0;
}

.admin table {
    width: 100%;
    border-collapse: collapse;
}

.admin th,
.admin td {
    padding: 8px 10px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--accent-color);
}

.admin th {
    color: var(--primary-color);
    border-bottom: 2px solid var(--secondary-color);
    white-space: nowrap;
}

.admin .num {
    text-align: right;
    width: 1%;
    white-space: nowrap;
}

.admin select.match {
    min-width: 170px;
}

.admin .match-note {
    display: block;
    margin-top: 2px;
    font-size: 13px;
    opacity: 0.75;
}

.admin tr.duplicate select {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

.admin .actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.admin .actions select {
    flex: 1 1 150px;
    min-width: 0;
}

.admin td.date {
    white-space: nowrap;
}

/* Phones: each preview row becomes a small card (rank · name · points, then the
   match dropdown at full width) so the dropdown never ends up off-screen. */
@media (max-width: 600px) {
    .preview-table thead {
        display: none;
    }

    .preview-table tr {
        display: grid;
        grid-template-columns: auto 1fr auto;
        align-items: baseline;
        gap: 4px 10px;
        padding: 10px 0;
        border-bottom: 1px solid var(--accent-color);
    }

    .preview-table td {
        padding: 0;
        border: none;
        width: auto;
    }

    .preview-table td.rank::after {
        content: ".";
    }

    .preview-table td.points::after {
        content: " pts";
    }

    .preview-table td.games {
        display: none;
    }

    .preview-table td.match-cell {
        grid-column: 1 / -1;
    }

    .preview-table select.match {
        width: 100%;
        min-width: 0;
    }

    /* Tournaments: name, then "date · N players", Delete on the right */
    .tournament-table thead,
    .guest-table thead {
        display: none;
    }

    .tournament-table tr,
    .guest-table tr {
        display: grid;
        align-items: center;
        gap: 4px 10px;
        padding: 10px 0;
        border-bottom: 1px solid var(--accent-color);
    }

    .tournament-table td,
    .guest-table td {
        padding: 0;
        border: none;
        width: auto;
        text-align: left;
    }

    .tournament-table tr {
        grid-template-columns: auto auto 1fr auto;
    }

    .tournament-table td.name {
        grid-column: 1 / 4;
    }

    .tournament-table td.date,
    .tournament-table td.count {
        grid-row: 2;
        font-size: 14px;
    }

    .tournament-table td.count::before {
        content: "· ";
    }

    .tournament-table td.count::after {
        content: " players";
    }

    .tournament-table td.action {
        grid-column: 4;
        grid-row: 1 / 3;
    }

    /* Guests: name and points, then the link controls at full width */
    .guest-table tr {
        grid-template-columns: 1fr auto;
    }

    .guest-table td.points::after {
        content: " pts";
    }

    .guest-table td.link-cell {
        grid-column: 1 / -1;
    }
}

/* Read-only account details at the top of the profile form */
.profile-info {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px 12px;
    margin: 0 0 16px;
    padding: 12px 16px;
    font-size: 15px;
    border: 1px solid var(--accent-color);
    border-radius: 6px;
}

.profile-info dt {
    font-weight: 600;
}

.profile-info dd {
    margin: 0;
    overflow-wrap: anywhere;    /* long email addresses wrap instead of overflowing */
}

.leaderboard {
    max-width: 420px;
    margin: 20px auto;
    padding: 0 16px;
    font-family: "Google Sans", sans-serif;
    color: var(--text-color);
}

.leaderboard table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard th,
.leaderboard td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--accent-color);
}

.leaderboard th {
    color: var(--primary-color);
    border-bottom: 2px solid var(--secondary-color);
}

.leaderboard th:first-child,
.leaderboard td:first-child {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.topnav {
    background-color: var(--secondary-color);
    overflow: hidden;
}

.topnav a {
    float: left;
    color: var(--background-color);
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-size: 17px;
}

.topnav img.split {
    float: right;
    margin: 8px;
}

.topnav a.auth {
    float: right;
}

.topnav .nav-user {
    float: right;
    color: var(--background-color);
    padding: 14px 8px;
    font-size: 17px;
}

.topnav a:hover {
    background-color: var(--primary-color);
}

.topnav a.active {
    background-color: var(--primary-color);
}

/* Menu button: only shown on small screens */
.nav-toggle {
    display: none;
}

@media (max-width: 600px) {
    /* Collapsed: a slim bar with the menu button on the left and the logo on the right.
       Open: the links drop down below it as full-width rows. */
    .topnav {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }

    .nav-toggle {
        order: -2;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 54px;
        height: 48px;
        padding: 0 15px;
        background: none;
        border: none;
        cursor: pointer;
    }

    .nav-toggle span {
        height: 3px;
        border-radius: 2px;
        background-color: var(--background-color);
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .nav-toggle:hover,
    .topnav.open .nav-toggle {
        background-color: var(--primary-color);
    }

    /* The three bars turn into an X while the menu is open */
    .topnav.open .nav-toggle span:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }

    .topnav.open .nav-toggle span:nth-child(2) {
        opacity: 0;
    }

    .topnav.open .nav-toggle span:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }

    .topnav img.split {
        order: -1;
        margin: 9px 12px 9px auto;  /* auto pushes the logo to the right edge */
    }

    .topnav a,
    .topnav .nav-user {
        display: none;
        flex: 1 1 100%;
        padding: 14px 16px;
        font-size: 17px;
        text-align: left;
        border-top: 1px solid rgba(253, 240, 213, 0.15);  /* faint --background-color line */
    }

    .topnav.open a,
    .topnav.open .nav-user {
        display: block;
    }

    /* Signed-in name (links to the profile page) and the admin's "Admin" link above "Log out",
       at the bottom of the list. .auth.nav-user / .auth.nav-admin outrank the a.auth rule below,
       which would otherwise move them under "Log out". */
    .topnav .auth.nav-user,
    .topnav .auth.nav-admin {
        order: 1;
    }

    .topnav .auth.nav-user {
        font-size: 15px;
        opacity: 0.8;
    }

    .topnav .nav-user::before {
        content: "Signed in as ";
    }

    .topnav a.auth {
        order: 2;
    }
}
