:root {
  --panel: rgba(15, 29, 52, 0.82);
  --panel-strong: rgba(9, 22, 42, 0.94);
  --line: rgba(125, 211, 252, 0.18);
  --line-strong: rgba(125, 211, 252, 0.32);
  --text: #e5f3ff;
  --muted: #91a8c0;
  --blue: #38bdf8;
  --green: #38d888;
  --red: #fb7185;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Inter", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  background:
    radial-gradient(circle at 8% 8%, rgba(56, 189, 248, .22), transparent 28%),
    radial-gradient(circle at 92% 10%, rgba(99, 102, 241, .24), transparent 25%),
    radial-gradient(circle at 52% 55%, rgba(20, 184, 166, .08), transparent 30%),
    linear-gradient(135deg, #06101f 0%, #0b1526 55%, #07111f 100%);
}

.shell { width: min(1360px, calc(100% - 32px)); margin: 0 auto; padding: 26px 0 44px; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 24px; }
.eyebrow { color: var(--blue); letter-spacing: .22em; text-transform: uppercase; font-size: 11px; margin: 0 0 8px; }
h1 { font-size: clamp(28px, 3vw, 38px); margin: 0 0 9px; letter-spacing: -.04em; }
.sub { color: var(--muted); margin: 0; max-width: 820px; line-height: 1.7; font-size: 14px; }
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.tabs { display: flex; gap: 8px; padding: 6px; border: 1px solid var(--line); border-radius: 16px; background: rgba(2, 8, 23, .28); }
.tab { color: var(--muted); background: transparent; padding: 8px 14px; }
.tab.active { color: #04111f; background: linear-gradient(135deg, #67e8f9, #60a5fa); }
.user-card { display: flex; align-items: center; gap: 10px; color: var(--text); background: rgba(56,189,248,.08); border: 1px solid var(--line); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #22d3ee, #2563eb); color: white; background-size: cover; background-position: center; }

.page { display: none; }
.page.active { display: block; }
.layout { display: grid; grid-template-columns: minmax(420px, 0.95fr) minmax(460px, 1.05fr); gap: 20px; align-items: start; }
.api-page { display: grid; gap: 20px; }
.api-top-grid { display: grid; grid-template-columns: minmax(500px, .9fr) minmax(560px, 1.1fr); gap: 20px; align-items: stretch; }
.api-docs { display: grid; gap: 20px; }
.left-col, .right-col { display: grid; gap: 18px; }

.panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255,255,255,.05);
  padding: 18px;
  backdrop-filter: blur(14px);
}

.api-card, .redeem-card { min-height: 0; padding: 16px; }
.doc-panel { background: rgba(12, 26, 49, .78); }
.toolbar, .actions, .legend { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toolbar label { display: block; font-weight: 700; margin-bottom: 2px; font-size: 14px; }
.toolbar small { color: var(--muted); font-size: 12px; }

textarea {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 16px;
  background: rgba(2, 8, 23, .5);
  color: var(--text);
  padding: 15px;
  line-height: 1.8;
  outline: none;
}

input {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 14px;
  background: rgba(2, 8, 23, .5);
  color: var(--text);
  padding: 11px 13px;
  outline: none;
}

input:focus { border-color: rgba(56, 189, 248, .7); box-shadow: 0 0 0 4px rgba(56,189,248,.08); }

textarea:focus { border-color: rgba(56, 189, 248, .7); box-shadow: 0 0 0 4px rgba(56,189,248,.08); }
.actions { justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }

button {
  border: 0;
  border-radius: 14px;
  padding: 8px 13px;
  color: #04111f;
  background: linear-gradient(135deg, #67e8f9, #60a5fa);
  font-weight: 700;
  cursor: pointer;
  transition: transform .18s ease, filter .18s ease, background .18s ease;
}

button:hover, .link-button:hover { transform: translateY(-1px); filter: brightness(1.05); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost { color: var(--text); background: rgba(148, 163, 184, .12); }
button.small { padding: 8px 12px; border-radius: 10px; font-size: 13px; }
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  padding: 10px 16px;
  color: var(--text);
  background: rgba(148, 163, 184, .12);
  font-weight: 700;
  text-decoration: none;
}
#message { color: var(--muted); }
#redeemMessage { color: var(--muted); }
.hidden { display: none !important; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.api-grid { display: grid; grid-template-columns: .78fr 1.22fr; gap: 12px; }
.score-card { border-radius: 18px; padding: 15px; border: 1px solid rgba(255,255,255,.08); background: rgba(2, 8, 23, .36); }
.score-card span { color: var(--muted); display: block; margin-bottom: 8px; }
.score-card strong { font-size: 28px; }
.score-card.human strong { color: var(--green); }
.score-card.ai strong { color: var(--red); }
.metric-card {
  min-height: 66px;
  border-radius: 16px;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,.08);
  background:
    linear-gradient(180deg, rgba(56, 189, 248, .08), transparent),
    rgba(2, 8, 23, .42);
}
.metric-card span { color: var(--muted); display: block; margin-bottom: 5px; font-size: 12px; }
.metric-card strong { display: block; font-size: clamp(18px, 1.85vw, 24px); line-height: 1.08; word-break: normal; }
.metric-card.balance strong { color: #e8f6ff; }
.metric-card.key strong {
  color: #cfeaff;
  font-size: clamp(17px, 1.45vw, 21px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.summary { margin-top: 16px; color: var(--muted); line-height: 1.7; }

.api-key-box {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 7px 9px;
  border-radius: 12px;
  font-size: 12px;
  background: rgba(2, 8, 23, .45);
  border: 1px solid rgba(255,255,255,.07);
  word-break: break-all;
  color: #bdeaff;
}

.api-key-box span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.redeem-box {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  margin-top: 14px;
  padding: 11px;
  border-radius: 18px;
  background: rgba(2, 8, 23, .34);
  border: 1px solid rgba(255,255,255,.07);
}
.redeem-footer {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

pre { overflow: auto; margin: 8px 0 0; padding: 13px; border-radius: 15px; background: rgba(2, 8, 23, .68); border: 1px solid rgba(255,255,255,.06); color: #bdeaff; }
code { font-family: "Cascadia Mono", "Consolas", monospace; font-size: 12px; line-height: 1.55; }
.code-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 14px; }
.code-title { color: #d8efff; font-weight: 800; margin-bottom: 5px; font-size: 13px; }
.field-table {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.field-table div {
  min-height: 66px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(2, 8, 23, .36);
  border: 1px solid rgba(255,255,255,.07);
}
.field-table b { display: block; color: #c8efff; margin-bottom: 5px; font-size: 13px; }
.field-table span { color: var(--muted); line-height: 1.55; font-size: 12px; }
.compact-actions { margin-top: 9px; }
.report-panel { min-height: 620px; position: sticky; top: 20px; }
.legend { justify-content: flex-start; color: var(--muted); margin: 14px 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 999px; margin-right: 6px; }
.human-dot { background: var(--green); }
.ai-dot { background: var(--red); }
.segments {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}
.empty {
  border: 1px dashed rgba(148, 163, 184, .25);
  color: var(--muted);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
}

.segment {
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.68;
  white-space: pre-wrap;
  border: 1px solid rgba(255,255,255,.08);
  font-size: 13px;
}

.segment .meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  opacity: .9;
}
.segment .meta strong {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.segment .meta span {
  color: var(--muted);
}
.segment-text {
  color: rgba(229, 243, 255, .9);
}
.segment.human { background: rgba(34, 197, 94, .075); border-color: rgba(34, 197, 94, .20); }
.segment.human .meta strong { color: #bbf7d0; background: rgba(34, 197, 94, .15); }
.segment.ai { background: rgba(244, 63, 94, .09); border-color: rgba(244, 63, 94, .24); }
.segment.ai .meta strong { color: #fecdd3; background: rgba(244, 63, 94, .18); }
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 23, .72);
  z-index: 20;
}

.modal-card {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: #0f1d34;
  box-shadow: 0 30px 100px rgba(0,0,0,.45);
}

.modal-card p { color: var(--muted); line-height: 1.8; }
.close { position: absolute; right: 14px; top: 12px; color: var(--text); background: transparent; font-size: 24px; padding: 6px 10px; }
.qr-box { display: grid; place-items: center; min-height: 220px; }
.qr-img {
  display: block;
  width: 220px;
  height: 220px;
  padding: 10px;
  border-radius: 16px;
  background: white;
  object-fit: contain;
  margin: 16px auto;
}

.qr-placeholder {
  display: grid;
  place-items: center;
  width: 220px;
  height: 220px;
  margin: 18px auto;
  border-radius: 16px;
  color: var(--muted);
  background: repeating-linear-gradient(45deg, rgba(255,255,255,.08), rgba(255,255,255,.08) 8px, rgba(255,255,255,.03) 8px, rgba(255,255,255,.03) 16px);
}

@media (max-width: 980px) {
  .topbar { display: block; }
  .top-actions { justify-content: flex-start; margin-top: 18px; }
  .layout, .api-top-grid, .code-grid, .field-table { grid-template-columns: 1fr; }
  .report-panel { position: static; min-height: auto; }
  .redeem-box { grid-template-columns: 1fr; }
}
