.spend {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--red);
  border-radius: 14px;
  background: white;
}

.spend p { margin: 0 0 8px; font-weight: 700; }

.rate { margin-top: 12px; }

.rate-bar {
  height: 10px;
  background: var(--cream-deep);
  border-radius: 99px;
  overflow: hidden;
}

#rate-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--red);
  transform-origin: left center;
}

#rate-label { margin: 8px 0 0; font-weight: 700; color: var(--ink); }

.stage.rating { cursor: pointer; touch-action: manipulation; }

.hof { margin: 0; }

.hof-grid {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.hof-grid li {
  background: var(--paper);
  border-radius: 14px;
  padding: 8px;
  border: 1px solid var(--line);
}

.hof-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: #ddd4c6;
  display: block;
}

.hof-grid p { margin: 6px 0 0; font-size: 13px; font-weight: 700; }
.hof-grid span { display: block; color: var(--muted); font-weight: 650; font-size: 12px; }

button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 16px;
  min-height: 44px;
  min-width: 44px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 1;
  background: #e6ded2;
  color: #4a433c;
  border-color: #cfc4b6;
  cursor: not-allowed;
}

button.primary { min-height: 48px; }

button.primary {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

button.primary:hover:not(:disabled) { background: var(--red-deep); }

button.primary:disabled {
  background: #e6ded2;
  color: #4a433c;
  border-color: #cfc4b6;
}

button.primary:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  box-shadow: 0 0 0 2px #fff;
}

button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

footer {
  padding: 4px max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  color: var(--muted);
  font-size: 13px;
}

.legal-row {
  display: flex;
  gap: 16px;
}

.text-link {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 10px 8px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-link:disabled {
  background: transparent;
  color: #6a6158;
}

.fold {
  margin-top: 4px;
  padding: 12px 14px;
  background: var(--paper);
  border-radius: 14px;
  line-height: 1.45;
}

.fold p { margin: 0 0 12px; }
.fold p:last-child { margin-bottom: 0; }

.hint { color: var(--muted); font-size: 13px; }

.disclaimer dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

.disclaimer dl div { display: grid; gap: 2px; }

.disclaimer dt {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.disclaimer dd {
  margin: 0;
  color: var(--ink);
  word-break: break-all;
}

.peep-attach {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: var(--ink);
  font-weight: 700;
}

.disclaimer dd.pair-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 22px;
  letter-spacing: 0.18em;
  font-weight: 700;
  word-break: normal;
}

.gate-block {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--red);
  border-radius: 14px;
  background: white;
  color: var(--red-deep);
  font-weight: 700;
}

#fingerprint { margin-top: 12px; }
#fingerprint dl { margin-bottom: 12px; }
#challenge-fields { display: grid; gap: 0; }

.peep-attach select, .peep-attach input, .disclaimer button {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  font: inherit;
  padding: 8px 12px;
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  background: var(--cream);
  color: var(--ink);
}

.boot p {
  margin: 12px 0 0;
  font-weight: 700;
}

.boot.done { display: none; }

body.app-hold .top,
body.app-hold #app,
body.app-hold footer {
  visibility: hidden;
}

.onboard {
  position: fixed;
  inset: 0;
  z-index: 18;
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
}

