:root {
  --paper: #f6f3ee;
  --wall: #ece7df;
  --ink: #1c1b19;
  --ink-soft: #5d5850;
  --rule: #cfc8bc;
  --accent: #c8452c;
  --common: #6f6a62;
  --rare: #2f5d9b;
  --legendary: #a8822a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; }
p { margin: 0; }
a { color: inherit; text-underline-offset: 3px; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 48px) 14px;
  border-bottom: 1px solid var(--ink);
}
.masthead h1 { font-size: clamp(1.7rem, 5vw, 2.6rem); line-height: 1.05; letter-spacing: -0.01em; }
.masthead-nav { display: flex; flex-wrap: wrap; gap: 6px clamp(12px, 3vw, 28px); justify-content: flex-end; }
.brand { min-width: 0; }

.link-button {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--ink);
  padding: 6px 0 3px;
  font-size: 0.95rem;
  white-space: nowrap;
}
.link-button:hover { color: var(--accent); border-color: var(--accent); }
.count { font-variant-numeric: tabular-nums; color: var(--ink-soft); margin-left: 4px; }

/* ---------- floor ---------- */

.floor {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  padding: 16px clamp(16px, 4vw, 48px) 32px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

.machine { display: flex; flex-direction: column; align-items: center; min-width: 0; }

.stage {
  width: min(100%, 520px, calc(58vh * 600 / 640));
  width: min(100%, 520px, calc(58dvh * 600 / 640));
  aspect-ratio: 600 / 640;
}
.stage canvas { display: block; width: 100% !important; height: 100% !important; margin: 0 !important; touch-action: manipulation; }

.controls { display: grid; justify-items: center; gap: 8px; margin-top: 8px; text-align: center; }
.tokens { font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.tokens strong { font-family: var(--serif); font-size: 1.3rem; font-weight: 500; }
.tokens .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.status { min-height: 1.5em; font-size: 0.9rem; color: var(--ink-soft); max-width: 34ch; }

.primary {
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  padding: 13px 28px;
  font-size: 1rem;
  letter-spacing: 0.04em;
  min-width: min(100%, 260px);
}
.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.primary:disabled { background: transparent; color: var(--ink-soft); border-color: var(--rule); }

.secondary {
  background: none;
  border: 1px solid var(--ink);
  padding: 10px 18px;
  font-size: 0.95rem;
}
.secondary:hover { background: var(--ink); color: var(--paper); }

/* ---------- wall (side panels) ---------- */

.wall { display: grid; gap: 22px; align-content: start; min-width: 0; }
.panel { border-top: 1px solid var(--ink); padding-top: 10px; }
.panel h2 { font-size: 1.05rem; margin-bottom: 10px; }
.summary { font-size: 0.92rem; color: var(--ink-soft); }
.summary button { margin-left: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(28, 27, 25, 0.35); flex: none; }
.chip[aria-pressed="true"] .swatch { border-color: var(--paper); }

.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.recent li { border-bottom: 1px solid var(--rule); }
.recent button {
  width: 100%;
  background: none;
  border: 0;
  padding: 8px 0;
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: baseline;
}
.recent button:hover .recent-title { color: var(--accent); }
.recent-title { font-family: var(--serif); font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { font-size: 0.75rem; color: var(--ink-soft); white-space: nowrap; }
.empty { color: var(--ink-soft); font-size: 0.92rem; }

.rarity-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--common); flex: none; }
.rarity-dot.rare { background: var(--rare); }
.rarity-dot.legendary { background: var(--legendary); }

/* ---------- colophon ---------- */

.colophon {
  border-top: 1px solid var(--rule);
  padding: 14px clamp(16px, 4vw, 48px) 22px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  display: grid;
  gap: 4px;
}
.noscript { padding: 24px; text-align: center; }

/* ---------- dialogs ---------- */

dialog.sheet {
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 0;
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog.sheet.wide { width: min(980px, calc(100vw - 24px)); }
dialog.sheet::backdrop { background: rgba(28, 27, 25, 0.55); }

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--paper);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--ink);
}
.sheet-head h2 { font-size: 1.6rem; line-height: 1.1; }
dialog h2:focus { outline: none; }
.sheet-body { padding: 18px 22px 22px; display: grid; gap: 22px; }
.sheet-foot {
  position: sticky;
  bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  padding: 12px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.sheet-foot .hint { margin-right: auto; font-size: 0.85rem; color: var(--ink-soft); }
.lede { color: var(--ink-soft); max-width: 56ch; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-family: var(--serif); font-size: 1.1rem; padding: 0; margin-bottom: 4px; }
.field-hint { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 10px; }

/* ---------- product card ---------- */

.card { display: grid; grid-template-columns: minmax(0, 1fr); }
.plate {
  margin: 0;
  background: var(--wall);
  display: grid;
  border-bottom: 1px solid var(--ink);
}
.plate-frame { aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden; padding: 18px; }
.plate img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; box-shadow: 0 10px 24px -14px rgba(28, 27, 25, 0.6); background: #fff; }
.plate-blank { display: grid; place-items: center; gap: 6px; text-align: center; color: var(--ink-soft); }
.plate-blank .glyph { font-family: var(--serif); font-size: clamp(4.5rem, 20vw, 8rem); line-height: 1; color: var(--ink); font-style: italic; }
.plate-blank .plate-word { font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase; }
.plate figcaption[hidden] { display: none; }
.plate figcaption { font-size: 0.7rem; color: var(--ink-soft); padding: 0 14px 8px; text-align: right; }

.label { padding: 18px 22px 22px; display: grid; gap: 12px; align-content: start; }
.label h2 { font-size: clamp(1.6rem, 5vw, 2.1rem); line-height: 1.1; }
.label .eyebrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rarity-word { font-weight: 600; color: var(--common); }
.card.rare .rarity-word { color: var(--rare); }
.card.legendary .rarity-word { color: var(--legendary); }
.card { border-top: 6px solid var(--common); }
.card.rare { border-top-color: var(--rare); }
.card.legendary { border-top-color: var(--legendary); }
.about { font-size: 0.95rem; color: var(--ink-soft); margin-top: -6px; }
.note { font-size: 0.88rem; color: var(--accent); }
.blurb { font-family: var(--serif); font-size: 1.08rem; line-height: 1.5; }
.quote { margin: 2px 0 0; padding: 2px 0 2px 16px; border-left: 2px solid var(--accent); }
.quote blockquote { margin: 0; font-family: var(--serif); font-style: italic; font-size: 1.02rem; line-height: 1.45; }
.quote figcaption { margin-top: 6px; font-size: 0.8rem; color: var(--ink-soft); }
.quote cite { font-style: italic; }
.tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { border: 1px solid var(--rule); border-radius: 999px; padding: 2px 10px; font-size: 0.78rem; color: var(--ink-soft); }
.why { font-size: 0.85rem; color: var(--ink-soft); }
.links { display: flex; flex-wrap: wrap; gap: 6px 18px; border-top: 1px solid var(--rule); padding-top: 12px; }
.links a { font-size: 0.95rem; white-space: nowrap; }
.links a:hover { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.actions .primary { min-width: 0; flex: 1 1 200px; white-space: nowrap; }
.actions .secondary { white-space: nowrap; flex: 1 1 auto; }

/* ---------- collection ---------- */

.stats { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 0.9rem; color: var(--ink-soft); }
.stats strong { font-family: var(--serif); font-size: 1.25rem; font-weight: 500; color: var(--ink); margin-right: 4px; }
.chip .progress { font-size: 0.75rem; opacity: 0.7; font-variant-numeric: tabular-nums; }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px; }
.tile {
  width: 100%;
  background: none;
  border: 1px solid var(--rule);
  padding: 0;
  text-align: left;
  display: grid;
}
.tile:hover { border-color: var(--ink); }
.tile-plate { aspect-ratio: 1; background: var(--wall); display: grid; place-items: center; overflow: hidden; }
.tile-plate img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-plate .glyph { font-family: var(--serif); font-size: 3rem; font-style: italic; }
.tile-label { padding: 8px 10px 10px; display: grid; gap: 2px; }
.tile-title { font-family: var(--serif); font-size: 0.95rem; line-height: 1.2; }
.tile-meta { font-size: 0.72rem; color: var(--ink-soft); display: flex; gap: 6px; align-items: center; }

/* ---------- wider screens ---------- */

@media (min-width: 900px) {
  .floor { grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr); gap: 48px; padding-top: 28px; }
  .wall { padding-top: 12px; }
  .card { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .plate { border-bottom: 0; border-right: 1px solid var(--ink); align-content: center; }
  dialog.sheet.card-sheet { width: min(900px, calc(100vw - 24px)); }
}

@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: rise 0.28s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(14px); } }
}

