:root {
  --bg: #07080d;
  --panel: #10121b;
  --panel2: #171a26;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9ecf5;
  --dim: #8a90a2;
  --accent: #3ef0ff;
  --violet: #8b5cff;
  --pink: #ff4fd8;
  --green: #3dffa2;
  --amber: #ffb547;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

.ico {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.ico.big { width: 44px; height: 44px; stroke-width: 1.6; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------- header -- */

.bar {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 4px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.02em; }
.brand .ico { color: var(--accent); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 14px;
  font-weight: 600;
}
.chip .ico { width: 16px; height: 16px; color: var(--accent); }
.chip.slow .ico { color: var(--amber); }

/* -------------------------------------------------------------- stage -- */

.stage {
  position: relative;
  height: min(48vh, 100vw, 440px);
  min-height: 260px;
}
.stage #orb { position: absolute; inset: 0; width: 100%; height: 100%; }
.center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  text-align: center;
  width: 56%;
}
.center .ico.big { color: var(--accent); opacity: 0.9; }
.center .ico.big.off { color: var(--dim); }
.center .ico.big.ok { color: var(--green); }
.center .ico.big.bad { color: var(--pink); }
.pct {
  font-size: clamp(34px, 12vw, 60px);
  font-weight: 750;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.pct:empty { display: none; }
.sub { color: var(--dim); font-size: 14px; font-variant-numeric: tabular-nums; min-height: 1.4em; }

body:not(.busy) .stage-meta,
body:not(.busy) .stage-close { display: none; }

body.busy { overflow: hidden; }
body.busy .stage {
  position: fixed;
  inset: 0;
  height: auto;
  max-height: none;
  z-index: 40;
  background: radial-gradient(120% 70% at 50% 35%, #121528 0%, var(--bg) 65%);
  animation: fade 0.25s ease;
}
body.busy .stage #orb { height: calc(100% - 150px - env(safe-area-inset-bottom)); }
body.busy .center { top: calc((100% - 150px - env(safe-area-inset-bottom)) / 2); }
body.busy .stage-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
}
body.busy .stage-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
}
.what {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 24px;
  margin-bottom: 12px;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.what .ico { color: var(--accent); width: 18px; height: 18px; }
.waterfall {
  display: block;
  width: 100%;
  height: 92px;
  border-radius: 14px;
  background: #07080d;
  border: 1px solid var(--line);
}

/* ------------------------------------------------------------ actions -- */

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 4px 16px 0;
}
.actions button {
  flex: 0 0 calc((100% - 20px) / 3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 92px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.08s ease, border-color 0.2s;
}
.actions button[hidden] { display: none; }
.actions button .ico { width: 26px; height: 26px; color: var(--accent); }
.actions button:active { transform: scale(0.96); border-color: var(--accent); }

/* -------------------------------------------------------------- inbox -- */

.inbox { padding: 22px 16px 0; display: grid; gap: 8px; }
.inbox:empty { display: none; }
.inbox h3 { margin: 0 0 2px; font-size: 13px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  text-align: left;
}
.item .ico { color: var(--accent); }
.item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }

.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 26px 16px 0;
  color: var(--dim);
  font-size: 12px;
}
.foot .ico { width: 14px; height: 14px; }
.repo {
  display: flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  margin: 12px auto 0;
  padding: 5px 12px 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--dim);
  font-size: 12px;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.repo .ico { width: 14px; height: 14px; }
.thanks { margin: 10px 0 0; text-align: center; color: var(--dim); font-size: 11px; opacity: 0.8; }
.thanks a { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.thanks a:hover { color: var(--accent); }
.repo:hover, .repo:active { color: var(--accent); border-color: var(--accent); }

/* -------------------------------------------------------------- sheet -- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: rgba(3, 4, 8, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 0.2s ease;
}
.sheet[hidden] { display: none; }
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  max-height: 90vh;
  overflow: auto;
  background: #10121b;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: up 0.25s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet h2 { margin: 2px 44px 14px 2px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet h2 .ico { color: var(--accent); }
.sheet-x { position: absolute; top: 12px; right: 12px; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel2);
  display: grid;
  place-items: center;
}

.sheet label { display: block; margin: 0 0 10px; }
.sheet label span { display: block; font-size: 12px; color: var(--dim); margin: 0 0 4px 2px; }
.sheet input, .sheet textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #090a10;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
}
.sheet input:focus, .sheet textarea:focus { border-color: var(--accent); }
.sheet textarea { resize: vertical; min-height: 120px; }

.meta { color: var(--dim); font-size: 13px; margin: 10px 2px; font-variant-numeric: tabular-nums; min-height: 1.4em; }
.meta.warn { color: var(--amber); }

.primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 15px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--accent), var(--violet));
  color: #05060a;
  font-weight: 750;
  font-size: 17px;
}
.primary:disabled { opacity: 0.4; }
.primary .ico { width: 20px; height: 20px; }

.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btns button {
  flex: 1 1 0;
  min-width: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel2);
  font-weight: 600;
  font-size: 15px;
}
.btns button .ico { width: 18px; height: 18px; color: var(--accent); }
.btns button.main { background: linear-gradient(90deg, var(--accent), var(--violet)); color: #05060a; border: 0; }
.btns button.main .ico { color: #05060a; }

.textbox {
  padding: 14px;
  border-radius: 14px;
  background: #090a10;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 46vh;
  overflow: auto;
  user-select: text;
  -webkit-user-select: text;
}
.textbox a { color: var(--accent); }

.card {
  padding: 16px;
  border-radius: 16px;
  background: linear-gradient(160deg, #161a2b, #0d0f17);
  border: 1px solid var(--line);
}
.card .name { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.card .line { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 4px 0; overflow-wrap: anywhere; }
.card .line .ico { width: 16px; height: 16px; color: var(--dim); }
.card .secret { font: 600 22px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.02em; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }
.card .label { font-size: 12px; color: var(--dim); margin-top: 10px; }

.preview { display: flex; gap: 14px; align-items: center; }
.preview img { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; background: #090a10; }
.preview .fi { width: 84px; height: 84px; border-radius: 12px; display: grid; place-items: center; background: #090a10; border: 1px solid var(--line); }
.preview .fi .ico { width: 34px; height: 34px; color: var(--accent); }
.preview .nm { font-weight: 600; overflow-wrap: anywhere; }
.preview .sz { color: var(--dim); font-size: 14px; }
.full-img { display: block; width: 100%; max-height: 50vh; object-fit: contain; border-radius: 14px; background: #090a10; }

.seg { display: flex; gap: 6px; margin-top: 14px; padding: 4px; border-radius: 14px; background: #090a10; border: 1px solid var(--line); }
.seg button { flex: 1; padding: 10px 6px; border: 0; border-radius: 10px; background: transparent; color: var(--dim); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

/* -------------------------------------------------------------- toast -- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  padding: 10px 16px;
  border-radius: 999px;
  background: #1b1f2e;
  border: 1px solid var(--line);
  font-size: 14px;
  white-space: nowrap;
  animation: up 0.2s ease;
}
.toast[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.toast { animation-name: toast-up; }
@keyframes toast-up { from { transform: translate(-50%, 20px); opacity: 0; } }

@media (min-width: 700px) {
  .stage { height: 440px; }
}
