/* Hugo Ballot — deep-space console with Mars-rust accents. */

:root {
  --void: #07060f;
  --void-2: #0d0b1a;
  --panel: #14122363;
  --panel-solid: #16142a;
  --line: #2b2745;
  --line-soft: #221f3a;
  --ink: #eceaf6;
  --ink-dim: #a7a2c4;
  --ink-faint: #6f6a92;
  --rust: #e2643a;
  --rust-soft: #ff8a5c;
  --gold: #f2c14e;
  --plasma: #7c6bff;
  --ok: #4fd6a0;
  --radius: 16px;
  --row-gap: 14px;
  --shadow: 0 18px 40px -18px #000, 0 2px 0 #ffffff0d inset;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 90% at 50% -10%, #1c1636 0%, var(--void-2) 45%, var(--void) 100%);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.starfield {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 18%, #fff9 0, transparent 100%),
    radial-gradient(1.2px 1.2px at 78% 8%, #fff7 0, transparent 100%),
    radial-gradient(1.6px 1.6px at 33% 62%, #cfd6ff8c 0, transparent 100%),
    radial-gradient(1px 1px at 61% 40%, #fff6 0, transparent 100%),
    radial-gradient(1.3px 1.3px at 88% 71%, #ffd9c28f 0, transparent 100%),
    radial-gradient(1px 1px at 22% 88%, #fff5 0, transparent 100%),
    radial-gradient(1.1px 1.1px at 47% 27%, #fff6 0, transparent 100%),
    radial-gradient(900px 420px at 88% 108%, #7a2c1a3d 0, transparent 70%);
}

header, nav, main, footer { position: relative; z-index: 1; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding-top: 0;
  padding-right: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-right) + 12px));
  padding-bottom: 64px;
  padding-left: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-left) + 12px));
}

/* ---------- top bar ---------- */

.topbar {
  max-width: 900px;
  margin: 0 auto;
  padding-top: max(clamp(20px, 4vw, 34px), calc(env(safe-area-inset-top) + 16px));
  padding-right: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-right) + 12px));
  padding-bottom: 14px;
  padding-left: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-left) + 12px));
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
}

.brand { display: flex; gap: 12px; align-items: center; }

.app-mark {
  display: block;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  box-shadow: 0 10px 26px -12px #000, 0 0 24px -8px #f2c14e8c;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 6vw, 36px);
  letter-spacing: -0.02em;
  font-weight: 800;
  background: linear-gradient(96deg, #fff 10%, var(--gold) 55%, var(--rust-soft) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline { margin: 2px 0 0; color: var(--ink-dim); font-size: 14px; }

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.install-btn {
  min-height: 44px;
  border-color: #f2c14e73;
  color: var(--gold);
}

.offline-notice {
  position: relative;
  z-index: 2;
  width: min(872px, calc(100% - 28px));
  margin: 0 auto 12px;
  padding: 9px 13px;
  border: 1px solid #f2c14e4d;
  border-radius: 11px;
  background: #2d2417e8;
  color: #f5d98d;
  font-size: 13px;
  text-align: center;
}

/* ---------- buttons ---------- */

.ghost-btn, .primary-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: transform .12s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease;
  white-space: nowrap;
}

.ghost-btn {
  background: #ffffff0a;
  border: 1px solid var(--line);
  color: var(--ink-dim);
}

.ghost-btn:hover { background: #ffffff14; color: var(--ink); border-color: #3d3762; }
.ghost-btn[aria-pressed="true"] {
  background: #4fd6a01f;
  border-color: #4fd6a066;
  color: var(--ok);
}

.primary-btn {
  background: linear-gradient(180deg, var(--rust-soft), var(--rust));
  border: 1px solid #ff9d74;
  color: #200d06;
  box-shadow: 0 10px 24px -12px var(--rust), 0 1px 0 #fff6 inset;
}

.primary-btn:hover { transform: translateY(-1px); }
.ghost-btn:active, .primary-btn:active { transform: translateY(1px); }

:where(button, [tabindex]):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- year rail ---------- */

.year-rail {
  max-width: 900px;
  margin: 0 auto;
  padding-top: 4px;
  padding-right: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-right) + 12px));
  padding-bottom: 18px;
  padding-left: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-left) + 12px));
}

