:root {
  --bg: #070a0f;
  --bg-soft: #0d131b;
  --card: #121a24;
  --card-2: #16202c;
  --line: #1f2b3a;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #4cc2ff;
  --accent-2: #56e0b0;
  --warn: #ffb457;
  --danger: #ff6b6b;
  --radius: 18px;
  --tab-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding-top: env(safe-area-inset-top);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-decoration: none; }

/* ---------------------------------------------------------------- login */
#login {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px max(24px, env(safe-area-inset-left)) calc(32px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(76, 194, 255, 0.18), transparent 60%),
    radial-gradient(90% 60% at 80% 100%, rgba(86, 224, 176, 0.12), transparent 60%),
    var(--bg);
  z-index: 50;
}

#login .brand { text-align: center; margin-bottom: 34px; }
#login .logo {
  width: 84px; height: 84px; margin: 0 auto 16px;
  border-radius: 26px;
  background: linear-gradient(145deg, #1b3a52, #10222f);
  border: 1px solid rgba(76, 194, 255, 0.35);
  display: grid; place-items: center;
  box-shadow: 0 18px 44px rgba(76, 194, 255, 0.18);
}
#login h1 { font-size: 25px; margin: 0 0 6px; letter-spacing: 0.5px; font-weight: 650; }
#login p { margin: 0; color: var(--muted); font-size: 14px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 7px 4px; }
.field input {
  width: 100%;
  padding: 15px 16px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 17px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.field input:focus { border-color: var(--accent); background: var(--card-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 15px 18px;
  border-radius: 14px;
  background: linear-gradient(180deg, #4cc2ff, #2f9fe0);
  color: #03121c;
  font-weight: 650;
  font-size: 17px;
  transition: transform 0.12s, opacity 0.2s;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); font-weight: 550; }
.btn.danger { background: linear-gradient(180deg, #ff7b7b, #e05252); color: #260607; }

.hint { margin-top: 18px; color: var(--muted); font-size: 12.5px; text-align: center; line-height: 1.6; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 4px 10px; }

/* ---------------------------------------------------------------- shell */
#app { display: none; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px); }
#app.on { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 12px;
  background: rgba(7, 10, 15, 0.86);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid rgba(31, 43, 58, 0.75);
  padding-top: calc(14px + env(safe-area-inset-top));
}
.topbar h2 { margin: 0; font-size: 22px; font-weight: 680; letter-spacing: 0.3px; }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.iconbtn {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
}
.iconbtn:active { background: var(--card-2); }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page { display: none; padding: 16px 16px 8px; }
.page.on { display: block; animation: fade 0.22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card.tight { padding: 13px 14px; }
.card h3 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.stat .k { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat .v { font-size: 22px; font-weight: 680; letter-spacing: 0.2px; }
.stat .u { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 3px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid rgba(31, 43, 58, 0.6); }
.row:last-child { border-bottom: 0; padding-bottom: 0; }
.row:first-child { padding-top: 0; }
.row .l { color: var(--text); font-size: 15.5px; }
.row .r { color: var(--muted); font-size: 14.5px; text-align: right; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.pill.ok { background: rgba(86, 224, 176, 0.14); color: var(--accent-2); }
.pill.warn { background: rgba(255, 180, 87, 0.14); color: var(--warn); }
.pill.bad { background: rgba(255, 107, 107, 0.14); color: var(--danger); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.bar { height: 6px; border-radius: 99px; background: #1b2532; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #4cc2ff, #56e0b0); }

/* ---------------------------------------------------------------- plugin list */
.plugin { display: flex; gap: 13px; padding: 14px 0; border-bottom: 1px solid rgba(31, 43, 58, 0.55); }
.plugin:last-child { border-bottom: 0; padding-bottom: 0; }
.plugin:first-child { padding-top: 0; }
.plugin .avatar {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 13px;
  background: linear-gradient(150deg, #1a2a3a, #101a24);
  border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 17px;
}
.plugin .meta { flex: 1; min-width: 0; }
.plugin .name { font-size: 15.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.plugin .id { color: var(--muted); font-size: 11.5px; margin-top: 2px; word-break: break-all; }
.plugin .desc { color: #b7c4d4; font-size: 13px; margin-top: 5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.plugin .tags { margin-top: 7px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; color: var(--muted); background: #0f1720; border: 1px solid var(--line); padding: 2px 7px; border-radius: 7px; }

/* ---------------------------------------------------------------- logs */
.logbox {
  background: #05080c;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: #c3d0de;
  max-height: 64vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
.logbox .e { color: #ff8f8f; }
.logbox .w { color: #ffc978; }
.logbox .i { color: #8fd6ff; }

.segmented { display: flex; background: #0e151d; border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.segmented button { flex: 1; padding: 9px 6px; border-radius: 9px; font-size: 14px; color: var(--muted); font-weight: 550; }
.segmented button.on { background: var(--card-2); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset; }

/* ---------------------------------------------------------------- memory */
.md {
  white-space: pre-wrap; word-break: break-word;
  font-size: 14.5px; line-height: 1.72; color: #d6e0ec;
}
.memtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.memtable td { padding: 7px 0; border-bottom: 1px solid rgba(31, 43, 58, 0.55); color: #c9d5e3; }
.memtable td:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.memtable tr:last-child td { border-bottom: 0; }

/* ---------------------------------------------------------------- memes */
.memegrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.memegrid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: #0c131a; border: 1px solid var(--line); }

/* ---------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 15, 21, 0.92);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-top: 1px solid rgba(31, 43, 58, 0.9);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 550; }
.tabbar button.on { color: var(--accent); }
.tabbar svg { width: 23px; height: 23px; }

/* ---------------------------------------------------------------- misc */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
  transform: translate(-50%, 12px);
  background: #17222e; color: var(--text);
  border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 14px;
  font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 60; max-width: 86vw; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.skeleton { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
.divider { height: 1px; background: rgba(31, 43, 58, 0.7); margin: 14px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.loghead { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.loghead #logMeta { font-size: 12px; line-height: 1.4; }
.loghead .segmented { margin: 0; width: 168px; }

#lightbox {
  position: fixed; inset: 0; z-index: 80;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  padding: 18px;
}
#lightbox.on { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }
