:root {
    color-scheme: light;
    --ink: #1d3557;
    --muted: #65738a;
    --line: #dce3ed;
    --surface: #ffffff;
    --soft: #f6f8fc;
    --blue: #315f82;
    --blue-dark: #1d3557;
    --teal: #167b72;
    --danger: #b4233d;
    --shadow: 0 20px 60px rgba(29, 53, 87, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        linear-gradient(rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0.12)),
        #eaf0fb;
    font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
    letter-spacing: 0;
}

.site-shell {
    width: min(920px, calc(100% - 30px));
    margin: 0 auto;
    padding: 40px 0 24px;
}

.redeem-card {
    padding: 36px;
    border: 1px solid rgba(255, 255, 255, 0.92);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 34px;
}

.brand-mark {
    display: grid;
    width: 54px;
    height: 54px;
    flex: 0 0 54px;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: var(--ink);
    font-size: 15px;
    font-weight: 800;
}

.site-header h1 {
    margin: 0 0 6px;
    color: var(--ink);
    font-size: 32px;
    line-height: 1.2;
}

.site-header p {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
}

.announcement,
.alert {
    margin-bottom: 22px;
    padding: 14px 16px;
    border-radius: 8px;
    line-height: 1.65;
}

.announcement {
    border: 1px solid #f0d79d;
    color: #765316;
    background: #fff9eb;
}

.alert-error {
    border: 1px solid #f0b8c3;
    color: #8c1d34;
    background: #fff3f5;
}

.alert-success {
    border: 1px solid #a8d8ce;
    color: #0f5f58;
    background: #eefaf7;
}

.result-meta {
    margin-top: 5px;
    color: #53736f;
    font-size: 14px;
}

.cdk-result {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin-top: 14px;
}

.cdk-result code {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    overflow-wrap: anywhere;
    padding: 12px 14px;
    border: 1px dashed #65a99f;
    border-radius: 6px;
    color: #9f1731;
    background: #fff;
    font-family: Consolas, monospace;
    font-size: 22px;
    font-weight: 700;
}

.copy-button {
    min-width: 76px;
    border: 0;
    border-radius: 6px;
    color: #fff;
    background: var(--teal);
    cursor: pointer;
}

.redeem-form {
    display: grid;
    gap: 22px;
}

.field {
    position: relative;
}

.field label {
    display: block;
    margin-bottom: 9px;
    color: #314760;
    font-size: 14px;
    font-weight: 700;
}

.field input,
.field select {
    width: 100%;
    min-height: 56px;
    padding: 0 17px;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    color: #1d2e42;
    background: #fff;
    font-size: 16px;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus,
.field select:focus {
    border-color: #5688aa;
    box-shadow: 0 0 0 3px rgba(69, 123, 157, 0.14);
}

.field-hint {
    display: block;
    margin-top: 7px;
    color: #8994a5;
    font-size: 12px;
}

.primary-button {
    display: flex;
    min-height: 58px;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(90deg, var(--blue), var(--blue-dark));
    box-shadow: 0 8px 20px rgba(29, 53, 87, 0.16);
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
    transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.primary-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(29, 53, 87, 0.24);
}

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

.history-button {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid #b9c6d5;
    border-radius: 8px;
    color: #284660;
    background: #f9fbfd;
    text-decoration: none;
    font-size: 16px;
    font-weight: 700;
    transition: border-color 160ms ease, background 160ms ease;
}

.history-button:hover {
    border-color: #6f91a9;
    background: #f0f6fa;
}

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
}

.page-heading .site-header {
    justify-content: flex-start;
    margin: 0;
}

.back-button {
    flex: 0 0 auto;
    color: #50627a;
    text-decoration: none;
    font-size: 14px;
}

.history-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    margin-bottom: 28px;
}

.history-search .field {
    margin: 0;
}

.history-search .primary-button {
    align-self: end;
    min-width: 128px;
    box-shadow: none;
}

