/* LightTail: phone first. 16px inputs (no iOS zoom), 44px+ touch targets, safe-area aware, light and dark. */
:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #0e1525;
  --muted: #5b6478;
  --line: #dde2ee;
  --accent: #ea6a12;
  --accent-ink: #ffffff;
  --accent-soft: #fff1e6;
  --ok: #047857;
  --ok-soft: #e3f5ec;
  --busy: #1d4ed8;
  --busy-soft: #e7eeff;
  --warn: #a15c07;
  --warn-soft: #fff3dc;
  --bad: #c81e1e;
  --bad-soft: #fdeaea;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.05), 0 6px 20px rgb(15 23 42 / 0.06);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1d;
    --surface: #121a2d;
    --surface-2: #1a2440;
    --text: #e8ecf6;
    --muted: #9aa5bf;
    --line: #26314d;
    --accent: #fb8a3c;
    --accent-ink: #1f0e02;
    --accent-soft: #2b1a0e;
    --ok: #34d399;
    --ok-soft: #0f2b23;
    --busy: #7cb0ff;
    --busy-soft: #14233f;
    --warn: #fbbf24;
    --warn-soft: #2b230d;
    --bad: #f87171;
    --bad-soft: #2f1517;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

body.sheet-open { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }

#main {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--safe-t) calc(16px + var(--safe-r)) calc(150px + var(--safe-b)) calc(16px + var(--safe-l));
}

.booting, .fatal { padding: 40vh 0 0; text-align: center; color: var(--muted); }

.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.sm { width: 18px; height: 18px; }

.mono { font-family: var(--mono); font-size: 0.94em; }
.muted { color: var(--muted); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.error-text { color: var(--bad); }
.ok-text { color: var(--ok); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Buttons ------------------------------------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { width: 100%; min-height: 54px; font-size: 17px; border-radius: 14px; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 15px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.4; }
.icon-btn.spin .icon { animation: spin 0.9s linear infinite; }

.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

/* Top bar and banners ------------------------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -16px 8px;
  padding: calc(6px + var(--safe-t)) 8px 6px 16px;
  margin-top: calc(-1 * var(--safe-t));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.logo { width: 32px; height: 32px; border-radius: 8px; }
.top-actions { display: flex; }

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 8px 10px 14px;
  border-radius: 14px;
  font-size: 15px;
}
.banner > .icon { color: currentColor; }
.banner-text { flex: 1; min-width: 0; }
.banner.info { background: var(--busy-soft); color: var(--busy); }
.banner.info .banner-text { color: var(--text); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner .icon-btn { width: 36px; height: 36px; }

/* Node cards ---------------------------------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.nodes { display: grid; gap: 12px; }

.node { transition: box-shadow 0.3s, border-color 0.3s; }
.node.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.node.ok { border-left: 4px solid var(--ok); }
.node.busy { border-left: 4px solid var(--busy); }
.node.warn { border-left: 4px solid var(--warn); }
.node.bad { border-left: 4px solid var(--bad); }
.node.muted { opacity: 0.8; }

.node-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.node-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.node-name { font-weight: 700; font-family: var(--mono); font-size: 16px; overflow-wrap: anywhere; }
.node-meta { margin: 2px 0 8px; color: var(--muted); font-size: 14px; }
.node-note { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.busy { background: var(--busy-soft); color: var(--busy); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.muted { background: var(--surface-2); color: var(--muted); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 6px 0 10px; padding: 0; list-style: none; }
.steps li { display: grid; justify-items: center; gap: 4px; position: relative; color: var(--muted); font-size: 12px; text-align: center; }
.steps li::before { content: ""; position: absolute; top: 5px; left: -50%; right: 50%; height: 2px; background: var(--line); }
.steps li:first-child::before { display: none; }
.steps li.done::before, .steps li.now::before { background: var(--busy); }
.step-dot { position: relative; width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.steps li.done .step-dot { background: var(--busy); }
.steps li.now .step-dot { background: var(--busy); box-shadow: 0 0 0 4px var(--busy-soft); animation: pulse 1.2s ease-in-out infinite; }
.steps li.now { color: var(--text); font-weight: 600; }

.node-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }

.addr {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 6px;
  margin: 0 -8px 0 0;
}
.addr-label { color: var(--muted); font-size: 13px; }
.addr-value { overflow-wrap: anywhere; user-select: all; }
.addr .icon-btn { width: 40px; height: 40px; }

.life { margin: 8px 0 6px; }
.life-text { font-size: 15px; font-weight: 600; }
.life-text .muted { font-weight: 400; }
.bar { height: 6px; margin-top: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.fill { height: 100%; width: 100%; border-radius: 999px; background: var(--ok); transition: width 1s linear; }

.node-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

.history { margin-top: 18px; }
.history summary { min-height: 44px; display: flex; align-items: center; color: var(--muted); font-weight: 600; cursor: pointer; }
.history .node { margin-bottom: 10px; box-shadow: none; }

.empty { padding: 12vh 12px 0; text-align: center; }
.empty-logo { width: 88px; height: 88px; border-radius: 22px; box-shadow: var(--shadow); }
.empty h2 { margin: 18px 0 6px; font-size: 22px; }
.empty p { margin: 0 auto; max-width: 330px; color: var(--muted); }

/* Launch bar ---------------------------------------------------------------------------------------------------- */
.launchbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 10px calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.launchbar-inner { max-width: 560px; margin: 0 auto; display: grid; gap: 6px; }
.summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 36px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sheets -------------------------------------------------------------------------------------------------------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgb(3 7 18 / 0.45); animation: fade 0.2s ease; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--safe-t) - 12px);
  margin: 0 auto;
  max-width: 600px;
  border-radius: 22px 22px 0 0;
  background: var(--bg);
  animation: rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 4px 20px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 20px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }

