/* Ink & parchment.
 * Every colour lives here as a custom property; the canvas code reads --ink
 * and --guide off the element, so retheming does not mean touching JS.
 */

:root {
  --paper:   #f4efe4;
  --card:    #fffdf7;
  --ink:     #2b2118;
  --guide:   #d5cab2;
  --rule:    #cbbfa8;
  --muted:   #7d6d57;
  --accent:  #8c2f22;
  --good:    #2c5c2c;
  --mid:     #b07a14;
  --gold:    #a8842c;

  --pad-h: clamp(230px, 42vh, 420px);
  --radius: 10px;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* The wordmark. Pinyon Script is embedded by css/wordmark.css, subset to the
     few characters it needs (19 KB) and inlined as a data URI so it survives
     being opened straight from the filesystem, where a linked font file counts
     as cross-origin and is refused. It is a 19th-century copperplate - the
     actual hand of the documents these signatures came off - which no system
     font gets near. The rest is insurance while it loads or if it fails. */
  --script: "Pinyon Script", "Snell Roundhand", "Apple Chancery", "Segoe Script",
            "Brush Script MT", Gabriola, "Lucida Handwriting", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  /* A faint tooth to the paper. Cheap, and it keeps large flat areas from
     looking like a plain white app. */
  background-image:
    radial-gradient(circle at 20% 30%, rgba(160,140,105,.06) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 65%, rgba(160,140,105,.05) 0 1px, transparent 1px);
  background-size: 37px 37px, 53px 53px;
}

#app {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 18px env(safe-area-inset-bottom);
}

.screen { display: none; }
.screen.on { display: block; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- home */

.masthead { padding: 40px 2px 18px; }
.eyebrow {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
}
.masthead h1 {
  margin: 0;
  font-family: var(--script);
  /* Copperplate carries tall ascenders and deep descenders inside its line box,
     so the leading has to be pulled well under 1 to stop the two words drifting
     apart. The swashes still clear each other at this setting. */
  font-size: clamp(46px, 15vw, 70px);
  font-weight: 400;
  line-height: .82;
  letter-spacing: 0;
  color: var(--ink);
}
.lede {
  margin: 14px 0 0;
  max-width: 34ch;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.55;
}

.tracks { display: grid; gap: 10px; padding: 8px 0 20px; }

.track {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--rule);
  background: var(--card);
  border-radius: var(--radius);
  padding: 15px 16px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color .15s, transform .08s;
}
.track:active { transform: scale(.994); }
.track:hover { border-color: var(--muted); }

.track-top { display: flex; align-items: baseline; gap: 10px; }
.track h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  flex: 1;
}
.track .count {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.track p { margin: 5px 0 11px; font-size: 13px; color: var(--muted); }

.meter { height: 3px; background: #e5dcc8; border-radius: 2px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }

.colophon { padding: 6px 0 32px; }
.linkish {
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 13px;
  text-decoration: underline; text-underline-offset: 3px;
}

/* --------------------------------------------------------------- bars */

.bar {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 22px 0 14px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 12px;
}
.back {
  flex: none;
  width: 38px; height: 38px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.bar-title { flex: 1; min-width: 0; }
.bar-title h2 {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  line-height: 1.15;
}
.bar-title p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

/* -------------------------------------------------------------- track */

.levels { list-style: none; margin: 0; padding: 0 0 34px; }

.level {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.level[disabled] { cursor: default; opacity: .5; background: transparent; }
.level .idx {
  flex: none;
  width: 24px;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.level .who { flex: 1; min-width: 0; }
.level .who b {
  display: block;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.level .who span { font-size: 12px; color: var(--muted); }
.level .score {
  flex: none;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.level .score.done { color: var(--good); font-weight: 700; }
/* Wax-seal dot standing in for a padlock on locked rows. */
.level .score.locked {
  color: transparent;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--rule);
  box-shadow: inset 0 0 0 2px var(--card);
}

.pips { display: flex; gap: 3px; flex: none; }
.pips i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--rule);
}
.pips i.lit { background: var(--accent); }

/* --------------------------------------------------------------- play */

.screen-play.on { display: flex; flex-direction: column; min-height: 100dvh; }
.bar-play { align-items: center; }

.card-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* The card takes back most of the page gutter. A wider card is a bigger
     signature, and a bigger signature is finer effective touch resolution --
     the finger's error is fixed in screen terms while the score is measured in
     signature units. The header and tools keep the normal gutter. */
  margin: 0 -12px;
}

#pad {
  display: block;
  width: 100%;
  height: var(--pad-h);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  /* Without this the browser claims the gesture and the player scrolls the
     page instead of drawing. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* The magnifier. Positioned from JS in viewport coordinates, which is why it is
   fixed and anchored at the origin - the transform does all the moving. */
#loupe {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 15;                 /* over the card, under the result sheet */
  border-radius: 50%;
  pointer-events: none;
  background: var(--card);
  box-shadow: 0 0 0 1px var(--rule), 0 6px 18px rgba(43, 33, 24, .22);
  will-change: transform;
}

.hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  min-height: 1.4em;
}

.tools {
  display: flex;
  gap: 8px;
  padding: 16px 0 max(18px, env(safe-area-inset-bottom));
}
.tool {
  flex: 1;
  padding: 14px 10px;
  font: inherit;
  font-size: 15px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 48px;          /* comfortable thumb target */
}
.tool:disabled { opacity: .4; cursor: default; }
.tool.primary { background: var(--ink); border-color: var(--ink); color: var(--card); flex: 1.5; }
.tool.danger { background: none; border-color: var(--accent); color: var(--accent); flex: none; padding: 10px 16px; }

/* ------------------------------------------------------------- result */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 17, .38);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(14px); opacity: .4 } }

