:root {
  --paper: #f2eee4;
  --paper-2: #e9e4d6;
  --ink: #1b1a17;
  --ink-2: #57534a;
  --rule: #1b1a17;
  --faint: #cfc8b6;
  --red: #c8321f;
  --green: #1f6b3a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  font: 17px/1.55 var(--serif);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--red); }

code, .mono { font-family: var(--mono); font-size: .85em; }

.page {
  width: min(760px, 100% - 2.5rem);
  margin: 0 auto;
  padding: clamp(2rem, 7vw, 4.5rem) 0 3rem;
}

/* Masthead */
.masthead {
  border-top: 6px solid var(--rule);
  padding-top: 1rem;
  margin-bottom: 2rem;
}

.form-id {
  font: .78rem var(--mono);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
}

h1 {
  font-size: clamp(2.1rem, 7vw, 3.6rem);
  line-height: 1.02;
  font-weight: 400;
  letter-spacing: -.015em;
  margin: .6rem 0 1.2rem;
}

.intro { max-width: 36em; margin: 0; }

.demo-note {
  margin: 1rem 0 0;
  padding: .6rem .8rem;
  border-left: 4px solid var(--red);
  background: var(--paper-2);
  font-size: .92rem;
}

/* Attempt sheet */
.attempt {
  position: relative;
  border: 1.5px solid var(--rule);
  background: #f8f5ee;
  padding: 0 1.1rem 1.1rem;
  overflow: hidden;
}

.attempt-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font: .8rem var(--mono);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1.5px solid var(--rule);
  margin: 0 -1.1rem 1rem;
  padding: .55rem 1.1rem;
}

.field { margin-bottom: 1rem; }

.field-label {
  font-size: .85rem;
  color: var(--ink-2);
  border-bottom: 1px solid var(--faint);
  padding-bottom: .2rem;
  margin-bottom: .45rem;
}

.digits {
  font: .72rem/1.5 var(--mono);
  word-break: break-all;
  color: var(--ink);
  max-height: 7.5em;
  overflow: auto;
}
#candidate { height: 7.5em; }
.digits.big { font-size: 1.4rem; line-height: 1.2; max-height: 2.4em; }
.digits.rolling { color: var(--ink-2); }

/* Fixed heights keep the button below from moving as messages change. */
.verdict {
  margin: .4rem 0 0;
  height: 3.1em;
  font-style: italic;
}

.result { position: relative; }

/* Rubber stamp */
.stamp {
  position: absolute;
  right: .2rem;
  top: 1.6rem;
  font: 700 clamp(1.1rem, 4vw, 1.6rem) var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--red);
  border: 3px solid currentColor;
  padding: .15rem .6rem;
  transform: rotate(-8deg);
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.stamp.on { animation: stamp .22s ease-out forwards; }
.stamp.good { color: var(--green); }

@keyframes stamp {
  from { opacity: 0; transform: rotate(-8deg) scale(1.6); }
  to   { opacity: .85; transform: rotate(-8deg) scale(1); }
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin: 1.4rem 0 2.8rem;
}

#crack {
  flex: none;
  font: 600 1.05rem var(--serif);
  color: var(--paper);
  background: var(--ink);
  border: 0;
  padding: .95rem 1.6rem;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--red);
  transition: transform .08s, box-shadow .08s;
}
#crack:hover { background: #000; }
#crack:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--red); }
#crack:focus-visible { outline: 2px solid var(--red); outline-offset: 4px; }
#crack:disabled { cursor: wait; opacity: .75; }

.tally {
  display: flex;
  flex-direction: column;
  font-size: .9rem;
  color: var(--ink-2);
}
.tally b { color: var(--ink); font-family: var(--mono); }

/* Win */
.win {
  border: 3px double var(--green);
  background: #eef3e8;
  padding: 1.2rem 1.3rem;
  margin: -1.2rem 0 2.8rem;
}
.win h2 { font-weight: 400; font-size: 2rem; margin: 0 0 .5rem; color: var(--green); }
.win h3 { font-size: 1rem; margin: 1.4rem 0 .4rem; }
.win ol { margin: 0; padding-left: 1.3rem; }
.win li { margin-bottom: .35rem; }
.win .digits { max-height: 10em; }

.copy, .link-btn {
  font: .75rem var(--mono);
  background: none;
  border: 1px solid var(--ink-2);
  color: var(--ink);
  padding: .1rem .45rem;
  margin-left: .5rem;
  cursor: pointer;
}
.copy:hover, .link-btn:hover { border-color: var(--ink); background: var(--paper); }
.link-btn { margin: 1.2rem 0 0; }

/* Notes */
.notes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  border-top: 1.5px solid var(--rule);
  padding-top: 1.2rem;
}

.note h2 {
  font: .8rem var(--mono);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 0 0 .7rem;
}
.note p { margin: 0 0 .8rem; font-size: .95rem; }
.small { font-size: .88rem; }

table { border-collapse: collapse; width: 100%; font-size: .9rem; margin-bottom: .8rem; }
th, td { text-align: left; vertical-align: top; padding: .3rem 0; border-bottom: 1px solid var(--faint); }
th { font-weight: 400; color: var(--ink-2); padding-right: 1rem; white-space: nowrap; }
td.mono { font-size: .72rem; line-height: 1.6; }

.modulus {
  margin-top: 2rem;
  border-top: 1px solid var(--faint);
  padding-top: .8rem;
}
.modulus summary { cursor: pointer; font-size: .95rem; }
.modulus .digits { margin-top: .8rem; max-height: none; }

footer {
  margin-top: 2.5rem;
  font-size: .85rem;
  color: var(--ink-2);
}

@media (max-width: 640px) {
  body { font-size: 16px; }
  .controls { flex-direction: column; align-items: stretch; gap: .9rem; }
  #crack { width: 100%; }
  .tally { text-align: center; }
  .notes { grid-template-columns: 1fr; gap: 1.2rem; }
  .verdict { height: 4.65em; }
}

@media (prefers-reduced-motion: reduce) {
  .stamp.on { animation: none; opacity: .85; }
}
