:root {
  --ink: #1f2024;
  --muted: #898b95;
  --quiet: #b6b8c1;
  --canvas: #f6f5f9;
  --card: rgba(255, 255, 255, 0.93);
  --line: #e5e4ea;
  --well: #f1f1f3;
  --blue: #3d82ee;
  --blue-dark: #2468d1;
  --blue-soft: #e9f1ff;
  --green: #278a65;
  --green-soft: #e7f6f0;
  --red: #d94c59;
  --shadow: 0 18px 60px rgba(54, 55, 74, 0.07), 0 1px 2px rgba(30, 31, 42, 0.04);
  --radius: 17px;
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(213, 228, 255, 0.5), transparent 28rem),
    radial-gradient(circle at 82% 78%, rgba(235, 225, 255, 0.38), transparent 27rem),
    var(--canvas);
  overflow-x: hidden;
}

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

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(61, 130, 238, 0.24);
  outline-offset: 2px;
}

.ambient {
  position: fixed;
  width: 260px;
  height: 260px;
  border-radius: 999px;
  filter: blur(75px);
  opacity: 0.35;
  pointer-events: none;
}

.ambient-one { top: -110px; left: -90px; background: #bcd8ff; }
.ambient-two { right: -120px; bottom: -100px; background: #e1d2ff; }

.app-shell {
  position: relative;
  width: min(760px, calc(100% - 36px));
  margin: 0 auto;
  padding: 50px 0 30px;
}

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 0 4px;
}

.lab-mark {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
  color: #7488a7;
  font: 650 10px/1.2 ui-monospace, "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.16em;
}

.lab-mark span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5fa880;
  box-shadow: 0 0 0 4px rgba(95, 168, 128, 0.12);
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 40px);
  line-height: 1.14;
  letter-spacing: -0.035em;
  font-weight: 770;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 4px;
  border-radius: 13px;
  background: #e8e7ec;
}

#rechargeView > .segmented { margin-top: 26px; }

