:root {
    color-scheme: dark;
    --background: #0d1218;
    --panel: #151d27;
    --surface: #1e2936;
    --surface-hover: #283647;
    --border: #2b3949;
    --text: #eaf0f7;
    --muted: #a7b4c4;
    --subtle: #7f8d9f;
    --accent: #5b84f5;
    --accent-hover: #7198ff;
    --focus: #9ab8ff;
    --danger: #f0a5ae;
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html { scrollbar-color: #43566f var(--background); }
body { min-width: 320px; margin: 0; background: var(--background); color: var(--text); }
button, input { font: inherit; }
form { margin: 0; }
button, .button {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 42px; padding: 9px 16px; border: 1px solid var(--accent);
    border-radius: 8px; background: var(--accent); color: #fff;
    font-weight: 650; line-height: 1.3; text-align: center; text-decoration: none;
    white-space: nowrap; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--accent-hover); background: var(--accent-hover); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button:disabled:hover { border-color: var(--accent); background: var(--accent); }
.secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.secondary:hover { border-color: #536981; background: var(--surface-hover); }
.compact { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.danger { border-color: #864049; background: #793741; color: #fff; }
.danger:hover { border-color: #b85461; background: #97414e; }
input {
    width: 100%; min-width: 0; min-height: 42px; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text);
}
input::placeholder { color: var(--subtle); opacity: 1; }
input:hover { border-color: #536981; }
input:focus { border-color: var(--accent); }
input[readonly] { background: #1a2430; color: #c0cad6; }
input[aria-invalid="true"] { border-color: #df7d89; }
.file-control { position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; min-width: 0; padding: 5px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.file-control:hover { border-color: #536981; }
.file-control:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; }
.file-control .file-input { position: absolute; width: 1px; height: 1px; min-height: 1px; padding: 0; border: 0; opacity: 0; overflow: hidden; clip-path: inset(50%); }
.file-trigger { display: inline-flex; align-items: center; min-height: 32px; padding: 5px 12px; border: 1px solid #405168; border-radius: 6px; background: #2b3a4c; color: var(--text); font-size: 12px; font-weight: 650; white-space: nowrap; cursor: pointer; }
.file-trigger:hover { background: #354a61; }
.file-name { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
a { color: #aac4ff; text-underline-offset: 3px; }
a:hover { color: #d1dfff; }

.site-header { position: relative; z-index: 10; border-bottom: 1px solid var(--border); background: #111820; }
.header-inner {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center; gap: 24px; max-width: 1248px; min-height: 74px;
    margin: auto; padding: 0 28px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; font-size: 18px; font-weight: 750; line-height: 1.15; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: .01em; }
.brand-mark { width: 40px; height: 40px; flex: none; object-fit: contain; }
.menu-toggle { display: none; }
.main-nav { display: flex; align-items: center; min-width: 0; gap: 4px; }
.main-nav a { display: inline-flex; align-items: center; min-height: 40px; padding: 7px 14px; border-radius: 8px; color: var(--muted); font-weight: 600; text-decoration: none; white-space: nowrap; }
.main-nav a:hover { background: var(--surface); color: var(--text); }
.main-nav a[aria-current="page"] { background: #223452; color: #d5e3ff; }
.session-actions { grid-column: 3; display: flex; align-items: center; justify-content: end; min-width: 0; gap: 12px; }
.session-name { display: grid; min-width: 0; line-height: 1.2; text-align: right; }
.session-name strong { overflow: hidden; max-width: 180px; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.session-name small { margin-top: 3px; color: var(--subtle); font-size: 11px; white-space: nowrap; }
.language-switch { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: #1a2531; white-space: nowrap; }
.language-switch button { min-height: 30px; padding: 4px 9px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.language-switch button:hover { background: var(--surface-hover); color: var(--text); }
.language-switch button[aria-pressed="true"] { background: #344f80; color: #fff; }
.logout-button { min-height: 36px; }

.page-shell { max-width: 1248px; margin: auto; padding: 30px 28px 64px; }
.guest-shell { max-width: 520px; padding-top: clamp(36px, 9vh, 96px); }
.page-heading { margin-bottom: 22px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 25px; font-weight: 750; line-height: 1.25; letter-spacing: -.025em; }
h2 { margin-bottom: 16px; font-size: 17px; line-height: 1.3; }
h3 { margin-bottom: 10px; font-size: 14px; }
.panel { min-width: 0; padding: 22px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.editor-panel { max-width: 680px; }
.guest-shell .editor-panel { max-width: none; }
.guest-shell .editor > button:last-child { width: 100%; margin-top: 8px; }
.section-intro { margin-bottom: 20px; color: var(--muted); font-size: 13px; }
.setup-intro { margin-bottom: 16px; }
.editor { display: grid; gap: 9px; }
.editor label, .panel > label { color: #cbd6e3; font-size: 13px; font-weight: 600; }
.editor label > input:not([type="checkbox"]) { display: block; margin-top: 7px; }
.panel > label + input { margin-top: 7px; }
.editor .hint { margin: -2px 0 10px; }
.hint { margin-bottom: 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.check { display: flex !important; align-items: center; gap: 10px; margin: 8px 0; color: var(--text) !important; }
.check input { width: 18px; height: 18px; min-height: 18px; margin: 0; accent-color: var(--accent); }
.form-actions, .actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.form-actions { margin-top: 12px; }

.toolbar { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.search-form { flex: 0 1 360px; min-width: 240px; }
.search-form label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.search-controls, .toolbar-actions { display: flex; align-items: center; gap: 8px; }
.search-controls input { flex: 1; }
.toolbar-actions { justify-content: end; flex-wrap: wrap; }
.table-scroll { max-width: 100%; overflow-x: auto; scrollbar-color: #4c6280 var(--panel); }
table { width: 100%; border-collapse: collapse; text-align: left; white-space: nowrap; }
th, td { padding: 13px 14px; border-bottom: 1px solid #2a3645; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
thead th { color: var(--subtle); font-size: 11px; font-weight: 700; letter-spacing: .025em; }
tbody th { font-weight: 650; }
tbody tr:hover { background: #1b2836; }
td:last-child { text-align: right; }
.row-action .button { min-width: 88px; }
.empty-state { padding: 34px 14px; color: var(--muted); text-align: center !important; white-space: normal; }
.status { display: inline-block; padding: 3px 8px; border: 1px solid; border-radius: 6px; font-size: 11px; font-weight: 700; }
.status-active { border-color: #356e5a; background: #19382f; color: #9dd4b9; }
.status-expired { border-color: #78674a; background: #3a3022; color: #e0c99d; }
.status-disabled { border-color: #754750; background: #39242a; color: #efb2b6; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 20px; color: var(--muted); font-size: 12px; }
.pagination .button { min-height: 34px; padding: 5px 11px; font-size: 12px; }

.notice, .error, .credentials { margin-bottom: 20px; padding: 16px 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.notice { border-left: 3px solid var(--accent); }
.error { border-left: 3px solid #d06d7a; color: #f6c2c6; }
.error ul { margin: 0; padding-left: 20px; }
.credentials { border-color: #3c5b92; background: #1a2840; }
.credentials-heading h2 { margin-bottom: 4px; }
.credentials-heading p { margin-bottom: 16px; color: #c0d0e8; font-size: 13px; }
.credentials dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 0; }
.credentials dt { color: #9aafd0; font-size: 11px; }
.credentials dd { margin: 4px 0 0; font-weight: 650; overflow-wrap: anywhere; }
.credentials code { color: #fff; font: 600 14px/1.5 ui-monospace, Consolas, monospace; user-select: all; }
.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.moderators-layout { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
.account-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 300px); gap: 18px; align-items: start; }
.account-editor-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 20px; }
.account-editor-heading h2 { margin: 0; }
.account-delete-button { min-height: 36px; padding: 6px 12px; border-color: #70414a; background: transparent; color: var(--danger); font-size: 12px; }
.account-delete-button:hover { border-color: #a9515e; background: #39242a; color: #ffd5d9; }
.account-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.account-field-column { display: grid; align-content: start; gap: 18px; }
.account-field label { display: block; margin-bottom: 7px; color: #cbd6e3; font-size: 13px; font-weight: 600; }
.account-field .hint { margin: 6px 0 0; }
.account-check { margin: 0; font-size: 13px; font-weight: 600; }
.account-session-hint { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
.account-actions { margin-top: 16px; }
.account-rail { display: grid; gap: 18px; }
.account-rail-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; }
.account-rail-heading h2 { margin: 0; }
.account-device-hint { margin: 12px 0 16px; }
.account-rail .section-intro { margin-bottom: 16px; }
.account-rail .extension-form { align-items: stretch; flex-direction: column; }
.account-rail .extension-form button { width: 100%; }
.extension-form { display: flex; align-items: end; gap: 10px; }
.extension-form label { flex: 1; color: #cbd6e3; font-size: 13px; font-weight: 600; }
.extension-form input { display: block; margin-top: 7px; }
.hwid { font: 12px/1.5 ui-monospace, Consolas, monospace; }
.back-link { margin: 18px 0; }
.build-list { margin-bottom: 18px; }
.build-panel .actions { margin-top: 8px; }
.build-current { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.build-current p { margin-bottom: 10px; overflow-wrap: anywhere; }
.build-current strong { color: var(--text); }
.build-current label { display: block; margin-bottom: 7px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
[hidden] { display: none !important; }

@media (max-width: 1000px) {
    .header-inner { grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; padding-top: 12px; }
    .main-nav { grid-column: 1 / -1; grid-row: 2; min-height: 48px; overflow-x: auto; scrollbar-width: none; }
    .main-nav::-webkit-scrollbar { display: none; }
    .session-actions { grid-column: 2; grid-row: 1; }
    .session-name { display: none; }
}
@media (max-width: 900px) {
    .account-layout { grid-template-columns: minmax(0, 1fr); }
    .account-rail .extension-form { align-items: end; flex-direction: row; }
    .account-rail .extension-form button { width: auto; }
}
@media (max-width: 720px) {
    html, body, .table-scroll, .main-nav { scrollbar-width: none; }
    html::-webkit-scrollbar, body::-webkit-scrollbar, .table-scroll::-webkit-scrollbar, .main-nav::-webkit-scrollbar { display: none; width: 0; height: 0; }
    .header-inner { padding: 10px 16px; }
    .site-header.has-nav .header-inner { grid-template-columns: minmax(0, 1fr) 36px; min-height: 58px; gap: 8px; padding: 9px 12px; }
    .site-header.has-nav .brand { grid-column: 1; grid-row: 1; }
    .site-header.has-nav .brand-mark { width: 30px; height: 30px; }
    .site-header.has-nav .brand small { display: none; }
    .site-header.has-nav .menu-toggle { grid-column: 2; grid-row: 1; display: inline-flex; width: 36px; min-height: 36px; padding: 0; border-color: var(--border); background: var(--surface); color: #c4d6ff; }
    .site-header.has-nav .menu-toggle:hover { border-color: #536981; background: var(--surface-hover); }
    .site-header.has-nav .menu-toggle[aria-expanded="true"] { border-color: #496ca7; background: #223452; }
    .site-header.has-nav .main-nav { grid-column: 1 / -1; grid-row: 2; display: none; flex-direction: column; align-items: stretch; gap: 2px; min-height: 0; max-height: calc(100dvh - 170px); padding: 9px 0 0; border-top: 1px solid var(--border); overflow-y: auto; }
    .site-header.has-nav.is-menu-open .main-nav { display: flex; }
    .site-header.has-nav .main-nav a { width: 100%; min-height: 42px; padding: 9px 12px; }
    .site-header.has-nav .session-actions { grid-column: 1 / -1; grid-row: 3; display: none; }
    .site-header.has-nav.is-menu-open .session-actions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
    .site-header.has-nav.is-menu-open .session-name { display: grid; flex: 1 0 100%; text-align: left; }
    .page-shell { padding: 24px 16px 44px; }
    .guest-shell { padding-top: 40px; }
    .panel { padding: 18px; }
    .toolbar { align-items: stretch; flex-direction: column; }
    .search-form { flex: none; min-width: 0; width: 100%; }
    .toolbar-actions { justify-content: stretch; }
    .toolbar-actions > *, .toolbar-actions form { flex: 1 1 auto; }
    .toolbar-actions button, .toolbar-actions .button { width: 100%; white-space: normal; }
    .two-column, .moderators-layout { grid-template-columns: 1fr; }
    .account-fields { grid-template-columns: 1fr; gap: 18px; }
    .credentials dl { grid-template-columns: 1fr 1fr; }
    .table-scroll { overflow: visible; }
    table, tbody, tr, th, td { display: block; width: 100%; }
    thead { display: none; }
    tbody { display: grid; gap: 10px; }
    tbody tr { padding: 15px; border: 1px solid var(--border); border-radius: 9px; background: #1a2531; }
    tbody tr:hover { background: #1d2a38; }
    tbody th, tbody td { padding: 0; border: 0; text-align: left !important; }
    tbody th { margin-bottom: 9px; font-size: 15px; overflow-wrap: anywhere; }
    tbody th::before { display: block; margin-bottom: 2px; color: var(--subtle); content: attr(data-label); font-size: 11px; font-weight: 500; }
    tbody td:not(.row-action):not(.empty-state) { display: grid; grid-template-columns: minmax(92px, .8fr) minmax(0, 1fr); gap: 8px; align-items: baseline; padding: 5px 0; overflow-wrap: anywhere; }
    tbody td:not(.row-action):not(.empty-state)::before { color: var(--subtle); content: attr(data-label); font-size: 11px; }
    tbody td.row-action { margin-top: 12px; }
    tbody td.row-action .button, tbody td.row-action button { width: 100%; }
    tbody td.empty-state { padding: 16px; }
    .pagination { margin-top: 18px; }
}
@media (max-width: 480px) {
    .header-inner { gap: 5px 8px; padding-right: 12px; padding-left: 12px; }
    .brand { gap: 6px; font-size: 15px; }
    .brand-mark { width: 34px; height: 34px; }
    .brand small { margin-top: 2px; font-size: 10px; }
    .session-actions { gap: 6px; }
    .language-switch { padding: 2px; }
    .language-switch button { min-height: 28px; padding: 3px 6px; font-size: 11px; }
    .logout-button { min-height: 32px; padding: 5px 8px; font-size: 11px; }
    .site-header.has-nav .main-nav a { min-height: 42px; font-size: 13px; }
    .page-shell { padding-right: 12px; padding-left: 12px; }
    .guest-shell { padding-top: 34px; }
    .page-heading { margin-bottom: 16px; }
    h1 { font-size: 22px; }
    .panel { padding: 15px; }
    .credentials { padding: 15px; }
    .credentials dl { grid-template-columns: 1fr; gap: 11px; }
    .search-controls { align-items: stretch; }
    .search-controls button { padding-right: 12px; padding-left: 12px; }
    .toolbar-actions { flex-direction: column; }
    .toolbar-actions > *, .toolbar-actions form { width: 100%; }
    .form-actions > * { flex: 1 1 auto; }
    .extension-form { align-items: stretch; flex-direction: column; }
    .extension-form button { width: 100%; }
    .account-rail .extension-form { align-items: stretch; flex-direction: column; }
    .account-rail .extension-form button { width: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
    button, .button, .main-nav a, .language-switch button, input { transition: background-color .16s ease, border-color .16s ease, color .16s ease; }
}
