:root {
  --bg: #0b0e14;
  --bg-glow: #131b2b;
  --surface: #131822;
  --surface-2: #1a212e;
  --surface-3: #212a39;
  --line: #242e3d;
  --line-soft: #1c242f;
  --fg: #e8eef6;
  --fg-dim: #96a3b6;
  --fg-mute: #5e6b7e;
  --accent: #7c9fff;
  --accent-dim: #4a6fd6;
  --ok: #3ddc84;
  --warn: #f0b429;
  --err: #ff5c5c;
  --hot: #ff5c5c;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

/* The `hidden` attribute only works through the UA stylesheet, which any author
 * `display` rule outranks — and .gate/.panel/.drawer below all set `display`.
 * Without this, hiding the login gate or a panel silently does nothing.
 * Must stay above every rule that sets display. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body {
  background-image:
    radial-gradient(900px 460px at 12% -8%, var(--bg-glow) 0%, transparent 62%),
    radial-gradient(760px 400px at 100% 0%, #16202f 0%, transparent 55%);
  background-attachment: fixed;
  min-height: 100dvh;
}

h1, h2 { margin: 0; font-weight: 640; letter-spacing: -.01em; }
h1 { font-size: 1.02rem; }
h2 { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-dim); }
p { margin: 0; }
code { font-family: var(--mono); font-size: .84em; color: var(--accent); background: rgba(124,159,255,.1); padding: .08em .34em; border-radius: 4px; }
b { font-weight: 640; }
.muted { color: var(--fg-dim); }
.small { font-size: .8rem; }
.err { color: var(--err); font-size: .82rem; min-height: 1.15em; }
.danger-text { color: var(--err) !important; }
.row { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
button {
  font: inherit; font-size: .85rem; font-weight: 560;
  padding: .48rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface-3); color: var(--fg);
  cursor: pointer; transition: background .15s, border-color .15s, color .15s, transform .06s;
}
button:hover { background: var(--line); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #08101f; border-color: var(--accent); }
button.primary:hover { background: #93b0ff; }
button.danger { background: var(--hot); color: #2b0808; border-color: var(--hot); }
button.danger:hover { background: #ff7676; }
button.ghost { background: transparent; color: var(--fg-dim); border-color: var(--line); }
button.ghost:hover { background: var(--surface-2); color: var(--fg); }
button.tiny { padding: .26rem .58rem; font-size: .76rem; }
button.block { width: 100%; padding: .62rem; }
button.icon {
  background: transparent; border-color: var(--line); color: var(--fg-dim);
  width: 34px; height: 34px; padding: 0; display: grid; place-items: center; font-size: .95rem;
}
button.icon:hover { color: var(--fg); background: var(--surface-2); }
button[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- inputs ---------- */
input, textarea, select {
  font: inherit; width: 100%;
  padding: .55rem .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(0,0,0,.28); color: var(--fg);
  transition: border-color .15s, box-shadow .15s;
}
textarea { font-family: var(--mono); font-size: .78rem; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(124,159,255,.16);
}
input[type=number] { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.gate-card {
  width: min(370px, 100%);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 2rem 1.7rem 1.5rem;
  display: grid; gap: .65rem; text-align: center;
  box-shadow: var(--shadow);
}
.gate-mark {
  font-size: 2rem; width: 62px; height: 62px; margin: 0 auto .3rem;
  display: grid; place-items: center; border-radius: 18px;
  background: linear-gradient(145deg, rgba(124,159,255,.22), rgba(124,159,255,.05));
  border: 1px solid rgba(124,159,255,.25);
}
.gate-card h1 { font-size: 1.3rem; }
.gate-card input { text-align: center; margin-top: .5rem; }
.sign { color: var(--fg-mute); font-size: .74rem; letter-spacing: .08em; margin-top: .2rem; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem clamp(.8rem, 3vw, 1.6rem);
  background: rgba(11,14,20,.82);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1rem; }
.brand-text p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .4rem; flex: none; }
.dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--fg-mute); flex: none;
  box-shadow: 0 0 0 3px rgba(255,255,255,.04);
}
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(61,220,132,.16); animation: pulse 2.4s ease-in-out infinite; }
.dot.stale { background: var(--warn); box-shadow: 0 0 0 3px rgba(240,180,41,.16); }
.dot.down { background: var(--err); box-shadow: 0 0 0 3px rgba(255,92,92,.16); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .4 } }

