:root {
  --bg: #0b1220; --card: #131c2e; --line: #23304a; --text: #e6ebf5; --muted: #8b97ad;
  --accent: #3b82f6; --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h2 { margin: .2em 0 .6em; font-size: 1.25rem; }
h3 { margin: 0 0 .7em; font-size: 1rem; display: flex; align-items: center; gap: .6em; justify-content: space-between; }
h4 { margin: 1.4em 0 .5em; font-size: .95rem; color: #c7d2fe; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; }
pre { white-space: pre-wrap; word-break: break-word; background: #0a101c; border: 1px solid var(--line); border-radius: 8px; padding: .7em; font-size: .85rem; margin: .5em 0; }
pre.reply { font-size: .95rem; border-color: var(--ok); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: .7em 1em; background: #0f172acc; backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; letter-spacing: .5px; } .brand span { color: var(--accent); margin-left: 2px; }
.top-right { display: flex; gap: .8em; align-items: center; }
main { max-width: 1050px; margin: 0 auto; padding: 1em 1em 6em; }
.tabs { display: flex; gap: .3em; max-width: 1050px; margin: .6em auto 0; padding: 0 1em; }
.tabs a { flex: 1; text-align: center; padding: .55em; border-radius: 10px; text-decoration: none; color: var(--muted); background: var(--card); border: 1px solid var(--line); }
.tabs a span { margin-left: .4em; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.tab { display: none; } .tab.active { display: block; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1em; margin-bottom: 1em; }
.card.rule.off { opacity: .55; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1em; }
.row { display: flex; gap: .5em; flex-wrap: wrap; align-items: center; margin: .3em 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .5em; }

label { display: block; margin: .45em 0; font-size: .9rem; color: #c3cbdb; }
label.inline { display: inline-flex; align-items: center; gap: .4em; margin: 0; }
label.check { display: flex; gap: .55em; align-items: center; }
input, select, textarea { width: 100%; margin-top: .25em; padding: .6em .7em; border-radius: 8px; border: 1px solid var(--line); background: #0a101c; color: var(--text); font: inherit; }
input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
input.w60 { width: 70px; display: inline-block; }
textarea { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 .8em; padding: .3em .8em .6em; }
legend { padding: 0 .3em; font-weight: 600; }

.btn { display: inline-block; padding: .55em .95em; border-radius: 9px; border: 1px solid var(--line); background: #1b2740; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.btn.danger { color: #fecaca; border-color: #7f1d1d; }
.btn.ok { color: #bbf7d0; border-color: #166534; }
.btn.tiny { padding: .25em .6em; font-size: .8rem; }
.btn.big { padding: .85em 1.4em; font-size: 1.05rem; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.pill { display: inline-block; padding: .15em .6em; border-radius: 999px; font-size: .75rem; font-weight: 700; background: #1e293b; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #14532d; color: #bbf7d0; } .pill.warn { background: #78350f; color: #fde68a; }
.pill.bad { background: #7f1d1d; color: #fecaca; } .pill.muted { background: #1e293b; color: var(--muted); }
.chip { display: inline-block; padding: .2em .6em; margin: .15em; border-radius: 999px; background: #1e293b; font-size: .85rem; }
.chip a { color: var(--muted); text-decoration: none; margin-left: .2em; }
.chips { margin: .4em 0; }
.toggles button { padding: .4em .7em; margin: .15em; border-radius: 8px; border: 1px solid var(--line); background: #0a101c; color: var(--muted); cursor: pointer; text-transform: capitalize; }
.toggles button.on { background: var(--accent); color: white; border-color: var(--accent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: .3em 0 .6em; }
.seg button { flex: 1; padding: .6em .4em; border: 0; background: #0a101c; color: var(--muted); font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: white; font-weight: 600; }
.seg.small button { font-size: .85rem; padding: .5em .3em; }

.switch { display: inline-flex; align-items: center; gap: .4em; margin: 0; cursor: pointer; font-size: .85rem; }
.switch input { display: none; }
.switch span { width: 38px; height: 22px; border-radius: 99px; background: #334155; position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: white; transition: .2s; }
.switch input:checked + span { background: var(--warn); }
.switch input:checked + span::after { left: 19px; }
.switch em { font-style: normal; color: var(--muted); }

.list .item { display: flex; justify-content: space-between; align-items: center; gap: .8em; padding: .6em 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list .item:first-child { border-top: 0; }
.events { max-height: 420px; overflow: auto; }
.ev { border-top: 1px solid var(--line); padding: .35em 0; font-size: .88rem; }
.ev summary { cursor: pointer; list-style: none; }
.ev .ts { color: var(--muted); font-size: .78rem; margin-right: .3em; }
.ev.warn summary { color: #fde68a; } .ev.error summary { color: #fecaca; }
.banner { background: #451a03; border: 1px solid #92400e; color: #fde68a; padding: .6em .9em; border-radius: 10px; margin-bottom: .8em; }

.scroll { overflow-x: auto; }
table.sim { border-collapse: collapse; width: 100%; font-size: .88rem; }
table.sim th, table.sim td { border-bottom: 1px solid var(--line); padding: .45em; text-align: left; vertical-align: top; }
table.sim tr.sel { background: #0f2a1a; }
table.sim td.why { min-width: 240px; }

dialog { width: min(760px, 100vw); max-height: 92vh; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); }
dialog::backdrop { background: #000a; }
dialog form { display: flex; flex-direction: column; max-height: 92vh; }
.dlg-head, .dlg-foot { display: flex; align-items: center; gap: .5em; padding: .8em 1em; border-bottom: 1px solid var(--line); }
.dlg-head { justify-content: space-between; } .dlg-head h3 { margin: 0; }
.dlg-foot { border-top: 1px solid var(--line); border-bottom: 0; }
.dlg-body { overflow-y: auto; padding: .3em 1em 1em; }
ol.rank { padding: 0; list-style: none; counter-reset: r; }
ol.rank li { display: flex; align-items: center; gap: .5em; padding: .35em .5em; border: 1px solid var(--line); border-radius: 8px; margin: .25em 0; background: #0a101c; }
ol.rank li.off { opacity: .45; }

.sticky-save { position: sticky; bottom: 0; padding: .8em 0; background: linear-gradient(transparent, var(--bg) 35%); display: flex; gap: 1em; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); opacity: 0; background: #1e293b; border: 1px solid var(--line); padding: .7em 1.1em; border-radius: 10px; transition: .25s; z-index: 50; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%); } .toast.bad { border-color: var(--bad); }

.login { display: grid; place-items: center; min-height: 100vh; padding: 1em; }
.login .card { width: min(360px, 100%); } .login button { width: 100%; margin-top: .6em; }
.err { color: #fecaca; }
body.tap { display: grid; place-items: center; min-height: 100vh; padding: 1em; }
body.tap .card { width: min(480px, 100%); }
.tap-list { padding-left: 1.1em; } .tap-list li { margin: .5em 0; }

@media (max-width: 700px) {
  .grid2 { grid-template-columns: 1fr; }
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; padding: .4em .4em calc(.4em + env(safe-area-inset-bottom)); background: #0f172aee; border-top: 1px solid var(--line); z-index: 10; }
  .tabs a { display: flex; flex-direction: column; font-size: 1.1rem; padding: .35em; border: 0; background: transparent; }
  .tabs a span { margin: 0; font-size: .7rem; }
  .tabs a.active { background: #1b2740; }
  main { padding-bottom: 7em; }
  .sticky-save { bottom: 64px; }
  .toast { bottom: 110px; }
  .brand { font-size: .95rem; }
  .switch em { display: none; }
}
