:root {
    color-scheme: dark;
    --bg: #08080b;
    --surface: #121219;
    --surface-2: #191923;
    --line: rgba(255, 255, 255, .09);
    --line-hover: rgba(255, 255, 255, .2);
    --text: #f2f1ec;
    --muted: #9d9da5;
    --accent: #00d4ff;
    --accent-hover: #33d7ff;
    --accent-text: #03141a;
    --green: #53c58c;
    --danger: #ff6872;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 84% -8%, rgba(0, 212, 255, .11) 0, transparent 30rem),
        linear-gradient(rgba(255, 255, 255, .018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px),
        var(--bg);
    background-size: auto, 44px 44px, 44px 44px, auto;
    color: var(--text);
}
body::before {
    content: "武";
    position: fixed;
    right: max(-2rem, calc((100vw - 1360px) / 2));
    bottom: -4rem;
    z-index: -1;
    color: rgba(0, 212, 255, .035);
    font-family: serif;
    font-size: clamp(18rem, 38vw, 40rem);
    line-height: .8;
    pointer-events: none;
}
a { color: inherit; }
code, .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.topbar {
    height: 72px;
    padding: 0 max(24px, calc((100vw - 1180px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    background: rgba(8, 8, 11, .78);
    backdrop-filter: blur(16px) saturate(150%);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    text-decoration: none;
}
.brand-mark { width: 24px; height: 24px; object-fit: contain; }
.brand-name {
    color: var(--text);
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: -.035em;
}
.brand-name > span { color: var(--accent); }
.brand-context {
    margin-left: 7px;
    padding-left: 16px;
    border-left: 1px solid var(--line-hover);
    color: var(--muted);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: .63rem;
    font-weight: 600;
    letter-spacing: .14em;
    line-height: 1;
    text-transform: uppercase;
}
nav { display: flex; align-items: center; gap: 22px; }
nav a, .link-button {
    color: var(--muted);
    text-decoration: none;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    background: none;
    border: 0;
    cursor: pointer;
    padding: 0;
}
nav a:hover, .link-button:hover { color: var(--accent); }
nav form { display: inline; }

.container { width: min(1180px, calc(100% - 32px)); margin: 48px auto 80px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
h1 { font-size: clamp(1.55rem, 2.6vw, 2.15rem); line-height: 1.12; letter-spacing: -.04em; margin: 4px 0 12px; text-transform: uppercase; }
h2 { font-size: clamp(1.1rem, 1.7vw, 1.3rem); line-height: 1.2; margin: 3px 0 0; letter-spacing: -.02em; }
.muted { color: var(--muted); max-width: 760px; line-height: 1.55; }
.metrics { display: flex; flex-wrap: wrap; gap: 12px; }
.metric { min-width: 120px; padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.metric strong { display: block; font-size: 1.6rem; }
.metric span { color: var(--muted); font-size: .8rem; }

.card { padding: 28px; background: rgba(22, 22, 30, .97); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 55px rgba(0, 0, 0, .2); margin-bottom: 24px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.card.rule-editor { padding: 0; overflow: hidden; }
.rule-editor-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 28px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background-color .16s ease;
}
.rule-editor-summary::-webkit-details-marker { display: none; }
.rule-editor-summary:hover { background: rgba(255, 255, 255, .035); }
.rule-editor-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rule-editor-summary h2 { margin: 0; }
.rule-editor-summary::after {
    content: "+";
    display: grid;
    place-items: center;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    color: var(--muted);
    border: 1px solid var(--line-hover);
    border-radius: 7px;
    font-size: 1.15rem;
    line-height: 1;
}
.rule-editor[open] > .rule-editor-summary { border-bottom: 1px solid var(--line); }
.rule-editor[open] > .rule-editor-summary::after { content: "−"; }
.rule-editor-body { padding: 24px 28px 28px; }
.notice { background: #153226; color: #9be0ba; border: 1px solid #285a43; padding: 13px 16px; border-radius: 10px; margin-bottom: 20px; }
.notice.error { background: rgba(255, 104, 114, .09); color: #ffb8bd; border-color: rgba(255, 104, 114, .4); }
.group-selector { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.group-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.group-card.selected { border-color: rgba(0, 212, 255, .65); box-shadow: 0 0 0 2px rgba(0, 212, 255, .1); }
.group-card-select { display: grid; gap: 5px; min-width: 0; text-decoration: none; }
.group-card-select:hover .group-card-title { color: var(--accent); }
.group-card-title { font-weight: 800; transition: color .16s ease; }
.group-card-meta { color: var(--muted); font-size: .75rem; }
.inline-editor { margin-top: 20px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.inline-editor[open] > .rule-editor-summary { border-bottom: 1px solid var(--line); }
.inline-editor[open] > .rule-editor-summary::after { content: "−"; }
.login-card { width: min(430px, 100%); margin: 12vh auto 0; }
.stack { display: grid; gap: 18px; margin-top: 24px; }

label { display: grid; gap: 8px; color: #c8d0d5; font-size: .86rem; font-weight: 650; }
[hidden] { display: none !important; }
input, textarea, select {
    width: 100%;
    color: var(--text);
    background: #09090d;
    border: 1px solid var(--line-hover);
    border-radius: 9px;
    padding: 11px 12px;
    font: inherit;
    outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 212, 255, .12); }
textarea { resize: vertical; line-height: 1.45; }
.rule-form { display: grid; grid-template-columns: 1.3fr 1.5fr .5fr; gap: 18px; align-items: end; }
.name-rule-form { grid-template-columns: 1fr 1fr; }
.rule-form .check { align-self: center; display: flex; align-items: center; gap: 9px; }
.check input { width: 17px; height: 17px; }
.wide { grid-column: 1 / -1; }
.field-hint { color: var(--muted); font-size: .78rem; line-height: 1.45; }
.json-editor { font-size: .84rem; tab-size: 2; }
.template-help { color: var(--muted); background: var(--surface-2); padding: 13px 15px; border-radius: 9px; line-height: 1.7; font-size: .83rem; }
.template-help code { color: #7ce8ff; }
.actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

button, .button {
    appearance: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
    padding: 0 16px;
    border-radius: 9px;
    border: 1px solid transparent;
    font: inherit;
    font-size: .85rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition:
        color .16s ease,
        background-color .16s ease,
        border-color .16s ease,
        box-shadow .16s ease,
        transform .08s ease;
}
.primary, .secondary-action {
    min-height: 42px;
    padding: 0 20px;
    border-radius: 0;
    clip-path: polygon(0 0, calc(100% - 11px) 0, 100% 11px, 100% 100%, 0 100%);
    font-weight: 800;
    letter-spacing: .03em;
    cursor: pointer;
}
.primary {
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
}
.primary:hover { background: var(--accent-hover); }
.secondary-action {
    color: #d6dde1;
    background: transparent;
    border-color: var(--line-hover);
    clip-path: none;
}
.secondary-action:hover { color: #fff; border-color: rgba(255, 255, 255, .35); }
.subtle { background: var(--surface-2); border-color: var(--line); color: #d6dde1; }
.subtle:hover {
    color: #fff;
    background: #242431;
    border-color: rgba(255, 255, 255, .25);
    box-shadow: 0 5px 16px rgba(0, 0, 0, .18);
}
.danger { color: var(--danger); background: transparent; border-color: #552d32; }
.danger:hover {
    color: #ff8e96;
    background: rgba(255, 104, 114, .1);
    border-color: rgba(255, 104, 114, .55);
}
button:active, .button:active { transform: translateY(1px); }
.small { min-height: 32px; padding: 0 10px; font-size: .76rem; }
.validation { color: #ff8a92; font-size: .8rem; }
.validation ul { margin: 5px 0; padding-left: 18px; }

.table-card { padding: 0; overflow: hidden; }
.table-card > .section-title { padding: 26px 28px 0; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th { color: var(--muted); font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; text-transform: uppercase; letter-spacing: .1em; font-size: .64rem; text-align: left; background: #0e0e15; }
th, td { padding: 15px 18px; border-top: 1px solid var(--line); vertical-align: middle; }
.right { text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.rule-summary-row { cursor: pointer; transition: background-color .16s ease; }
.rule-summary-row:hover,
.rule-summary-row[aria-expanded="true"] { background: rgba(255, 255, 255, .035); }
.rule-summary-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rule-preview-row > td { padding: 0; background: #0e0e15; }
.rule-template-panel {
    display: grid;
    gap: 14px;
    padding: 18px 22px 22px;
    border-left: 3px solid var(--accent);
}
.rule-template-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.rule-template-heading strong { color: #dce5e9; }
.rule-template-heading span { color: var(--muted); font-size: .75rem; }
.rule-conditions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.rule-conditions > div {
    display: grid;
    gap: 7px;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: rgba(255, 255, 255, .025);
}
.rule-conditions span { color: var(--muted); font-size: .72rem; }
.rule-conditions code {
    color: #c9d5dc;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.json-tree-host {
    max-height: 680px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #111118;
}
.json-tree-host andypf-json-viewer {
    display: block;
    min-width: 620px;
    padding: 10px;
}
.json-preview-error {
    margin: 0;
    padding: 16px;
    color: #d6dde1;
    font: .8rem/1.55 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    white-space: pre-wrap;
}
.order { display: inline-grid; place-items: center; min-width: 32px; height: 28px; background: var(--surface-2); border-radius: 7px; }
.node-name { color: #c9d5dc; overflow-wrap: anywhere; }
.name-replacement { display: grid; gap: 3px; }
.name-replacement > span { color: var(--muted); font-size: .72rem; }
.badge { display: inline-block; padding: 5px 8px; border-radius: 99px; font-size: .72rem; font-weight: 700; }
.badge.on { color: #a3e8c3; background: #183a2a; }
.badge.off { color: #a6b0b7; background: #273039; }
.badge.exclude { color: #ff9ba2; background: rgba(255, 104, 114, .14); }
.disabled-row { opacity: .58; }
.empty { display: grid; gap: 7px; text-align: center; color: var(--muted); padding: 50px 24px; }
.empty strong { color: var(--text); font-size: 1.05rem; }
.user-agent { max-width: 460px; overflow-wrap: anywhere; color: #bdc7cd; }
.nowrap { white-space: nowrap; }

.search-form { display: flex; align-items: end; gap: 10px; }
.search-form label { flex: 1; }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 18px; color: var(--muted); border-top: 1px solid var(--line); font-size: .82rem; }

@media (max-width: 820px) {
    .topbar { padding-inline: 18px; }
    .brand-context { display: none; }
    nav { gap: 14px; }
    .container { margin-top: 28px; }
    .page-heading { align-items: stretch; flex-direction: column; }
    .metrics { width: 100%; }
    .metric { flex: 1; }
    .rule-form { grid-template-columns: 1fr; }
    .wide { grid-column: auto; }
    .row-actions { min-width: 270px; }
    .rule-template-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
    .rule-conditions { grid-template-columns: 1fr; }
    .card { padding: 20px; }
    .card.rule-editor { padding: 0; }
    .rule-editor-summary { padding: 20px; }
    .rule-editor-body { padding: 20px; }
    .table-card { padding: 0; }
    .search-form { align-items: stretch; flex-direction: column; }
}

@media (max-width: 540px) {
    .topbar { height: auto; min-height: 68px; flex-wrap: wrap; gap: 12px; padding-block: 12px; }
    .brand-mark { width: 21px; height: 21px; }
    nav { width: 100%; justify-content: space-between; }
}