main {
  padding: clamp(.8rem, 2.5vw, 1.6rem);
  display: grid; gap: .9rem;
  max-width: 1120px; margin: 0 auto;
}

/* ---------- hero ---------- */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 1.05rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  position: relative; overflow: hidden;
}
.hero::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--fg-mute);
  transition: background .3s;
}
.hero.is-open::before { background: var(--ok); }
.hero.is-armed::before { background: var(--hot); }
.hero.is-dry::before { background: var(--warn); }
.hero.is-won::before { background: var(--ok); }
.hero.is-open { box-shadow: inset 0 0 60px rgba(61,220,132,.09); }
.hero.is-armed { box-shadow: inset 0 0 60px rgba(255,92,92,.08); }
.hero-main { min-width: 0; }
.hero-state { font-size: 1.32rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.25; }
.hero-sub { color: var(--fg-dim); font-size: .84rem; margin-top: .15rem; }
.hero-actions { display: flex; gap: .45rem; flex: none; flex-wrap: wrap; }

/* ---------- metrics ---------- */
.metrics { display: grid; gap: .55rem; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); }
.metric {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: .6rem .75rem;
  display: grid; gap: .12rem;
}
.metric .k { font-size: .7rem; color: var(--fg-mute); letter-spacing: .03em; }
.metric .v { font-size: 1rem; font-weight: 620; font-variant-numeric: tabular-nums; }
.metric .v.ok { color: var(--ok); }
.metric .v.warn { color: var(--warn); }
.metric .v.err { color: var(--err); }