/* ---------- timing gauge ---------- */

.gauge { position: relative; width: min(100%, 360px); height: 18px; border: 1px solid var(--ink); background: var(--wall); overflow: hidden; }
.gauge-good, .gauge-perfect { position: absolute; top: 0; bottom: 0; left: 40%; width: 20%; }
.gauge-good { background: rgba(47, 93, 155, 0.25); }
.gauge-perfect { background: var(--legendary); left: 47%; width: 6%; }
.gauge-needle { position: absolute; top: -3px; bottom: -3px; left: 0; width: 3px; margin-left: -1.5px; background: var(--ink); }
.gauge:not(.live) .gauge-good, .gauge:not(.live) .gauge-perfect { opacity: 0.35; }
.gauge-verdict { min-height: 1.4em; font-family: var(--serif); font-size: 1.05rem; letter-spacing: 0.14em; text-transform: uppercase; }
.gauge-verdict.perfect { color: var(--legendary); }
.gauge-verdict.good { color: var(--rare); }
.gauge-verdict.miss { color: var(--ink-soft); }
.gauge-verdict.pop { animation: pop 0.45s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } }
.primary.aiming { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.hint-line { font-size: 0.78rem; color: var(--ink-soft); max-width: 40ch; }
kbd { font-family: var(--sans); font-size: 0.75rem; border: 1px solid var(--rule); border-bottom-width: 2px; padding: 0 5px; border-radius: 3px; background: #fff; }
.combo { color: var(--accent); font-weight: 600; }

/* ---------- meters, fever, level, missions ---------- */

.meter { position: relative; height: 8px; background: var(--wall); border: 1px solid var(--rule); overflow: hidden; }
.meter-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--ink); transition: width 0.4s ease; }
.fever { display: grid; grid-template-columns: auto minmax(110px, 220px) auto; align-items: center; gap: 10px; font-size: 0.8rem; }
.fever-label { letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-soft); }
.fever-text { color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 9ch; }
.fever .meter-fill { background: var(--accent); }
.fever.on .meter { border-color: var(--accent); }
.fever.on .meter-fill { animation: throb 0.5s ease-in-out infinite alternate; }
.fever.on .fever-label, .fever.on .fever-text { color: var(--accent); font-weight: 600; }
@keyframes throb { from { opacity: 0.5; } to { opacity: 1; } }

