:root {
    --bg: #fff6f4;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: #ffffff;
    --stroke: rgba(130, 18, 18, 0.12);
    --primary: #b42318;
    --primary-deep: #7a1010;
    --accent: #ffddcf;
    --text: #351010;
    --muted: #7f5555;
    --success: #166534;
    --danger: #b91c1c;
    --shadow: 0 24px 60px rgba(122, 16, 16, 0.12);
    --radius: 24px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Sarabun", "TH Sarabun New", "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(255, 185, 159, 0.5), transparent 32%),
        linear-gradient(180deg, #fff9f7 0%, #ffecea 100%);
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: var(--primary-deep);
}

.public-body,
.admin-body,
.vote-body,
.admin-auth-body {
    min-height: 100vh;
}

.public-body {
    height: 100vh;
    overflow: hidden;
}

.public-shell,
.admin-shell,
.form-shell,
.vote-shell {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
}

.public-shell {
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 0;
    gap: 10px;
}

.hero-bar,
.admin-topbar,
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.82rem;
}

h1, h2, p {
    margin-top: 0;
}

h2 {
    margin-bottom: 18px;
    line-height: 1.2;
}

h1, h2, th, td, label, input, button, a, p, div {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.status-pill,
.status-tag {
    padding: 10px 16px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--stroke);
    font-weight: 700;
}

.waiting-card,
.admin-card,
.student-card,
.auth-card {
    background: var(--surface);
    backdrop-filter: blur(16px);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.admin-card {
    padding: 24px;
    overflow: hidden;
}

.waiting-card {
    padding: 12px;
}

#waitingSection,
#liveSection {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.banner-image,
.banner-placeholder {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 18px;
}

.banner-slider {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 18px;
    background: #fff3ef;
}

.banner-slider .slide,
.banner-slider .banner-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
    object-position: center;
    opacity: 0;
    transition: opacity 0.6s ease;
    border-radius: 0;
}

.banner-slider .slide.is-active {
    opacity: 1;
}

.banner-placeholder {
    display: grid;
    place-items: center;
    text-align: center;
    padding: 32px;
    background: linear-gradient(135deg, #ffe0d5, #fff9f7);
}

.live-grid,
.admin-grid {
    display: grid;
    grid-template-columns: 1.08fr 0.92fr;
    gap: 24px;
}

.live-grid {
    align-items: stretch;
    min-height: 0;
    height: 100%;
}

.poster-panel,
.vote-panel,
.student-card {
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.poster-panel,
.vote-panel {
    min-height: 0;
}

.a4-frame {
    width: 100%;
    aspect-ratio: 210 / 297;
    height: 100%;
    max-height: calc(100vh - 120px);
    overflow: hidden;
    border-radius: 24px;
    background: #fff;
    border: 8px solid #fff;
    box-shadow: inset 0 0 0 1px rgba(122, 16, 16, 0.08);
}

.a4-frame img,
.vote-image,
.band-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.vote-panel {
    display: grid;
    gap: 12px;
    grid-template-rows: auto auto auto 1fr;
    height: 100%;
}

.band-card,
.timer-box,
.score-box,
.qr-box,
.status-panel {
    padding: 14px 16px;
    background: var(--surface-strong);
    border-radius: 20px;
    border: 1px solid var(--stroke);
}

.band-card,
.timer-box,
.score-box {
    display: grid;
    align-content: center;
}

.timer-box strong,
.score-box strong {
    display: block;
    font-size: clamp(2.1rem, 5vw, 4.4rem);
    line-height: 1;
    color: var(--primary-deep);
}

.score-box strong {
    font-size: clamp(2.5rem, 6vw, 5rem);
}

.qr-box {
    text-align: center;
    display: grid;
    align-content: center;
    gap: 10px;
}

.qr-box img {
    width: min(180px, 100%);
    margin: 0 auto 8px;
    border-radius: 18px;
    background: #fff;
    padding: 10px;
}

.hidden {
    display: none;
}

.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
}

.admin-nav a,
.ghost-button,
.primary-button,
.text-button,
.vote-button {
    border: 0;
    border-radius: 14px;
    padding: 12px 18px;
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
}

.admin-nav a {
    flex: 0 1 auto;
    white-space: normal;
    text-align: center;
}

.primary-button,
.vote-button {
    background: linear-gradient(135deg, var(--primary), var(--primary-deep));
    color: #fff;
}

.ghost-button,
.admin-nav a {
    background: #fff;
    color: var(--primary-deep);
    border: 1px solid var(--stroke);
}

.text-button {
    padding: 0;
    background: none;
    color: var(--primary-deep);
}

.danger {
    color: var(--danger);
}

.stack-form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 8px;
    font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="file"] {
    width: 100%;
    padding: 13px 14px;
    border-radius: 14px;
    border: 1px solid rgba(122, 16, 16, 0.16);
    background: #fff;
    font: inherit;
}