/* ---------- panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .95rem 1.1rem 1.1rem;
  display: grid; gap: .8rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; }
.pill {
  font-size: .74rem; padding: .18rem .58rem; border-radius: 999px;
  background: var(--surface-3); color: var(--fg-dim); font-variant-numeric: tabular-nums;
}
.pill.hot { background: rgba(61,220,132,.16); color: var(--ok); }
.empty { color: var(--fg-mute); font-size: .82rem; text-align: center; padding: .6rem 0; }
.legend { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; color: var(--fg-mute); }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.open { background: rgba(61,220,132,.5); }
.sw.full { background: rgba(255,255,255,.07); }
.sw.tgt { background: transparent; box-shadow: inset 0 0 0 1.5px var(--accent); }

/* ---------- target slots ---------- */
.targets { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
.slot {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .6rem .7rem; background: var(--surface-2);
  display: grid; gap: .1rem; position: relative; overflow: hidden;
  transition: border-color .2s, background .2s;
}
.slot .d { font-family: var(--mono); font-size: .74rem; color: var(--fg-mute); }
.slot .t { font-size: 1.12rem; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.slot .s { font-size: .73rem; color: var(--fg-mute); }
.slot.open {
  border-color: rgba(61,220,132,.45);
  background: linear-gradient(150deg, rgba(61,220,132,.14), var(--surface-2));
  animation: breathe 2s ease-in-out infinite;
}
.slot.open .s { color: var(--ok); font-weight: 620; }
.slot.open .t { color: var(--ok); }
@keyframes breathe { 0%,100% { box-shadow: 0 0 0 0 rgba(61,220,132,0) } 50% { box-shadow: 0 0 18px 0 rgba(61,220,132,.18) } }
.slot.past, .slot.stale { opacity: .38; }

/* ---------- matrix ---------- */
.edit-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap;
  padding: .5rem .7rem; border-radius: var(--radius-sm);
  background: rgba(124,159,255,.1); border: 1px solid rgba(124,159,255,.28);
}
.matrix-wrap { overflow-x: auto; margin: 0 -.35rem; padding: 0 .35rem; }
.matrix { border-collapse: separate; border-spacing: 0 2px; font-size: .78rem; width: 100%; min-width: 400px; }
.matrix th { color: var(--fg-mute); font-weight: 500; font-family: var(--mono); font-size: .72rem; padding: 0 .2rem .3rem; text-align: center; }
.matrix td { padding: 0 .12rem; }
.matrix td.date {
  text-align: left; font-family: var(--mono); font-size: .74rem;
  color: var(--fg-dim); white-space: nowrap; padding-right: .5rem; width: 1%;
}
.matrix tr.is-target td.date { color: var(--accent); font-weight: 620; }
.matrix tr.is-past td.date { opacity: .4; }
.matrix .cell {
  display: block; border-radius: 5px; padding: .26rem 0; text-align: center;
  font-family: var(--mono); font-size: .72rem; user-select: none;
  background: rgba(255,255,255,.045); color: var(--fg-mute);
  transition: background .15s, box-shadow .15s, color .15s;
}
.matrix .cell.open { background: rgba(61,220,132,.26); color: #7ff0af; font-weight: 700; }
.matrix .cell.unknown { background: rgba(255,255,255,.02); color: #363f4d; }
.matrix .cell.target { box-shadow: inset 0 0 0 1.5px var(--accent); }
.matrix tr.is-past .cell { opacity: .38; }
.matrix.editing .cell { cursor: pointer; }
.matrix.editing .cell:hover { background: rgba(124,159,255,.24); color: var(--fg); }
.matrix.editing .cell.target { box-shadow: inset 0 0 0 2px var(--accent); background: rgba(124,159,255,.2); color: #cfdcff; }
.matrix.editing tr.is-past .cell { cursor: not-allowed; }

/* ---------- attempts ---------- */
.attempts { border-collapse: collapse; width: 100%; font-size: .78rem; min-width: 520px; }
.attempts th, .attempts td { padding: .38rem .55rem; border-bottom: 1px solid var(--line-soft); text-align: left; white-space: nowrap; }
.attempts th { color: var(--fg-mute); font-weight: 500; font-size: .72rem; }
.attempts td { font-family: var(--mono); font-size: .74rem; color: var(--fg-dim); }
.attempts tr.ok td { color: var(--ok); }

/* ---------- success ---------- */
.success-panel { border-color: rgba(61,220,132,.4); background: linear-gradient(150deg, rgba(61,220,132,.09), var(--surface)); }
.success-body { display: grid; gap: .35rem; }
.success-body .kv { display: flex; justify-content: space-between; gap: 1rem; font-size: .84rem; padding: .3rem 0; border-bottom: 1px solid var(--line-soft); }
.success-body .kv:last-child { border-bottom: none; }
.success-body .kv span:first-child { color: var(--fg-mute); }
.success-body .kv span:last-child { font-family: var(--mono); font-size: .8rem; }

/* ---------- log ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; color: var(--fg-mute); padding: .22rem .62rem; font-size: .74rem; }
.seg button.on { background: var(--surface-3); color: var(--fg); }
.log { max-height: 320px; overflow-y: auto; display: grid; gap: 1px; font-family: var(--mono); font-size: .74rem; align-content: start; }
.log .line { display: grid; grid-template-columns: 58px 60px 1fr; gap: .5rem; padding: .22rem .3rem; border-radius: 4px; }
.log .line:hover { background: rgba(255,255,255,.035); }
.log .ts, .log .kind { color: var(--fg-mute); }
.log .msg { color: var(--fg-dim); word-break: break-word; }
.log .line.warn .msg { color: var(--warn); }
.log .line.error .msg { color: var(--err); }
.log .line.success .msg { color: var(--ok); font-weight: 620; }

.foot { display: flex; justify-content: center; gap: .5rem; padding: 1rem 0 .3rem; color: var(--fg-mute); font-size: .75rem; letter-spacing: .03em; }
.foot .sep { opacity: .45; }

/* ---------- drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(460px, 100%);
  background: var(--surface); border-left: 1px solid var(--line);
  display: grid; grid-template-rows: auto auto 1fr auto;
  box-shadow: -20px 0 50px rgba(0,0,0,.5);
  animation: slidein .22s ease-out;
}
@keyframes slidein { from { transform: translateX(24px); opacity: .4 } to { transform: none; opacity: 1 } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line-soft); }
.drawer-head h2 { font-size: .95rem; text-transform: none; letter-spacing: 0; color: var(--fg); }
.tabs { display: flex; gap: .25rem; padding: .6rem 1.1rem 0; border-bottom: 1px solid var(--line-soft); overflow-x: auto; }
.tabs button {
  background: transparent; border: none; border-radius: 0; color: var(--fg-mute);
  padding: .4rem .55rem .55rem; font-size: .83rem; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.on { color: var(--fg); border-bottom-color: var(--accent); }
.drawer-body { overflow-y: auto; padding: 1.1rem; }
.tabpane { display: none; gap: .85rem; }
.tabpane.on { display: grid; }
.drawer-foot { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .8rem 1.1rem; border-top: 1px solid var(--line-soft); background: var(--surface-2); }

.note { background: rgba(124,159,255,.07); border: 1px solid rgba(124,159,255,.18); border-radius: var(--radius-sm); padding: .7rem .85rem; font-size: .8rem; color: var(--fg-dim); display: grid; gap: .4rem; }
.note ol { margin: 0; padding-left: 1.1rem; display: grid; gap: .22rem; }
.session-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem .85rem; font-size: .84rem; display: grid; gap: .3rem; }
.session-box .kv { display: flex; justify-content: space-between; gap: 1rem; }
.session-box .kv span:first-child { color: var(--fg-mute); font-size: .78rem; }
.session-box .kv span:last-child { font-family: var(--mono); font-size: .78rem; }

.field { display: grid; gap: .3rem; }
.flabel { font-size: .82rem; color: var(--fg-dim); }
.fhint { font-size: .73rem; color: var(--fg-mute); }
.field-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .8rem; }
.suffix { display: flex; align-items: center; gap: .4rem; }
.suffix .unit { color: var(--fg-mute); font-size: .78rem; flex: none; }
.group { display: grid; gap: .8rem; padding-bottom: .3rem; }
.group > .gtitle { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-mute); border-bottom: 1px solid var(--line-soft); padding-bottom: .35rem; }

/* toggle */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; }
.toggle .tt { display: grid; gap: .1rem; }
.switch { width: 42px; height: 24px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line); position: relative; flex: none; transition: background .18s, border-color .18s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--fg-mute); transition: transform .18s, background .18s; }
input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; }
input[type=checkbox]:checked + .switch { background: rgba(124,159,255,.3); border-color: var(--accent-dim); }
input[type=checkbox]:checked + .switch::after { transform: translateX(18px); background: var(--accent); }
input[type=checkbox]:focus-visible + .switch { box-shadow: 0 0 0 3px rgba(124,159,255,.2); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.3rem; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line);
  padding: .6rem 1.1rem; border-radius: 999px; font-size: .84rem;
  box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 2rem); text-align: center;
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translate(-50%, 8px); opacity: 0 } to { transform: translate(-50%, 0); opacity: 1 } }
.toast.err { border-color: var(--err); color: var(--err); }
.toast.ok { border-color: var(--ok); color: var(--ok); }

@media (max-width: 620px) {
  .hero { padding: .9rem 1rem; }
  .hero-state { font-size: 1.14rem; }
  .hero-actions { width: 100%; }
  .hero-actions button { flex: 1; }
  .metrics { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
  .panel { padding: .85rem .9rem 1rem; }
  .drawer { width: 100%; }
  .log .line { grid-template-columns: 52px 1fr; }
  .log .kind { display: none; }
}