.year-rail ul {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 4px 0 10px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.year-rail button {
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  padding: 7px 15px;
  border-radius: 11px;
  border: 1px solid var(--line-soft);
  background: #ffffff08;
  color: var(--ink-faint);
  cursor: pointer;
  transition: all .15s ease;
}

.year-rail button:hover { color: var(--ink); border-color: #3d3762; }

.year-rail button[aria-selected="true"] {
  background: linear-gradient(180deg, #2a2350, #1b1738);
  border-color: var(--plasma);
  color: #fff;
  box-shadow: 0 0 0 1px #7c6bff33, 0 8px 20px -12px var(--plasma);
}

.year-rail button .dot {
  display: inline-block;
  width: 5px; height: 5px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--gold);
  vertical-align: 2px;
}

/* ---------- stack ---------- */

.stack-head { margin-bottom: 16px; }

.stack-head h2 {
  margin: 0;
  font-size: clamp(19px, 4.5vw, 23px);
  letter-spacing: -0.01em;
}

#yearHeading { color: var(--gold); font-variant-numeric: tabular-nums; }

.stack-sub { margin: 3px 0 0; color: var(--ink-faint); font-size: 13.5px; }

.hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--ink-dim);
  border-left: 2px solid var(--rust);
  padding-left: 10px;
}

.stack {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
  touch-action: pan-y;
}

