:root {
  --night: #0b1424;
  --night-2: #13213a;
  --glass: rgba(11, 20, 36, 0.62);
  --glass-strong: rgba(9, 16, 30, 0.86);
  --line: rgba(160, 190, 230, 0.16);
  --text: #e8eef8;
  --muted: #9fb0c8;
  --lamp: #ffc66b;
  --glow: #5fe3ff;
  --beanie: #d9573f;
  --ok: #7be38f;
  --warn: #ffc66b;
  --bad: #ff6b5f;
  --radius: 16px;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'VT323', ui-monospace, 'Cascadia Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--night);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- backdrop ---------- */
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.backdrop__img, .backdrop__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 62% center; }
.backdrop__video { opacity: 0; transition: opacity 1.2s ease; }
.backdrop__video.is-ready { opacity: 1; }
.backdrop__shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg, rgba(8, 14, 26, 0.78) 0%, rgba(8, 14, 26, 0.25) 38%, rgba(8, 14, 26, 0) 55%),
    linear-gradient(0deg, rgba(8, 14, 26, 0.55) 0%, rgba(8, 14, 26, 0) 35%);
}
body[data-status="DEAD"] .backdrop { filter: grayscale(0.9) brightness(0.45); }
body[data-status="PAUSED"] .backdrop { filter: saturate(0.5) brightness(0.7); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 24px 8px;
}
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand__name { margin: 0; font-weight: 800; font-size: 1.5rem; letter-spacing: 0.06em; text-shadow: 0 0 18px rgba(95, 227, 255, 0.45); }
.brand__sub { color: var(--muted); font-size: 0.85rem; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); font-weight: 700; font-size: 0.9rem;
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: pulse 2.4s infinite; }
body[data-status="PAUSED"] .status-pill .dot { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
body[data-status="DEAD"] .status-pill .dot { background: var(--bad); box-shadow: none; animation: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 20px;
  padding: 8px 24px 24px;
  min-height: calc(100vh - 80px);
}
.col { display: flex; flex-direction: column; gap: 14px; }
.col--right { align-items: flex-end; justify-content: space-between; }

.card {
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.card__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tag { font-size: 0.65rem; padding: 2px 7px; border-radius: 6px; background: rgba(255, 198, 107, 0.18); color: var(--lamp); letter-spacing: 0.08em; }
.tag--live { background: rgba(123, 227, 143, 0.18); color: var(--ok); }

/* ---------- life bar ---------- */
.life__headline { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 10px; }
.life__days { font-size: 3.2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.life__unit { color: var(--muted); font-weight: 600; }
.life__status { margin-left: auto; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.1em; padding: 3px 8px; border-radius: 6px; background: rgba(123, 227, 143, 0.15); color: var(--ok); }
.bar { height: 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; border: 1px solid var(--line); }
.bar__fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #3fbf6a, var(--ok)); transition: width 1s ease, background 0.6s; box-shadow: 0 0 14px rgba(123, 227, 143, 0.5); }
.life__meta { margin-top: 8px; color: var(--muted); font-size: 0.88rem; }
.sponsor { margin: 8px 0 0; font-size: 0.82rem; color: var(--muted); }
.sponsor b { color: var(--lamp); }
.tanks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.tank { background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 2px; font-size: 0.75rem; color: var(--muted); }
.tank b { color: var(--text); font-size: 0.95rem; font-variant-numeric: tabular-nums; }

body[data-life="LOW"] .bar__fill { background: linear-gradient(90deg, #d79b2b, var(--warn)); box-shadow: 0 0 14px rgba(255, 198, 107, 0.5); }
body[data-life="LOW"] .life__status { background: rgba(255, 198, 107, 0.15); color: var(--warn); }
body[data-life="CRITICAL"] .bar__fill, body[data-life="DEAD"] .bar__fill { background: linear-gradient(90deg, #b8322a, var(--bad)); animation: pulse 1.2s infinite; }
body[data-life="CRITICAL"] .life__status, body[data-life="DEAD"] .life__status { background: rgba(255, 107, 95, 0.15); color: var(--bad); }
body[data-life="THRIVING"] .life__status { background: rgba(95, 227, 255, 0.15); color: var(--glow); }

/* ---------- wallet ---------- */
.balances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 12px; }
.balances div { display: flex; flex-direction: column; }
.balances__k { font-size: 0.72rem; color: var(--muted); }
.balances b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.address {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 10px; border: 1px dashed rgba(95, 227, 255, 0.4);
  background: rgba(95, 227, 255, 0.06); cursor: pointer; font-family: var(--mono); font-size: 1.15rem;
}
.address:hover, .address:focus-visible { background: rgba(95, 227, 255, 0.12); outline: none; }
.address__hint { font-family: var(--font); font-size: 0.75rem; color: var(--glow); }
.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn { flex: 1; text-align: center; text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 700; font-size: 0.9rem; cursor: pointer; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); }
.btn:hover, .btn:focus-visible { background: rgba(255, 255, 255, 0.12); outline: none; }
.btn--tea { background: linear-gradient(135deg, #e9884c, var(--beanie)); border-color: transparent; color: #fff; }
.btn--tea:hover { filter: brightness(1.08); }
.btn--share { display: block; margin-top: 8px; }
button.btn--blink { width: 100%; }

/* ---------- one-click wallet tip dialog ---------- */
.tip-dialog {
  width: min(440px, calc(100vw - 32px)); padding: 20px 22px; border-radius: 18px; border: 1px solid var(--line);
  background: #0f1a2b; color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.tip-dialog::backdrop { background: rgba(5, 8, 14, 0.7); backdrop-filter: blur(3px); }
.tip-dialog__head { display: flex; justify-content: space-between; align-items: center; }
.tip-dialog__head h2 { margin: 0; font-size: 1.25rem; }
.tip-dialog__sub { color: var(--muted); font-size: 0.85rem; margin: 6px 0 14px; }
.tip-presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tip-preset { padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-weight: 800; cursor: pointer; }
.tip-preset.is-active { border-color: var(--glow); background: rgba(95, 227, 255, 0.14); }
.tip-preset:focus-visible { outline: 2px solid var(--glow); }
.tip-custom { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; font-size: 0.8rem; color: var(--muted); }
.tip-custom input, .tip-custom textarea { font: inherit; resize: vertical; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: #0b1424; color: var(--text); }
.tip-wallets { display: flex; flex-direction: column; gap: 8px; }
.tip-wallets .btn { flex: none; }
.tip-status { min-height: 1.2em; margin: 12px 0 0; font-size: 0.86rem; color: var(--muted); overflow-wrap: anywhere; }
.tip-status--good { color: var(--ok); }
.tip-status--bad { color: var(--bad); }
.tip-status a { color: var(--glow); }
.btn--blink { display: block; margin-top: 8px; background: rgba(95, 227, 255, 0.1); border-color: rgba(95, 227, 255, 0.35); }
.btn--blink:hover, .btn--blink:focus-visible { background: rgba(95, 227, 255, 0.18); }
.qr { margin-top: 12px; padding: 12px; background: #fff; border-radius: 12px; display: grid; place-items: center; }
.qr svg, .qr img { width: 180px; height: 180px; }
.fineprint { color: var(--muted); font-size: 0.72rem; line-height: 1.45; margin: 10px 0 0; }

/* ---------- mood ---------- */
.mood__row { display: flex; align-items: center; gap: 12px; }
.mood__emoji { font-size: 2rem; }
.mood__reason { color: var(--muted); font-size: 0.85rem; margin: 8px 0 4px; }
.staszek { margin: 6px 0 0; font-size: 0.9rem; }
.golden { margin: 8px 0 0; font-size: 0.85rem; color: var(--lamp); }

/* ---------- radio ---------- */
.radio {
  display: flex; gap: 14px; align-items: center; width: min(420px, 100%);
  background: linear-gradient(160deg, rgba(60, 36, 28, 0.85), rgba(30, 20, 18, 0.85));
  border: 1px solid rgba(255, 198, 107, 0.25); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); backdrop-filter: blur(8px);
}
.cassette { width: 76px; height: 50px; border-radius: 8px; background: #2a1d17; border: 2px solid #6b4a36; display: flex; align-items: center; justify-content: space-around; flex-shrink: 0; }
.reel { width: 18px; height: 18px; border-radius: 50%; border: 3px dashed var(--lamp); }
.radio.is-playing .reel { animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.radio__body { flex: 1; min-width: 0; }
.radio__title { font-weight: 800; color: var(--lamp); font-size: 0.85rem; letter-spacing: 0.06em; }
.radio__fm { color: var(--muted); font-weight: 600; margin-left: 4px; }
.radio__track { font-family: var(--mono); font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.radio__controls { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.icon-btn { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 50%; width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center; font-size: 0.85rem; }
.icon-btn--big { width: 40px; height: 40px; background: var(--lamp); color: #2a1d17; border: none; font-size: 1rem; }
.icon-btn:focus-visible { outline: 2px solid var(--glow); }
.volume { flex: 1; min-width: 60px; accent-color: var(--lamp); }

/* ---------- terminal ---------- */
.terminal {
  width: min(520px, 100%); display: flex; flex-direction: column;
  background: var(--glass-strong); border: 1px solid rgba(95, 227, 255, 0.22); border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(95, 227, 255, 0.08), 0 10px 30px rgba(0, 0, 0, 0.35); overflow: hidden;
  height: min(52vh, 520px);
}
.terminal__bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 0.78rem; color: var(--muted); }
.terminal__dots { display: inline-flex; gap: 5px; }
.terminal__dots i { width: 9px; height: 9px; border-radius: 50%; background: #43506a; }
.terminal__dots i:first-child { background: var(--beanie); }
.terminal__title { flex: 1; font-family: var(--mono); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.terminal__live { color: var(--ok); font-weight: 800; }
.terminal__live.is-off { color: var(--bad); }
.terminal__log { list-style: none; margin: 0; padding: 10px 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; }
.thought { font-family: var(--mono); font-size: 1.12rem; line-height: 1.25; color: #cfe6ff; animation: appear 0.6s ease; overflow-wrap: anywhere; }
.thought__time { color: #5d7393; margin-right: 6px; }
.thought__icon { margin-right: 4px; }
.thought--ambient { color: #8aa0bd; }
.thought--event { color: #8fb2a0; }
.thought--trade { color: var(--lamp); }
.thought--tip { color: #ffd9a0; }
.thought--caretaker { color: #c7b5ff; }
.thought--essay { color: #f2f6ff; background: rgba(255, 255, 255, 0.04); padding: 6px 8px; border-radius: 8px; }
.thought--audit { color: #9fe6c4; }
.thought__cost { color: #5d7393; font-size: 0.9rem; margin-left: 6px; }
@keyframes appear { from { opacity: 0; transform: translateY(6px); } }
.terminal__thinking { padding: 6px 14px; font-family: var(--mono); font-size: 1.05rem; color: var(--glow); border-top: 1px solid var(--line); }
.terminal__thinking .dots::after { content: ''; animation: dots 1.4s steps(4, end) infinite; }
.terminal__thinking-why { color: var(--muted); margin-left: 8px; font-size: 0.9rem; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.terminal__foot { border-top: 1px solid var(--line); padding: 6px 12px; font-size: 0.75rem; color: var(--muted); }

/* ---------- bailiff ---------- */
.bailiff {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 10px; align-items: center; justify-content: center;
  padding: 10px 16px; background: linear-gradient(90deg, rgba(120, 22, 18, 0.92), rgba(170, 40, 30, 0.92));
  font-size: 0.92rem; text-align: center; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
.bailiff__icon { font-size: 1.3rem; animation: sway 2s ease-in-out infinite; }
@keyframes sway { 50% { transform: translateX(6px) rotate(6deg); } }

/* ---------- ledger drawer ---------- */
.topbar__actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.topbar__actions > * { white-space: nowrap; }
.ledger-toggle {
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass);
  backdrop-filter: blur(10px); font-weight: 700; font-size: 0.9rem; cursor: pointer;
}
.ledger-toggle:hover, .ledger-toggle:focus-visible { background: rgba(255, 255, 255, 0.12); outline: none; }
.live-link { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-decoration: none; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff4d4d; box-shadow: 0 0 8px #ff4d4d; animation: live-pulse 1.6s ease-in-out infinite; }
@keyframes live-pulse { 50% { opacity: 0.35; } }
.ledger {
  position: fixed; inset: 0 0 0 auto; width: min(560px, 100vw); z-index: 30;
  background: rgba(9, 16, 30, 0.97); border-left: 1px solid var(--line); padding: 18px 20px; overflow-y: auto;
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.45);
}
.ledger__head { display: flex; justify-content: space-between; align-items: center; }
.ledger__head h2 { margin: 0; font-size: 1.2rem; }
.tabs { display: flex; gap: 6px; margin: 14px 0; flex-wrap: wrap; }
.tab { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.tab.is-active { background: rgba(95, 227, 255, 0.14); color: var(--text); border-color: rgba(95, 227, 255, 0.4); }
.ledger__body { display: flex; flex-direction: column; gap: 8px; }
.entry { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); font-size: 0.88rem; }
.entry__sub { color: var(--muted); font-size: 0.78rem; grid-column: 1 / -1; overflow-wrap: anywhere; }
.entry__sub a { color: var(--glow); }
.pos { color: var(--ok); font-weight: 800; }
.neg { color: var(--bad); font-weight: 800; }
.empty { color: var(--muted); font-style: italic; padding: 10px 0; }

/* ---------- tombstone ---------- */
.tombstone { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(5, 8, 14, 0.55); pointer-events: none; }
.tombstone__stone {
  pointer-events: auto; text-align: center; padding: 34px 40px 28px; width: min(380px, 90vw);
  background: linear-gradient(#7d828c, #5b6069); color: #1d2129; border-radius: 140px 140px 16px 16px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}
.tombstone__rip { font-weight: 800; font-size: 2.2rem; letter-spacing: 0.2em; }
.tombstone__name { font-family: var(--mono); font-size: 1.6rem; margin-bottom: 8px; }
.tombstone__window { font-weight: 800; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 8px 16px 90px; }
  .col--right { align-items: stretch; }
  .radio, .terminal { width: 100%; }
  .terminal { height: 60vh; }
  .backdrop__shade { background: rgba(8, 14, 26, 0.55); }
  .topbar { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 760px) {
  .backdrop__video { display: none; }
  .brand__name { font-size: 1.25rem; }
  .ledger-toggle, .status-pill { padding: 5px 10px; font-size: 0.8rem; }
  .topbar__actions { flex-wrap: wrap; justify-content: flex-end; flex-shrink: 1; }
  .life__days { font-size: 2.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .backdrop__video { display: none; }
}
