@import url("https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap");

:root {
    --ink: #162033;
    --muted: #667085;
    --line: #e4e7ec;
    --brand: #1d4ed8;
    --brand-dark: #143d9a;
    --soft: #f6f8fb;
    --pink: #ff8ec3;
    --green: #039855;
    --orange: #dc6803;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: #ffffff;
    font-family: "Sarabun", "TH Sarabun New", Tahoma, sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

.home-page,
.certificate-page {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 22px 0 44px;
}

.home-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 0 24px;
}

.home-header img {
    width: 142px;
    max-width: 36vw;
}

.home-header p,
.title-box p {
    margin: 0;
    color: var(--muted);
}

.home-header h1 {
    margin: 2px 0 0;
    font-size: clamp(24px, 5vw, 40px);
}

.home-header a {
    margin-left: auto;
    padding: 9px 13px;
    color: var(--brand);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
}

.home-intro {
    padding: 22px 0 8px;
    border-top: 1px solid var(--line);
}

.home-intro h2 {
    margin: 0;
    font-size: clamp(22px, 4vw, 34px);
}

.home-intro p {
    margin: 8px 0 0;
    color: var(--muted);
}

.public-project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 22px;
}

.public-project-card {
    display: grid;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    transition: 0.16s ease;
}

.public-project-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 40px rgba(22, 32, 51, 0.08);
}

.public-project-card img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--soft);
}

.public-project-card div {
    padding: 14px;
}

.public-project-card h3 {
    margin: 10px 0 6px;
    font-size: 20px;
}

.public-project-card p,
.public-project-card small {
    color: var(--muted);
}

.badge {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.badge.success {
    color: #067647;
    background: #dcfae6;
}

.badge.warning {
    color: #b54708;
    background: #fef0c7;
}

.badge.muted {
    color: #475467;
    background: #f2f4f7;
}

.certificate-head {
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
    gap: clamp(18px, 3vw, 34px);
    align-items: center;
    padding: clamp(16px, 3vw, 28px) 0;
    border-bottom: 1px solid var(--line);
}

.poster-box {
    width: min(100%, 280px);
    aspect-ratio: var(--poster-ratio, 4 / 5);
    overflow: hidden;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 16px 38px rgba(22, 32, 51, 0.08);
}

.poster-box.is-landscape {
    width: min(36vw, 440px);
}

.poster-box.is-portrait {
    width: min(24vw, 280px);
}

.poster-box.is-square {
    width: min(28vw, 340px);
}

.poster-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.title-box {
    text-align: center;
    min-width: 0;
}

.title-box h1 {
    max-width: 980px;
    margin: 8px auto;
    font-size: clamp(24px, 3.2vw, 40px);
    line-height: 1.16;
    overflow-wrap: anywhere;
    text-wrap: balance;
}

.certificate-head.is-title-long .title-box h1 {
    font-size: clamp(22px, 2.75vw, 34px);
}

.certificate-head.is-title-very-long .title-box h1 {
    font-size: clamp(20px, 2.45vw, 30px);
    line-height: 1.2;
}

.title-box span {
    color: var(--muted);
    font-size: clamp(14px, 1.5vw, 17px);
}

.title-box p {
    font-size: clamp(14px, 1.45vw, 17px);
}

.project-description,
.public-alert,
.line-browser-alert,
.search-panel,
.certificate-table-wrap {
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.project-description,
.public-alert {
    padding: 16px;
    font-size: clamp(15px, 1.4vw, 18px);
    line-height: 1.75;
}

.public-alert {
    color: #b54708;
    background: #fffbeb;
}

.line-browser-alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
    color: #164c63;
    border-color: #a5f3fc;
    background: #ecfeff;
}

.line-browser-alert strong {
    display: block;
    margin-bottom: 4px;
}

.line-browser-alert p,
.line-helper-card p {
    margin: 0;
    line-height: 1.65;
}

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

.line-copy-btn {
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid #0e7490;
    border-radius: var(--radius);
    color: #0e7490;
    background: #fff;
    font: inherit;
    cursor: pointer;
}

.line-helper-card .line-browser-actions {
    margin-top: 16px;
}

.search-panel {
    display: grid;
    grid-template-columns: 1fr minmax(220px, 2fr) auto;
    align-items: center;
    gap: 12px;
    padding: 14px;
}

.search-panel label {
    font-weight: 700;
}

.search-panel input {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    border: 1px solid #d0d5dd;
    border-radius: var(--radius);
    font: inherit;
}

.search-panel p {
    margin: 0;
    color: var(--muted);
    white-space: nowrap;
}

.certificate-table-wrap {
    overflow-x: auto;
}

.certificate-table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
}