.book {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: grid;
  grid-template-columns: 42px 62px 1fr 30px;
  gap: 12px;
  align-items: center;
  padding: 12px 12px 12px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background:
    linear-gradient(100deg, #1a1731f2, #14122ae8 60%, #191534f2);
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .28s cubic-bezier(.2,.9,.3,1), box-shadow .2s ease, border-color .2s ease;
  will-change: transform;
}

.book:hover { border-color: #3a3460; }

.book.dragging {
  transition: box-shadow .2s ease, border-color .2s ease;
  cursor: grabbing;
  z-index: 40;
  border-color: var(--rust);
  box-shadow: 0 28px 60px -20px #000, 0 0 0 1px #e2643a55, 0 0 30px -6px #e2643a55;
}

.book.settling { transition: transform .22s cubic-bezier(.2,.9,.3,1); }

/* Top of the pile gets a little ceremony. */
.book.rank-1 {
  border-color: #6c5a2a;
  background: linear-gradient(100deg, #241f33f2, #1a152ce8 60%, #201a35f2);
  box-shadow: var(--shadow), 0 0 0 1px #f2c14e26;
}

.rank {
  display: grid;
  place-items: center;
  justify-self: center;
  width: 34px; height: 34px;
  border-radius: 11px;
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  background: #ffffff0d;
  border: 1px solid var(--line);
  color: var(--ink-dim);
}

.rank-1 .rank {
  background: linear-gradient(180deg, #f7d271, #d9a12c);
  border-color: #ffe08a;
  color: #35240a;
  box-shadow: 0 0 16px -4px #f2c14e88;
}

.book-cover {
  width: 62px;
  height: 93px;
  object-fit: cover;
  border-radius: 5px;
  background: linear-gradient(160deg, #2a2545, #191531);
  box-shadow: 0 6px 16px -6px #000c, 0 0 0 1px #ffffff14;
  pointer-events: none;
}

.book-cover.missing {
  display: grid;
  place-items: center;
}

.book-meta { min-width: 0; }

.book-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.book-author { margin: 3px 0 0; font-size: 13px; color: var(--ink-dim); }

.book-tags { margin: 6px 0 0; display: flex; gap: 6px; flex-wrap: wrap; }

.tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 2.5px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-faint);
  background: #ffffff08;
}

.tag.winner {
  border-color: #f2c14e66;
  background: #f2c14e1f;
  color: var(--gold);
}

/* The touch drag handle. `touch-action: none` is what lets a finger drag here
   at all — everything else on the card stays pan-y so the page can still be
   scrolled. Sized as a real target, not a decoration. */
.grip {
  justify-self: stretch;
  align-self: stretch;
  display: grid;
  place-items: center;
  min-width: 34px;
  color: var(--ink-faint);
  font-size: 19px;
  line-height: 1;
  letter-spacing: 1px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #ffffff08;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.grip:hover { color: var(--ink); background: #ffffff14; }
.grip:active { cursor: grabbing; background: #ffffff1f; }

.stack-foot {
  display: flex;
  justify-content: space-between;
  margin: 14px 2px 0;
  font-size: 11.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
}

.pos-label.best { color: var(--gold); }
.pos-label.worst { color: var(--ink-faint); }

/* ---------- panels ---------- */

.panel {
  margin-top: 34px;
  padding: clamp(18px, 4vw, 24px);
  border-radius: 20px;
  border: 1px solid var(--line-soft);
  background: var(--panel);
  backdrop-filter: blur(6px);
}

.panel h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -0.01em; }
.panel h3 { margin: 0; font-size: 20px; letter-spacing: -0.015em; }
.panel-copy { margin: 0 0 16px; color: var(--ink-dim); font-size: 14px; }
.panel-note { margin: 14px 0 0; color: var(--ink-faint); font-size: 12.5px; }

.field { display: block; margin-bottom: 14px; }
.field span {
  display: block;
  font-size: 11.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  font: inherit;
  font-size: 14.5px;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #0c0a1a;
  color: var(--ink);
}

.field select {
  min-height: 44px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-faint) 50%),
    linear-gradient(135deg, var(--ink-faint) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.field-note {
  display: block;
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-faint);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.field-note em { color: var(--rust-soft); font-style: normal; font-weight: 600; }

.field input::placeholder { color: var(--ink-faint); }
.field input:focus,
.field select:focus { outline: none; border-color: var(--plasma); box-shadow: 0 0 0 3px #7c6bff2b; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.render-out { margin-top: 18px; }

/* Covers both outputs: the 4:5 share card and the 3:2 poster. `height: auto`
   means neither needs a size of its own — swapping boy-1 from portrait to
   landscape changed nothing here. */
.render-out canvas {
  width: 100%;
  max-width: 460px;
  height: auto;
  display: block;
  margin: 0 auto 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.warn {
  margin: 14px 0 0;
  padding: 11px 13px;
  border-radius: 11px;
  font-size: 13px;
  background: #f2c14e14;
  border: 1px solid #f2c14e3d;
  color: #f0d79a;
}

.warn code {
  background: #0009;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12.5px;
}

/* ---------- creation studio ---------- */

.panel.studio {
  padding: 0;
  overflow: hidden;
  border-color: #3a3266;
  background:
    linear-gradient(150deg, #201936d9, #111020e8 56%, #171226e8),
    var(--panel);
}

.studio-head {
  padding: clamp(20px, 4vw, 28px) clamp(18px, 4vw, 28px) 0;
}

.studio-head h2 {
  font-size: clamp(24px, 5vw, 31px);
  margin-bottom: 6px;
}

.eyebrow,
.mode-kicker {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--rust-soft);
}

.studio > .field {
  margin: 18px clamp(18px, 4vw, 28px) 0;
  max-width: 440px;
}

.studio > .studio-scene-field {
  margin-top: 12px;
}

.studio-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-top: 22px;
  padding: 0 clamp(12px, 3vw, 20px);
  border-bottom: 1px solid var(--line-soft);
}

.studio-tab {
  position: relative;
  min-width: 0;
  min-height: 58px;
  padding: 11px 12px 13px;
  border: 0;
  border-radius: 13px 13px 0 0;
  background: transparent;
  color: var(--ink-faint);
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  transition: color .16s ease, background .16s ease;
}

.studio-tab:hover {
  color: var(--ink);
  background: #ffffff08;
}

.studio-tab[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(180deg, #2c244c, #1c1734);
  box-shadow: 0 1px 0 var(--rust) inset, 0 -1px 0 #332b54 inset;
}

.studio-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--rust-soft), transparent);
  box-shadow: 0 0 12px var(--rust);
}

.studio-tab-num {
  display: block;
  margin-bottom: 2px;
  color: var(--rust-soft);
  font-size: 9px;
  letter-spacing: .12em;
}

.studio-panel {
  padding: clamp(20px, 4vw, 28px);
}

.studio-panel[hidden] { display: none; }

.mode-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.mode-heading > p {
  max-width: 34em;
  margin: 0;
  color: var(--ink-dim);
  font-size: 13.5px;
  text-align: right;
}

/* ---------- poster builder ---------- */

.studio-panel.poster {
  border-color: #3a3266;
}

.seg-field { border: 0; padding: 0; margin: 0 0 14px; }

.seg-field legend {
  padding: 0;
  font-size: 11.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c0a1a;
}

.seg-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 7px 22px;
  border-radius: 9px;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.seg-btn:hover { color: var(--ink); }

.seg-btn[aria-checked="true"] {
  background: linear-gradient(180deg, var(--rust-soft), var(--rust));
  color: #200d06;
  box-shadow: 0 6px 16px -10px var(--rust);
}

.poster button[disabled] { opacity: .45; cursor: not-allowed; }

.face-block {
  margin: 4px 0 18px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: #ffffff05;
  padding: 12px 14px;
}

.face-block summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 9px;
}

.face-block summary::-webkit-details-marker { display: none; }

.face-block summary::before {
  content: "▸";
  color: var(--ink-faint);
  transition: transform .18s ease;
  display: inline-block;
}

.face-block[open] summary::before { transform: rotate(90deg); }

.face-block .opt {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--plasma);
  border: 1px solid #7c6bff4d;
  background: #7c6bff1a;
  padding: 2px 8px;
  border-radius: 999px;
}

.face-stage {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-top: 12px;
}

.face-frame {
  position: relative;
  width: 168px;
  height: 168px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: #080714;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.face-frame.live { border-color: var(--ok); box-shadow: 0 0 0 3px #4fd6a01f; }
.face-frame.shot { border-color: var(--gold); box-shadow: 0 0 0 3px #f2c14e1f; }

.face-frame video,
.face-frame canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Mirrored preview only — js/facecam.js grabs the un-mirrored frame. */
.face-frame video { transform: scaleX(-1); }

.face-guide {
  position: absolute;
  inset: 13%;
  border: 2px dashed #ffffff5c;
  border-radius: 50%;
  pointer-events: none;
}

.face-frame.shot .face-guide { display: none; }

.face-idle {
  position: absolute;
  margin: 0;
  font-size: 12px;
  color: var(--ink-faint);
  text-align: center;
  padding: 0 18px;
}

.face-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.upload-btn { display: inline-block; margin: 0; }

/* ---------- face placement ---------- */

.face-adjust {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.face-adjust h4 {
  margin: 0 0 4px;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.face-adjust canvas {
  display: block;
  width: 100%;
  max-width: 310px;
  height: auto;
  margin: 12px auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #080713;
  /* The whole point is dragging the face around, so the browser must not take
     the gesture for a scroll. */
  touch-action: none;
  cursor: grab;
}

.face-adjust canvas:active { cursor: grabbing; }

.slider {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.slider span {
  font-size: 11.5px;
  letter-spacing: .07em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-faint);
}

.slider input[type="range"] {
  width: 100%;
  accent-color: var(--rust);
  touch-action: none;
}

.poster-caption {
  margin: 0 0 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
  text-align: center;
}

/* ---------- direct-manipulation output editor ---------- */

.editor-toolbar {
  width: 100%;
  max-width: 460px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.editor-actions .ghost-btn {
  min-height: 44px;
  padding-inline: 14px;
}

.editor-toolbar > p {
  margin: 0;
  color: var(--ink-faint);
  font-size: 11.5px;
  line-height: 1.35;
  text-align: right;
}

.layer-stage {
  position: relative;
  width: 100%;
  max-width: 460px;
  margin: 0 auto 14px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.layer-stage > canvas {
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: none;
  display: block;
}

.layer-editor-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}

.layer-editor-overlay[hidden] { display: none; }
.layer-editor-overlay:focus-visible {
  outline: 3px solid var(--plasma);
  outline-offset: 3px;
}

.layer-stage.is-editing {
  box-shadow: var(--shadow), 0 0 0 2px #7c6bff59;
}

.layer-stage.is-gesturing .layer-editor-overlay { cursor: grabbing; }

/* ---------- full-body Star Yourself ---------- */

.body-grid {
  display: grid;
  grid-template-columns: minmax(240px, .72fr) minmax(0, 1.28fr);
  align-items: start;
  gap: clamp(18px, 4vw, 30px);
}

.body-controls { min-width: 0; }

.body-upload-card {
  padding: 15px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: #08071470;
}

.body-upload-title {
  margin: 0 0 3px;
  font-size: 13.5px;
  font-weight: 750;
  color: var(--ink);
}

.body-file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 12px;
}

.body-file-actions { margin-top: 10px; }
.body-file-actions .ghost-btn { min-height: 40px; }

.body-status {
  min-height: 2.8em;
  margin: 12px 0 0;
  color: var(--ink-dim);
  font-size: 12.5px;
  line-height: 1.45;
}

.body-status[data-tone="ok"] { color: var(--ok); }
.body-status[data-tone="error"] { color: #f0b59e; }

.privacy-note {
  margin: 12px 0 0;
  padding-top: 11px;
  border-top: 1px solid var(--line-soft);
  color: var(--ink-faint);
  font-size: 11.5px;
  line-height: 1.5;
}

.privacy-note span {
  color: var(--ok);
  font-size: 16px;
}

.body-out { margin: 0; }

.body-out .layer-stage,
.body-out .editor-toolbar {
  max-width: none;
}

.body-out .layer-stage { margin-bottom: 8px; }

#bodyCanvas {
  background:
    #090812
    url("../scenes/clean/frontiers-loft.png?v=20260728-9")
    center / cover no-repeat;
}

.drag-hint {
  margin: 0;
  color: var(--ink-faint);
  font-size: 11.5px;
  text-align: center;
}

.render-out.rendering canvas {
  opacity: .72;
  filter: saturate(.75);
}

.render-out canvas {
  transition: opacity .16s ease, filter .16s ease;
}

button[disabled] {
  opacity: .45;
  cursor: not-allowed;
}


/* ---------- detail sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #05040bd9;
  backdrop-filter: blur(4px);
  animation: fade .18s ease;
}

@keyframes fade { from { opacity: 0 } }

.sheet {
  position: fixed;
  z-index: 61;
  inset: auto 0 0;
  margin: 0 auto;
  width: min(720px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px clamp(16px, 4vw, 26px) calc(22px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: linear-gradient(180deg, #1b1734, #100e21 60%);
  color: var(--ink);
  box-shadow: 0 -30px 80px -20px #000;
  animation: rise .26s cubic-bezier(.2,.9,.3,1);
}

.sheet::backdrop { background: transparent; }

@keyframes rise { from { transform: translateY(22px); opacity: 0 } }

@media (min-width: 720px) {
  .sheet {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    border-radius: 22px;
    border-bottom: 1px solid var(--line);
    max-height: 86dvh;
  }
  @keyframes rise { from { transform: translate(-50%, -46%); opacity: 0 } }
}

.sheet-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #ffffff0f;
  color: var(--ink-dim);
  font-size: 14px;
  cursor: pointer;
}

.sheet-close:hover { background: #ffffff1c; color: #fff; }

.sheet-body { display: flex; gap: 22px; flex-wrap: wrap; }

.sheet-cover-wrap { position: relative; flex: 0 0 auto; margin-inline: auto; }

.sheet-cover {
  width: 178px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: linear-gradient(160deg, #2a2545, #191531);
  box-shadow: 0 22px 44px -18px #000, 0 0 0 1px #ffffff1a;
  display: block;
}

.sheet-rankpill {
  position: absolute;
  top: -10px; left: -10px;
  min-width: 34px; height: 34px;
  padding: 0 9px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-weight: 800;
  font-size: 13px;
  background: linear-gradient(180deg, #f7d271, #d9a12c);
  color: #35240a;
  box-shadow: 0 6px 16px -6px #000c;
}

.sheet-text { flex: 1 1 300px; min-width: 0; }

.sheet-eyebrow {
  margin: 0 0 4px;
  font-size: 11.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--rust-soft);
}

.sheet h3 { margin: 0; font-size: clamp(21px, 5vw, 27px); letter-spacing: -0.02em; line-height: 1.15; }
.sheet-author { margin: 5px 0 0; color: var(--ink-dim); font-size: 15px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 13px 0 0; padding: 0; }

.chips li {
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff08;
  color: var(--ink-dim);
}

.chips li.win { border-color: #f2c14e66; background: #f2c14e1f; color: var(--gold); }

.sheet-desc {
  margin-top: 16px;
  font-size: 14.5px;
  line-height: 1.65;
  color: #dcd8ee;
}

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

.sheet-src { margin: 14px 0 0; font-size: 12px; color: var(--ink-faint); }

.sheet-nav {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

/* ---------- footer ---------- */

.sitefoot {
  max-width: 900px;
  margin: 0 auto;
  padding-top: 0;
  padding-right: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-right) + 12px));
  padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px));
  padding-left: max(clamp(14px, 4vw, 28px), calc(env(safe-area-inset-left) + 12px));
}

