:root {
    color-scheme: light;
    --page-bg: #f7f8fb;
    --surface: rgba(255, 255, 255, 0.96);
    --surface-strong: #ffffff;
    --border: rgba(21, 29, 46, 0.12);
    --border-strong: rgba(21, 29, 46, 0.2);
    --text: #111827;
    --text-muted: #526072;
    --accent: #2f855a;
    --accent-strong: #246847;
    --shadow: 0 14px 36px rgba(17, 24, 39, 0.12);
    --header-gap: clamp(12px, 2.5vw, 22px);
    --page-pad: clamp(14px, 3vw, 28px);
    --thumb-radius: 18px;
    --action-height: 46px;
    --vh: 1vh;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background: linear-gradient(180deg, #f5f7fb 0%, #eef3f8 100%);
}

body {
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    margin: 0;
    background: transparent;
    color: var(--text);
    font-family: Arial, sans-serif;
    text-align: center;
    overflow-x: hidden;
}

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

a,
button,
input {
    -webkit-tap-highlight-color: transparent;
}

button,
input {
    font: inherit;
}

body.modal-open {
    overflow: hidden;
    touch-action: none;
}

.search-container {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--header-gap);
    width: 100%;
    padding:
        calc(16px + env(safe-area-inset-top, 0px))
        var(--page-pad)
        18px;
    background:
        linear-gradient(180deg, rgba(247, 248, 251, 0.98) 0%, rgba(247, 248, 251, 0.94) 72%, rgba(247, 248, 251, 0.86) 100%);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    justify-content: center;
    margin: 0;
}

.logo a {
    display: inline-flex;
    justify-content: center;
}

.imgLogo {
    display: block;
    width: min(260px, 44vw);
    max-width: 100%;
    height: auto;
}

.search-form {
    width: 100%;
}

.input-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: min(980px, 100%);
    margin: 0 auto;
}

.search-field {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.search-bar {
    width: 100%;
    min-height: 54px;
    padding: 14px 56px 14px 18px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--text);
    font-size: clamp(16px, 2vw, 22px);
    line-height: 1.2;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.search-bar:focus {
    outline: none;
    border-color: rgba(47, 133, 90, 0.5);
    box-shadow: 0 0 0 4px rgba(47, 133, 90, 0.15);
}

.search-bar::placeholder {
    color: #758295;
}

.clear-input {
    position: absolute;
    top: 50%;
    right: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #5b6677;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%);
    transition: opacity 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.show-clear-button {
    opacity: 1;
    pointer-events: auto;
}

.clear-input:hover,
.clear-input:focus-visible {
    background: rgba(17, 24, 39, 0.08);
    color: #111827;
    outline: none;
}

.search-button {
    flex: 0 0 auto;
    min-height: 54px;
    padding: 0 22px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(47, 133, 90, 0.24);
    transition: background-color 0.18s ease, transform 0.18s ease;
}

.search-button:hover,
.search-button:focus-visible {
    background: var(--accent-strong);
    outline: none;
}

.search-button:active {
    transform: translateY(1px);
}

#divUnderSearch {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: center;
    gap: 12px;
    width: min(900px, 100%);
    margin: 0 auto;
    padding: 0 2px;
}

.spanCenterMiddle,
.upload-text {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
    padding: 0 10px;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.35;
}

.upload-text {
    border-radius: 999px;
    background: rgba(47, 133, 90, 0.08);
    color: var(--accent-strong);
    font-weight: 700;
    cursor: pointer;
}

.page-notice {
    width: min(900px, 100%);
    margin: 0 auto;
    padding: 12px 16px;
    border: 1px solid rgba(180, 83, 9, 0.18);
    border-radius: 16px;
    background: rgba(255, 247, 237, 0.95);
    color: #9a3412;
    font-size: 15px;
    line-height: 1.4;
}

.results {
    width: 100%;
    padding:
        22px
        max(var(--page-pad), env(safe-area-inset-right, 0px))
        calc(32px + env(safe-area-inset-bottom, 0px))
        max(var(--page-pad), env(safe-area-inset-left, 0px));
}

.results.has-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    align-items: start;
}

