:root {
    --header-height: 60px; /* Define once to use everywhere */
    --logo-height: 60px;
}

/* (Re)set some more useful defaults */
body {
    font-family: sans-serif;
}
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Remove default margin */
*:not(dialog) {
    margin: 0;
}

button {
    cursor: pointer;
}

.navbar {
    position: sticky;
    top: 0;
    height: var(--header-height);
    color: #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 0 0;
    z-index: 1000;
    box-sizing: border-box;
}

/* Hamburger menu */
.menu-toggle {
    position: relative;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* Base style for all three lines */
.menu-toggle span {
    display: block;
    position: absolute;
    height: 4px;
    width: 100%;
    background-color: #444;
    border-radius: 2px;
    opacity: 1;
    left: 0;

    /* Transform form exact center */
    transform-origin: center center;
    transition: 0.25s ease-in-out;
}

/* 3 horizontal lines ("hamburger"), evenly spaced. */
.menu-toggle span:nth-child(1) {
    top: 10px;
}
.menu-toggle span:nth-child(2) {
    top: 18px;
}
.menu-toggle span:nth-child(3) {
    top: 26px;
}

/* Animation to "X" state */
/* Middle line fades away */
.menu-toggle.open span:nth-child(2) {
    width: 0%;
    opacity: 0;
}

/* 2. Top and Bottom lines move to the middle (top: 18px) and rotate */
.menu-toggle.open span:nth-child(1) {
    top: 18px; /* Move to the center vertical position */
    transform: rotate(45deg);
}
.menu-toggle.open span:nth-child(3) {
    top: 18px; /* Move to the center vertical position */
    transform: rotate(-45deg);
}

/* Navigation / menu */
.nav-links {
    position: absolute;
    top: var(--header-height);
    left: 0;
    width: 100%;
    display: none; /* Hidden by default */
    flex-direction: column;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.nav-links.active {
    display: flex;
}

.nav-links :is(a, button) {
    color: #333;
    padding: 15px;
    text-decoration: none;
    border-bottom: 1px solid #555;
    /*font-family: sans-serif;*/

    display: inline-block; /* Ensures padding/margins behave the same */
    background: none; /* Removes default grey button color */
    border-top: none; /* Removes default 3D button borders */
    border-left: none;
    border-right: none;
    cursor: pointer; /* Gives the button the 'link' hand icon */
    font-size: inherit; /* Buttons often default to smaller text */
    line-height: normal; /* Matches text flow */
}

.nav-links :is(a, button):hover {
    background: #555;
    color: #fff;
}

.controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 5px;
    font-size: 0.7rem;
    position: relative;
}
.controls select {
    font-size: 0.7rem;
}

.progress-indicator {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: bold;
}

.sound-control {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Main grid */
.grid-container {
    display: flex;
    flex-wrap: wrap;
    /* Keep some room for the "add" button at the bottom */
    padding: 10px 10px 100px 10px;
    width: 100%;
    margin: 0 auto;
}

.grid-item {
    display: grid;
    grid-template-columns: auto min-content;

    padding: 5px;
    margin: 3px;

    overflow: hidden;
}
.grid-item :is(object, plate-svg) {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    cursor: pointer;
    pointer-events: none;

    grid-column: 1;
    grid-row: 1;
}

.grid-item .timestamp {
    text-align: center;
    padding-top: 3px;
    font-size: 0.6rem;
}

.grid-container:not(#all-time-grid-container) .grid-item:last-child {
    animation: notification-fade 0.3s ease-in-out 3;
}
@keyframes notification-fade {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.25;
    }
    100% {
        opacity: 1;
    }
}

/* "I saw a thing!" button */
.add-btn {
    position: fixed;
    bottom: 30px;
    left: 50%;
    height: 60px;
    transform: translateX(-50%); /* Perfectly centers the button */
    padding: 15px 40px;
    font-size: 1.2rem;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
    white-space: nowrap;
}

/* "I saw a thing!" button */
.stats-btn {
    position: fixed;
    bottom: 45px;
    right: 30px;

    height: 30px;
    width: 30px;
    border-radius: 50%;

    display: flex;
    align-items: center;
    justify-content: center;

    background-color: #7b7b7b;
    color: white;
    border: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

/* The license-plate-y header */
.logo {
    /* Use flex to ensure children can fill the height */
    display: inline-flex;
    align-items: stretch; /* Forces children to be the same height */
    height: var(--logo-height);
}

dialog:open {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: var(--logo-height);
    border-radius: 8px;
    text-align: center; /* Ensures text itself is centered */
    width: auto;
}

dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(1px);
}

dialog h2 {
    margin: 10px 0;
    text-align: center; /* Ensures text itself is centered */
    font-size: 1.2rem;
}
dialog p,
dialog table {
    margin: 0 0 1.5rem;
}

#stats-modal {
    width: 90%;
}

#all-time-modal,
#achievement-modal {
    width: 95%;
    max-height: 90vh; /* A bit more space */
}

#all-time-grid-container,
#achievement-list {
    padding-bottom: 20px;
    overflow-y: auto;
    flex-grow: 1;
    width: 100%;
}

#achievement-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#welcome-modal {
...
    max-width: 450px;
    line-height: 1.4;
}

#stats-modal table th {
    text-align: right;
    font-weight: normal;
}

#add-plate-modal form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

#add-plate-form button {
    font-size: 1.5rem;
}

#add-plate-label {
    font-size: 0.8rem;
}

#add-plate-new-code {
    text-align: center;

    /* Make the code entry field nice and big */
    font-size: 2rem;
    margin-top: 0.75rem;

    text-transform: uppercase;
}

#close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
}

#close-button:hover {
    color: red;
}

#add-plate-error {
    width: 100%;
    padding: 0.25rem;

    color: white;
    background-color: #990000;
    border-radius: 5px 5px;

    box-sizing: border-box;
    visibility: hidden;
}

#add-plate-error.active {
    padding: 0.3em;
    visibility: visible;
}

#about-modal p {
    text-align: left;
}

#toast-container {
    position: fixed;
    top: calc(var(--header-height) + 20px);
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.achievement-toast {
    background: #333;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    border-left: 5px solid gold;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);

    display: grid;
    grid-template-columns: 3ch auto;

    animation:
        slideIn 0.5s ease forwards,
        fadeOut 0.5s ease 4s forwards;
}
.achievement-toast .icon {
    grid-column: 1;
    grid-row: 2;
}
.achievement-toast .title {
    font-size: 0.8rem;
    grid-column: 1 / 2;
    grid-row: 1;
}
.achievement-toast .name {
    font-weight: bold;
    grid-column: 2;
    grid-row: 2;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.achievement {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    border-radius: 8px;
    background: #ddd;
    color: black;
    border: 1px solid #444;
}

.achievement.unlocked {
    border-left: 5px solid gold; /* Gold accent */
    background: linear-gradient(90deg, #ddd, #bbb);
}

.achievement.locked {
    opacity: 0.6;
    filter: grayscale(1);
    background: #999;
}
.achievement h3 {
    margin: 0 0 5px 0;
    font-size: 1rem;
}

.achievement p {
    margin: 0;
    font-size: 0.9rem;
}

.achievement .timestamp {
    display: block;
    margin-top: 8px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #333;
}

.visually-hidden {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

.historic {
    opacity: 0.75;
}
