/* ==========================================================================
   THE RECORDS CLERK — visual system (Companion v2).
   Same family as the ledger of the Guild: aged paper, iron-gall ink, ONE
   accent of sealing-wax red — plus the Clerk's own fitting: counter brass.
   Mobile-first. One action at a time. The sheets remain the record.
   ========================================================================== */

:root {
  --paper:        #e9dfc8;
  --paper-hi:     #f2ead6;
  --paper-dk:     #ddd0b2;
  --paper-shadow: #c8b993;
  --ink:          #262119;
  --ink-soft:     #4c4335;
  --ink-faint:    #8a7d66;
  --rule:         #b9aa88;
  --rule-blue:    #8fa89e;
  --wax:          #a5341f;
  --wax-bright:   #c04326;
  --wax-dim:      #7c2717;
  --brass:        #8a6f2f;
  --brass-hi:     #c9ad64;
  --counter:      #262119;
  --ok:           #4c5b3f;

  --f-display: 'Alfa Slab One', 'Georgia', serif;
  --f-body:    'Spectral', 'Georgia', serif;
  --f-fell:    'IM Fell English', 'Georgia', serif;
  --f-mono:    'IBM Plex Mono', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }

body {
  font-family: var(--f-body);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.2 0 0 0 0 0.17 0 0 0 0 0.12 0 0 0 0.045 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#clerk { flex: 1; display: flex; flex-direction: column; width: 100%; }

/* ------------------------------------------------------ counter bar ----- */
#counterbar {
  /* Above the drawers (z 60): the mute control stays visible AND reachable on
     every screen, drawers included — sound guide rule R2. */
  position: sticky; top: 0; z-index: 70;
  display: flex; align-items: center; gap: .4rem;
  background: var(--counter);
  border-bottom: 2px solid var(--brass);
  padding: .45rem .6rem;
  padding-top: calc(.45rem + env(safe-area-inset-top, 0px));
}
.cb-status {
  flex: 1; min-width: 0;
  font-family: var(--f-mono); font-size: .62rem; letter-spacing: .14em;
  color: var(--brass-hi); text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cb-btn {
  flex: 0 0 auto;
  font-family: var(--f-mono); font-size: .8rem; line-height: 1;
  color: var(--brass-hi); background: transparent;
  border: 1px solid var(--brass); border-radius: 3px;
  min-width: 40px; min-height: 40px; padding: .3rem .5rem;
  cursor: pointer; box-shadow: none;
}
.cb-btn:active { background: rgba(201, 173, 100, .18); transform: none; box-shadow: none; }
.cb-btn.lit { background: var(--brass); color: var(--counter); font-weight: 600; }

/* ------------------------------------------------------------ boot ------ */
.boot { margin: 18vh auto 0; text-align: center; }
.boot-stamp {
  font-family: var(--f-mono); font-weight: 600; letter-spacing: .35em;
  color: var(--wax); border: 3px double var(--wax); display: inline-block;
  padding: .6rem 1.4rem; transform: rotate(-2deg); opacity: .85;
}
.boot-sub { margin-top: 1rem; font-family: var(--f-fell); font-style: italic; color: var(--ink-soft); }

/* ------------------------------------------------------------ desk ------ */
#desk {
  flex: 1; width: 100%; max-width: 620px; margin: 0 auto;
  padding: .9rem .8rem 5.5rem;
}

/* ------------------------------------------------------------ footer ---- */
#clerk-footer {
  padding: .55rem 1rem calc(.55rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-family: var(--f-mono); font-size: .62rem; color: var(--ink-faint);
  border-top: 1px solid var(--rule);
}

/* ------------------------------------------------------------ cards ----- */
.card {
  background: var(--paper-hi);
  border: 1.5px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(38, 33, 25, .25);
  padding: .85rem .95rem;
  margin: .8rem 0;
  opacity: 0; transform: translateY(7px);
  transition: opacity .3s ease, transform .3s ease;
}
.card.revealed { opacity: 1; transform: none; }
.card.waxline { border-color: var(--wax); box-shadow: 3px 3px 0 rgba(165, 52, 31, .3); }
.card.dim { opacity: .55; }