.image-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--thumb-radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.image-link {
    display: block;
    background: #dfe7ef;
}

.image-container img {
    display: block;
    width: 100%;
    height: auto;
    max-width: none;
    max-height: min(42vh, 420px);
    object-fit: contain;
    background: linear-gradient(180deg, #edf2f7 0%, #dce5ee 100%);
}

.flag,
.dupe {
    position: absolute;
    bottom: 12px;
    min-width: 64px;
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.78);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    backdrop-filter: blur(8px);
}

.flag {
    left: 12px;
}

.dupe {
    right: 12px;
}

#noResults {
    width: min(460px, 100%);
    margin: 24px auto 0;
    padding: 20px 18px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-muted);
    font-size: 18px;
    user-select: none;
    box-shadow: var(--shadow);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding:
        calc(16px + env(safe-area-inset-top, 0px))
        max(16px, env(safe-area-inset-right, 0px))
        calc(16px + env(safe-area-inset-bottom, 0px))
        max(16px, env(safe-area-inset-left, 0px));
    background: rgba(7, 12, 20, 0.88);
    overscroll-behavior: contain;
}

.modal.is-open {
    display: flex;
}

.modal-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(960px, 100%);
    max-height: calc(var(--vh, 1vh) * 100 - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    padding: 18px;
    border-radius: 22px;
    background: rgba(17, 24, 39, 0.92);
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.38);
}

.close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.close:hover,
.close:focus-visible {
    background: rgba(255, 255, 255, 0.18);
    outline: none;
}

.modal-content {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: calc(var(--vh, 1vh) * 100 - 210px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    margin: 0 auto;
    border-radius: 16px;
    object-fit: contain;
    background: #0f172a;
}

.modal-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.modal-pill,
.modal-action {
    min-height: var(--action-height);
    padding: 0 16px;
    border-radius: 999px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.modal-pill {
    background: rgba(255, 255, 255, 0.12);
    color: #e5eef9;
}

.modal-action {
    border: 0;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.modal-action:hover,
.modal-action:focus-visible {
    background: rgba(255, 255, 255, 0.22);
    outline: none;
}

@media screen and (max-width: 1000px) {
    .imgLogo {
        width: min(250px, 58vw);
    }

    #divUnderSearch {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

@media screen and (max-width: 700px) {
    .search-container {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        padding-bottom: 14px;
    }

    .input-container {
        flex-direction: column;
        gap: 10px;
    }

    .search-field,
    .search-button {
        width: 100%;
    }

    .search-button {
        min-height: 50px;
    }

    .results.has-results {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
    }

    .image-container img {
        max-height: 32vh;
    }

    .flag,
    .dupe {
        min-width: 58px;
        min-height: 34px;
        padding: 7px 12px;
        font-size: 13px;
    }

    .modal-card {
        padding: 16px 14px 14px;
        border-radius: 18px;
    }

    .modal-content {
        max-height: calc(var(--vh, 1vh) * 100 - 250px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
}

@media screen and (max-width: 480px) {
    .imgLogo {
        width: min(220px, 64vw);
    }

    .search-bar {
        min-height: 50px;
        padding: 13px 50px 13px 16px;
        font-size: 16px;
    }

    .search-button {
        font-size: 15px;
    }

    .spanCenterMiddle,
    .upload-text {
        min-height: auto;
        padding: 0 6px;
        font-size: 14px;
    }

    .results {
        padding-top: 18px;
    }

    .results.has-results {
        grid-template-columns: 1fr;
    }

    .image-container {
        border-radius: 16px;
    }

    .image-container img {
        max-height: 42vh;
    }

    .close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    .modal-toolbar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .modal-pill {
        grid-column: 1 / -1;
    }
}