.segment {
  min-height: 40px;
  padding: 8px 16px;
  border: 0;
  border-radius: 10px;
  color: #888992;
  background: transparent;
  font-weight: 620;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.segment:hover { color: #5f6169; }
.segment.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 4px rgba(37, 38, 46, 0.09);
}

.mode-panel { display: none; }
.mode-panel.active { display: block; animation: panel-in 220ms ease both; }

#rechargeMode {
  border: 1px solid rgba(225, 225, 232, 0.72);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

#rechargeMode { margin-top: 28px; padding: 28px 22px 26px; }

.mode-heading h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.mode-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.field { display: block; margin-top: 16px; }
.field-label { display: block; margin: 0 0 8px; color: #73747c; font-size: 13px; }

.field input,
.field textarea {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--ink);
  background: var(--well);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.field input { height: 53px; padding: 0 15px; }
.field textarea { min-height: 118px; padding: 14px 15px; line-height: 1.55; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #b8b9c0; }
.field input:focus, .field textarea:focus { border-color: rgba(61, 130, 238, 0.33); background: #fff; box-shadow: 0 0 0 4px rgba(61, 130, 238, 0.08); outline: 0; }

.primary-button {
  width: 100%;
  min-height: 53px;
  margin-top: 19px;
  border: 0;
  border-radius: 11px;
  color: #fff;
  background: var(--blue);
  font-weight: 650;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}

.primary-button:hover:not(:disabled) { background: var(--blue-dark); transform: translateY(-1px); }
.primary-button:disabled { color: rgba(255,255,255,0.75); background: #a9c7f7; cursor: not-allowed; }
.primary-button.loading { opacity: 0.72; cursor: wait; }

.secondary-button {
  min-height: 45px;
  padding: 0 17px;
  border: 1px solid #d9dfeb;
  border-radius: 10px;
  color: #576a86;
  background: #f8faff;
  font-weight: 610;
  cursor: pointer;
}

.mode-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow { color: var(--blue) !important; font-weight: 650; }
.text-button {
  flex: 0 0 auto;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
}

.text-button { padding: 9px 8px; border: 0; color: #8b8d95; background: transparent; }

.recharge-card {
  padding: 17px;
  border: 1px solid #e8e8ed;
  border-radius: 13px;
  background: #fbfbfc;
}

.recharge-fields { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 11px; }
.recharge-fields .field { margin-top: 13px; }
.recharge-fields input { height: 47px; }

.recharge-result {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 14px;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid rgba(39, 138, 101, 0.18);
  border-radius: 13px;
  background: linear-gradient(135deg, rgba(231, 246, 240, 0.92), rgba(248, 252, 250, 0.96));
}

.result-symbol {
  display: grid;
  width: 38px;
  height: 38px;
  grid-row: 1 / 3;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(39, 138, 101, 0.18);
}

.result-heading p { margin: 0 0 3px; color: var(--green); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; }
.result-heading h3 { margin: 0; font-size: 17px; }
.recharge-result dl { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; margin: 17px 0 0; }
.recharge-result dl div { min-width: 0; padding: 11px 12px; border-radius: 9px; background: rgba(255, 255, 255, 0.68); }
.recharge-result dt { margin-bottom: 4px; color: #7d8c85; font-size: 11px; }
.recharge-result dd { margin: 0; overflow: hidden; color: #29352f; font: 650 12px/1.5 ui-monospace, "SFMono-Regular", Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }

.back-button { margin: 0 0 36px; padding: 0; border: 0; color: var(--blue); background: transparent; font-size: 15px; cursor: pointer; }

footer {
  padding: 29px 0 0;
  color: #b0b1b8;
  text-align: center;
  font: 600 10px/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.12em;
}

/* Relay records */
.records-body {
  background:
    radial-gradient(circle at 8% 6%, rgba(194, 218, 255, 0.62), transparent 31rem),
    radial-gradient(circle at 92% 90%, rgba(222, 211, 255, 0.44), transparent 28rem),
    #f5f5f9;
}

.records-shell {
  position: relative;
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 42px 0 48px;
}

.records-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 31px;
}

.records-header h1 { font-size: clamp(34px, 5vw, 48px); }
.records-header p { max-width: 620px; margin: 10px 0 0; color: var(--muted); line-height: 1.6; }
.records-back { display: inline-block; margin-bottom: 25px; text-decoration: none; }
.logout-button { flex: 0 0 auto; margin-bottom: 4px; }

.login-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(280px, 380px);
  align-items: center;
  gap: 25px;
  min-height: 230px;
  padding: 34px;
  border: 1px solid rgba(222, 225, 234, 0.86);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.91);
  box-shadow: var(--shadow);
}

.login-symbol {
  display: grid;
  width: 68px;
  height: 68px;
  place-items: center;
  border-radius: 18px;
  color: var(--blue);
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px rgba(61, 130, 238, 0.08);
}

.login-symbol svg { width: 32px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.login-copy .eyebrow { margin: 0 0 5px; font-size: 12px; }
.login-copy h2 { margin: 0; font-size: 23px; letter-spacing: -0.02em; }
.login-copy > p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.login-form .field { margin-top: 0; }
.login-form .primary-button { margin-top: 10px; }
.form-error { min-height: 18px; margin: 7px 0 0; color: var(--red); font-size: 12px; }

.record-filters {
  display: grid;
  grid-template-columns: minmax(190px, 1.25fr) minmax(170px, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(222, 225, 234, 0.82);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 36px rgba(52, 57, 73, 0.05);
  backdrop-filter: blur(12px);
}

.record-filters label { display: grid; gap: 7px; color: #777984; font-size: 12px; }
.record-filters input,
.record-filters select {
  width: 100%;
  height: 43px;
  padding: 0 12px;
  border: 1px solid #e0e2e9;
  border-radius: 10px;
  color: #31343c;
  background: #f8f8fa;
}

.filter-button,
.load-more-button {
  height: 43px;
  padding: 0 17px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--blue);
  font-weight: 650;
  cursor: pointer;
}

.refresh-button { height: 43px; }
.ledger-summary { display: flex; flex-wrap: wrap; gap: 9px 22px; margin: 18px 3px 13px; color: #797b85; font-size: 12px; }
.ledger-summary span { display: inline-flex; align-items: center; gap: 6px; }
.ledger-summary strong { color: #2d3038; font-size: 16px; }
.summary-dot { width: 7px; height: 7px; border-radius: 50%; }
.summary-dot.success { background: var(--green); }
.summary-dot.rejected { background: #d99a36; }
.summary-dot.error { background: var(--red); }

.corrupt-warning {
  margin-bottom: 12px;
  padding: 10px 13px;
  border: 1px solid #ead8a9;
  border-radius: 10px;
  color: #7b632b;
  background: #fff8df;
  font-size: 12px;
}

.record-list { display: grid; gap: 11px; }
.record-card {
  overflow: hidden;
  border: 1px solid rgba(222, 225, 233, 0.9);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: 0 9px 34px rgba(52, 56, 71, 0.045);
}

.record-card > summary {
  display: grid;
  align-items: center;
  cursor: pointer;
  list-style: none;
}

.record-card > summary::-webkit-details-marker { display: none; }

.record-card > summary {
  grid-template-columns: auto minmax(210px, 1fr) auto auto;
  gap: 14px;
  min-height: 74px;
  padding: 14px 17px;
}

.record-card[open] > summary { border-bottom: 1px solid #ebecf1; background: #fbfbfd; }
.outcome-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 5px rgba(60, 70, 90, 0.05); }
.outcome-success .outcome-dot { background: var(--green); box-shadow: 0 0 0 5px rgba(39, 138, 101, 0.1); }
.outcome-rejected .outcome-dot { background: #d99a36; box-shadow: 0 0 0 5px rgba(217, 154, 54, 0.11); }
.outcome-error .outcome-dot { background: var(--red); box-shadow: 0 0 0 5px rgba(217, 76, 89, 0.1); }

.record-main { display: grid; min-width: 0; gap: 3px; }
.record-operation { color: var(--blue); font-size: 10px; font-weight: 700; letter-spacing: 0.04em; }
.record-main strong { overflow: hidden; font: 650 13px/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.record-message { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { display: flex; align-items: center; justify-content: flex-end; gap: 14px; color: #8c8e98; font: 500 11px/1.4 ui-monospace, "SFMono-Regular", Menlo, monospace; }
.record-chevron { color: #989aa4; transition: transform 160ms ease; }
.record-card[open] > summary .record-chevron { transform: rotate(180deg); }

.record-detail { padding: 0 19px 21px; }
.detail-loading,
.detail-error { padding: 21px 0 0; color: var(--muted); font-size: 12px; }
.detail-error { color: var(--red); }

.relay-track {
  position: relative;
  display: grid;
  gap: 0;
  margin-top: 4px;
  padding-left: 34px;
}

.relay-track::before {
  content: "";
  position: absolute;
  top: 25px;
  bottom: 25px;
  left: 12px;
  width: 2px;
  background: linear-gradient(180deg, var(--blue), #a8b8d2 50%, var(--green));
}

.track-node { position: relative; padding: 15px 0 7px; }
.track-marker {
  position: absolute;
  top: 24px;
  left: -28px;
  width: 14px;
  height: 14px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 0 2px rgba(61, 130, 238, 0.25);
}

.track-node.upstream .track-marker { background: #8591a7; box-shadow: 0 0 0 2px rgba(91, 107, 133, 0.2); }
.track-node.response .track-marker { background: var(--green); box-shadow: 0 0 0 2px rgba(39, 138, 101, 0.22); }
.track-node-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 8px; }
.track-node-head small { display: block; max-width: 730px; overflow: hidden; color: #8b8d96; font: 500 10px/1.45 ui-monospace, "SFMono-Regular", Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.track-node-head h3 { margin: 2px 0 0; font-size: 14px; }
.copy-button { padding: 6px 9px; border: 1px solid #dce1eb; border-radius: 7px; color: #65728a; background: #f7f9fc; font-size: 10px; cursor: pointer; }
.track-node pre { max-height: 330px; margin: 0; overflow: auto; padding: 13px 14px; border: 1px solid #e5e7ed; border-radius: 10px; color: #323743; background: #f5f6f8; font: 500 11px/1.6 ui-monospace, "SFMono-Regular", Menlo, monospace; white-space: pre-wrap; word-break: break-word; }

.empty-ledger { padding: 70px 20px; text-align: center; }
.empty-ledger h2 { margin: 18px 0 6px; font-size: 20px; }
.empty-ledger p { margin: 0; color: var(--muted); font-size: 13px; }
.empty-pulse { display: block; width: 16px; height: 16px; margin: 0 auto; border-radius: 50%; background: #a8b9d6; box-shadow: 0 0 0 10px rgba(102, 133, 184, 0.08), 0 0 0 22px rgba(102, 133, 184, 0.035); }
.load-more-button { display: block; margin: 18px auto 0; }

.toast-region {
  position: fixed;
  z-index: 10;
  right: 18px;
  bottom: 18px;
  display: grid;
  width: min(340px, calc(100% - 36px));
  gap: 9px;
}

.toast {
  padding: 13px 15px;
  border: 1px solid rgba(51, 57, 74, 0.08);
  border-radius: 11px;
  color: #fff;
  background: #323744;
  box-shadow: 0 13px 40px rgba(25, 28, 36, 0.2);
  font-size: 13px;
  animation: toast-in 200ms ease both;
}

.toast.error { background: #9e3e49; }

@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 640px) {
  .app-shell { width: min(100% - 24px, 760px); padding-top: 28px; }
  .site-header { display: block; }
  #rechargeMode { padding: 21px 16px 20px; }
  .mode-heading { gap: 12px; }
  .recharge-fields { grid-template-columns: 1fr; gap: 0; }
  .recharge-result dl { grid-template-columns: 1fr; }
  .segment { padding-inline: 7px; font-size: 13px; }

  .records-shell { width: min(100% - 24px, 1120px); padding-top: 25px; }
  .records-header { display: grid; gap: 17px; align-items: start; }
  .records-back { margin-bottom: 21px; }
  .logout-button { justify-self: start; }
  .login-card { grid-template-columns: auto 1fr; padding: 23px 18px; }
  .login-form { grid-column: 1 / -1; }
  .record-filters { grid-template-columns: 1fr 1fr; }
  .record-filters label:first-child { grid-column: 1 / -1; }
  .record-card > summary { grid-template-columns: auto minmax(0, 1fr) auto; gap: 11px; }
  .record-meta { grid-column: 2 / -1; justify-content: flex-start; flex-wrap: wrap; gap: 7px 12px; }
  .record-chevron { grid-column: 3; grid-row: 1; }
  .record-detail { padding-inline: 13px; }
  .relay-track { padding-left: 29px; }
  .relay-track::before { left: 9px; }
  .track-marker { left: -26px; }
  .track-node-head { align-items: flex-start; }
  .track-node-head small { white-space: normal; word-break: break-all; }
}

@media (max-width: 430px) {
  h1 { font-size: 29px; }
  .mode-heading { display: grid; }
  .secondary-button { order: 2; }
  .record-filters { grid-template-columns: 1fr; }
  .record-filters label:first-child { grid-column: auto; }
  .login-symbol { width: 54px; height: 54px; }
  .login-copy h2 { font-size: 19px; }
  .track-node-head { display: grid; }
  .copy-button { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