.sitefoot p { margin: 0; font-size: 12px; color: var(--ink-faint); line-height: 1.6; }

@media (max-width: 430px) {
  .book { grid-template-columns: 32px 50px 1fr 44px; gap: 8px; padding: 10px 6px 10px 4px; }
  .book-cover { width: 50px; height: 75px; }
  .rank { width: 30px; height: 30px; font-size: 14px; border-radius: 9px; }
}

@media (max-width: 680px) {
  .studio-tabs { padding-inline: 7px; }
  .studio-tab { padding-inline: 5px; font-size: 11.5px; }
  .mode-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .mode-heading > p { text-align: left; }
  .body-grid { grid-template-columns: 1fr; }
  .body-out { grid-row: 1; }
  .body-controls { grid-row: 2; }
  .editor-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .editor-toolbar > p { text-align: left; }
}

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

/* ---------- save sheet ---------- */

/* The always-works path when a frame blocks downloads: the finished image,
   full-screen, ready for a long-press save. */
.save-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #05040bee;
  backdrop-filter: blur(6px);
  animation: fade .18s ease;
}

.save-sheet[hidden] { display: none; }

.save-sheet-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 100%;
}

.save-sheet-how {
  margin: 0;
  max-width: 34em;
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}

.save-sheet-img {
  display: block;
  max-width: min(94vw, 900px);
  max-height: 68dvh;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px -20px #000;
  /* Let the browser's own press-and-hold menu through — that's the whole point. */
  -webkit-touch-callout: default;
  touch-action: auto;
}

