:root {
    color-scheme: dark;
    --surface: #101512;
    --surface-soft: #171d19;
    --surface-raised: #1d2420;
    --line: rgba(226, 235, 229, 0.13);
    --line-strong: rgba(226, 235, 229, 0.24);
    --text: #f1f5f2;
    --text-muted: #9ca9a1;
    --accent: #d6ad5d;
    --accent-soft: rgba(214, 173, 93, 0.12);
    --danger: #e07968;
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-width: 1024px;
    min-height: 100%;
    margin: 0;
    background: var(--surface);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    color: var(--text);
    font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
img {
    font: inherit;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

[v-cloak] {
    display: none;
}

.screen-shell {
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
    isolation: isolate;
    background:
        radial-gradient(circle at 82% 18%, rgba(63, 91, 74, 0.18), transparent 34%),
        linear-gradient(135deg, #101512 0%, #121814 58%, #0e1310 100%);
}

.screen-shell::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    content: "";
    pointer-events: none;
    opacity: 0.16;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 40px 40px;
}

.topbar {
    height: 84px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 28px;
    padding: 0 clamp(28px, 3vw, 64px);
    border-bottom: 1px solid var(--line);
    background: rgba(16, 21, 18, 0.9);
}

.brand-block,
.topbar-actions,
.match-summary,
.player-identity,
.clock-block,
.summary-item {
    display: flex;
    align-items: center;
}

.brand-block {
    grid-column: 1;
    gap: 14px;
}

.brand-mark {
    width: 14px;
    height: 34px;
    border-radius: 4px;
    background: var(--accent);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.brand-name,
.brand-subtitle,
.section-kicker,
.qr-panel p,
.qr-panel small,
.player-name,
.player-meta,
.score-block span,
.connection-state,
.pairing-copy p,
.match-heading h1 {
    margin: 0;
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.brand-subtitle,
.summary-label,
.clock-block span,
.qr-panel small,
.player-meta,
.score-block span,
.stat-item dt,
.snooker-overview span {
    color: var(--text-muted);
}

.brand-subtitle {
    margin-top: 2px;
    font-size: 12px;
}

.match-summary {
    grid-column: 2;
    height: 54px;
    gap: 24px;
    padding: 0 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(29, 36, 32, 0.72);
}

.summary-item {
    gap: 10px;
}

.summary-label {
    font-size: 12px;
}

.summary-item strong {
    font-size: 16px;
}

.summary-divider {
    width: 1px;
    height: 24px;
    background: var(--line);
}

.timer-value {
    min-width: 76px;
    color: var(--accent);
    font-family: "Bahnschrift", "DIN Alternate", monospace;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

.timer-value.is-over {
    color: var(--danger);
}

.topbar-actions {
    grid-column: 3;
    justify-content: flex-end;
    gap: 22px;
}

.clock-block {
    flex-direction: column;
    align-items: flex-end;
    font-variant-numeric: tabular-nums;
}

.clock-block strong {
    font-size: 18px;
    line-height: 1.1;
}

.clock-block span {
    margin-top: 3px;
    font-size: 11px;
}

.exit-button {
    min-width: 120px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: transparent;
    color: #d6ded8;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.exit-button:hover {
    border-color: rgba(214, 173, 93, 0.62);
    background: var(--accent-soft);
}

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

.pairing-view {
    min-height: calc(100vh - 84px);
    min-height: calc(100dvh - 84px);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
    align-items: center;
    gap: clamp(60px, 8vw, 150px);
    max-width: 1500px;
    margin: 0 auto;
    padding: 54px clamp(54px, 7vw, 120px);
}

.pairing-copy {
    max-width: 720px;
}

.section-kicker {
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.18em;
}

.pairing-copy h1 {
    max-width: 660px;
    margin: 18px 0 22px;
    font-size: clamp(42px, 4.1vw, 70px);
    line-height: 1.12;
    letter-spacing: -0.04em;
}

.pairing-copy > p:not(.section-kicker) {
    max-width: 610px;
    color: #b9c4bd;
    font-size: clamp(16px, 1.2vw, 20px);
    line-height: 1.8;
}

.pairing-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 42px 0 28px;
    padding: 0;
    list-style: none;
}

.pairing-steps li {
    min-height: 92px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
    border-top: 1px solid var(--line-strong);
    color: #d7ded9;
    font-size: 14px;
}

.pairing-steps span {
    color: var(--accent);
    font-family: "Bahnschrift", monospace;
    font-size: 14px;
}

.connection-state {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
}

.state-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.connection-state.has-error .state-indicator {
    background: var(--danger);
}

.connection-state.has-error {
    color: #e7aa9f;
}

.qr-panel {
    justify-self: center;
    width: min(100%, 440px);
    padding: clamp(34px, 4vw, 54px);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: rgba(29, 36, 32, 0.82);
    box-shadow: 0 28px 80px rgba(3, 8, 5, 0.34);
    text-align: center;
}

.qr-frame {
    width: min(24vw, 286px);
    min-width: 220px;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    margin: 0 auto 26px;
    padding: 15px;
    border-radius: 12px;
    background: #f4f7f5;
}

.qr-code {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.qr-placeholder {
    display: flex;
    gap: 8px;
}

.qr-placeholder span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #566159;
    animation: qr-wait 1s ease-in-out infinite alternate;
}

.qr-placeholder span:nth-child(2) {
    animation-delay: 160ms;
}

.qr-placeholder span:nth-child(3) {
    animation-delay: 320ms;
}

.qr-panel p {
    font-size: 20px;
    font-weight: 700;
}

.qr-panel small {
    display: block;
    margin-top: 8px;
    font-size: 12px;
}

.match-view {
    height: calc(100vh - 84px);
    height: calc(100dvh - 84px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: clamp(18px, 2vh, 30px);
    padding: clamp(24px, 3vh, 42px) clamp(28px, 3vw, 64px) clamp(28px, 4vh, 54px);
}

.match-heading {
    min-height: 64px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 30px;
}

.match-heading h1 {
    margin-top: 8px;
    font-size: clamp(26px, 2.1vw, 38px);
    letter-spacing: -0.03em;
}

.snooker-overview {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(23, 29, 25, 0.76);
}

.snooker-overview > div {
    min-width: 122px;
    padding: 12px 20px;
    border-left: 1px solid var(--line);
}

.snooker-overview > div:first-child {
    border-left: 0;
}

.snooker-overview span,
.snooker-overview strong {
    display: block;
}

.snooker-overview span {
    margin-bottom: 5px;
    font-size: 11px;
}

.snooker-overview strong {
    font-family: "Bahnschrift", monospace;
    font-size: 20px;
    font-variant-numeric: tabular-nums;
}

.players-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(16px, 1.5vw, 28px);
}

.players-grid--1 {
    grid-template-columns: minmax(0, 1fr);
    max-width: 880px;
    width: 100%;
    margin: 0 auto;
}

.players-grid--4,
.players-grid--5,
.players-grid--6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.player-panel {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: clamp(12px, 1.8vh, 24px);
    padding: clamp(20px, 2.2vw, 38px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: linear-gradient(145deg, rgba(29, 36, 32, 0.94), rgba(20, 27, 23, 0.94));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025), 0 24px 70px rgba(3, 8, 5, 0.2);
}

.player-panel::after {
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    content: "";
    background: transparent;
}

.player-panel.is-active {
    border-color: rgba(214, 173, 93, 0.58);
    background: linear-gradient(145deg, rgba(45, 43, 30, 0.94), rgba(22, 28, 23, 0.96));
}

.player-panel.is-active::after {
    background: var(--accent);
}

.player-identity {
    min-width: 0;
    gap: clamp(12px, 1vw, 18px);
}

.avatar-wrap {
    width: clamp(58px, 5vw, 86px);
    height: clamp(58px, 5vw, 86px);
    flex: 0 0 auto;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    background: #2b342e;
}

.player-avatar,
.avatar-fallback {
    width: 100%;
    height: 100%;
}

.player-avatar {
    display: block;
    object-fit: cover;
}

.avatar-fallback {
    display: grid;
    place-items: center;
    color: var(--accent);
    font-size: clamp(24px, 2vw, 34px);
    font-weight: 700;
}

.player-name-block {
    min-width: 0;
}

.player-name {
    overflow: hidden;
    color: var(--text);
    font-size: clamp(22px, 2vw, 34px);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-meta {
    display: block;
    margin-top: 6px;
    font-size: clamp(11px, 0.8vw, 13px);
}

.player-meta--active {
    color: var(--accent);
}

.score-block {
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.score-block span {
    font-size: clamp(12px, 1vw, 16px);
    letter-spacing: 0.12em;
}

.score-block strong {
    color: var(--accent);
    font-family: "Bahnschrift", "DIN Alternate", monospace;
    font-size: clamp(84px, 13vh, 168px);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 0.96;
    letter-spacing: -0.04em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 0;
    border-top: 1px solid var(--line);
}

.match-view--2 .players-grid--2 .stats-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.stat-item {
    min-width: 0;
    padding: clamp(14px, 1.4vw, 22px) 12px 0;
    border-left: 1px solid var(--line);
    text-align: center;
}

.stat-item:first-child {
    border-left: 0;
}

.stat-item dt {
    overflow: hidden;
    font-size: clamp(10px, 0.78vw, 13px);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-item dd {
    margin: 5px 0 0;
    color: #e4eae6;
    font-family: "Bahnschrift", monospace;
    font-size: clamp(20px, 2vw, 32px);
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.players-grid--3 .player-panel,
.players-grid--4 .player-panel,
.players-grid--5 .player-panel,
.players-grid--6 .player-panel {
    gap: 10px;
    padding: clamp(16px, 1.5vw, 26px);
}

.players-grid--3 .score-block strong,
.players-grid--4 .score-block strong,
.players-grid--5 .score-block strong,
.players-grid--6 .score-block strong {
    font-size: clamp(56px, 8vh, 94px);
}

.players-grid--3 .avatar-wrap,
.players-grid--4 .avatar-wrap,
.players-grid--5 .avatar-wrap,
.players-grid--6 .avatar-wrap {
    width: clamp(46px, 3.8vw, 66px);
    height: clamp(46px, 3.8vw, 66px);
}

.players-grid--3 .stats-grid,
.players-grid--4 .stats-grid,
.players-grid--5 .stats-grid,
.players-grid--6 .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.match-view--2 .players-grid--3 .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.offline-banner {
    position: fixed;
    right: 28px;
    bottom: 24px;
    padding: 12px 16px;
    border: 1px solid rgba(224, 121, 104, 0.38);
    border-radius: 10px;
    background: rgba(57, 29, 26, 0.94);
    color: #f0c1b9;
    font-size: 13px;
}

@keyframes qr-wait {
    from { transform: translateY(0); opacity: 0.45; }
    to { transform: translateY(-5px); opacity: 1; }
}

@media (max-height: 800px) {
    .topbar {
        height: 72px;
    }

    .match-view,
    .pairing-view {
        height: calc(100vh - 72px);
        min-height: calc(100vh - 72px);
    }

    .match-view {
        gap: 14px;
        padding-top: 18px;
        padding-bottom: 22px;
    }

    .match-heading {
        min-height: 52px;
    }

    .player-panel {
        gap: 10px;
        padding-top: 18px;
        padding-bottom: 18px;
    }

    .score-block strong {
        font-size: clamp(66px, 12vh, 112px);
    }

    .stat-item {
        padding-top: 10px;
    }
}

@media (min-width: 1900px) and (min-height: 900px) {
    .topbar {
        height: 96px;
    }

    .match-view {
        height: calc(100dvh - 96px);
    }

    .players-grid--2 {
        gap: 34px;
    }
}

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