:root {
  color-scheme: dark;
  --bg: #0b0f17;
  --panel: #111824;
  --panel-raised: #151e2c;
  --field: #090d14;
  --line: #273244;
  --line-strong: #3b4b62;
  --text: #f1f5f9;
  --muted: #7e8da3;
  --muted-strong: #a9b6c8;
  --cyan: #70e2de;
  --cyan-soft: rgba(112, 226, 222, 0.12);
  --violet: #a997ff;
  --violet-soft: rgba(169, 151, 255, 0.12);
  --orange: #ff9c6e;
  --orange-soft: rgba(255, 156, 110, 0.12);
  --green: #6ee7a8;
  --red: #ff6d76;
  --yellow: #f4c95d;
  --shadow: rgba(0, 0, 0, 0.24);
}

body.light {
  color-scheme: light;
  --bg: #edf1f4;
  --panel: #f9fbfc;
  --panel-raised: #ffffff;
  --field: #f3f6f8;
  --line: #ccd5df;
  --line-strong: #98a8ba;
  --text: #17202b;
  --muted: #69798b;
  --muted-strong: #4d5c6c;
  --cyan: #087d7b;
  --cyan-soft: rgba(8, 125, 123, 0.1);
  --violet: #6751d6;
  --violet-soft: rgba(103, 81, 214, 0.1);
  --orange: #c65327;
  --orange-soft: rgba(198, 83, 39, 0.1);
  --green: #138352;
  --red: #c73d48;
  --yellow: #a16a00;
  --shadow: rgba(35, 51, 69, 0.09);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 9% -12%, rgba(112, 226, 222, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  transition: background-color 0.2s, color 0.2s;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }

.app { width: min(1220px, calc(100% - 48px)); margin: 0 auto; }

.topbar {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.17em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  font: 600 12px "IBM Plex Mono", monospace;
}

.brand-mark i { color: var(--cyan); font-style: normal; }
.brand-mark b { color: var(--orange); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 20px; }

.local-status {
  color: var(--muted);
  font: 500 10px "IBM Plex Mono", monospace;
  letter-spacing: 0.12em;
}

.local-status i {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 9px var(--green);
}

.square-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: transparent;
}

.square-button:hover { border-color: var(--line-strong); background: var(--panel); }
.square-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.intro {
  min-height: 174px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 48px;
  padding: 40px 0 31px;
}

.eyebrow, .card-label, .section-head > label {
  margin: 0;
  color: var(--muted);
  font: 500 9px "IBM Plex Mono", monospace;
  letter-spacing: 0.15em;
}

.intro h1 {
  max-width: 730px;
  margin: 8px 0 0;
  font-size: clamp(33px, 4.4vw, 58px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.045em;
}

.intro > p {
  width: min(360px, 36%);
  margin: 0 0 3px;
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.65;
}

.token-input-card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 50px var(--shadow);
}

.section-head {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.text-actions { display: flex; align-items: center; gap: 9px; color: var(--line-strong); }

.text-actions button {
  padding: 5px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 9px "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
}

.text-actions button:hover { color: var(--text); }

#tokenInput {
  width: 100%;
  min-height: 134px;
  display: block;
  resize: vertical;
  padding: 21px 20px;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  background: var(--field);
  color: var(--text);
  font: 13px/1.7 "IBM Plex Mono", monospace;
  overflow-wrap: anywhere;
}

#tokenInput:focus { box-shadow: inset 3px 0 0 var(--cyan); }
#tokenInput::placeholder { color: var(--muted); }

.input-footer {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px;
  padding-left: 19px;
}

.input-footer > span {
  color: var(--muted);
  font: 400 9px "IBM Plex Mono", monospace;
  letter-spacing: 0.04em;
}

.primary-button {
  width: 202px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 17px;
  border: 0;
  background: var(--cyan);
  color: #061414;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
}

.primary-button b { font-size: 18px; font-weight: 500; }
.primary-button:hover { filter: brightness(1.08); }

