:root {
  --bg: #0d0f1a;
  --panel: #161a2b;
  --panel-2: #1e2338;
  --ink: #e7e9f3;
  --muted: #8a90ab;
  --line: #2a3050;
  --accent: #7c5cff;
  --accent-2: #29e0c4;
  --gold: #ffcf5c;
  --danger: #ff6b81;
  --ok: #46d69a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a1f38 0%, var(--bg) 55%);
  color: var(--ink);
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 15, 26, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.55rem; }
.logo { color: var(--accent-2); font-size: 1.4rem; }
.brandname { font-weight: 700; letter-spacing: 0.5px; font-size: 1.15rem; }

.tabs { display: flex; gap: 0.4rem; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  background: var(--panel-2);
  border-color: var(--line);
}

/* ---------- layout ---------- */
main { max-width: 1040px; margin: 0 auto; padding: 1.6rem 1.2rem 4rem; }
.view { display: none; }
.view.active { display: block; }
h2 { margin: 0.2rem 0 0.4rem; }
.tagline { color: var(--muted); max-width: 60ch; margin: 0.2rem 0 1.4rem; }
.muted { color: var(--muted); }

/* ---------- marketplace grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.1rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card.target { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset, 0 8px 30px -12px var(--gold); }

.blob {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  background: #000;
}
.blob svg { display: block; width: 100%; height: 100%; }

.metric-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
  color: var(--accent-2);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.card.target .metric-badge { color: var(--gold); border-color: var(--gold); }

.card-body { padding: 0.8rem 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }
.card-item { font-weight: 700; }
.card-seller { font-size: 0.82rem; color: var(--muted); }
.card-seller b { color: var(--ink); font-weight: 600; }
.card-desc { font-size: 0.82rem; color: var(--muted); flex: 1; }
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 0.5rem; }
.card-price { color: var(--gold); font-weight: 600; font-size: 0.9rem; }

/* ---------- panels / workshop ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  margin-top: 1rem;
}
.workshop-cols { display: grid; grid-template-columns: 1fr 260px; gap: 1rem; }
@media (max-width: 760px) { .workshop-cols { grid-template-columns: 1fr; } }

.field-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.6rem 0 0.3rem;
}
.field-label:first-child { margin-top: 0; }

textarea, select, input[type="text"], input[type="password"], .code {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-family: "JetBrains Mono", ui-monospace, "Consolas", monospace;
  font-size: 0.85rem;
}
select { width: auto; min-width: 120px; }
textarea { resize: vertical; }
input[type="text"], input[type="password"] { font-family: inherit; }
.dialog input[type="text"], .dialog input[type="password"] { margin-bottom: 0.6rem; }
.code { white-space: pre-wrap; word-break: break-all; margin: 0; }
.readonly { color: var(--accent-2); background: #0b1120; }

.row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.7rem; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.secondary { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.redeem-btn { background: var(--accent-2); color: #04231d; }

/* ---------- jwt.io-style debugger ---------- */
:root { --jwt-h: #fb015b; --jwt-p: #d63aff; --jwt-s: #00b9f1; }

.jwt-debugger {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
  margin-top: 1rem;
}
@media (max-width: 820px) { .jwt-debugger { grid-template-columns: 1fr; } }

.jwt-col-head {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.jwt-col-head span {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-left: 0.4rem;
}

/* Encoded box: a highlight <pre> behind a transparent <textarea>, sharing
   identical typography so the colored segments line up under the caret. */
.encoded-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b1020;
  min-height: 168px;
}
.encoded-hl,
.encoded-input {
  margin: 0;
  border: 0;
  padding: 14px;
  width: 100%;
  min-height: 168px;
  box-sizing: border-box;
  font-family: "JetBrains Mono", ui-monospace, "Consolas", monospace;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0.2px;
  white-space: pre-wrap;
  word-break: break-all;
  background: transparent;
}
.encoded-hl { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.encoded-input {
  position: relative;
  z-index: 1;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: #fff;
  resize: vertical;
}
.encoded-input::placeholder { color: var(--muted); -webkit-text-fill-color: var(--muted); }
.j-h { color: var(--jwt-h); }
.j-p { color: var(--jwt-p); }
.j-s { color: var(--jwt-s); }
.j-dot { color: #6b7194; }

.validity {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 1.2em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.validity.ok { color: var(--ok); }
.validity.bad { color: var(--danger); }
.validity.neutral { color: var(--jwt-s); }
.validity::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.validity:empty { display: none; }

/* Decoded boxes */
.dec-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.9rem;
}
.dec-box.j-header { border-left-color: var(--jwt-h); }
.dec-box.j-payload { border-left-color: var(--jwt-p); }
.dec-box.j-verify { border-left-color: var(--jwt-s); }
.dec-label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}
.j-header .dec-label { color: var(--jwt-h); }
.j-payload .dec-label { color: var(--jwt-p); }
.j-verify .dec-label { color: var(--jwt-s); }
.dec-label span { color: var(--muted); font-weight: 600; }
.dec-edit {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  background: #0b1020;
}
.dec-edit.invalid { border-color: var(--danger); }

/* Verify Signature body */
.verify-formula {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.verify-formula .fn { color: var(--jwt-s); }
.verify-formula .arg-h { color: var(--jwt-h); }
.verify-formula .arg-p { color: var(--jwt-p); }
.verify-secret {
  display: inline-block;
  min-width: 180px;
  margin: 0.15rem 0;
  padding: 0.25rem 0.5rem;
  font-family: inherit;
}
.verify-note { color: var(--muted); font-size: 0.88rem; }
.verify-note b { color: var(--jwt-s); }
.secret-b64 { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.5rem; font-size: 0.82rem; color: var(--muted); }
.secret-b64 input { width: auto; }

/* Fingerprint box under the encoded token */
.fingerprint-box {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  background: var(--panel);
}
.fp-head {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.fp-row { display: flex; align-items: center; gap: 0.9rem; }
.fingerprint-box .blob { width: 116px; flex: 0 0 116px; border-radius: 10px; border: 1px solid var(--line); }
.metric-line { color: var(--muted); font-size: 0.85rem; line-height: 1.4; }
.metric-big { font-size: 1.7rem; font-weight: 800; color: var(--accent-2); }

/* result text */
.result { margin: 0.7rem 0 0; font-size: 0.9rem; min-height: 1.2em; word-break: break-word; }
.result.ok { color: var(--ok); }
.result.err { color: var(--danger); }
.result .flag {
  display: inline-block;
  background: #04231d;
  border: 1px dashed var(--ok);
  color: var(--ok);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  margin-top: 0.3rem;
}

/* ---------- redeem dialog ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 12, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.overlay.hidden { display: none; }
.dialog {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.4rem;
  width: min(520px, 100%);
}
.dialog h3 { margin: 0 0 0.3rem; }
.dialog textarea { margin-top: 0.8rem; }
.close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  padding: 0.1rem 0.4rem;
}

/* ---------- generic utility ---------- */
.hidden { display: none !important; }

/* ---------- topbar auth controls ---------- */
.auth-box { display: flex; align-items: center; }
.auth-box > div { display: flex; align-items: center; gap: 0.6rem; }
#auth-username { font-size: 0.85rem; }

/* ---------- marketplace landing (logged-out) ---------- */
#market-landing {
  max-width: 60ch;
  margin: 2.5rem auto;
  text-align: center;
}
#market-landing h2 { font-size: 1.6rem; }
#market-landing .tagline { margin-left: auto; margin-right: auto; }
#market-landing .row { justify-content: center; }

/* ---------- login / register panels ---------- */
.auth-panel { max-width: 380px; margin: 2rem auto 0; }
.auth-panel h2 { margin-top: 0; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0;
  margin-top: 0.9rem;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
#forgot-box { margin-top: 0.6rem; }

/* ---------- workshop auth hint ---------- */
.needs-auth-hint { margin: 0.7rem 0 0; font-size: 0.82rem; }

/* ---------- account ("Мои токены") ---------- */
#account-content .panel { max-width: 560px; }
#account-content .code { margin-bottom: 0.9rem; }
.listing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.listing-row:last-child { border-bottom: none; }

/* ---------- topbar balance ---------- */
#auth-balance { color: var(--gold); font-weight: 600; font-size: 0.85rem; }