.kicker {
  font-family: var(--f-mono); font-size: .6rem; font-weight: 600;
  letter-spacing: .2em; color: var(--wax); text-transform: uppercase;
  margin-bottom: .3rem;
}
.kicker .tag {
  display: inline-block; margin-left: .45rem; padding: .05rem .4rem;
  border: 1.5px solid var(--brass); color: var(--brass);
  transform: rotate(-1deg); letter-spacing: .14em;
}
.card-name {
  font-family: var(--f-display); font-size: 1.25rem; line-height: 1.15;
  letter-spacing: .01em; margin: .15rem 0 .3rem;
}
.flavor { font-family: var(--f-fell); font-style: italic; color: var(--ink-soft); margin: .35rem 0; line-height: 1.45; }
.line { margin: .4rem 0; line-height: 1.5; font-size: .95rem; }
.smallprint {
  font-family: var(--f-mono); font-size: .62rem; color: var(--ink-faint);
  line-height: 1.55; margin-top: .45rem;
}
.divider { border: none; border-top: 1px dashed var(--rule); margin: .7rem 0; }

/* ----------------------------------------------- pencil-work blocks ----- */
.pencil {
  margin: .6rem 0; padding: .6rem .7rem .65rem;
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent 22px, rgba(143, 168, 158, .35) 22px, rgba(143, 168, 158, .35) 23px),
    #f5efdd;
  border: 1.5px solid var(--ink);
  border-left: 5px solid var(--wax);
}
.pencil-k {
  font-family: var(--f-mono); font-size: .6rem; font-weight: 600;
  letter-spacing: .22em; color: var(--wax); margin-bottom: .3rem;
}
.pencil .line { font-size: .97rem; }
.pencil b { letter-spacing: .01em; }

/* ------------------------------------------------------------ stamps ---- */
.stamp {
  display: inline-block; font-family: var(--f-mono); font-weight: 600;
  letter-spacing: .25em; color: var(--wax); border: 3px double var(--wax);
  padding: .3rem .9rem; transform: rotate(-3deg);
  mix-blend-mode: multiply; opacity: .9; font-size: .78rem;
}
@keyframes stampIn {
  0%   { transform: rotate(-3deg) scale(2.4); opacity: 0; }
  60%  { transform: rotate(-3deg) scale(.95); opacity: 1; }
  100% { transform: rotate(-3deg) scale(1);  opacity: .9; }
}
.stamp.animate { animation: stampIn .38s cubic-bezier(.2, 1.4, .4, 1) both; }
.stamp.brassy { color: var(--brass); border-color: var(--brass); }
.stamp-row { text-align: center; margin: .5rem 0 .2rem; }