.save-sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.save-sheet-actions .primary-btn { text-decoration: none; display: inline-block; }

/* ---------- install sheet ---------- */

.install-sheet {
  position: fixed;
  z-index: 96;
  inset: auto 0 0;
  width: min(460px, 100%);
  margin: 0 auto;
  padding: 28px 24px max(28px, calc(env(safe-area-inset-bottom) + 20px));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: linear-gradient(180deg, #1b1734, #100e21 72%);
  color: var(--ink);
  box-shadow: 0 -30px 80px -20px #000;
}

.install-sheet::backdrop {
  background: #05040bd9;
  backdrop-filter: blur(5px);
}

.install-icon {
  display: block;
  width: 76px;
  height: 76px;
  margin: 0 0 18px;
  border-radius: 21px;
  box-shadow: 0 15px 34px -16px #000, 0 0 28px -9px #f2c14e70;
}

.install-sheet h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -.02em;
}

.install-sheet > p:not(.sheet-eyebrow) {
  margin: 9px 0 20px;
  color: var(--ink-dim);
}

.install-done {
  min-height: 46px;
  width: 100%;
}

.terms-sheet {
  max-height: min(760px, calc(100dvh - 24px));
  overflow: auto;
}

.terms-copy {
  margin: 14px 0 22px;
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.55;
}

.terms-copy h3 {
  margin: 21px 0 5px;
  color: var(--ink);
  font-size: 15px;
}

.terms-copy p {
  margin: 8px 0;
}

@media (min-width: 540px) {
  .install-sheet {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    border-bottom: 1px solid var(--line);
    border-radius: 24px;
  }
}

/* Big, always-visible export controls. */
.export-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.export-row > * { flex: 1 1 180px; }

.export-row .primary-btn,
.export-row .ghost-btn {
  padding: 15px 20px;
  font-size: 16px;
  border-radius: 14px;
  width: 100%;
}