.onboard-screen {
  min-height: 100%;
  padding: max(28px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(36px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  display: grid;
  align-content: center;
  gap: 12px;
  max-width: 440px;
  margin: 0 auto;
}

.onboard-screen h2 {
  margin: 0;
  font-size: 32px;
  line-height: 1.05;
}

.onboard-screen p { margin: 0; line-height: 1.45; }

.eyebrow {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

#onboard-launch { width: 100%; margin-top: 8px; }

#onboard-fetch { align-content: start; padding-top: 36px; }
#onboard-fetch .spinner { margin: 8px auto 0; }
#onboard-fetch-label { text-align: center; font-weight: 700; }

.onboard-cast { margin-top: 8px; }

.onboard-cast .glyph {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  background:
    radial-gradient(circle at 50% 36%, #cfc4b4 0 18%, transparent 19%),
    radial-gradient(ellipse at 50% 92%, #cfc4b4 0 36%, transparent 37%),
    #e4d8c6;
}

.onboard-cast canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 10px;
  display: block;
  image-rendering: pixelated;
}

.onboard-cast span.name {
  color: var(--muted);
}

.onboard-cast li.shown span.name { color: var(--ink); }

#onboard-ready { justify-items: center; text-align: center; }
.ready-mark {
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-size: 42px;
  font-weight: 600;
}

body.sheet-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  align-items: end;
  justify-items: center;
  background: rgba(28, 25, 21, 0.4);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.sheet-card {
  width: min(100%, 520px);
  max-height: min(88vh, calc(100dvh - env(safe-area-inset-top)));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px max(28px, env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}

.sheet-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -16px 8px;
  padding: 4px 8px 4px 16px;
  background: var(--paper);
}

#disclaimer-sheet { z-index: 40; }
#challenge-sheet { z-index: 50; }

.sheet-card > .primary,
#challenge-check,
#challenge-back {
  width: 100%;
}

#challenge-form[hidden],
#challenge-done[hidden],
#fingerprint[hidden] { display: none !important; }

.sheet-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  padding: 0;
}

.sheet-close:focus-visible {
  outline-offset: 0;
}

.sheet-card p { margin: 0 0 12px; line-height: 1.45; }

.onboard[hidden],
.onboard-screen[hidden],
.sheet[hidden] { display: none !important; }

@media (min-width: 840px) {
  .top, .layout, footer { padding-left: 22px; padding-right: 22px; }
  h1 { font-size: 42px; }
  .layout {
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 22px;
    align-items: start;
  }
  .stage { min-height: 560px; }
  .sheet { align-items: center; padding: 24px; }
  .sheet-card { border-radius: 18px; }
  .actions button { flex: 0 0 auto; }
}

.focus-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 6;
  margin: 0 0 8px;
  padding: 8px 0;
  background: var(--cream);
  opacity: 0;
  visibility: hidden;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

#cast-back {
  flex: 0 0 auto;
  min-height: 48px;
  min-width: 88px;
  padding: 0 16px;
  transition: transform 0.12s ease;
}

.hero {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 48px;
}

.hero img {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  object-fit: cover;
  background: #ddd4c6;
  box-shadow: var(--shadow);
  transform: scale(0.82);
  transition: transform 0.32s ease;
}

.hero span {
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cast-panel .cast {
  transform-origin: top center;
}

.cast-panel .cast button {
  transition: transform 0.12s ease, border-color 0.2s ease;
}

.cast-panel .cast button:active,
#cast-back:active {
  transform: scale(0.96);
}

.stage-panel {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

body:not(.focus) .stage-panel {
  position: absolute;
  visibility: hidden;
  height: 0;
  overflow: hidden;
}

body.focus {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
}

body.focus .top {
  flex: 0 0 auto;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: 10px;
}

body.focus h1 { font-size: 22px; }

body.focus .layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  padding: 8px 12px 0;
  grid-template-columns: 1fr;
}

body.focus .cast-panel {
  display: block;
  flex: 0 0 auto;
  height: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: visible;
}

body.focus #cast {
  display: none !important;
}

body.focus .cast-panel .panel-head,
body.focus #stage-heading,
body.focus .hero,
body.focus .sub,
body.focus #hof,
body.focus #hof-toggle,
body.focus #ladder-note,
body.focus #action-hint,
body.focus #storage-note,
body.focus footer { display: none !important; }

body.focus .focus-bar {
  position: fixed;
  left: 0;
  right: auto;
  top: auto;
  bottom: 0;
  width: max-content;
  z-index: 14;
  display: flex;
  align-items: center;
  height: auto;
  margin: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: transparent;
  border: 0;
  opacity: 1;
  visibility: visible;
  overflow: visible;
  pointer-events: none;
}

body.focus #cast-back {
  position: relative;
  z-index: 14;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  pointer-events: auto;
}

body.focus .stage-panel {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  opacity: 1;
  transform: none;
  visibility: visible;
  height: auto;
  overflow: hidden;
  pointer-events: auto;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

body.focus .stage-panel .panel-head {
  flex: 0 0 auto;
  margin-bottom: 8px;
}

body.focus .stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.focus #source-view,
body.focus #result-view {
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
  padding: 0;
}

body.focus #source-view img,
body.focus #result-view img {
  width: 100%;
  max-width: 100%;
  max-height: none;
  height: auto;
  margin-inline: auto;
  object-fit: contain;
}

body.focus .actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 13;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(112px + env(safe-area-inset-left));
  background: transparent;
  pointer-events: none;
}

body.focus .actions > * { pointer-events: auto; }

body.focus #studio-more-toggle {
  flex: 0 0 auto;
}

body.focus #studio-actions > #generate,
body.focus.studio-done #studio-actions > #download {
  flex: 1 1 auto;
  min-height: 48px;
}

body.focus:not(.studio-done) #download { display: none !important; }

body.focus.studio-done #studio-actions > #download {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

body.focus #studio-secondary { display: none !important; }

body.focus.studio-more #studio-secondary {
  display: flex !important;
  flex-direction: column;
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(68px + env(safe-area-inset-bottom));
  z-index: 13;
  gap: 8px;
  margin: 0;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

body.focus.studio-more #studio-secondary button {
  flex: 1 1 auto;
  width: 100%;
  min-height: 44px;
}

body.focus.studio-done #studio-secondary #generate {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}

body.focus #spend:not([hidden]) {
  position: fixed;
  z-index: 15;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(76px + env(safe-area-inset-bottom));
  margin: 0;
}

body:not(.focus) #studio-secondary { display: contents; }

body:not(.focus) #studio-more-toggle { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