/* ------------------------------------------------------------ buttons --- */
button {
  font-family: var(--f-body); font-size: .95rem; cursor: pointer;
  color: var(--ink); background: var(--paper-hi);
  border: 1.5px solid var(--ink);
  padding: .55rem 1rem;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform .06s ease, box-shadow .06s ease, background .12s;
  min-height: 44px;
}
button:hover { background: #fff6e0; }
button:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
button.primary {
  background: var(--wax); color: var(--paper-hi); border-color: var(--wax-dim);
  box-shadow: 2px 2px 0 var(--wax-dim);
  font-weight: 600; letter-spacing: .04em;
}
button.primary:hover { background: var(--wax-bright); }
button.ghost {
  background: transparent; box-shadow: none; border: 1px dashed var(--ink-soft);
  font-size: .85rem; min-height: 38px;
}
button.linky {
  background: none; border: none; box-shadow: none; min-height: 0;
  font-family: var(--f-mono); font-size: .68rem; color: var(--ink-faint);
  text-decoration: underline; padding: .25rem .3rem;
}
button:disabled { opacity: .4; cursor: not-allowed; }
button.chosen { outline: 2px solid var(--wax); outline-offset: 1px; }

.btnrow { display: flex; flex-direction: column; gap: .55rem; margin: .6rem 0 .2rem; }
.btnrow.wrap { flex-direction: row; flex-wrap: wrap; }
.btnrow button { width: 100%; text-align: center; }
.btnrow.wrap button { width: auto; flex: 1 1 auto; }

/* ------------------------------------------------------------ dice ------ */
.dicebox { margin: .6rem 0 .2rem; padding: .65rem .7rem; border: 1px dashed var(--ink-faint); background: rgba(245, 239, 221, .6); }
.dice-label { font-family: var(--f-mono); font-size: .64rem; font-weight: 600; letter-spacing: .16em; margin-bottom: .5rem; }
.dice-row { display: flex; gap: .7rem; align-items: center; justify-content: center; min-height: 58px; }
.die {
  width: 54px; height: 54px; background: #f7f1de; border: 2px solid var(--ink);
  border-radius: 9px; display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 7px; box-shadow: 1px 2px 0 rgba(38, 33, 25, .4);
}
.die .pip { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); align-self: center; justify-self: center; visibility: hidden; }
.die.wax .pip { background: var(--wax); }
.die.rolling { animation: tumble .13s linear infinite; }
@keyframes tumble {
  0%   { transform: rotate(-7deg) translateY(0); }
  50%  { transform: rotate(6deg) translateY(-4px); }
  100% { transform: rotate(-7deg) translateY(0); }
}
.dice-total { font-family: var(--f-mono); font-size: .8rem; font-weight: 600; text-align: center; margin-top: .5rem; min-height: 1.2em; }
.dice-tapline { text-align: center; margin-top: .4rem; }
.dice-tapline button { width: 100%; }

/* manual entry pips — real dice faces (drawn with the same pip grid as the
   animated dice), one button per face. */
.padgroup { margin: .3rem 0; }
.padgroup .plbl { font-family: var(--f-mono); font-size: .6rem; letter-spacing: .16em; color: var(--ink-faint); display: block; margin-bottom: .3rem; }
.pips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.pipbtn {
  width: 48px; height: 48px; min-height: 44px; padding: 0;
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
}
/* the die shown inside a button: smaller than the tumbling dice, no drop shadow */
.die.face {
  width: 34px; height: 34px; border-width: 1.5px; border-radius: 5px;
  padding: 4px; box-shadow: none; pointer-events: none;
}
.die.face .pip { width: 5px; height: 5px; }
.pipbtn.on { background: var(--ink); border-color: var(--ink); }
.pipbtn.on .die.face { box-shadow: 0 0 0 1.5px var(--paper); }

/* ------------------------------------------------------------ trackers -- */
.trackrow { display: flex; gap: .6rem; flex-wrap: wrap; margin: .55rem 0; }
.tracker {
  border: 1.5px solid var(--ink); background: #f5efdd; padding: .45rem .6rem;
  text-align: center; flex: 1 1 40%;
}
.tracker .tlbl { font-family: var(--f-mono); font-size: .58rem; letter-spacing: .16em; color: var(--ink-faint); display: block; margin-bottom: .25rem; }
.tracker .tnum { font-family: var(--f-mono); font-size: 1.35rem; font-weight: 600; margin: 0 .55rem; display: inline-block; min-width: 2.4em; }
.tracker .tmax { font-size: .8rem; color: var(--ink-faint); }
.tracker button { min-height: 36px; width: 36px; padding: 0; font-weight: 700; box-shadow: 1px 1px 0 var(--ink); }
.tickboxes { display: flex; gap: 4px; justify-content: center; margin-top: .35rem; flex-wrap: wrap; }
.tickboxes i { width: 13px; height: 13px; border: 1.5px solid var(--ink); display: inline-block; }
.tickboxes i.x { background: var(--wax); border-color: var(--wax); }