.sheet-inner {
  width: 100%;
  max-width: 620px;
  background: var(--paper);
  border-radius: 16px 16px 0 0;
  border-top: 3px solid var(--ink);
  padding: 20px 18px max(20px, env(safe-area-inset-bottom));
  animation: rise .22s ease-out;
  max-height: 92dvh;
  overflow-y: auto;
}

.verdict {
  margin: 0;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}
.verdict.win { color: var(--good); }
.verdict.lose { color: var(--accent); }

.bigscore {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 62px;
  line-height: 1;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.bigscore i { font-style: normal; font-size: 26px; color: var(--muted); }
.res-need { margin: 4px 0 12px; font-size: 13px; color: var(--muted); }

#res-map {
  display: block;
  width: 100%;
  /* Hard guard: JS sets an explicit pixel width, and measures before the
     sheet's own scrollbar appears, so without this it can overhang. */
  max-width: 100%;
  height: 150px;
  margin: 0 auto;              /* JS narrows it to the signature's aspect */
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.breakdown {
  list-style: none;
  display: flex;
  margin: 12px 0 0;
  padding: 0;
  gap: 8px;
}
.breakdown li {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 6px;
  text-align: center;
}
.breakdown b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.breakdown span { font-size: 11px; color: var(--muted); }

.legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}
.legend i { width: 13px; height: 3px; border-radius: 2px; display: inline-block; }
.sw-good { background: var(--good); }
.sw-mid  { background: var(--mid); }
.sw-bad  { background: var(--accent); }

.readmore { margin: 10px 0 0; font-size: 13px; }
.readmore a { color: var(--accent); text-decoration: none;
              border-bottom: 1px solid rgba(140,47,34,.35); padding-bottom: 1px; }

.sheet-tools { display: flex; gap: 8px; margin-top: 16px; }

/* -------------------------------------------------------------- about */

.prose { padding-bottom: 40px; font-size: 14.5px; line-height: 1.62; }
.prose p { margin: 0 0 13px; max-width: 46ch; }
.prose .quiet { color: var(--muted); font-size: 13px; }
.prose h3 {
  font-family: var(--serif);
  font-size: 16px;
  margin: 26px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.credits { list-style: none; margin: 0; padding: 0; font-size: 11.5px; color: var(--muted); }
.credits li { padding: 5px 0; border-bottom: 1px solid rgba(203,191,168,.45); }
.credits b, .credits .who { color: var(--ink); font-weight: 600; }
.credits a { color: var(--muted); }
.credits .who { text-decoration: none; border-bottom: 1px solid var(--rule); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
