:root {
    color-scheme: light;
    --sky: #5bc7ef;
    --blue: #0758ad;
    --ink: #08315e;
    --navy: #073770;
    --ice: #edf8ff;
    --line: #d6e8f5;
    --muted: #4b6683;
    --orange: #fdb15d;
    --paper: #fff;
    --green: #0b664a;
    --red: #a52234;
    --shadow: 0 12px 32px #0d497810;
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
    font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: #f2f8fc; min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid #f48736; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(25px, 3.2vw, 38px); letter-spacing: -.035em; }
h2 { font-size: 18px; letter-spacing: -.02em; }
hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
small { font-size: .82em; }
strong, h1, h2 { font-weight: 750; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0; }
.muted { color: var(--muted); font-size: .91rem; line-height: 1.55; }
.error, .success { padding: 11px 14px; border-radius: 10px; font-size: .92rem; background: #fff0f1; color: var(--red); }
.success { background: #e4f9f0; color: var(--green); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); min-width: 0; }
.stack { display: grid; align-content: start; gap: 14px; min-width: 0; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fields.trio { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wide { grid-column: 1 / -1; }
label { display: grid; align-content: start; gap: 6px; color: var(--ink); font-size: .9rem; font-weight: 650; min-width: 0; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
    min-height: 42px; padding: 9px 11px; width: 100%; min-width: 0; color: var(--ink);
    border: 1px solid #bfd7e9; background: #fff; border-radius: 9px; font-weight: 500;
}
input[type=file] { font-size: .85rem; }
textarea { resize: vertical; }
.check-line { display: flex; align-items: center; font-weight: 500; }
input[type=checkbox], input[type=radio] { accent-color: var(--blue); }
.btn { border-radius: 9px; min-height: 41px; padding: 9px 14px; border: 1px solid transparent; text-align: center; font-weight: 700; line-height: 1.25; transition: background .14s, box-shadow .14s; }
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn.small { font-size: .84rem; min-height: 33px; padding: 6px 10px; }
.primary { background: var(--blue); color: white; }
.ghost { color: var(--blue); background: #eff7ff; border-color: #d2e5f4; }
.positive { background: var(--green); color: white; }
.negative { background: var(--red); color: white; }
.warning { background: #fff0d9; color: #784014; border-color: #f4d4a9; }
.danger-text { color: var(--red); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.busy [data-cmd], .busy button[type=submit], .busy [data-action] button { cursor: wait; }
.connection { color: #34627d; font-size: .79rem; }
.connection::before, .status-dot::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; background: #109773; vertical-align: 1px; }
.connection.offline::before { background: #d75449; }

.topbar, .landing-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 70px; padding: 12px clamp(16px, 3vw, 42px); }
.topbar { background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 750; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand img { width: 36px; height: 36px; object-fit: contain; flex-shrink: 0; }
.brand small { display: block; color: var(--muted); font-weight: 550; margin-top: 3px; }
.landing-head { max-width: 1164px; margin: 0 auto; padding-inline: 22px; }
.status-dot { font-size: .79rem; color: #225a7a; white-space: nowrap; }
body[data-page=home], body[data-page=join] { background: linear-gradient(178deg, #dff5ff 0, #edf9ff 53%, #f9fcff 90%); }
.home { max-width: 1164px; margin: 0 auto; padding: 0 22px; }
.home-hero { overflow: hidden; border: 1px solid #fff; border-radius: 24px; background: #fff; box-shadow: 0 18px 44px #1a699a23; }
.kv { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #61c9ef; }
.home-time { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; padding: clamp(14px, 2vw, 22px); color: var(--blue); }
.home-time > span { font-size: .78rem; background: var(--ice); border-radius: 30px; padding: 5px 11px; font-weight: 700; }
.home-time time { font-size: clamp(15px, 2vw, 20px); font-variant-numeric: tabular-nums; font-weight: 650; }
.home-time time strong { color: var(--ink); padding-left: 5px; }
.entry-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.entry { border: 1px solid #c7e6f9; background: white; color: var(--ink); display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: clamp(13px, 2vw, 21px); border-radius: 15px; box-shadow: var(--shadow); }
.entry:hover { text-decoration: none; box-shadow: 0 10px 22px #10487724; }
.entry strong { font-size: clamp(16px, 2vw, 21px); }
.entry div > span { display: block; font-size: .83rem; margin-top: 5px; color: var(--muted); }
.entry > span { font-size: 1.45rem; }
.entry-team { background: var(--blue); color: white; border-color: var(--blue); }
.entry-team div > span { color: #e2f3ff; }
.landing-footer { padding: 24px 12px 20px; text-align: center; font-size: .76rem; }
.landing-footer a { color: #496881; }

.auth-wrap { width: min(100%, 540px); margin: auto; padding: 30px 16px 42px; }
.auth { display: grid; gap: 17px; padding: clamp(18px, 4vw, 30px); }
.auth-kv { width: 100%; border-radius: 11px; }
.auth h1 { font-size: 28px; }
.auth .btn { margin-top: 4px; }
.auth .back { font-size: .85rem; text-align: center; }

.admin-layout { max-width: 1580px; margin: auto; display: grid; grid-template-columns: 206px minmax(0, 1fr); }
.sidebar { min-width: 0; align-self: start; position: sticky; top: 0; padding: 24px 16px; display: grid; gap: 22px; }
.sidebar nav { display: grid; gap: 7px; }
.sidebar a { color: #31577a; padding: 12px 14px; border-radius: 10px; font-size: .94rem; font-weight: 680; white-space: nowrap; }
.sidebar a:hover { background: #e6f1fb; text-decoration: none; }
.sidebar a.selected { color: #fff; background: var(--navy); }
.admin-main { display: grid; align-content: start; gap: 15px; padding: 24px 24px 48px 4px; min-width: 0; }
.admin-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.admin-title .connection { margin-top: 7px; }
.links { padding: 14px 17px; display: grid; gap: 10px; }
.links > strong { font-size: .86rem; }
.links-row { display: flex; flex-wrap: wrap; gap: 7px; }
.links-row > div { background: #f1f8ff; border: 1px solid var(--line); border-radius: 7px; display: flex; align-items: center; gap: 7px; padding: 5px 7px 5px 9px; font-size: .82rem; }
.copy { border: 0; border-radius: 5px; background: #dbeeff; color: #245888; padding: 4px 6px; font-size: .75rem; }
.panel { padding: clamp(14px, 2vw, 22px); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 13px; }
.panel-head a { font-size: .83rem; }
.stack > .panel-head { margin-bottom: 0; }
.panel .field-note { margin: 11px 0; }
.control-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; }
.empty { color: var(--muted); padding: 22px 14px; text-align: center; background: #f5faff; border-radius: 10px; font-size: .91rem; line-height: 1.5; }
.message:empty { display: none; }
.message { border-radius: 9px; padding: 9px 12px; color: var(--green); background: #dff5eb; font-size: .89rem; }
.message.is-error { color: var(--red); background: #ffecee; }
.loading { padding: 25px; color: var(--muted); }
.team-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px; }
.pin-box { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--muted); background: #f4faff; padding: 8px; border-radius: 9px; font-size: .85rem; }
.pin-box code { font-size: 1.05rem; letter-spacing: .07em; color: var(--ink); }
.import-panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.import-panel h2 { margin-bottom: 5px; }
.import-panel a { display: inline-block; margin-top: 6px; font-size: .85rem; }
.filter { width: min(100%, 235px); margin: 0 0 12px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
th, td { padding: 9px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #edf6fc; white-space: nowrap; }
td small { display: block; color: var(--muted); white-space: nowrap; margin-top: 4px; }
.bank-text { min-width: 150px; max-width: 420px; overflow-wrap: anywhere; }
.row-actions { white-space: nowrap; }
.media-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.media-line + p { margin-top: 10px; }
.danger-panel { border-color: #f0c5cc; }
.danger-panel form { max-width: 500px; }
.submission { margin-top: 10px; color: var(--blue); overflow-wrap: anywhere; }
.stage-controls { margin-top: 13px; }

.question-top, .stage-active { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.tags { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.tag { display: inline-flex; align-items: center; white-space: nowrap; padding: 4px 9px; border-radius: 20px; background: var(--blue); color: #fff; font-size: .78rem; font-weight: 750; }
.tag.soft { background: #e9f5fe; color: #1d5c96; }
.tag.amber { background: #ffebce; color: #7a3e10; }
.phase-pill { color: #185487; font-size: .84rem; font-weight: 670; }
.active-team { margin: 8px 0 9px; font-weight: 720; color: #245a8b; overflow-wrap: anywhere; }
.q-body { display: grid; gap: 10px; }
.q-text { font-size: clamp(19px, 3vw, 26px); font-weight: 750; line-height: 1.46; white-space: pre-wrap; overflow-wrap: anywhere; }
.q-image-link { justify-self: start; }
.q-image { border: 1px solid var(--line); border-radius: 9px; max-height: 245px; width: auto; object-fit: contain; }
.choices { display: grid; gap: 7px; }
.choice { display: flex; min-width: 0; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 9px; background: #f7fbff; padding: 8px 10px; overflow-wrap: anywhere; font-size: .95rem; }
.choice .letter { border-radius: 6px; background: #dfedfa; min-width: 28px; height: 27px; display: inline-grid; place-items: center; font-weight: 800; color: #205a93; }
.correct-choice { background: #ecfaf3; border-color: #abe0c9; }
.correct-choice .letter { background: #bcead5; color: var(--green); }
label.choice { cursor: pointer; min-height: 46px; }
label.choice:has(input:checked) { background: #e1f2ff; border-color: #72abe0; }
.clock-pair { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.clock { min-width: 93px; background: #e8f5ff; color: #124d80; padding: 7px 9px; border-radius: 9px; }
.clock span, .clock strong { display: block; }
.clock span { font-size: .75em; }
.clock strong { margin-top: 3px; font-variant-numeric: tabular-nums; }
.clock.hurry { color: #992735; background: #ffebe9; }
.answer-detail { border-radius: 9px; background: #edf7ff; color: #195582; padding: 10px 12px; margin-top: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-detail p { margin-top: 5px; }
.result { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; border-radius: 9px; padding: 10px 12px; margin-top: 12px; font-weight: 750; }
.result.right { background: #e0f8ed; color: var(--green); }
.result.wrong { background: #ffedef; color: var(--red); }
.transfer-note { margin-top: 11px; color: #88450d; }
.score-row { min-width: 0; display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 9px; align-items: center; border-bottom: 1px solid #e1edf6; padding: 8px 1px; }
.score-row:last-child { border: none; }
.placing { border-radius: 6px; padding: 5px; min-width: 28px; text-align: center; font-size: .78em; font-variant-numeric: tabular-nums; color: #3b6180; background: #eaf4fc; }
.leader .placing { background: #ffdfa9; color: #773d06; }
.score-name { min-width: 0; overflow-wrap: anywhere; font-size: .93em; }
.score-row strong { font-variant-numeric: tabular-nums; }

body[data-page=team] { background: linear-gradient(#e6f4ff, #f5fbff 550px); }
.team-wrap { width: min(100%, 620px); margin: auto; padding: 18px 14px 38px; display: grid; gap: 12px; }
.team-strip { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: white; background: var(--navy); border-radius: 14px; padding: 14px 15px; box-shadow: 0 10px 26px #163f7326; }
.team-strip > div { min-width: 0; font-weight: 750; overflow-wrap: anywhere; }
.team-strip small { display: block; color: #d4eaff; margin-top: 4px; font-weight: 450; }
.waiting { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 39px 16px; }
.waiting h1 { font-size: 22px; }
.waiting p { color: var(--muted); font-size: .9rem; }
.pulse { width: 13px; height: 13px; border-radius: 50%; background: #38a9dc; box-shadow: 0 0 0 7px #e1f7ff; margin-bottom: 5px; }
.player-question, .mini-rank { padding: 15px; }
.mini-rank h2 { margin-bottom: 7px; }
.player-actions { display: grid; grid-template-columns: 1fr; gap: 9px; margin-top: 13px; }
.player-actions .btn { min-height: 47px; }
.player-actions .buzzer, .player-actions .warning { min-height: 68px; font-size: 1.28rem; }
.player-actions .buzzer { background: #0758ad; box-shadow: 0 5px 0 #043974; }
.player-actions .buzzer:active { transform: translateY(4px); box-shadow: 0 1px 0 #043974; }

body:is([data-page=screen], [data-page=watch]) { min-height: 100vh; background: linear-gradient(153deg, #83d9fb, #dcf5ff 57%, #b2e9fa); }
.stage { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.stage-bar { padding: clamp(9px, 1.2vw, 22px) clamp(12px, 2vw, 32px); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stage-bar .brand img { width: clamp(30px, 3.5vw, 60px); height: clamp(30px, 3.5vw, 60px); }
.stage-bar .brand { font-size: clamp(.9rem, 1.42vw, 1.55rem); }
.stage-bar .brand small { color: #245a84; }
.stage-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 7px; }
.stage-actions .connection { white-space: nowrap; }
.screen-live { min-height: 0; }
.standby { padding: 0 clamp(12px, 2vw, 32px) clamp(12px, 2vw, 32px); height: 100%; display: grid; place-items: center; }
.standby img { width: auto; max-width: 100%; max-height: calc(100vh - 104px); aspect-ratio: 16 / 9; object-fit: contain; background: #69c8f2; border-radius: clamp(10px, 2vw, 26px); box-shadow: 0 14px 44px #154f7433; }
.stage-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(230px, 1fr); gap: clamp(10px, 1.5vw, 24px); padding: 0 clamp(12px, 2vw, 32px) clamp(12px, 2vw, 32px); align-items: start; }
.stage-question, .screen-score { border-radius: clamp(13px, 1.8vw, 25px); padding: clamp(14px, 2vw, 32px); box-shadow: 0 15px 38px #144b7d22; }
.stage-question { background: #fff; min-height: 68vh; }
.stage-active { margin: 12px 0; color: #165591; font-size: clamp(.94rem, 1.5vw, 1.65rem); }
.stage-active .clock-pair { margin: 0; }
.stage-question .q-text { font-size: clamp(24px, 2.7vw, 53px); }
.stage-question .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stage-question .choice { font-size: clamp(.94rem, 1.4vw, 1.55rem); }
.stage-question .q-image { max-height: min(30vh, 360px); }
.stage-question .tag, .stage-question .phase-pill { font-size: clamp(.83rem, 1vw, 1.2rem); }
.stage-question .result { font-size: clamp(1.05rem, 1.7vw, 1.85rem); }
.stage-question .answer-detail { font-size: clamp(.93rem, 1.15vw, 1.3rem); }
.screen-score { color: white; background: var(--navy); }
.screen-score h2 { font-size: clamp(1.1rem, 1.6vw, 1.95rem); margin-bottom: 8px; }
.screen-score .score-row { border-color: #ffffff25; padding: clamp(9px, 1.1vw, 17px) 0; font-size: clamp(.98rem, 1.42vw, 1.55rem); }
.screen-score .score-row strong { color: #ffddaa; }
.screen-score .score-row small { color: #e2efff; font-size: .6em; }
.ranking-screen { width: min(100%, 1320px); padding: 4vh 22px 34px; margin: auto; }
.ranking-screen header { text-align: center; margin-bottom: 21px; }
.ranking-screen h1 { margin-top: 8px; font-size: clamp(30px, 4vw, 68px); }
.ranking-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.ranking-grid .score-row { border: 1px solid #fff; box-shadow: var(--shadow); border-radius: 14px; padding: clamp(10px, 1.5vw, 22px); background: #f9fdff; font-size: clamp(1rem, 1.7vw, 2rem); }
.ranking-grid .leader { background: #fff8ed; }

@media (max-width: 960px) {
    .admin-layout { grid-template-columns: 162px minmax(0,1fr); }
    .sidebar { padding-inline: 11px; }
    .control-grid { grid-template-columns: 1fr; }
    .control-grid > .stack { display: contents; }
    .control-grid > .stack:first-child > :first-child { order: 1; }
    .control-grid:has(.question-top) > .stack:first-child > :first-child { order: -1; }
    .control-grid > .stack:nth-child(2) > :nth-child(2) { order: 2; }
    .control-grid > .stack:nth-child(2) > :last-child { order: 3; }
    .control-grid > .stack:first-child > :last-child { order: 4; }
    .team-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
    .topbar, .landing-head { min-height: 57px; padding-inline: 12px; }
    .brand { font-size: .87rem; line-height: 1.3; }
    .brand img { width: 31px; height: 31px; }
    .landing-head { padding-inline: 15px; }
    .home { padding: 0 12px; }
    .home-hero { border-radius: 14px; }
    .entry-grid { gap: 8px; margin-top: 11px; }
    .entry { border-radius: 11px; }
    .entry div > span { font-size: .72rem; }
    .auth-wrap { padding-top: 18px; }
    .admin-layout { display: block; }
    .sidebar { position: static; padding: 9px 9px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
    .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
    .sidebar a { padding: 7px; font-size: .77rem; }
    .sidebar .btn { font-size: .74rem; min-height: 27px; }
    .admin-main { padding: 13px 9px 28px; gap: 10px; }
    .admin-title .btn { font-size: .82rem; min-height: 35px; }
    .import-panel, .media-line { grid-template-columns: 1fr; }
    .stage-grid { grid-template-columns: 1fr; }
    .stage-question { min-height: auto; }
    .stage-question .choices { grid-template-columns: 1fr; }
    .stage-actions .connection { width: 100%; text-align: right; }
    .stage-actions .btn.small { font-size: .68rem; min-height: 27px; padding: 5px 6px; }
    .stage-bar .brand small { font-size: .67em; }
    .standby { height: auto; margin-top: 6vh; }
    .ranking-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