.bigclock {
  font-family: var(--f-mono); font-size: 2.4rem; font-weight: 600; letter-spacing: .05em;
  border: 3px double var(--brass); color: var(--brass);
  background: #f5efdd; display: inline-block; padding: .1rem 1.1rem;
}

/* ------------------------------------------------------------ stats ----- */
.statrow { display: flex; gap: .45rem; flex-wrap: wrap; margin: .5rem 0; }
.statchip {
  border: 1.5px solid var(--ink); background: #f5efdd;
  padding: .28rem .55rem; font-family: var(--f-mono); font-size: .76rem;
  text-align: center; min-width: 64px; flex: 0 1 auto;
}
.statchip .lbl { display: block; font-size: .55rem; letter-spacing: .16em; color: var(--ink-faint); }
.statchip .val { font-size: 1rem; font-weight: 600; }
.statchip .was { color: var(--ink-faint); text-decoration: line-through; font-weight: 400; font-size: .8rem; margin-right: .25rem; }
.statchip.adjusted { border-color: var(--wax); }
.statchip.adjusted .val { color: var(--wax); }
.adjust-note { font-family: var(--f-mono); font-size: .62rem; color: var(--wax); margin: .25rem 0; }

/* ------------------------------------------------------------ banners --- */
.banner {
  border: 2px solid var(--wax); color: var(--wax-dim); background: rgba(165, 52, 31, .07);
  font-weight: 600; padding: .55rem .7rem; margin: .6rem 0; line-height: 1.45; font-size: .93rem;
}
.banner.calm { border-color: var(--ok); color: var(--ok); background: rgba(76, 91, 63, .08); }

/* ------------------------------------------------------------ home ------ */
.masthead { text-align: center; padding: 1.1rem 0 .4rem; }
.mast-guild { font-family: var(--f-mono); font-size: .62rem; letter-spacing: .4em; color: var(--ink-soft); text-transform: uppercase; }
.mast-title {
  font-family: var(--f-display); font-size: clamp(1.7rem, 7.5vw, 2.6rem);
  line-height: 1.05; margin: .35rem 0 .15rem; color: var(--ink);
  text-shadow: 2px 2px 0 var(--paper-shadow);
}
.mast-title .u { color: var(--wax); }
.mast-sub { font-family: var(--f-fell); font-style: italic; color: var(--ink-soft); font-size: 1rem; margin-top: .2rem; }

.delve-card { cursor: pointer; }
.delve-card:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(38, 33, 25, .25); }
.delve-meta { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .4rem; }
.delve-meta span {
  font-family: var(--f-mono); font-size: .6rem; letter-spacing: .1em;
  border: 1px solid var(--rule); padding: .15rem .4rem; color: var(--ink-soft);
}

/* checklist */
.checklist { list-style: none; margin: .4rem 0; }
.checklist li { padding: .22rem 0 .22rem 1.5rem; position: relative; line-height: 1.45; }
.checklist li::before {
  content: '☐'; position: absolute; left: .1rem; top: .18rem;
  font-family: var(--f-mono); color: var(--wax); font-weight: 600;
}

/* ------------------------------------------------------------ tables ---- */
.scrollx { overflow-x: auto; }
table.ledger { border-collapse: collapse; width: 100%; margin: .5rem 0; font-size: .82rem; }
table.ledger th {
  font-family: var(--f-mono); font-size: .58rem; letter-spacing: .12em; text-align: left;
  border-bottom: 2px solid var(--ink); padding: .3rem .4rem; text-transform: uppercase;
}
table.ledger td { border-bottom: 1px solid var(--rule-blue); padding: .35rem .4rem; vertical-align: top; }
table.ledger tr td:first-child { font-weight: 600; }