.segment-strip {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.segment {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  padding: 15px 17px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.segment:last-child { border-right: 0; }
.segment:hover { background: var(--panel-raised); }

.segment span, .segment strong {
  font: 500 9px "IBM Plex Mono", monospace;
  letter-spacing: 0.09em;
}

.segment strong { color: var(--muted); }
.segment small {
  grid-column: 1 / -1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font: 400 10px "IBM Plex Mono", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-segment span, .header-ink { color: var(--cyan); }
.payload-segment span, .payload-ink { color: var(--violet); }
.signature-segment span { color: var(--orange); }

.notice {
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 16px 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.notice-icon {
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: var(--muted);
  font: 600 11px "IBM Plex Mono", monospace;
}

.notice strong { display: block; font-size: 11px; font-weight: 600; }
.notice p { margin: 3px 0 0; color: var(--muted); font: 400 9px "IBM Plex Mono", monospace; }
.notice.is-success { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.notice.is-success .notice-icon { color: var(--green); }
.notice.is-warning { border-color: color-mix(in srgb, var(--yellow) 45%, var(--line)); }
.notice.is-warning .notice-icon { color: var(--yellow); }
.notice.is-error { border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }
.notice.is-error .notice-icon { color: var(--red); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.75fr);
  gap: 16px;
}

.decoded-column, .details-column { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.code-panel, .status-card, .claims-card, .signature-card {
  border: 1px solid var(--line);
  background: var(--panel);
}

.panel-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 17px;
  border-bottom: 1px solid var(--line);
}

.panel-head > div { display: flex; align-items: center; gap: 14px; }
.panel-index { font: 600 11px "IBM Plex Mono", monospace; }
.panel-head p { margin: 0 0 5px; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.11em; }
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 500; }
.panel-actions { display: flex; align-items: center; gap: 7px; }

.copy-button, .edit-button {
  flex: 0 0 auto;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: 500 8px "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
}

.copy-button:hover, .edit-button:not(:disabled):hover { border-color: var(--line-strong); color: var(--text); }
.edit-button.is-active { border-color: var(--orange); background: var(--orange-soft); color: var(--orange); }
.edit-button:disabled { cursor: not-allowed; opacity: 0.4; }

pre {
  min-height: 181px;
  max-height: 440px;
  margin: 0;
  padding: 22px;
  overflow: auto;
  outline: 0;
  background: var(--field);
  color: var(--muted-strong);
  font: 12px/1.75 "IBM Plex Mono", monospace;
  tab-size: 2;
}

pre:focus { box-shadow: inset 3px 0 0 var(--line-strong); }
.json-editor {
  display: block;
  width: 100%;
  min-height: 225px;
  max-height: 520px;
  margin: 0;
  padding: 22px;
  resize: vertical;
  border: 0;
  outline: 0;
  background: var(--field);
  color: var(--text);
  font: 12px/1.75 "IBM Plex Mono", monospace;
  tab-size: 2;
}
.json-editor[hidden] { display: none; }
.json-editor:focus { box-shadow: inset 3px 0 0 var(--orange); }
.json-editor[aria-invalid="true"] { box-shadow: inset 3px 0 0 var(--red); }
.code-key { color: var(--cyan); }
#payloadJson .code-key { color: var(--violet); }
.code-string { color: var(--text); }
.code-number { color: var(--orange); }
.code-boolean { color: var(--yellow); }
.code-null { color: var(--muted); font-style: italic; }

.status-card, .claims-card, .signature-card { padding: 18px; }
.card-label { padding-bottom: 15px; border-bottom: 1px solid var(--line); }

.status-main { display: flex; align-items: center; gap: 13px; padding: 20px 0 18px; }
.status-orb { width: 12px; height: 12px; flex: 0 0 auto; border-radius: 50%; background: var(--muted); }
.status-orb.is-active { background: var(--green); box-shadow: 0 0 13px rgba(110, 231, 168, 0.48); }
.status-orb.is-warning { background: var(--yellow); box-shadow: 0 0 13px rgba(244, 201, 93, 0.4); }
.status-orb.is-error { background: var(--red); box-shadow: 0 0 13px rgba(255, 109, 118, 0.4); }
.status-main h2 { margin: 0; font-size: 17px; font-weight: 600; }
.status-main p { margin: 4px 0 0; color: var(--muted); font: 400 9px "IBM Plex Mono", monospace; }

.time-track { height: 3px; overflow: hidden; background: var(--line); }
.time-track i { width: 0; height: 100%; display: block; background: var(--green); transition: width 0.35s; }
.time-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 9px; color: var(--muted); font: 400 8px "IBM Plex Mono", monospace; }

.claims-card dl { margin: 0; }
.claims-card dl > div {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.claims-card dl > div:last-child { border-bottom: 0; padding-bottom: 0; }
.claims-card dt { color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.07em; }
.claims-card dd { min-width: 0; margin: 0; overflow-wrap: anywhere; color: var(--muted-strong); font: 500 9px/1.45 "IBM Plex Mono", monospace; text-align: right; }

.card-help { margin: 15px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.signature-card label { display: block; margin-bottom: 7px; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.secret-field { min-height: 104px; display: flex; align-items: stretch; border: 1px solid var(--line); background: var(--field); }
.secret-field:focus-within { border-color: var(--line-strong); }
.secret-field textarea {
  min-width: 0;
  flex: 1;
  min-height: 102px;
  padding: 11px 12px;
  resize: vertical;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: 10px/1.55 "IBM Plex Mono", monospace;
  overflow-wrap: anywhere;
}
.secret-field textarea.is-concealed { -webkit-text-security: disc; }
.secret-field button { width: 42px; flex: 0 0 42px; display: grid; place-items: start center; padding-top: 13px; border: 0; background: transparent; color: var(--muted); }
.secret-field button:hover { color: var(--text); }
.secret-field svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; }

.verify-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 8px; }
.verify-row select, .sign-button, .verify-button { height: 39px; border: 1px solid var(--line); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.07em; }
.verify-row select { padding: 0 9px; outline: 0; background: var(--field); color: var(--muted-strong); }
.signature-actions { display: grid; grid-template-columns: 72px 72px; gap: 6px; }
.sign-button { background: transparent; border-color: var(--orange); color: var(--orange); font-weight: 600; }
.sign-button:hover { background: var(--orange-soft); }
.verify-button { background: var(--orange); border-color: var(--orange); color: #241006; font-weight: 600; }
.verify-button:hover { filter: brightness(1.07); }

.verification-result { display: flex; align-items: center; gap: 8px; margin-top: 13px; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.verification-result i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.verification-result.is-valid { color: var(--green); }
.verification-result.is-valid i { background: var(--green); box-shadow: 0 0 8px var(--green); }
.verification-result.is-invalid { color: var(--red); }
.verification-result.is-invalid i { background: var(--red); }
.verification-result.is-warning { color: var(--yellow); }
.verification-result.is-warning i { background: var(--yellow); }

.export-button {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted-strong);
  font: 500 9px "IBM Plex Mono", monospace;
  letter-spacing: 0.06em;
}
.export-button:not(:disabled):hover { border-color: var(--line-strong); background: var(--panel); color: var(--text); }
.export-button:disabled { cursor: not-allowed; opacity: 0.45; }
.export-button svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; }

footer {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: var(--muted);
  font: 400 8px "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  padding: 10px 14px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  font: 500 9px "IBM Plex Mono", monospace;
  transition: 0.2s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 860px) {
  .intro { align-items: flex-start; flex-direction: column; gap: 18px; }
  .intro > p { width: min(100%, 560px); }
  .workspace { grid-template-columns: 1fr; }
  .details-column { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .signature-card, .export-button { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .app { width: min(100% - 24px, 1220px); }
  .topbar { height: 66px; }
  .local-status { display: none; }
  .intro { min-height: 0; padding: 30px 0 24px; }
  .intro h1 { font-size: 36px; }
  .input-footer { align-items: stretch; flex-direction: column; padding: 10px; }
  .input-footer > span { padding: 4px 8px 0; }
  .primary-button { width: 100%; }
  .segment-strip { grid-template-columns: 1fr; }
  .segment { border-right: 0; border-bottom: 1px solid var(--line); }
  .segment:last-child { border-bottom: 0; }
  .details-column { display: flex; align-items: stretch; }
  .panel-head { min-height: 65px; }
  .panel-head h2 { font-size: 12px; }
  .panel-actions { gap: 5px; }
  .copy-button, .edit-button { padding: 8px; }
  pre { min-height: 160px; padding: 17px; font-size: 11px; }
  .json-editor { min-height: 190px; padding: 17px; font-size: 11px; }
  footer span:nth-child(2) { display: none; }
}

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