.certificate-table th,
.certificate-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.certificate-table th {
    color: var(--muted);
    font-size: 14px;
}

.certificate-table th:first-child,
.certificate-table td:first-child {
    width: 84px;
    text-align: center;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 14px;
    border-radius: var(--radius);
    color: #fff;
    background: var(--brand);
}

.download-btn:hover {
    background: var(--brand-dark);
}

.is-download-status-open {
    overflow: hidden;
}

.download-status-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.38);
    backdrop-filter: blur(6px);
}

.download-status-card {
    width: min(360px, 100%);
    padding: clamp(18px, 4vw, 24px);
    text-align: center;
    border: 1px solid rgba(228, 231, 236, 0.9);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 22px 70px rgba(22, 32, 51, 0.22);
}

.download-status-media {
    position: relative;
    width: min(220px, 58vw);
    aspect-ratio: 1;
    margin: 0 auto 8px;
    display: grid;
    place-items: center;
}

.download-status-media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: download-frame-hop 0.72s ease-in-out infinite alternate;
}

.download-status-overlay.is-frame-missing .download-status-media img {
    display: none;
}

.download-status-fallback {
    display: none;
    width: 74px;
    height: 74px;
    border: 7px solid #e0f2fe;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: download-fallback-spin 0.8s linear infinite;
}

.download-status-overlay.is-frame-missing .download-status-fallback {
    display: block;
}

.download-status-text h2 {
    margin: 8px 0 4px;
    font-size: clamp(22px, 7vw, 30px);
}

.download-status-text p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.download-status-dots {
    display: inline-flex;
    gap: 6px;
    margin-top: 14px;
}

.download-status-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--brand);
    animation: download-dot-pulse 0.9s ease-in-out infinite;
}

.download-status-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.download-status-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes download-frame-hop {
    from {
        transform: translateY(3px) scale(0.98);
    }
    to {
        transform: translateY(-4px) scale(1.01);
    }
}

@keyframes download-fallback-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes download-dot-pulse {
    0%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    50% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

.public-empty {
    padding: 28px;
    text-align: center;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.site-footer {
    margin-top: 24px;
    border-top: 1px solid var(--line);
    background: #f8fafc;
}

.site-footer-inner {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 22px 0 26px;
    color: #475467;
    font-size: 14px;
    line-height: 1.8;
    text-align: center;
}

.site-footer-inner strong {
    display: block;
    margin-bottom: 8px;
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
}

.site-footer-inner p {
    margin: 3px 0;
}

.hidden {
    display: none !important;
}

.message-page,
.countdown-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 22px;
    background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
}

.message-card,
.countdown-wrap {
    width: min(780px, 100%);
    text-align: center;
}

.message-card img,
.countdown-poster {
    width: min(260px, 70vw);
    max-height: 320px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--line);
}

.message-card h1,
.countdown-wrap h1 {
    margin: 18px 0 8px;
    font-size: clamp(28px, 7vw, 54px);
}

.countdown-wrap h1 {
    max-width: 980px;
    margin: 16px auto 10px;
    font-size: clamp(24px, 3.2vw, 38px);
    font-weight: 700;
    line-height: 1.32;
    letter-spacing: 0;
    overflow-wrap: anywhere;
    text-wrap: balance;
}

.countdown-wrap p,
.message-card p {
    color: var(--muted);
}

.countdown-wait-message {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 8px 0 4px;
    padding: 8px 14px;
    color: #b54708;
    font-weight: 700;
    line-height: 1.45;
    border: 1px solid #fedf89;
    border-radius: var(--radius);
    background: #fffbeb;
}