.history-summary {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.history-summary h2 {
    margin: 0;
    font-size: 18px;
}

.history-summary span {
    color: var(--muted);
    font-size: 13px;
}

.history-list {
    display: grid;
}

.history-row {
    display: grid;
    grid-template-columns: minmax(150px, 1.1fr) minmax(220px, 1fr) auto;
    gap: 18px;
    align-items: center;
    padding: 18px 0;
    border-bottom: 1px solid #edf0f4;
}

.history-game,
.history-code {
    min-width: 0;
}

.history-game strong,
.history-game time {
    display: block;
}

.history-game strong {
    overflow: hidden;
    margin-bottom: 5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-game time {
    color: var(--muted);
    font-size: 12px;
}

.history-code code {
    overflow-wrap: anywhere;
    color: #9f1731;
    font-family: Consolas, monospace;
    font-size: 15px;
    font-weight: 700;
}

.history-row .copy-button {
    min-height: 40px;
    padding: 0 16px;
}

.history-empty {
    padding: 34px 12px 12px;
    color: var(--muted);
    text-align: center;
    line-height: 1.8;
}

.rules {
    margin-top: 30px;
    padding: 20px;
    border-left: 4px solid var(--teal);
    border-radius: 6px;
    color: #526174;
    background: var(--soft);
}

.rules-heading {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
    color: #243c58;
}

.rules-icon {
    display: grid;
    width: 22px;
    height: 22px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--teal);
    font-family: Georgia, serif;
    font-weight: 700;
}

.rules-content {
    line-height: 1.9;
    font-size: 15px;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    padding: 18px 8px 0;
    color: #7b8798;
    font-size: 12px;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 10;
    padding: 11px 16px;
    border-radius: 6px;
    color: #fff;
    background: #173a3a;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

body.popup-open {
    overflow: hidden;
}

.auto-popup {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.auto-popup.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.auto-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 31, 45, .58);
}

.auto-popup-dialog {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: auto minmax(260px, var(--popup-height, 620px));
    width: min(960px, 100%);
    max-height: calc(100vh - 40px);
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 31, 45, .28);
    transform: translateY(8px);
    transition: transform 180ms ease;
}

.auto-popup.is-visible .auto-popup-dialog {
    transform: translateY(0);
}

.auto-popup-header {
    display: flex;
    min-height: 54px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px 0 20px;
    border-bottom: 1px solid var(--line);
}

.auto-popup-header h2 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 17px;
}

.auto-popup-close {
    display: grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    border: 0;
    border-radius: 6px;
    color: #34485a;
    background: #eef3f7;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.auto-popup iframe {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

@media (max-width: 640px) {
    .site-shell {
        width: min(100% - 20px, 920px);
        padding-top: 16px;
    }

    .redeem-card {
        padding: 24px 18px;
        border-radius: 10px;
    }

    .site-header {
        align-items: flex-start;
        justify-content: flex-start;
        gap: 12px;
        margin-bottom: 26px;
    }

    .brand-mark {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
        font-size: 13px;
    }

    .site-header h1 {
        font-size: 23px;
    }

    .site-header p {
        font-size: 13px;
    }

    .page-heading {
        align-items: flex-start;
    }

    .page-heading .site-header {
        flex: 1;
    }

    .back-button {
        padding-top: 12px;
    }

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

    .history-search .primary-button {
        width: 100%;
    }

    .history-row {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px;
    }

    .history-code {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .history-row .copy-button {
        grid-column: 2;
        grid-row: 1;
    }

    .cdk-result {
        flex-direction: column;
    }

    .cdk-result code {
        font-size: 17px;
    }

    .copy-button {
        min-height: 44px;
    }

    .site-footer {
        gap: 12px;
    }

    .auto-popup {
        padding: 10px;
    }

    .auto-popup-dialog {
        grid-template-rows: auto minmax(260px, min(var(--popup-height, 620px), calc(100vh - 74px)));
        max-height: calc(100vh - 20px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