.level { font-family: var(--serif); font-size: 1.05rem; margin-bottom: 8px; }
.level strong { font-size: 1.6rem; font-weight: 500; margin-right: 6px; }
#xp-meter .meter-fill { background: var(--legendary); }
.small { font-size: 0.8rem; color: var(--ink-soft); margin-top: 6px; }

.missions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.missions li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 0.88rem; }
.missions .meter { grid-column: 1 / -1; height: 5px; }
.missions .reward { font-size: 0.75rem; color: var(--ink-soft); white-space: nowrap; }
.missions li.done { color: var(--ink-soft); }
.missions li.done .mission-text { text-decoration: line-through; }
.missions li.done .meter-fill { background: var(--legendary); }

.now-playing { margin-top: 10px; font-size: 0.82rem; color: var(--ink-soft); }
.now-playing em { font-family: var(--serif); color: var(--ink); }
.link-button.sound[aria-pressed="false"] { color: var(--ink-soft); border-color: var(--rule); }

/* ---------- notices ---------- */

.toasts { position: fixed; z-index: 30; left: 50%; top: 14px; transform: translateX(-50%); display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); padding: 10px 16px; font-size: 0.92rem; box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.5); animation: toast-in 0.3s ease-out; }
.toast strong { font-family: var(--serif); font-weight: 500; font-size: 1.05rem; margin-right: 8px; }
.toast.gold { background: var(--legendary); color: var(--ink); }
.toast.red { background: var(--accent); }
.toast.leaving { opacity: 0; transition: opacity 0.4s; }
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } }

/* ---------- card: reward, shops, pairings ---------- */

.reward { font-size: 0.88rem; }
.reward strong { font-weight: 600; }
.reward.perfect strong { color: var(--legendary); }
.reward.good strong { color: var(--rare); }
.reward.miss strong { color: var(--ink-soft); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h3 { font-size: 1rem; }
.shop, .pairs { border-top: 1px solid var(--rule); padding-top: 12px; display: grid; gap: 10px; }
.buy { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--ink); color: var(--paper); text-decoration: none; padding: 12px 16px; font-size: 1rem; }
.buy:hover { background: var(--accent); color: var(--paper); }
.shops { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.shops li { display: flex; align-items: baseline; gap: 6px; }
.shops a { white-space: nowrap; }
.shop-note, .fine { font-size: 0.75rem; color: var(--ink-soft); }
.research { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.92rem; }
.link-button.small { font-size: 0.8rem; }
.pair-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pair { width: 100%; background: none; border: 1px solid var(--rule); padding: 0; text-align: left; display: grid; align-content: start; }
.pair:hover { border-color: var(--ink); }
.pair .tile-plate { aspect-ratio: 4 / 3; }
.pair-title { font-family: var(--serif); font-size: 0.9rem; line-height: 1.2; padding: 6px 8px 0; }
.pair-meta { font-size: 0.7rem; color: var(--ink-soft); padding: 2px 8px 8px; }
.secondary.quiet { border-color: var(--rule); color: var(--ink-soft); }
.secondary.quiet:hover:not(:disabled) { background: var(--ink-soft); color: var(--paper); }
.secondary:disabled { opacity: 0.6; cursor: default; }
.card.preview { border-top-style: dashed; }
.card.legendary .plate { animation: shimmer 2.4s ease-in-out infinite alternate; }
@keyframes shimmer { from { box-shadow: inset 0 0 0 0 rgba(195, 154, 59, 0); } to { box-shadow: inset 0 0 70px 0 rgba(195, 154, 59, 0.35); } }
.select { font: inherit; padding: 8px 10px; border: 1px solid var(--ink); background: var(--paper); color: var(--ink); max-width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .fever.on .meter-fill, .card.legendary .plate, .gauge-verdict.pop, .toast { animation: none; }
}
