:root {
  --ink: #1d1b26;
  --paper: #f4f3ee;
  --accent: #e4572e;
  --tint: #fbe8e0;
}
html[data-mode="stretch"] {
  --accent: #2f7e6d;
  --tint: #e2efea;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Archivo", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.45;
  transition: background 0.3s;
}

.display {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}

main, .masthead, footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Masthead */
.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  padding-top: 1.25rem;
  padding-bottom: 1.5rem;
}
.wordmark {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  font-size: 1.4rem;
  letter-spacing: 0.02em;
}
.wordmark em {
  font-style: normal;
  color: var(--accent);
  transition: color 0.3s;
}
.tagline {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.65;
}

/* Deck */
.deck h1 {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(1.9rem, 6vw, 3rem);
  line-height: 1.02;
  margin-bottom: 0.75rem;
}
.deck h1 .amp { color: var(--accent); transition: color 0.3s; }
.lede {
  font-size: 1.05rem;
  max-width: 34rem;
  margin-bottom: 1.5rem;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 3px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 5px 5px 0 var(--ink);
  margin-bottom: 1rem;
}
.mode {
  font: inherit;
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  padding: 0.9rem 0;
  background: var(--paper);
  color: var(--ink);
  border: none;
  cursor: pointer;
}
.mode[aria-selected="true"] {
  background: var(--accent);
  color: var(--paper);
}
.mode:focus-visible, .kind:focus-visible, button:focus-visible, .img-link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.length {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.length-kind {
  display: inline-flex;
  border: 2px solid var(--ink);
  border-radius: 9px;
  overflow: hidden;
}
.kind {
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.45rem 0.9rem;
  background: var(--paper);
  border: none;
  cursor: pointer;
}
.kind[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.stepper button {
  font: inherit;
  font-weight: 900;
  font-size: 1.2rem;
  width: 2.4rem;
  height: 2.4rem;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: var(--paper);
  cursor: pointer;
}
.stepper output {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  font-size: 1.5rem;
  min-width: 2.6rem;
  text-align: center;
}

/* The roll */
.roll { display: grid; gap: 0.6rem; margin-bottom: 1.25rem; }
.roll-card {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--tint);
  padding: 0.65rem 0.9rem;
  transition: background 0.3s;
}
.roll-card .group-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
  flex: 0 0 7.5rem;
}
.roll-card .pick {
  font-variation-settings: "wdth" 110;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 1rem;
  flex: 1;
}
.roll-card .pick-target { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.roll-card.rolling .pick { opacity: 0.35; }

.deck-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
}
.reroll {
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 1.2rem;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
}
.start {
  font: inherit;
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  font-size: 1.6rem;
  padding: 0.9rem 0;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--accent);
  color: var(--paper);
  box-shadow: 5px 5px 0 var(--ink);
  cursor: pointer;
  transition: background 0.3s;
}
.start:active, .reroll:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--ink); }

/* Catalog and about */
.catalog, .about, .history { margin-bottom: 2.5rem; }
.catalog h2, .about h2, .history h2 {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  font-size: 1.3rem;
  border-bottom: 3px solid var(--ink);
  padding-bottom: 0.3rem;
  margin-bottom: 1rem;
}
.group { margin-bottom: 1.25rem; }
.group h3 {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}
.group ul, .about ul { list-style: none; }
.group li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
}
.ex-name { font-weight: 600; }
.ex-target { font-size: 0.85rem; opacity: 0.7; margin-left: auto; white-space: nowrap; }
.img-link {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  text-decoration: none;
  border: 1.5px solid var(--accent);
  border-radius: 7px;
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
}
.about li { padding: 0.25rem 0; padding-left: 1.1rem; position: relative; }
.about li::before { content: "—"; position: absolute; left: 0; color: var(--accent); }

/* History */
.history li {
  display: flex;
  gap: 0.75rem;
  padding: 0.3rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 15%, transparent);
}
.history .h-date { opacity: 0.6; flex: 0 0 6.5rem; }
.history .h-mode { font-weight: 700; text-transform: uppercase; font-size: 0.8rem; }

