/* =========================================================================
   MCP TOKEN LEDGER — "industrial terminal ledger" aesthetic
   Phosphor-amber CRT manifest crossed with a thermal-receipt printout.
   Monospace throughout; hierarchy comes from weight, tracking, and color,
   not from mixing typefaces. No webfonts — fully offline-safe.
   ========================================================================= */

:root {
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono",
    "Fira Code", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #0a0c08;
  --bg-alt: #101208;
  --paper: #12130d;
  --paper-raised: #17190f;

  --ink: #e9e4d4;
  --ink-dim: #9a9484;
  --ink-faint: #5c5748;

  --amber: #ffb000;
  --amber-dim: #8a6100;
  --amber-glow: rgba(255, 176, 0, 0.35);

  --green: #7fd858;
  --green-dim: #3a5c26;

  --red: #ff5b4d;
  --red-dim: #6b2118;

  --line: #35341f;
  --line-bright: #4d4b2c;

  --shadow: rgba(0, 0, 0, 0.65);

  --radius: 2px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.55;
  position: relative;
  min-height: 100vh;
}

/* ---------- atmosphere: scanlines + grain ---------- */

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.018) 0px,
    rgba(255, 255, 255, 0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 49;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- masthead ---------- */

.masthead {
  padding: 3.5rem 1.5rem 2rem;
  text-align: center;
  position: relative;
  background: radial-gradient(ellipse at 50% -20%, rgba(255, 176, 0, 0.07), transparent 60%);
}

.masthead-eyebrow {
  margin: 0 0 0.9rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.masthead-title {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 3.6rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--amber);
  text-shadow: 0 0 22px var(--amber-glow), 0 0 2px rgba(255, 176, 0, 0.6);
}

.masthead-sub {
  margin: 0.75rem auto 0;
  max-width: 44rem;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.masthead-rule {
  margin-top: 2rem;
  height: 1px;
  background: repeating-linear-gradient(
    to right,
    var(--line-bright) 0,
    var(--line-bright) 6px,
    transparent 6px,
    transparent 12px
  );
}

/* ---------- layout ---------- */

.layout {
  max-width: 74rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem;
}

@media (min-width: 920px) {
  .layout {
    grid-template-columns: 0.8fr 1.2fr;
    grid-template-areas:
      "explainer input"
      "results   results";
  }
  .explainer { grid-area: explainer; }
  .input-panel { grid-area: input; }
  .results-panel { grid-area: results; }
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.75rem;
  animation: rise 0.5s ease both;
}

.explainer { animation-delay: 0.02s; }
.input-panel { animation-delay: 0.08s; }
.results-panel { animation-delay: 0.14s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel h2 {
  margin: 0 0 1.1rem;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--ink);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.panel h2 .idx {
  color: var(--bg);
  background: var(--amber);
  font-size: 0.72rem;
  padding: 0.15rem 0.4rem;
  border-radius: 1px;
  font-weight: 700;
}

/* ---------- explainer ---------- */

.explainer-body p {
  margin: 0 0 0.9rem;
  color: var(--ink-dim);
  font-size: 0.92rem;
}

.explainer-body code {
  color: var(--amber);
  background: rgba(255, 176, 0, 0.08);
  padding: 0.05rem 0.3rem;
  border-radius: 2px;
  font-size: 0.88em;
}

.explainer-body em {
  color: var(--ink);
  font-style: normal;
  border-bottom: 1px dotted var(--ink-faint);
}

.explainer-note {
  margin-top: 1.2rem !important;
  padding-top: 1rem;
  border-top: 1px dashed var(--line-bright);
  color: var(--amber) !important;
  font-size: 0.85rem !important;
}

/* ---------- input panel ---------- */

.schema-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 0.9rem;
  caret-color: var(--amber);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.schema-textarea::placeholder {
  color: var(--ink-faint);
}

.schema-textarea:focus {
  outline: none;
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 3px rgba(255, 176, 0, 0.08);
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
}

.btn {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--bg-alt);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--bg);
}

.btn-primary:hover {
  background: #ffc233;
  color: var(--bg);
  border-color: #ffc233;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border-color: var(--line);
}

.file-btn {
  position: relative;
}

.input-hint {
  margin: 0.9rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

/* ---------- results / receipt ---------- */

.receipt {
  position: relative;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px -20px var(--shadow);
}

.receipt-tear {
  height: 9px;
  background-image:
    linear-gradient(135deg, var(--paper) 25%, transparent 25%),
    linear-gradient(225deg, var(--paper) 25%, transparent 25%);
  background-size: 12px 12px;
  background-position: 0 0;
}

.receipt-tear-top { background-color: var(--paper-raised); }
.receipt-tear-bottom {
  transform: rotate(180deg);
  background-color: var(--paper-raised);
}

.receipt-inner {
  padding: 1.4rem 1.6rem 1.7rem;
}

/* empty state */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--ink-faint);
}