/* ------------------------------------------------------------ drawer ---- */
#drawer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(38, 33, 25, .5);
}
#drawer[hidden] { display: none; }
.drawer-pane {
  position: absolute; left: 0; right: 0; bottom: 0; top: 7vh;
  background: var(--paper);
  border-top: 3px solid var(--ink);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .35);
  display: flex; flex-direction: column;
  animation: drawerUp .22s ease-out;
  max-width: 680px; margin: 0 auto;
}
@keyframes drawerUp { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .9rem; border-bottom: 2px solid var(--ink); background: var(--paper-dk);
}
.drawer-title { flex: 1; font-family: var(--f-mono); font-size: .7rem; font-weight: 600; letter-spacing: .22em; }
.drawer-body { flex: 1; overflow-y: auto; padding: .6rem .9rem 2.2rem; -webkit-overflow-scrolling: touch; }
.drawer-close { min-height: 40px; }

/* records accordions */
details.rec { margin: .55rem 0; border: 1px solid var(--rule); background: var(--paper-hi); }
details.rec summary {
  cursor: pointer; font-family: var(--f-mono); font-size: .66rem; font-weight: 600;
  letter-spacing: .18em; padding: .65rem .8rem; list-style: none; text-transform: uppercase;
}
details.rec summary::-webkit-details-marker { display: none; }
details.rec summary::before { content: '▸ '; color: var(--wax); }
details.rec[open] summary::before { content: '▾ '; }
details.rec > div { padding: 0 .8rem .8rem; }
.rec-item { border-top: 1px dashed var(--rule); padding: .5rem 0; }
.rec-item .rn { font-weight: 700; }
.rec-item .rk { font-family: var(--f-mono); font-size: .6rem; color: var(--ink-faint); letter-spacing: .1em; }
.rec-item .rt { font-size: .88rem; line-height: 1.45; margin-top: .15rem; }

/* settings rows */
.set-row { border: 1px solid var(--rule); background: var(--paper-hi); padding: .7rem .8rem; margin: .6rem 0; }
.set-lbl { font-family: var(--f-mono); font-size: .62rem; font-weight: 600; letter-spacing: .2em; margin-bottom: .45rem; text-transform: uppercase; }
.set-fine { font-family: var(--f-mono); font-size: .6rem; color: var(--ink-faint); margin-top: .4rem; line-height: 1.5; }

/* ------------------------------------------------------------ misc ------ */
.shake { animation: shake .3s ease; }
@keyframes shake {
  0%, 100% { transform: none; } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); }
}
.center { text-align: center; }

/* --------------------- value-change pulses (r4 backport) ----------------- */
/* Only the ADVERSARY'S books live on this screen (wounds, arrears, the brass
   counter) — so only the red half of the ledger's inks applies: bad news
   blinks red-ink, twice. Nothing neon; same figures, same fonts — only the
   ink flashes. Your own gold and fatigue live on paper and pulse nowhere. */
.tracker .tnum.px-bad { animation: pxNumBad .27s ease-out 2; }
.bigclock.px-bad { animation: pxClockBad .27s ease-out 2; }
@keyframes pxNumBad {
  0%   { color: var(--wax-bright); transform: scale(1.3); }
  55%  { color: var(--wax-bright); }
  100% { transform: none; }
}
@keyframes pxClockBad {
  0%   { color: var(--wax-bright); border-color: var(--wax-bright); transform: scale(1.08); }
  55%  { color: var(--wax-bright); }
  100% { transform: none; }
}

/* prefers-reduced-motion (hard rule): the pulses are killed — the value
   simply changes. Scoped to the new pulses; the ratified reveal/stamp
   motion keeps its own approved behavior. */
@media (prefers-reduced-motion: reduce) {
  .tracker .tnum.px-bad, .bigclock.px-bad { animation: none !important; }
}

@media (min-width: 700px) {
  #desk { padding-top: 1.4rem; }
  .btnrow { flex-direction: row; flex-wrap: wrap; }
  .btnrow button { width: auto; flex: 0 1 auto; }
}