/* Session takeover */
#session {
  position: fixed;
  inset: 0;
  background: var(--ink);
  color: var(--paper);
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  overflow-y: auto;
}
.s-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.85rem;
}
.s-quit {
  font: inherit;
  background: none;
  border: 2px solid var(--paper);
  border-radius: 9px;
  color: var(--paper);
  padding: 0.3rem 0.8rem;
  cursor: pointer;
}
.s-mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 0.75rem;
  padding: 1.5rem 0;
}
.s-group {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.s-name {
  font-variation-settings: "wdth" 122;
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(2rem, 9vw, 3.6rem);
  line-height: 1.02;
}
.s-target { font-size: 1.2rem; font-weight: 600; }
.s-side { font-size: 1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.s-count {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  font-size: clamp(4rem, 22vw, 9rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.s-imglink { align-self: center; }
.s-bottom { display: grid; gap: 0.75rem; }
.s-action {
  font: inherit;
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  font-size: 1.5rem;
  padding: 1rem 0;
  border: 3px solid var(--paper);
  border-radius: 12px;
  background: var(--accent);
  color: var(--paper);
  cursor: pointer;
}
.s-progress { text-align: center; font-size: 0.85rem; opacity: 0.7; }

/* Done screen */
.s-done-title {
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(2.4rem, 10vw, 4rem);
}

footer {
  padding-top: 1rem;
  padding-bottom: 2.5rem;
  font-size: 0.8rem;
  opacity: 0.65;
  border-top: 3px solid var(--ink);
}
footer p { max-width: 40rem; margin-bottom: 0.35rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

#session[hidden] { display: none; }

.roll-card .card-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  align-self: center;
}
.trash {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.7;
}
.trash:hover, .trash:focus-visible { opacity: 1; }
.trash:active { transform: translateY(1px); }
.roll-note {
  display: none;
  flex-basis: 100%;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.75;
}
.roll-note.show { display: block; }

.img-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.28rem;
  line-height: 0;
}

/* Mobile */
html {
  overscroll-behavior-y: none;
}
button, .img-link, .mode, .kind {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
#session {
  padding-top: calc(1.25rem + env(safe-area-inset-top));
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
  padding-left: calc(1.25rem + env(safe-area-inset-left));
  padding-right: calc(1.25rem + env(safe-area-inset-right));
  overscroll-behavior: contain;
}
@media (max-width: 540px) {
  .roll-card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    row-gap: 0.15rem;
    column-gap: 0.6rem;
  }
  .roll-card .group-label { flex: none; grid-column: 1; grid-row: 1; }
  .roll-card .pick { grid-column: 1; grid-row: 2; font-size: 1.05rem; }
  .roll-card .pick-target { grid-column: 2; grid-row: 2; justify-self: end; }
  .roll-card .card-actions { grid-column: 2; grid-row: 1; justify-self: end; }
  .roll-card .roll-note { grid-column: 1 / -1; grid-row: 3; }
  .group li { flex-wrap: wrap; }
  .stepper button { width: 2.75rem; height: 2.75rem; }
}

/* Install nudge */
.install-nudge {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 50;
  padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  align-items: center; justify-content: space-between;
  background: var(--paper);
  color: var(--ink);
  border-top: 3px solid var(--ink);
}
.install-nudge-text { font-weight: 600; }
.install-nudge-actions { display: flex; gap: 0.6rem; }
.install-nudge-yes {
  font: inherit;
  font-variation-settings: "wdth" 125;
  font-weight: 900;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--accent);
  color: var(--paper);
  cursor: pointer;
}
.install-nudge-no {
  font: inherit;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
/* Keep the Done screen's Back button reachable while the bar is up. */
body:has(.install-nudge) #session { padding-bottom: calc(7rem + env(safe-area-inset-bottom)); }
@media (prefers-reduced-motion: no-preference) {
  .install-nudge { animation: install-nudge-in 220ms ease-out; }
}
@keyframes install-nudge-in { from { transform: translateY(100%); } to { transform: none; } }

footer [data-install-link] {
  font: inherit;
  font-weight: 700;
  margin-top: 0.5rem;
  padding: 0.35rem 0.8rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
