:root {
  --paper: #ebe4d4;
  --ink: #2a261c;
  --mute: #6f6758;
  --line: #cfc4ae;
  --amber: #e8b86d;
  --den: #0b0b0c;
  --den2: #14110d;
  --mist: #c8d7c4;
  --tap: 2.75rem;
  --pad-x: max(1.15rem, env(safe-area-inset-left, 0px));
  --pad-r: max(1.15rem, env(safe-area-inset-right, 0px));
  --pad-t: max(1.15rem, env(safe-area-inset-top, 0px));
  --pad-b: max(1.4rem, env(safe-area-inset-bottom, 0px));
  color-scheme: light;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { min-height: 100%; min-height: 100dvh; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(42, 38, 28, .12);
}
body.den {
  background: var(--den);
  color: #ece6d8;
  font-family: "Segoe UI", "Iowan Old Style", Georgia, serif;
  color-scheme: dark;
  -webkit-tap-highlight-color: rgba(232, 184, 109, .18);
}
img, canvas, svg { max-width: 100%; height: auto; }
.grain {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: .07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
.wrap {
  width: min(42rem, 100%);
  margin: 0 auto;
  padding: var(--pad-t) var(--pad-r) calc(var(--pad-b) + 1.4rem) var(--pad-x);
  position: relative; z-index: 2;
}
.mast {
  display: flex; justify-content: space-between; align-items: baseline; gap: .8rem;
  margin-bottom: 1.6rem; flex-wrap: wrap;
}
.mark { font-size: 1.05rem; letter-spacing: .22em; text-transform: uppercase; }
.mast nav { display: flex; gap: .75rem 1rem; font-size: .82rem; color: var(--mute); flex-wrap: wrap; align-items: baseline; }
.mast nav a { color: inherit; text-decoration: none; border-bottom: 1px solid transparent; }
.mast nav a:hover { border-bottom-color: var(--ink); }
.profile-open {
  margin: 0; min-height: 2.2rem; padding: .15rem 0; font-size: .82rem; color: var(--ink);
  border-bottom: 1px solid var(--ink);
}
.kicker { color: var(--mute); font-size: .95rem; line-height: 1.55; margin: 0 0 2.2rem; max-width: 34rem; }
.rubric { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--mute); margin-bottom: .45rem; }
.journal h2 { font-size: clamp(1.35rem, 4vw, 1.85rem); font-weight: 500; letter-spacing: -.02em; margin: 0 0 .8rem; }
.story, .poem, .issues { margin: 0 0 2.4rem; padding-top: 1.4rem; border-top: 1px solid var(--line); }
.story p, .issues li { font-size: 1.05rem; line-height: 1.7; margin: 0 0 .9rem; }
.verse p { font-size: 1.08rem; line-height: 1.65; margin: 0 0 1rem; }
.spread { margin: 0 0 2.4rem; }
.spread img { width: 100%; height: min(48vh, 22rem); object-fit: cover; display: block; border-radius: 2px; }
.spread figcaption { margin-top: .55rem; font-size: .8rem; color: var(--mute); }
.issues ul { list-style: none; }
.issues li { display: grid; gap: .2rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.issues li span { font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--mute); }
.form-note { color: var(--mute); font-size: .9rem; line-height: 1.5; margin: 0 0 .8rem; }
.colophon { margin-top: .7rem; }
.scan { position: fixed; inset: 0; z-index: 10; pointer-events: none; opacity: 0;
  background: repeating-linear-gradient(180deg, transparent 0 2px, rgba(0,0,0,.12) 2px 3px); mix-blend-mode: multiply; }

h1 { font-weight: 500; font-size: clamp(1.85rem, 7.2vw, 3.4rem); line-height: 1.08; letter-spacing: -.03em; margin: 0 0 .8rem; }
.lead { color: var(--mute); font-size: clamp(.98rem, 2.8vw, 1.05rem); line-height: 1.55; max-width: 34rem; }
.field {
  margin: 1.4rem 0 1.3rem; height: min(42vh, 22rem); min-height: 9.5rem;
  border-radius: 2px; overflow: hidden; position: relative;
  box-shadow: 0 20px 50px rgba(42,38,28,.14); background: #1c2416;
}
.field .hero { width: 100%; height: 100%; object-fit: cover; object-position: center 40%; display: block; }
.issue { font-size: .78rem; letter-spacing: .16em; text-transform: uppercase; color: var(--mute); margin-bottom: 1.1rem; }
form, .codebox { margin-top: 1.4rem; padding-top: 1.3rem; border-top: 1px solid var(--line); }
label { display: block; font-size: .82rem; color: var(--mute); margin-bottom: .45rem; }
input[type=email] {
  width: 100%; border: 0; border-bottom: 1px solid var(--ink); background: transparent;
  font: inherit; font-size: 1.05rem; padding: .7rem 0; color: var(--ink); outline: none;
  min-height: var(--tap); border-radius: 0;
}
.otp {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: .4rem; margin: .55rem 0 1rem; max-width: 22rem;
}
.otp input {
  width: 100%; min-height: var(--tap); height: 3rem; text-align: center;
  font-size: 1.2rem; border: 1px solid var(--line); background: #f6f1e4; color: var(--ink);
  border-radius: 6px; -webkit-appearance: none; appearance: none;
}
button, .btn {
  margin-top: .9rem; background: none; border: 0; border-bottom: 1px solid currentColor;
  font: inherit; cursor: pointer; padding: .55rem 0; color: inherit;
  min-height: var(--tap); touch-action: manipulation;
}
#go { display: inline-block; min-width: 8rem; }
button:disabled { opacity: .45; cursor: wait; }
.err { color: #8a3b2a; font-size: .9rem; margin-top: .7rem; min-height: 1.2em; }
footer { margin-top: 2.4rem; font-size: .78rem; color: var(--mute); line-height: 1.45; }
canvas#rain { position: fixed; inset: 0; z-index: 8; pointer-events: none; opacity: 0; width: 100%; height: 100%; }
.veil { position: fixed; inset: 0; z-index: 9; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 42%, transparent 0%, rgba(6,10,6,.18) 48%, #050805 100%); }
.bear-glow {
  position: fixed; left: 50%; top: 46%; width: min(22vw, 88px); height: min(22vw, 88px);
  margin: 0; transform: translate(-50%, -50%); z-index: 11;
  opacity: 0; pointer-events: none; filter: drop-shadow(0 0 18px rgba(232,184,109,.45)); object-fit: contain;
}
.whisper { position: fixed; inset: 0; z-index: 12; display: grid; place-items: center; text-align: center;
  color: #d7f7d0; font-family: ui-monospace, Consolas, monospace; letter-spacing: .22em; text-transform: uppercase;
  font-size: clamp(.68rem, 3.1vw, 1rem); opacity: 0; pointer-events: none; text-shadow: 0 0 18px #6fbf7a;
  padding: 0 max(1rem, env(safe-area-inset-left)) 0 max(1rem, env(safe-area-inset-right)); }
.whisper b { display: block; margin-top: .85rem; letter-spacing: .32em; color: var(--amber); font-size: 1.2em; font-weight: 600; word-break: break-word; }
.load-track {
  width: min(16rem, 62vw); height: 3px; margin: 1.4rem auto 0; border-radius: 99px;
  background: rgba(110,210,120,.18); overflow: hidden;
}
.load-track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3d6b45, var(--amber), #8fd39a); }
.load-hint { margin-top: .7rem; font-size: .72rem; letter-spacing: .16em; color: #9ad7a2; text-transform: uppercase; }

body.morph { overflow: hidden; }
body.morph #cover { will-change: filter, transform, opacity; }
body.morph .grain { animation: grainout 10s linear forwards; }
body.morph .scan { animation: scanin 14s linear forwards; }
body.morph .whisper { opacity: 1; }
body.morph .bear-glow { animation: bearin 14s ease forwards; }

/* 1. Journal falls apart */
body.morph-break { animation: paper-break 3s ease forwards; }
body.morph-break .shard {
  animation: shatter .95s cubic-bezier(.2,.7,.2,1) forwards;
  animation-delay: var(--d, 0ms);
}
body.morph-break #cover { filter: contrast(1.15) saturate(.7); }
body.morph-break .whisper { animation: say-break 3s ease forwards; }

/* 2. Transformation */
body.morph-xform { animation: paper-xform 3s ease forwards; }
body.morph-xform #cover { animation: sink-xform 2.8s ease forwards; }
body.morph-xform .veil { animation: veil-xform 2.8s ease forwards; }
body.morph-xform .field, body.morph-xform .spread img { animation: digit 2.8s ease forwards; }
body.morph-xform .whisper { animation: say-xform 3s ease forwards; }

/* 3. Matrix */
body.morph-matrix { background: #030805; }
body.morph-matrix canvas#rain { animation: rainin 1.2s ease forwards; }
body.morph-matrix .veil { opacity: .55; background: radial-gradient(circle at 50% 40%, rgba(20,60,28,.2), #030805 72%); }
body.morph-matrix #cover { opacity: 0; pointer-events: none; }
body.morph-matrix .whisper { animation: say-matrix 4.6s ease forwards; }

/* 4. Cabinet loading */
body.morph-load canvas#rain { opacity: .35; }
body.morph-load .veil { opacity: .85; background: #0b0b0c; }
body.morph-load .whisper { animation: say-load 3.4s ease forwards; }
body.morph-load .load-track i { animation: fillbar 3.2s ease forwards; }

@keyframes paper-break { 0%{background:#ebe4d4} 100%{background:#c5c2a8} }
@keyframes paper-xform { 0%{background:#c5c2a8} 40%{background:#6e7a62} 100%{background:#121a14} }
@keyframes shatter {
  0%{opacity:1; transform:none; filter:none}
  100%{opacity:0; transform: translate3d(var(--dx, 0), var(--dy, 40px), 0) rotate(var(--rot, 8deg)) scale(.94); filter: blur(3px)}
}
@keyframes sink-xform {
  0%{filter:contrast(1.2); opacity:1}
  100%{opacity:0; filter:blur(18px) brightness(.12) hue-rotate(80deg); transform:scale(1.12)}
}
@keyframes veil-xform { 0%{opacity:.15} 100%{opacity:.7} }
@keyframes rainin { 0%{opacity:0} 100%{opacity:.92} }
@keyframes scanin { 0%{opacity:0} 18%{opacity:.35} 70%{opacity:.55} 100%{opacity:0} }
@keyframes say-break { 0%{opacity:0} 30%{opacity:.95} 100%{opacity:.9} }
@keyframes say-xform { 0%{opacity:.9} 100%{opacity:1} }
@keyframes say-matrix { 0%{opacity:1} 85%{opacity:1} 100%{opacity:.85} }
@keyframes say-load { 0%{opacity:.85} 80%{opacity:1} 100%{opacity:0} }
@keyframes digit { 0%{filter:none} 100%{filter:contrast(2.4) brightness(.08) saturate(2) hue-rotate(90deg)} }
@keyframes bearin { 0%,42%{opacity:0;transform:scale(.86) translate(-50%,-50%)} 62%{opacity:.75;transform:scale(1) translate(-50%,-50%)} 88%{opacity:.95} 100%{opacity:0;transform:scale(1.16) translate(-50%,-50%)} }
@keyframes grainout { to { opacity: 0; } }
@keyframes fillbar { from { width: 0 } to { width: 100% } }

#den { min-height: 100dvh; position: relative; z-index: 4; }
#den.enter { animation: denin .7s ease; }
@keyframes denin { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }
#den::before {
  content: ""; position: fixed; inset: 0; z-index: -1; opacity: .42;
  background:
    radial-gradient(circle at 12% 0%, rgba(61,107,69,.28), transparent 42%),
    radial-gradient(circle at 88% 100%, rgba(232,184,109,.12), transparent 36%),
    url("/site/img/purify-den.jpg") center/cover no-repeat, #0b0b0c;
  pointer-events: none;
}
.den-shell {
  width: min(54rem, 100%);
  margin: 0 auto;
  padding: var(--pad-t) var(--pad-r) calc(var(--pad-b) + 1.6rem) var(--pad-x);
}
.den-top { display: flex; align-items: center; gap: .7rem; margin-bottom: 1rem; min-width: 0; flex-wrap: wrap; }
.den-top img { width: 42px; height: 42px; flex: none; object-fit: contain; filter: drop-shadow(0 0 12px rgba(232,184,109,.45)); }
.den-brand { display: grid; gap: .1rem; min-width: 0; }
.den-top strong { letter-spacing: .28em; font-size: .82rem; font-weight: 700; color: var(--amber); }
.den-top .mail {
  color: #9a9286; font-size: .8rem; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: min(52vw, 16rem);
}
.bal {
  margin-left: auto; flex: none; margin-top: 0;
  font-variant-numeric: tabular-nums; color: #f3e2c0;
  background: linear-gradient(180deg, rgba(232,184,109,.2), rgba(61,107,69,.16));
  border: 1px solid rgba(232,184,109,.4);
  border-radius: 999px; padding: .42rem .85rem; font-size: .92rem; font-weight: 700;
  box-shadow: 0 0 18px rgba(232,184,109,.12);
}
.den-nav {
  display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1.2rem;
  border-bottom: 1px solid #2a2722; padding-bottom: .55rem;
}
.den-nav button {
  border: 0; border-bottom: 2px solid transparent; margin: 0; padding: .55rem .65rem;
  color: #9a9286; font-size: .9rem; min-height: var(--tap); touch-action: manipulation;
}
.den-nav button.on { color: var(--amber); border-bottom-color: var(--amber); text-shadow: 0 0 12px rgba(232,184,109,.35); }
.nav-short { display: none; }
.stats {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-bottom: .9rem;
}
.stat {
  background: linear-gradient(160deg, rgba(24,48,30,.72), rgba(16,14,12,.82));
  border: 1px solid rgba(110,210,120,.22); border-radius: 14px; padding: .9rem .95rem;
}
.stat .lbl { color: #9a9286; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }
.stat .val { font-size: 1.25rem; font-weight: 700; margin-top: .25rem; color: #f2ebe0; }
.stat .val.ok { color: #8fd39a; }
.stat .val.warn { color: var(--amber); }
.card {
  background: linear-gradient(180deg, rgba(22,20,16,.86), rgba(12,11,10,.86));
  border: 1px solid #2e2a24; border-radius: 14px;
  padding: 1rem 1.05rem; margin-bottom: .9rem; backdrop-filter: blur(10px);
}
.card.live { border-color: rgba(110,210,120,.4); box-shadow: 0 0 28px rgba(61,107,69,.16); }
.card.warn-card { border-color: rgba(232,184,109,.35); }
.card h2 { font-size: clamp(1.05rem, 3vw, 1.22rem); font-weight: 650; margin-bottom: .45rem; }
.card p, .muted { color: #b7b0a4; font-size: .95rem; line-height: 1.5; }
.row { display: flex; justify-content: space-between; gap: .8rem; align-items: baseline; margin: .4rem 0; }
.row strong { text-align: right; }
.ok { color: #8fd39a; }
.warn { color: #e8b86d; }
.bad { color: #d9897a; }
.pill {
  display: inline-block; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase;
  padding: .2rem .5rem; border-radius: 999px; border: 1px solid currentColor; margin-left: .4rem;
}
.bar { height: 8px; background: #2a2722; border-radius: 99px; overflow: hidden; margin: .7rem 0; }
.bar.fat { height: 10px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #3d6b45, var(--amber)); width: 0; transition: width 1.2s ease; }
.apps { display: grid; gap: .55rem; margin-top: .8rem; }
.apps a, .pay, .act {
  display: block; padding: .85rem .95rem; border: 1px solid #3a342c; border-radius: 10px;
  color: #ece6d8; text-decoration: none; min-height: var(--tap); background: rgba(255,255,255,.02);
}
.pay.from-bal { border-color: rgba(143,211,154,.45); }
.pay.from-bal b { color: #8fd39a; }
.pick label:has(input:checked) { border-color: var(--amber); color: var(--amber); }
.pay b { display: block; color: var(--amber); font-size: 1.05rem; }
.pay .save { color: #8fd39a; font-size: .82rem; }
.acts { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .7rem; }
.act { margin: 0; cursor: pointer; font-size: .9rem; padding: .65rem .8rem; }
.act.primary { border-color: rgba(232,184,109,.55); color: var(--amber); }
.copy { font-family: ui-monospace, Consolas, monospace; font-size: .78rem; word-break: break-all; overflow-wrap: anywhere;
  background: #0a0a0b; padding: .7rem; border-radius: 8px; margin: .6rem 0; color: #c8d7c4; border: 1px solid #24201c; }
.ghost { display: inline-block; margin-top: .65rem; color: var(--amber); }
.qr-slot { margin-top: .6rem; }
.toast {
  position: fixed; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom));
  transform: translateX(-50%); background: #1c1914; color: var(--amber);
  padding: .6rem 1rem; border-radius: 8px; z-index: 30; font-size: .9rem;
  max-width: min(92vw, 28rem); text-align: center; border: 1px solid rgba(232,184,109,.25);
}
.qr { width: min(180px, 56vw); height: auto; border-radius: 8px; background: #fff; padding: 8px; }
.pick { display: flex; gap: .55rem; flex-wrap: wrap; margin: .6rem 0 1rem; }
.pick label {
  color: #ece6d8; font-size: .95rem; display: flex; align-items: center; gap: .4rem;
  min-height: var(--tap); padding: .2rem .55rem; border: 1px solid #3a342c; border-radius: 8px; cursor: pointer;
}
.pick input { width: 1.1rem; height: 1.1rem; }
.field-in {
  width: 100%; background: #0e0d0b; border: 1px solid #3a342c; color: #ece6d8;
  border-radius: 8px; padding: .7rem .8rem; font: inherit; min-height: var(--tap); margin: .35rem 0 .7rem;
}
.pay-list { display: grid; gap: .55rem; }
.hist { display: grid; gap: .45rem; margin-top: .6rem; }
.hist-row {
  display: grid; grid-template-columns: 1fr auto; gap: .4rem; padding: .65rem 0;
  border-bottom: 1px solid #2a2722; font-size: .9rem;
}
.key-pick { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.key-pick button { margin: 0; border: 1px solid #3a342c; border-radius: 999px; padding: .4rem .75rem; color: #cfc6b8; }
.key-pick button.on { border-color: var(--amber); color: var(--amber); }

@media (min-width: 640px) {
  .wrap { padding-top: max(1.8rem, env(safe-area-inset-top)); }
  .field { height: min(48vh, 24rem); }
  .apps { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .wrap { width: min(46rem, 100%); padding-top: 2.4rem; }
  .den-shell { width: min(60rem, 100%); padding-top: 1.8rem; }
  .field { height: min(52vh, 26rem); }
}
@media (min-width: 1400px) {
  .wrap, .den-shell { padding-left: max(2rem, env(safe-area-inset-left)); padding-right: max(2rem, env(safe-area-inset-right)); }
}

@media (max-width: 720px) {
  .mast nav { font-size: .75rem; gap: .65rem; }
  .den-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 16;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0;
    margin: 0; border-bottom: 0; border-top: 1px solid #2a2722;
    background: rgba(11, 11, 12, .96);
    padding: .22rem var(--pad-r) var(--pad-b) var(--pad-x);
    backdrop-filter: blur(14px);
  }
  .den-nav button {
    min-height: 3.2rem; padding: .25rem .1rem; font-size: .72rem; line-height: 1.15;
    border-bottom: 0; border-top: 2px solid transparent; width: 100%;
  }
  .den-nav button.on { border-top-color: var(--amber); border-bottom-color: transparent; }
  .nav-full { display: none; }
  .nav-short { display: inline; }
  .den-shell { padding-bottom: calc(4.8rem + env(safe-area-inset-bottom, 0px)); }
  .bal { font-size: .82rem; padding: .35rem .65rem; }
}

@media (max-width: 380px) {
  .mast nav { display: none; }
  h1 { font-size: 1.7rem; }
  .otp { gap: .28rem; }
  .stats { grid-template-columns: 1fr 1fr; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .field { height: min(34vh, 9.5rem); min-height: 6.5rem; margin: .8rem 0 1rem; }
  h1 { font-size: clamp(1.4rem, 5vw, 2rem); }
  .wrap { padding-top: max(.7rem, env(safe-area-inset-top)); padding-bottom: 1.2rem; }
  .lead { display: none; }
  .issue { margin-bottom: .5rem; }
}

@media (hover: hover) and (pointer: fine) {
  .apps a:hover, .pay:hover, .pick label:hover, .act:hover { border-color: var(--amber); }
}
@media (hover: none) {
  .apps a:hover, .pay:hover { border-color: #3a342c; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (prefers-contrast: more) {
  .card, .apps a, .pay, .otp input, .stat { border-width: 2px; }
}
