:root {
    color-scheme: light;
    --ink: #1c2a2f;
    --muted: #607277;
    --line: #dbe6e2;
    --paper: #fbfcfa;
    --surface: #ffffff;
    --primary: #167c63;
    --primary-dark: #0e5c4a;
    --accent: #d84d3a;
    --sky: #dff1f7;
    --leaf: #e2f3da;
    --gold: #ffe29a;
    --shadow: 0 18px 50px rgba(28, 42, 47, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    line-height: 1.5;
}

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

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

button,
input,
textarea {
    font: inherit;
}

.site-header {
    background:
        linear-gradient(120deg, rgba(223, 241, 247, 0.95), rgba(226, 243, 218, 0.92)),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cpath fill='%23ffffff' fill-opacity='.55' d='M18 20h22v22H18zM78 14h18v18H78zM64 70h32v32H64zM20 76h24v24H20z'/%3E%3C/svg%3E");
    border-bottom: 1px solid var(--line);
}

.nav,
.admin-header {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin: 0 auto;
    max-width: 1180px;
    padding: 20px 24px;
}

.brand {
    align-items: center;
    display: inline-flex;
    font-weight: 800;
    gap: 10px;
}

.brand-mark {
    align-items: center;
    background: var(--primary);
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    height: 34px;
    justify-content: center;
    width: 34px;
}

.admin-link {
    border: 1px solid rgba(22, 124, 99, 0.24);
    border-radius: 8px;
    color: var(--primary-dark);
    font-weight: 700;
    padding: 8px 12px;
}

.hero {
    align-items: center;
    display: grid;
    gap: 30px;
    grid-template-columns: minmax(0, 1fr) 260px;
    margin: 0 auto;
    max-width: 1180px;
    padding: 54px 24px 76px;
}

.eyebrow {
    color: var(--primary-dark);
    font-weight: 800;
    margin: 0 0 12px;
}

.hero h1 {
    font-size: clamp(34px, 5vw, 64px);
    line-height: 1.04;
    margin: 0;
    max-width: 920px;
}

.hero p {
    color: var(--muted);
    font-size: 18px;
    max-width: 720px;
}

.hero-panel {
    background: rgba(255, 255, 255, 0.76);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.hero-panel span,
.hero-panel small {
    color: var(--muted);
}

.hero-panel strong {
    display: block;
    font-size: 58px;
    line-height: 1;
    margin: 10px 0;
}

.page-main {
    margin: -34px auto 72px;
    max-width: 1180px;
    padding: 0 24px;
}

.game-grid {
    display: grid;
    gap: 22px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.game-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(28, 42, 47, 0.08);
    overflow: hidden;
}

.cover {
    align-items: center;
    aspect-ratio: 16 / 10;
    background:
        linear-gradient(135deg, rgba(22, 124, 99, 0.82), rgba(216, 77, 58, 0.72)),
        var(--cover, none);
    background-position: center;
    background-size: cover;
    color: #fff;
    display: flex;
    font-size: 64px;
    font-weight: 900;
    justify-content: center;
}

.game-body {
    padding: 20px;
}

.game-meta,
.progress-info {
    color: var(--muted);
    display: flex;
    font-size: 13px;
    gap: 12px;
    justify-content: space-between;
}

.game-body h2 {
    font-size: 22px;
    line-height: 1.25;
    margin: 12px 0 8px;
}

.game-body p {
    color: var(--muted);
    margin: 0 0 16px;
    min-height: 48px;
}

.progress-bar {
    background: #edf2f0;
    border-radius: 999px;
    height: 8px;
    margin: 8px 0 18px;
    overflow: hidden;
}

.progress-bar span {
    background: linear-gradient(90deg, var(--primary), var(--accent));
    display: block;
    height: 100%;
}

.button {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    font-weight: 800;
    justify-content: center;
    min-height: 42px;
    padding: 9px 14px;
    transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

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

.button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.button.primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.ghost {
    background: #fff;
    border-color: var(--line);
    color: var(--ink);
}

.button.danger,
.button.danger-light {
    background: #fff0ed;
    border-color: #ffd1ca;
    color: #a32d1e;
}

.button.small {
    min-height: 34px;
    padding: 6px 10px;
}

.empty-state,
.empty-mini {
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 42px;
    text-align: center;
}

.empty-state h2 {
    margin-top: 0;
}

.empty-state p,
.hint {
    color: var(--muted);
}

.empty-state .button {
    margin: 18px auto 0;
    max-width: 180px;
}

.modal[hidden] {
    display: none;
}

.modal {
    inset: 0;
    position: fixed;
    z-index: 50;
}

.modal-backdrop {
    background: rgba(28, 42, 47, 0.58);
    inset: 0;
    position: absolute;
}

.modal-dialog {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    left: 50%;
    max-height: calc(100vh - 40px);
    max-width: 430px;
    overflow: auto;
    padding: 26px;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 36px);
}

.modal-dialog h2 {
    margin: 0 34px 8px 0;
}

.modal-dialog p {
    color: var(--muted);
}

.close-button {
    background: #f3f6f4;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-size: 24px;
    height: 36px;
    line-height: 1;
    position: absolute;
    right: 18px;
    top: 18px;
    width: 36px;
}

.qr-tabs {
    background: #eef4f1;
    border-radius: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin: 20px 0;
    padding: 4px;
}

.tab-button {
    background: transparent;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 800;
    padding: 10px;
}

.tab-button.active {
    background: #fff;
    box-shadow: 0 6px 14px rgba(28, 42, 47, 0.08);
}

.tab-button:disabled {
    color: #9aa8aa;
    cursor: not-allowed;
}

.qr-view {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.qr-view img {
    aspect-ratio: 1;
    margin: auto;
    object-fit: contain;
    width: min(280px, 100%);
}

.qr-empty {
    background: #fff7df;
    border-radius: 8px;
    color: #7d5b00;
    padding: 14px;
}

.modal-open {
    overflow: hidden;
}

.admin-page {
    background: #f4f7f5;
}

.admin-header {
    background: #fff;
    border-bottom: 1px solid var(--line);
    max-width: none;
}

.admin-actions,
.form-actions,
.row-actions {
    align-items: center;
    display: flex;
    gap: 10px;
}

.admin-layout {
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
    margin: 0 auto;
    max-width: 1280px;
    padding: 24px;
}

.admin-form-panel,
.admin-list-panel,
.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(28, 42, 47, 0.06);
    padding: 24px;
}

.admin-form-panel h1,
.panel-heading h2 {
    margin-top: 0;
}

.alert {
    border-radius: 8px;
    font-weight: 700;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.alert.success {
    background: #e8f7ee;
    color: #166837;
}

.alert.error {
    background: #fff0ed;
    color: #a32d1e;
}

.game-form label,
.login-card label {
    display: grid;
    gap: 7px;
    margin-bottom: 16px;
}

.game-form label span,
.login-card label span {
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
}

input,
textarea {
    background: #fff;
    border: 1px solid #cfdeda;
    border-radius: 8px;
    color: var(--ink);
    outline: 0;
    padding: 11px 12px;
    width: 100%;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22, 124, 99, 0.12);
}

textarea {
    resize: vertical;
}

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

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

.upload-box {
    border: 1px dashed #b8cbc5;
    border-radius: 8px;
    padding: 12px;
}

.upload-box img {
    aspect-ratio: 1;
    background: #f5f7f6;
    border-radius: 6px;
    margin-top: 10px;
    object-fit: cover;
    width: 100%;
}

.checkbox-row {
    align-items: center;
    display: flex !important;
    gap: 10px !important;
}

.checkbox-row input {
    width: auto;
}

.panel-heading {
    align-items: center;
    display: flex;
    justify-content: space-between;
}

.panel-heading span {
    color: var(--muted);
}

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

table {
    border-collapse: collapse;
    min-width: 640px;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 14px 10px;
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
}

td small {
    color: var(--muted);
    display: block;
    margin-top: 4px;
}

.status,
.qr-badges span {
    background: #eef2f0;
    border-radius: 999px;
    color: var(--muted);
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    padding: 5px 8px;
}

.status.on,
.qr-badges span.ready {
    background: #e4f7ec;
    color: #166837;
}

.status.off {
    background: #f1f1f1;
    color: #777;
}

.qr-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.row-actions form {
    margin: 0;
}

.login-shell {
    align-items: center;
    display: flex;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    margin: auto;
    max-width: 420px;
    width: 100%;
}

.login-brand {
    margin-bottom: 24px;
}

.login-card h1 {
    margin: 0 0 18px;
}

@media (max-width: 980px) {
    .hero,
    .admin-layout {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 680px) {
    .nav,
    .admin-header,
    .admin-actions,
    .form-actions,
    .row-actions,
    .panel-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .hero {
        padding-top: 32px;
    }

    .hero h1 {
        font-size: 38px;
    }

    .game-grid,
    .form-grid,
    .upload-grid {
        grid-template-columns: 1fr;
    }

    .admin-layout {
        padding: 14px;
    }

    .admin-form-panel,
    .admin-list-panel,
    .login-card {
        padding: 18px;
    }
}