.field { margin: 14px 0; }
.field-label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.input, .select {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
}
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238892a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.plans { display: grid; gap: 8px; }
.plan {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name price" "spec price";
  align-items: center;
  gap: 0 12px;
  width: 100%;
  min-height: 60px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}
.plan.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.plan:disabled { opacity: 0.45; cursor: default; }
.plan-name { grid-area: name; font-weight: 700; }
.plan-spec { grid-area: spec; color: var(--muted); font-size: 14px; }
.plan-price { grid-area: price; display: grid; justify-items: end; font-weight: 700; font-variant-numeric: tabular-nums; }
.plan-price small { color: var(--muted); font-weight: 500; font-size: 13px; }

.lifetime { display: grid; gap: 10px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.stepper-value { min-width: 64px; text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.toggle-row { display: flex; align-items: center; gap: 12px; margin: 16px 0; cursor: pointer; }
.toggle-text { flex: 1; display: grid; }
.toggle-text .field-label { margin: 0; }
.switch {
  position: relative;
  width: 52px;
  height: 32px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: background 0.2s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skeleton-group { display: grid; gap: 8px; }
.skeleton { height: 50px; border-radius: 12px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }

.settings-section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.settings-section:last-child { border-bottom: 0; }
.settings-section h3 { margin: 0 0 6px; font-size: 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.passkeys { margin: 4px 0 8px; padding: 0; list-style: none; }
.invite { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.invite .input { flex: 1; min-width: 0; }
.users .row { display: flex; gap: 4px; flex: none; }
.users li { padding: 6px 0; }
.users li > .ellipsis small { display: block; white-space: normal; }
.passkeys li { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; border-bottom: 1px solid var(--line); }

/* Sign-in ------------------------------------------------------------------------------------------------------- */
.signin { padding: calc(8vh + var(--safe-t)) 0 40px; text-align: center; }
.signin-logo { width: 76px; height: 76px; border-radius: 20px; box-shadow: var(--shadow); }
.signin h1 { margin: 12px 0 2px; font-size: 28px; letter-spacing: -0.02em; }
.tagline { margin: 0 0 22px; color: var(--muted); }
.signin-card { text-align: left; padding: 18px; }
.signin-card h2 { margin: 0 0 4px; font-size: 20px; }
.form { display: grid; gap: 4px; }
.form .btn.big { margin-top: 10px; }
.signin-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0 16px; margin-top: 4px; }
.note { margin: 8px 0 0; font-size: 15px; }

/* Toast --------------------------------------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(132px + var(--safe-b));
  z-index: 40;
  width: max-content;
  max-width: min(calc(100vw - 32px), 520px);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.25);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) {
  .toast.ok { color: #04140e; }
  .toast.bad { color: #1f0606; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.45; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 640px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 22px; max-height: 86vh; animation: fade 0.2s ease; }
  .sheet-foot { padding-bottom: 14px; }
}
.use-hint { margin: 2px 0 8px; }
