:root {
  --bg: #0b0d17;
  --surface: #141827;
  --surface-2: #1c2137;
  --border: #2a2f4a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.2);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.08);
  --danger: #f43f5e;
  --danger-bg: rgba(244, 63, 94, 0.08);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.08);
  --radius: 12px;
  --transition: 0.3s ease;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Header ---- */
header {
  background: linear-gradient(135deg, #0f1a2e 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 2.5rem 2rem;
  text-align: center;
}

header h1 {
  font-size: 2.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-size: 1.05rem;
}

.intro {
  max-width: 700px;
  margin: 1rem auto 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: center;
}

/* ---- Layout ---- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.section {
  margin-bottom: 2rem;
}

.section h2 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
  font-weight: 600;
}

.hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.step-desc {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: -0.6rem;
  margin-bottom: 1rem;
}

/* ---- Role Buttons ---- */
.role-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.role-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.5rem 2rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  flex: 1;
  min-width: 160px;
  font-family: inherit;
}

.role-btn:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}

.role-btn.active {
  border-color: var(--primary);
  background: var(--primary-glow);
  box-shadow: 0 0 30px var(--primary-glow);
}

.role-icon {
  font-size: 1.6rem;
  font-weight: 800;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-2);
  transition: all var(--transition);
}

.role-btn.active .role-icon {
  background: var(--primary);
  color: #fff;
}

.role-label {
  font-size: 1.15rem;
  font-weight: 600;
}

.role-rights {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---- Token raw display ---- */
.token-raw {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
  word-break: break-all;
  color: var(--text-muted);
}

.token-raw .label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.token-meta {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.token-meta .meta-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.meta-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.token-blocks {
  margin-top: 1rem;
}

/* ---- Token Chain (Datalog blocks) ---- */
.token-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  animation: slideIn 0.3s ease;
}

.token-block.authority {
  border-color: var(--primary);
  border-width: 2px;
}

.token-block.attenuation {
  border-color: var(--warn);
  border-style: dashed;
}

.token-block-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.token-block.authority .badge { background: var(--primary); color: #fff; }
.token-block.attenuation .badge { background: var(--warn); color: #fff; }

.block-index {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.token-block pre {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.token-connector {
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 0.2rem 0;
  line-height: 1;
}

/* Revocation ID in token blocks */
.revocation-id {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
}

.revocation-label {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.65rem;
  white-space: nowrap;
}

.revocation-id code {
  font-family: var(--mono);
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* ---- Revocation Section ---- */
.revoke-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  background: var(--surface);
  border: 2px solid var(--success);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.revoke-toggle.revoked {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.revoke-status {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.revoke-indicator {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--success);
  transition: color var(--transition);
}

.revoked .revoke-indicator {
  color: var(--danger);
}

.revoke-id {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-revoke {
  background: var(--danger);
  flex-shrink: 0;
}

.btn-restore {
  background: var(--success);
  flex-shrink: 0;
}

/* Datalog highlighting */
.dl-kw { color: #60a5fa; font-weight: 600; }
.dl-str { color: #34d399; }
.dl-var { color: #fb923c; }

/* ---- Method Buttons & cURL Panel ---- */
.method-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.method-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95rem;
  transition: all var(--transition);
  flex: 1;
  min-width: 100px;
}

.method-btn:hover { transform: translateY(-2px); }

.method-btn.allowed {
  border-color: var(--success);
  background: var(--success-bg);
}

.method-btn.denied {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--text-muted);
}

.method-btn.allowed.selected {
  box-shadow: 0 0 0 3px var(--success);
}

.method-btn.denied.selected {
  box-shadow: 0 0 0 3px var(--danger);
}

.method-name { font-size: 1rem; }

.method-status {
  font-size: 1.4rem;
  font-weight: 300;
}

.method-btn.allowed .method-status { color: var(--success); }
.method-btn.denied .method-status { color: var(--danger); }

.curl-panel h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.curl-cmd-wrapper {
  position: relative;
}

.btn-copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.3rem 0.45rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: all var(--transition);
}

.btn-copy:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background: var(--border);
}

.curl-cmd {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.curl-response {
  border-radius: var(--radius);
  overflow: hidden;
  animation: slideIn 0.3s ease;
  background: var(--surface);
}

.response-header {
  padding: 0.6rem 1rem;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
}

.response-header.ok {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border-bottom: 2px solid var(--success);
}

.response-header.err {
  background: rgba(244, 63, 94, 0.15);
  color: var(--danger);
  border-bottom: 2px solid var(--danger);
}

.response-time {
  font-weight: 400;
  opacity: 0.7;
}

.response-detail {
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-bg);
  border-bottom: 1px solid var(--border);
  white-space: pre-wrap;
}

.response-body {
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
  padding: 1rem;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

/* ---- Callout ---- */
.callout {
  background: var(--surface);
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  padding: 0.8rem 1rem;
  margin-bottom: 1.2rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.callout strong {
  color: var(--text);
}

/* ---- Attenuation List ---- */
.att-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.att-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.att-item:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}

.att-item.active {
  border-color: var(--warn);
  background: var(--warn-bg);
}

.att-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 4px;
  border: 2px solid var(--border);
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
}

.att-item.active .att-check {
  background: var(--warn);
  border-color: var(--warn);
  color: #fff;
}

.att-text {
  display: flex;
  flex-direction: column;
  min-width: 10rem;
}

.att-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.att-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.att-code {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: #b0bdd0;
  background: var(--bg);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.att-item.active .att-code {
  color: var(--text);
}

.att-item .remove-btn {
  padding: 0.2rem 0.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  border-radius: 4px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.att-item .remove-btn:hover {
  color: var(--warn);
  background: var(--warn-bg);
}

/* ---- Custom check form ---- */
.custom-add-section {
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
}

.custom-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.ip-example-btn {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.ip-example-btn:hover {
  background: var(--border);
}

.custom-add-form {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color var(--transition);
}

.custom-add-form:focus-within {
  border-color: var(--primary);
}

.custom-add-form textarea {
  flex: 1;
  border: none;
  border-radius: 0;
  background: var(--surface);
  padding: 0.7rem 0.9rem;
  margin: 0;
  resize: none;
  font-size: 0.8rem;
  min-height: unset;
}

.custom-add-form textarea:focus {
  outline: none;
  border: none;
}

.custom-add-form .btn {
  border-radius: 0;
  padding: 0.7rem 1.2rem;
  font-size: 0.8rem;
}

textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  resize: vertical;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  padding: 0.6rem 1.1rem;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover { opacity: 0.85; }

/* ---- Focus ---- */
.role-btn:focus-visible,
.method-btn:focus-visible,
.att-item:focus-visible,
.btn:focus-visible,
.btn-copy:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---- Footer ---- */
footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

footer a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

footer a:hover {
  color: var(--primary);
}

footer .sep {
  margin: 0 0.5rem;
}

/* ---- Animations ---- */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake { animation: shake 0.35s ease; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  main { padding: 1rem; }
  header { padding: 1.5rem 1rem; }
  header h1 { font-size: 1.6rem; }
}