.inline-fields {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.alert {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 16px;
}

.alert.success {
    color: var(--success);
    background: rgba(22, 101, 52, 0.08);
}

.alert.error {
    color: var(--danger);
    background: rgba(185, 28, 28, 0.08);
}

.table-wrap {
    overflow-x: auto;
    margin-top: 8px;
}

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

th, td {
    padding: 14px 12px;
    border-bottom: 1px solid rgba(122, 16, 16, 0.08);
    text-align: left;
    vertical-align: top;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.action-row form {
    margin: 0;
}

.table-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid rgba(122, 16, 16, 0.12);
    background: #fff;
    color: var(--primary-deep);
    font-weight: 700;
    font-size: 0.92rem;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 8px 20px rgba(122, 16, 16, 0.08);
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease;
    cursor: pointer;
}

.table-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(122, 16, 16, 0.12);
}

.action-view {
    background: linear-gradient(135deg, #fff5f1, #ffffff);
}

.action-edit {
    background: linear-gradient(135deg, #fff1eb, #ffffff);
}

.action-start {
    background: linear-gradient(135deg, #b42318, #7a1010);
    color: #fff;
    border-color: transparent;
}

.action-stop {
    background: linear-gradient(135deg, #7f1d1d, #450a0a);
    color: #fff;
    border-color: transparent;
}

.action-delete {
    background: #fff;
    color: var(--danger);
    border-color: rgba(185, 28, 28, 0.16);
}

.action-order {
    background: linear-gradient(135deg, #fff4ef, #ffffff);
}

.table-action[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.admin-topbar > div:first-child,
.section-head > div:first-child,
.hero-bar > div:first-child {
    flex: 1 1 320px;
    min-width: 0;
}

.admin-topbar h1,
.section-head h1,
.hero-bar h1 {
    line-height: 1.15;
    margin-bottom: 0;
}

.hero-bar {
    margin-bottom: 4px;
}

.hero-bar h1 {
    font-size: clamp(1.5rem, 3vw, 2.4rem);
}

.band-card h2,
.timer-box p,
.score-box p,
.qr-box p {
    margin-bottom: 8px;
}

.admin-topbar .admin-nav {
    flex: 1 1 420px;
    min-width: 0;
}

td a,
th,
td {
    white-space: normal;
}

.admin-preview {
    border-radius: 18px;
    border: 1px solid var(--stroke);
}

.banner-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.banner-item {
    display: grid;
    gap: 10px;
}

.banner-preview-frame {
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 18px;
    border: 1px solid var(--stroke);
    background: #fff;
}

.banner-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-weight: 600;
}

.banner-item-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.banner-item-actions form {
    margin: 0;
}

.report-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
}

.banner-preview {
    width: 100%;
    height: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    object-position: center;
    border: 0;
    border-radius: 0;
}

.band-preview {
    max-width: 320px;
    aspect-ratio: 4 / 5;
}

.auth-card {
    width: min(440px, calc(100% - 32px));
    margin: 10vh auto;
    padding: 28px;
}

.helper-link {
    margin-bottom: 0;
    text-align: center;
}

.vote-shell {
    display: grid;
    place-items: center;
}

.site-footer {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto 14px;
    text-align: center;
    color: var(--muted);
    font-weight: 600;
    line-height: 1.25;
}

.site-footer p {
    margin: 0;
}

.compact-footer {
    margin-top: 12px;
}

.student-card {
    width: min(520px, 100%);
    text-align: center;
}

.vote-image {
    aspect-ratio: 4 / 5;
    border-radius: 24px;
    margin: 16px 0 20px;
}

.vote-message {
    color: var(--muted);
    min-height: 28px;
}

.vote-button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 980px) {
    .live-grid,
    .admin-grid,
    .inline-fields,
    .hero-bar,
    .admin-topbar,
    .section-head {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .public-shell,
    .admin-shell,
    .form-shell,
    .vote-shell {
        width: min(100%, calc(100% - 20px));
    }

    .public-shell {
        min-height: auto;
        height: auto;
        justify-content: flex-start;
    }

    .a4-frame {
        max-height: none;
    }

    .vote-panel {
        grid-template-rows: auto;
    }

    .admin-nav {
        justify-content: stretch;
    }

    .admin-nav a {
        flex: 1 1 180px;
    }
}

@media (max-width: 640px) {
    .admin-nav a,
    .ghost-button,
    .primary-button,
    .vote-button {
        width: 100%;
    }

    .auth-card,
    .poster-panel,
    .vote-panel,
    .student-card,
    .admin-card {
        padding: 20px;
    }
}