.countdown-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 20px;
}

.countdown-grid div {
    padding: 16px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.countdown-grid strong {
    display: block;
    font-size: clamp(28px, 8vw, 50px);
}

.countdown-grid span {
    color: var(--muted);
}

.countdown-runway {
    --runner-size: clamp(158px, 34vw, 252px);
    position: relative;
    width: min(680px, 100%);
    height: clamp(142px, 27vw, 230px);
    margin: 14px auto 4px;
    overflow: hidden;
    border-bottom: 3px dashed #f7b6d4;
}

.countdown-runway::after {
    content: none;
}

.countdown-runner {
    position: absolute;
    z-index: 1;
    left: calc(var(--runner-size) * -1);
    bottom: 6px;
    width: var(--runner-size);
    aspect-ratio: 1;
    animation: countdown-runner-cross 5.4s linear infinite;
}

.countdown-runner img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    animation-duration: 0.44s;
    animation-timing-function: steps(1, end);
    animation-iteration-count: infinite;
}

.countdown-runner img:nth-child(1) {
    animation-name: countdown-frame-1;
}

.countdown-runner img:nth-child(2) {
    animation-name: countdown-frame-2;
}

.countdown-runner img:nth-child(3) {
    animation-name: countdown-frame-3;
}

.countdown-runner img:nth-child(4) {
    animation-name: countdown-frame-4;
}

@keyframes countdown-runner-cross {
    from {
        left: calc(var(--runner-size) * -1);
    }
    to {
        left: 100%;
    }
}

@keyframes countdown-frame-1 {
    0%,
    24.999% {
        opacity: 1;
    }
    25%,
    100% {
        opacity: 0;
    }
}

@keyframes countdown-frame-2 {
    0%,
    24.999%,
    50%,
    100% {
        opacity: 0;
    }
    25%,
    49.999% {
        opacity: 1;
    }
}

@keyframes countdown-frame-3 {
    0%,
    49.999%,
    75%,
    100% {
        opacity: 0;
    }
    50%,
    74.999% {
        opacity: 1;
    }
}

@keyframes countdown-frame-4 {
    0%,
    74.999% {
        opacity: 0;
    }
    75%,
    100% {
        opacity: 1;
    }
}

@media (max-width: 900px) {
    .certificate-head {
        grid-template-columns: 1fr;
        gap: 14px;
        justify-items: center;
    }

    .poster-box,
    .poster-box.is-landscape,
    .poster-box.is-portrait,
    .poster-box.is-square {
        width: min(100%, 520px);
    }

    .poster-box.is-portrait {
        width: min(76vw, 320px);
    }

    .title-box {
        text-align: center;
    }

    .title-box h1 {
        font-size: clamp(22px, 6vw, 30px);
    }

    .certificate-head.is-title-long .title-box h1,
    .certificate-head.is-title-very-long .title-box h1 {
        font-size: clamp(20px, 5.4vw, 26px);
    }

    .search-panel {
        grid-template-columns: 1fr;
    }

    .line-browser-alert {
        align-items: stretch;
        flex-direction: column;
    }

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

@media (max-width: 520px) {
    .home-header {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .home-header a {
        margin-left: 0;
    }

    .certificate-table {
        min-width: 560px;
    }

    .certificate-page {
        width: min(100% - 22px, 1120px);
        padding-top: 14px;
    }

    .poster-box,
    .poster-box.is-landscape,
    .poster-box.is-square {
        width: 100%;
    }

    .poster-box.is-portrait {
        width: min(82vw, 300px);
    }

    .project-description,
    .public-alert,
    .search-panel {
        margin-top: 14px;
    }

    .site-footer-inner {
        font-size: 13px;
        line-height: 1.7;
    }
}

@media (prefers-reduced-motion: reduce) {
    .download-status-media img,
    .download-status-fallback,
    .download-status-dots span,
    .countdown-runner,
    .countdown-runner img {
        animation: none;
    }

    .countdown-runner {
        left: 50%;
        transform: translateX(-50%);
    }

    .countdown-runner img:first-child {
        opacity: 1;
    }
}