.empty-caret {
  color: var(--amber);
  font-size: 1.3rem;
  animation: blink 1.1s steps(1) infinite;
  margin-bottom: 0.8rem;
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.empty-title {
  margin: 0 0 0.4rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--ink-dim);
}

.empty-sub {
  margin: 0;
  font-size: 0.85rem;
  max-width: 28rem;
  margin-inline: auto;
}

/* error state */

.error-state {
  padding: 1.5rem 0.5rem 1rem;
  text-align: center;
}

.error-stamp {
  display: inline-block;
  color: var(--red);
  border: 3px solid var(--red);
  padding: 0.4rem 1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  transform: rotate(-3deg);
  border-radius: 4px;
  margin-bottom: 1.1rem;
  box-shadow: 0 0 18px rgba(255, 91, 77, 0.15);
}

.error-message {
  margin: 0 0 0.5rem;
  color: var(--ink);
  font-size: 0.88rem;
  word-break: break-word;
}

.error-hint {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.8rem;
  max-width: 32rem;
  margin-inline: auto;
}

/* skip note */

.skip-note {
  margin: 0 0 1rem;
  color: var(--amber);
  font-size: 0.78rem;
}

/* table */

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.ledger-table thead th {
  text-align: left;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
  padding: 0 0.5rem 0.6rem;
  border-bottom: 1px dashed var(--line-bright);
}

.ledger-table .col-rank { width: 2.2rem; }
.ledger-table .col-tokens { width: 8rem; }
.ledger-table .col-share { width: 9rem; }
.ledger-table .col-chars { width: 6rem; text-align: right; }
.ledger-table thead .col-chars { text-align: right; }

.ledger-table tbody tr {
  animation: row-in 0.35s ease both;
}

@keyframes row-in {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}

.ledger-table tbody td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.ledger-table .col-rank {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.ledger-table .col-name {
  color: var(--ink);
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-table .col-tokens {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ledger-table .col-chars {
  text-align: right;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.tier-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.tier-dot.tier-heavy { background: var(--red); box-shadow: 0 0 6px rgba(255, 91, 77, 0.7); }
.tier-dot.tier-moderate { background: var(--amber); box-shadow: 0 0 6px rgba(255, 176, 0, 0.6); }
.tier-dot.tier-light { background: var(--green); box-shadow: 0 0 6px rgba(127, 216, 88, 0.5); }

.tag-warn {
  font-size: 0.66rem;
  color: var(--red);
  border: 1px solid var(--red-dim);
  padding: 0.05rem 0.3rem;
  border-radius: 2px;
  margin-left: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-alt);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.bar-fill.bar-heavy { background: linear-gradient(to right, var(--red-dim), var(--red)); }
.bar-fill.bar-moderate { background: linear-gradient(to right, var(--amber-dim), var(--amber)); }
.bar-fill.bar-light { background: linear-gradient(to right, var(--green-dim), var(--green)); }

/* total block */

.ledger-total {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 2px solid var(--line-bright);
}

.total-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--ink-dim);
  padding: 0.25rem 0.1rem;
}

.total-line span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.total-line-emphasis {
  margin-top: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--line-bright);
  font-size: 1rem;
  font-weight: 700;
  color: var(--amber);
}

.total-line-emphasis span:last-child {
  color: var(--amber);
  text-shadow: 0 0 12px var(--amber-glow);
}

/* ---------- support panel ---------- */

.support-panel {
  animation-delay: 0.2s;
}

.support-body > p {
  margin: 0 0 1.4rem;
  color: var(--ink-dim);
  font-size: 0.88rem;
  max-width: 52rem;
}

.support-body strong {
  color: var(--ink);
}

.support-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.75rem;
  align-items: start;
}

@media (max-width: 640px) {
  .support-grid {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: left;
  }
}

.support-qr {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  flex: none;
}

.qr-code {
  width: 132px;
  height: 132px;
  display: block;
}

.support-details {
  min-width: 0;
}

.support-label {
  margin: 0 0 0.3rem;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.support-network {
  margin: 0 0 1.1rem;
  color: var(--amber);
  font-weight: 700;
  font-size: 0.92rem;
}

.support-network-note {
  display: block;
  margin-top: 0.3rem;
  color: var(--ink-dim);
  font-weight: 400;
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
}

.support-address-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}

.support-address {
  color: var(--ink);
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  font-size: 0.8rem;
  word-break: break-all;
}

.btn-copy {
  padding: 0.5rem 0.8rem;
}

.support-notes {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--ink-dim);
  font-size: 0.8rem;
  line-height: 1.6;
}

.support-notes li {
  margin-bottom: 0.4rem;
}

.support-notes strong {
  color: var(--ink);
}

/* ---------- footer ---------- */

.site-footer {
  max-width: 74rem;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

.site-footer p {
  color: var(--ink-faint);
  font-size: 0.74rem;
  line-height: 1.6;
  border-top: 1px dashed var(--line);
  padding-top: 1.2rem;
}

.site-footer strong {
  color: var(--ink-dim);
}
