:root {
  --bg: #0b1020;
  --panel: #141b30;
  --panel2: #1c2542;
  --border: #2a3557;
  --text: #e6ecff;
  --muted: #8b98c0;
  --accent: #4f8cff;
  --green: #2fd07a;
  --red: #ff5c6c;
  --amber: #ffb84d;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
}
header .title { flex: 1; min-width: 0; }
header h1 { font-size: 16px; margin: 0; font-weight: 600; }
header .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.err { background: var(--red); }
.dot.busy { background: var(--amber); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.lock-state { font-size: 14px; flex: 0 0 auto; }
.wrap { padding: 12px 14px 40px; max-width: 720px; margin: 0 auto; }

.statusbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
  margin-bottom: 12px;
}
.statusbar .txt { flex: 1; min-width: 0; }
.statusbar .name { font-weight: 600; word-break: break-all; }
.statusbar .detail { color: var(--muted); font-size: 12px; word-break: break-all; }

button {
  appearance: none; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 14px;
  cursor: pointer; min-height: 40px;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { background: transparent; border-color: var(--red); color: var(--red); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.small { padding: 6px 10px; min-height: 32px; font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; margin-bottom: 12px;
}
.card h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > button { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; font-size: 14px; font-family: ui-monospace, Menlo, monospace;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.hidden { display: none; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
code { color: var(--accent); }

/* --- menu tabs --- */
.menu-tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.menu-tabs::-webkit-scrollbar { display: none; }
.menu-tab {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 20px;
  background: var(--panel2); border: 1px solid var(--border);
  color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.menu-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* --- sections --- */
.section { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.section-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--panel2); cursor: pointer;
  font-weight: 600; font-size: 14px;
}
.section-head .count { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 400; }
.section-head .sec-title { flex: 1; min-width: 0; }
.section-head .sec-wiki {
  color: var(--accent); text-decoration: none; font-size: 12px;
  padding: 0 6px; border: 1px solid var(--border); border-radius: 6px; line-height: 1.5;
}
.section-head .sec-wiki.empty { display: none; }
.section-head .chev { transition: transform .15s; color: var(--muted); }
.section.collapsed .chev { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-body { padding: 4px 0; }

/* --- param rows --- */
.param {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-top: 1px solid var(--border);
}
.param:first-child { border-top: none; }
.param .meta { flex: 1; min-width: 0; }
.param .pname { font-size: 13px; word-break: break-word; }
.param .pid { font-size: 11px; color: var(--muted); }
.param .control { flex: 0 0 46%; max-width: 46%; }
.param input, .param select { padding: 7px 8px; font-size: 13px; }
.param.dirty { background: rgba(79, 140, 255, 0.08); }
.param.dirty .pname::after { content: " ●"; color: var(--accent); }
.param .units { font-size: 11px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper input { flex: 1; min-width: 0; text-align: center; }
.step-btn { min-height: 0; padding: 4px 8px; font-size: 14px; border-radius: 6px; }
.bitmask { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.bitmask-item { display: flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
.bitmask-item input { width: auto; }

/* --- search results --- */
.search-result { padding: 7px 12px; border-bottom: 1px solid var(--border); }
.search-result .where { font-size: 11px; color: var(--muted); }

/* --- info grid --- */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.info-grid .k { color: var(--muted); font-size: 12px; }
.info-grid .v { font-size: 13px; word-break: break-all; font-family: ui-monospace, Menlo, monospace; }

/* --- log --- */
.log {
  background: #0a0e1a; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; height: 220px; overflow-y: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-all;
}
.log .tx { color: var(--accent); }
.log .rx { color: var(--green); }
.log .sys { color: var(--muted); }
.log .err { color: var(--red); }
.cmdbar { display: flex; gap: 8px; margin-top: 8px; }
.cmdbar input { flex: 1; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 20;
  max-width: 90vw; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}

/* --- icon button --- */
.iconbtn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; min-height: 0; font-size: 16px; border-radius: 8px; cursor: pointer;
}

/* --- drawer --- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 80%; max-width: 320px;
  background: var(--panel); border-right: 1px solid var(--border);
  z-index: 50; transform: translateX(-102%); transition: transform .2s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.drawer input { margin: 10px 12px; width: auto; }
#drawerList { overflow-y: auto; flex: 1; }
.drawer-item {
  padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  font-size: 14px; display: flex; justify-content: space-between; align-items: center;
}
.drawer-item.active { background: var(--panel2); color: var(--accent); font-weight: 600; }
.drawer-item .cnt { font-size: 11px; color: var(--muted); }

/* --- current menu + search --- */
.cur-menu { color: var(--accent); font-weight: 600; text-transform: none; letter-spacing: 0; }
.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbar input { flex: 1; }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- sticky action bar --- */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border); z-index: 30;
}
.action-bar button { flex: 1; }
.action-bar.hidden { display: none; }
body.has-actionbar .wrap { padding-bottom: 90px; }

/* --- modal --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; width: 100%; max-width: 360px;
}
.modal-box h3 { margin: 0 0 8px; font-size: 16px; }

/* --- presets --- */
.preset-list { display: flex; flex-direction: column; gap: 8px; }
.preset-item {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  background: var(--panel2);
}
.preset-info { flex: 1; min-width: 0; }
.preset-info .pname { font-weight: 600; font-size: 14px; }
.preset-info .pid { font-size: 11px; color: var(--muted); }
.preset-extra-row {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--border); padding: 6px 0;
}
.preset-extra-row .pname { flex: 1; min-width: 0; font-size: 12px; word-break: break-word; }
.preset-extra-row input { flex: 0 0 40%; max-width: 40%; padding: 6px 8px; font-size: 13px; }