/* Arena — portrait gallery picker (av5). In-world: dark wood, parchment, brass, wax. Big taps, plain words. */
@font-face { font-family: "Cinzel Decorative"; src: url("assets/fonts/CinzelDecorative-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Crimson Text"; src: url("assets/fonts/CrimsonText-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Crimson Text"; src: url("assets/fonts/CrimsonText-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

/* ---- shared: small portrait chip (town top bar etc.) ---- */
.avatar-chip {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: linear-gradient(180deg, #f3e2c0, #d4b070); border: 2px solid #c9a24a; overflow: hidden;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35); text-decoration: none; color: #3e2616; font: 700 0.7rem "Crimson Text", Georgia, serif;
  -webkit-tap-highlight-color: transparent;
}
.avatar-chip canvas.arena-avatar { width: 100%; height: 100%; display: block; }
.avatar-chip:active { transform: scale(0.95); }
/* av6: ruler name beside the town chip (hidden on narrow bars; the chip title carries it there) */
.avatar-name {
  max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; min-width: 0;
  padding: 2px 9px; border-radius: 10px; border: 1.5px solid #c9a24a; background: linear-gradient(180deg, #f3e2c0, #d4b070);
  color: #3e2616; font: 700 0.85rem "Crimson Text", Georgia, serif; text-decoration: none; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
@media (max-width: 700px) { .avatar-name { display: none !important; } }

/* ---- page ---- */
html, body { margin: 0; height: 100%; overflow: hidden; }   /* ns2: lock page scroll; grid pages inside */
.av-page {
  --parch: #f3e2c0; --parch-d: #e0c892; --wood: #6b4226; --wood-d: #3e2616; --ink: #2e1d10; --brass: #c9a24a; --brass-b: #efd48a; --wax: #9a2424;
  --plum: #2c1828;
  margin: 0; min-height: 0; color: var(--ink);
  font: 400 18px/1.35 "Crimson Text", Georgia, serif;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(120,60,90,0.25), transparent 60%),
    repeating-linear-gradient(90deg, rgba(0,0,0,0.07) 0 2px, transparent 2px 74px),
    linear-gradient(180deg, #4a2e1a, #24150b);
  background-attachment: fixed;
}
.av-page * { box-sizing: border-box; }
.av-bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(180deg, #6b4226, #4a2c18); border-bottom: 3px solid #2a180c;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.av-bar h1 { flex: 1; margin: 0; text-align: center; font: 700 1.35rem "Cinzel Decorative", Georgia, serif; color: var(--parch); text-shadow: 0 2px 0 #1e120a; }
.av-back, .av-bar-spacer { min-width: 96px; }
.av-back {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: linear-gradient(180deg, #f3e2c0, #d4b070); border: 2px solid var(--brass); color: var(--ink); font-weight: 700; text-decoration: none;
}
.av-main { display: grid; grid-template-columns: minmax(300px, 440px) 1fr; gap: 20px; padding: 18px; max-width: 1240px; margin: 0 auto; align-items: start; }
.av-main > * { min-width: 0; }

/* stage: big preview in a carved frame */
.av-stage { position: sticky; top: 84px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.av-frame {
  width: 100%; max-width: 440px; aspect-ratio: 1; padding: 12px; border-radius: 20px;
  background: linear-gradient(180deg, #8a5a34, #4a2c18);
  box-shadow: inset 0 0 0 3px #2a180c, inset 0 0 0 6px rgba(201,162,74,0.55), 0 14px 30px rgba(0,0,0,0.5);
}
.av-preview { width: 100%; height: 100%; display: block; border-radius: 12px; background: var(--plum); object-fit: cover; box-shadow: inset 0 0 0 2px #1a0c14; }
.av-plate {
  margin-top: -30px; position: relative; padding: 6px 26px 8px; text-align: center; min-width: 220px;
  background: linear-gradient(180deg, var(--parch), var(--parch-d)); border: 3px solid #8a6a2a; border-radius: 12px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.45);
}
.av-plate h2 { margin: 0; font: 700 1.15rem "Cinzel Decorative", Georgia, serif; color: var(--wood-d); }
.av-plate p { margin: 0; font-size: 1rem; color: #5a4030; }
/* av6: ruler name field */
.av-namebox { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 4px; }
.av-nlab { font: 700 0.95rem "Cinzel Decorative", Georgia, serif; color: var(--parch); text-shadow: 0 1px 0 #1e120a; }
.av-nrow { display: flex; gap: 8px; }
.av-ninput {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 3px solid #8a6a2a;
  background: linear-gradient(180deg, #fff6e0, var(--parch)); color: var(--ink); font: 700 1.15rem "Crimson Text", Georgia, serif;
  box-shadow: inset 0 2px 4px rgba(90,58,24,0.25);
}
.av-ninput:focus { outline: none; border-color: var(--brass-b); box-shadow: 0 0 0 3px rgba(239,212,138,0.45), inset 0 2px 4px rgba(90,58,24,0.25); }
.av-ninput.bad { border-color: var(--wax); }
.av-dice {
  flex: 0 0 52px; min-height: 48px; border-radius: 12px; cursor: pointer; font-size: 1.5rem; line-height: 1;
  background: linear-gradient(180deg, #f3e2c0, #d4b070); border: 3px solid #8a6a2a; box-shadow: 0 3px 0 #5a3a18; -webkit-tap-highlight-color: transparent;
}
.av-dice:active { transform: translateY(2px) rotate(-12deg); box-shadow: none; }
.av-nerr { margin: 0; min-height: 1.3em; color: #ffb4a0; font-weight: 700; font-size: 0.98rem; text-shadow: 0 1px 0 #1e120a; }
.av-actions { display: flex; gap: 10px; width: 100%; max-width: 440px; }
.av-btn { flex: 1; min-height: 56px; border-radius: 14px; font: 700 1.1rem "Crimson Text", Georgia, serif; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.av-btn.wood { background: linear-gradient(180deg, #f3e2c0, #d4b070); border: 3px solid #8a6a2a; color: var(--ink); box-shadow: 0 4px 0 #5a3a18; }
.av-btn.wax {
  background: radial-gradient(circle at 35% 30%, #d04040, #7a1414 70%); color: #fde8c8; border: 3px solid #4a0a0a;
  box-shadow: 0 4px 0 #3a0808; text-shadow: 0 1px 0 #3a0808; border-radius: 28px;
}
.av-btn:disabled { opacity: 0.55; cursor: default; }
.av-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.av-btn.stamped { animation: avStamp 0.5s ease; }
@keyframes avStamp { 0% { transform: scale(1); } 40% { transform: scale(0.9) rotate(-4deg); } 100% { transform: scale(1); } }
.av-status { margin: 0; color: var(--parch); opacity: 0.88; min-height: 1.3em; text-align: center; }

/* panel: parchment with filter chips + grid */
.av-panel {
  background: linear-gradient(180deg, var(--parch), var(--parch-d)); border-radius: 16px; border: 3px solid #8a6a2a;
  box-shadow: inset 0 0 40px rgba(120,80,30,0.25), 0 10px 24px rgba(0,0,0,0.4); padding: 14px 16px 20px;
}
.av-filters { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 2px dashed rgba(90,58,24,0.35); }
.av-frow { display: flex; align-items: center; gap: 10px; }
.av-flab { flex: 0 0 64px; font: 700 0.95rem "Cinzel Decorative", Georgia, serif; color: var(--wood-d); }
.av-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.av-chip {
  min-height: 40px; padding: 0 14px; border-radius: 20px; border: 2px solid #8a6a2a; cursor: pointer; white-space: nowrap;
  background: #ead39e; color: var(--ink); font: 700 1rem "Crimson Text", Georgia, serif; -webkit-tap-highlight-color: transparent;
}
.av-chip:hover { background: #f1dcab; }
.av-chip.on { background: linear-gradient(180deg, #6b4226, #4a2c18); color: var(--parch); border-color: #2a180c; }
.av-count { margin: 10px 0 8px; font-size: 0.95rem; color: #5a4030; }
.av-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.av-tile {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 5px; border-radius: 12px; cursor: pointer;
  background: rgba(255,248,230,0.7); border: 2px solid rgba(138,106,42,0.55); color: var(--ink); font: 600 0.95rem "Crimson Text", Georgia, serif;
  -webkit-tap-highlight-color: transparent;
}
.av-tile img { width: 100%; height: auto; aspect-ratio: 1; display: block; border-radius: 8px; background: var(--plum); }
.av-tile:hover { border-color: #8a6a2a; }
.av-tile.on { border-color: var(--wax); box-shadow: 0 0 0 3px rgba(154,36,36,0.38); background: #fff6e0; }
.av-tile.saved::after {
  content: "\2713"; position: absolute; top: 9px; right: 9px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #d04040, #7a1414 70%); color: #fde8c8; font-size: 0.8rem; border: 2px solid #4a0a0a;
}
.av-tile:active { transform: scale(0.97); }
.av-tlab { text-align: center; line-height: 1.1; padding-bottom: 2px; }

@media (max-width: 760px) {
  .av-page { font-size: 17px; }
  .av-main { grid-template-columns: 1fr; padding: 10px; gap: 12px; }
  .av-stage { position: static; }
  .av-frame { max-width: 250px; padding: 8px; }
  .av-back, .av-bar-spacer { min-width: 0; }
  .av-bar-spacer { display: none; }
  .av-bar h1 { font-size: 1.15rem; text-align: left; }
  .av-panel { padding: 10px; }
  .av-frow { align-items: flex-start; flex-direction: column; gap: 4px; }
  .av-flab { flex: none; }
  .av-chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
  .av-chips::-webkit-scrollbar { display: none; }
  .av-chip { flex: 0 0 auto; }
  .av-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .av-tlab { font-size: 0.85rem; }
}

/* av7: paid-change confirm sheet, "Saved!" toast, not-enough-gems line with its fix-it button */
.av-ask { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(20,10,6,0.62); }
.av-ask-card { width: min(380px, 100%); padding: 20px 18px 16px; border-radius: 16px; text-align: center; color: var(--ink);
  background: linear-gradient(180deg, var(--parch), var(--parch-d)); border: 3px solid #8a6a2a; box-shadow: 0 10px 30px rgba(0,0,0,0.55); }
.av-ask-card h3 { margin: 0 0 8px; font: 700 1.2rem "Cinzel Decorative", Georgia, serif; color: var(--wood-d); }
.av-ask-line, .av-ask-have { margin: 0 0 8px; font: 1.08rem "Crimson Text", Georgia, serif; }
.av-ask-row { display: flex; gap: 10px; margin-top: 12px; }
.av-toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); z-index: 70; padding: 12px 26px; border-radius: 14px;
  font: 700 1.3rem "Cinzel Decorative", Georgia, serif; color: var(--parch); background: linear-gradient(180deg, #b03a2e, var(--wax));
  border: 2px solid var(--brass); box-shadow: 0 6px 18px rgba(0,0,0,0.5); animation: avToastIn 0.25s ease; }
@keyframes avToastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.av-status.blocked { opacity: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.av-status .av-need { color: #ffb4a0; font-weight: 700; }
.av-status .av-fix { min-height: 44px; }

/* ---- firsthero_v1: intro story + "Choose your first champion" (first_hero.js). Full-screen, never scrolls (390x844 .. 1280x800). ---- */
html.fh-open, html.fh-open body { overflow: hidden; }
.fh-story, .fh-screen {
  position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; overflow: hidden;
  height: 100vh; height: 100dvh; color: var(--parch); font: 400 18px/1.35 "Crimson Text", Georgia, serif;
}
/* story: placeholder bg = blurred town under dark parchment; a painted slot (story_bg_N) shows sharp */
.fh-story { background: #1c110a; cursor: pointer; -webkit-tap-highlight-color: transparent; outline: none; }
.fh-sbg { position: absolute; inset: -24px; background-size: cover; background-position: center; filter: blur(9px) brightness(0.45) sepia(0.5); }
.fh-sbg.painted { inset: 0; filter: brightness(0.7); }
.fh-story::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(60,36,20,0.25), rgba(20,11,6,0.85) 75%); }
.fh-sbody { position: relative; z-index: 2; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 70px 26px 40px; max-width: 760px; margin: 0 auto; text-align: center; }
.fh-sfig { flex: 0 1 auto; min-height: 0; max-height: 42vh; aspect-ratio: 1; padding: 8px; border-radius: 50%;
  background: linear-gradient(180deg, #c9a24a, #6b4226); box-shadow: 0 10px 30px rgba(0,0,0,0.6); }
.fh-sfig img { width: 100%; height: 100%; display: block; border-radius: 50%; object-fit: cover; }
.fh-sfig:not(.ruler) { border-radius: 18px; aspect-ratio: auto; }
.fh-sfig:not(.ruler) img { border-radius: 12px; object-fit: contain; }
.fh-stext { margin: 0; font-size: clamp(1.35rem, 5.4vw, 2rem); line-height: 1.35; color: #f6e8c8; text-shadow: 0 2px 6px rgba(0,0,0,0.8); }
.fh-stext b { color: #efd48a; }
.fh-stap { margin: 0; font-size: 1.05rem; color: rgba(243,226,192,0.75); animation: fhPulse 1.6s ease-in-out infinite; }
@keyframes fhPulse { 50% { opacity: 0.45; } }
.fh-sdots { display: flex; gap: 10px; }
.fh-sdots i { width: 12px; height: 12px; border-radius: 50%; background: rgba(243,226,192,0.3); border: 1px solid #c9a24a; }
.fh-sdots i.on { background: #efd48a; }
.fh-skip { position: absolute; z-index: 3; top: max(14px, env(safe-area-inset-top)); right: 14px; min-width: 88px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 2px solid var(--brass); background: linear-gradient(180deg, #f3e2c0, #d4b070); color: var(--ink);
  font: 700 1.1rem "Crimson Text", Georgia, serif; cursor: pointer; }

/* champion pick */
.fh-screen { background: radial-gradient(ellipse at 50% -10%, rgba(120,60,90,0.3), transparent 60%), linear-gradient(180deg, #4a2e1a, #1e1209); }
.fh-bar { flex: none; padding: max(10px, env(safe-area-inset-top)) 12px 10px; background: linear-gradient(180deg, #6b4226, #4a2c18);
  border-bottom: 3px solid #2a180c; box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
.fh-bar h1 { margin: 0; text-align: center; font: 700 clamp(1.15rem, 5vw, 1.6rem) "Cinzel Decorative", Georgia, serif; color: var(--parch); text-shadow: 0 2px 0 #1e120a; }
.fh-sub { flex: none; margin: 10px 14px 0; text-align: center; font-size: 1.05rem; color: rgba(243,226,192,0.85); }
.fh-cards { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  padding: 12px; width: 100%; max-width: 1000px; margin: 0 auto; }
.fh-card { min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px 10px; border-radius: 16px;
  background: linear-gradient(180deg, #f3e2c0, #d9bd84); border: 3px solid #8a6a2a; box-shadow: 0 5px 0 #4a2c18, 0 10px 20px rgba(0,0,0,0.4);
  color: var(--ink); font: inherit; text-align: center; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .15s, box-shadow .15s; }
.fh-card.on { border-color: #efd48a; transform: translateY(-3px);
  box-shadow: 0 0 0 3px #9a2424, 0 0 22px 4px rgba(239,212,138,0.75), 0 10px 20px rgba(0,0,0,0.45); }
.fh-art { flex: 1; min-height: 0; width: 100%; display: flex; align-items: flex-end; justify-content: center; border-radius: 10px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 85%, rgba(201,162,74,0.55), rgba(62,38,22,0.15) 70%), #6b4a2e; }
.fh-art img { max-width: 100%; max-height: 100%; height: 100%; object-fit: contain; object-position: center bottom; display: block; }
.fh-name { margin-top: 4px; font: 700 clamp(1.05rem, 4.6vw, 1.5rem) "Cinzel Decorative", Georgia, serif; line-height: 1.1; color: #3e2616; }
.fh-role { font-weight: 700; font-size: clamp(0.9rem, 3.6vw, 1.1rem); color: #9a2424; }
.fh-line { font-size: clamp(0.88rem, 3.5vw, 1.08rem); line-height: 1.2; color: var(--ink); }
.fh-foot { flex: none; padding: 4px 14px max(16px, env(safe-area-inset-bottom)); display: flex; justify-content: center; }
.fh-go { flex: 0 1 460px; width: 100%; min-height: 64px; font-size: 1.35rem; }
.fh-screen.chosen .fh-card:not(.on) { opacity: 0.45; }
/* firsthero_v2: 6 unarmed students (3x2 on phones, one row when wide) + first-study step */
.fh-cards.six { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); max-width: 1180px; }
@media (min-aspect-ratio: 5/4) { .fh-cards.six { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); } }
.fh-cards.six .fh-card { padding: 6px 4px 8px; }
/* races_v1: first honor guard = the 2 of your race (big cards, centered) */
.fh-cards.two { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 760px; }
.fh-more { flex: none; margin: 0 14px 4px; text-align: center; font-size: clamp(0.98rem, 3.9vw, 1.15rem); font-style: italic; color: #efd48a; }
.fh-says { display: block; max-width: 760px; margin: 0 auto; font-size: clamp(1rem, 4.2vw, 1.25rem); color: #f6e8c8; }
.fh-says b { color: #efd48a; }
.fh-art { position: relative; }
.fh-icon { position: absolute; left: 6px; top: 6px; width: clamp(30px, 9vw, 44px) !important; height: clamp(30px, 9vw, 44px) !important; max-height: none !important;
  padding: 4px; border-radius: 50%; background: rgba(243,226,192,0.92); border: 2px solid #c9a24a; object-fit: contain; }
.fh-foot { gap: 10px; }
.fh-back { flex: 0 0 auto; min-width: 96px; min-height: 64px; font-size: 1.15rem; }
/* firsthero_v2b: the knighting */
.fh-knight { flex: 1; min-height: 0; width: 100%; max-width: 900px; margin: 0 auto; padding: 8px 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
@media (min-aspect-ratio: 5/4) { .fh-knight { flex-direction: row; justify-content: center; gap: 28px; } }
.fh-kart { flex: 1 1 auto; min-height: 0; display: flex; align-items: flex-end; justify-content: center; padding: 8px 18px 0; border-radius: 16px;
  background: radial-gradient(ellipse at 50% 88%, rgba(239,212,138,0.55), rgba(62,38,22,0.1) 70%); }
.fh-kart img { max-height: 100%; max-width: 100%; height: 100%; object-fit: contain; display: block; }
@media (min-aspect-ratio: 5/4) { .fh-kart { height: 100%; flex: 0 1 40%; } }
.fh-kform { flex: none; width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 16px;
  background: linear-gradient(180deg, #f3e2c0, #d9bd84); border: 3px solid #8a6a2a; color: var(--ink); }
.fh-kform[hidden] { display: none; }
.fh-klab { font-weight: 700; font-size: 0.95rem; color: #6b4226; }
.fh-krow { display: flex; align-items: center; gap: 8px; }
.fh-kin { flex: 1; min-width: 0; height: 48px; font-size: 1.2rem; }
.fh-kepi { flex: none; font: 700 1.05rem "Crimson Text", Georgia, serif; color: #7a1414; white-space: nowrap; }
.fh-ksug { display: flex; flex-wrap: wrap; gap: 6px; }
.fh-kchip { min-height: 40px; font-size: 1.02rem; }
.fh-kmore { align-self: flex-start; background: none; border: 0; padding: 2px 0; color: #6b4226; text-decoration: underline; font: 700 0.95rem "Crimson Text", Georgia, serif; cursor: pointer; }
.fh-kerr { margin: 0; min-height: 1.2em; font-size: 0.95rem; color: #9a2424; }
.fh-keep { flex: 0 1 220px; min-height: 64px; font-size: 1.1rem; }
.fh-arise { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; animation: fhArise 0.7s ease; }
.fh-arise[hidden] { display: none; }
.fh-afull { font: 700 clamp(1.5rem, 6.5vw, 2.4rem) "Cinzel Decorative", Georgia, serif; color: #efd48a; text-shadow: 0 2px 0 #1e120a, 0 0 18px rgba(239,212,138,0.6); }
.fh-asay { font-size: clamp(1.15rem, 4.8vw, 1.5rem); font-style: italic; color: #f6e8c8; }
.fh-screen.knighted .fh-kart { animation: fhGlow 1.2s ease-in-out infinite; }
@keyframes fhArise { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }
@keyframes fhGlow { 50% { filter: drop-shadow(0 0 18px rgba(255,216,106,0.9)); } }

/* ---- av8: 120 portraits (20 per folk x body). The page fits the screen with no page scroll (390x844 .. 1280x800):
   fixed-height column, compact stage on phones, short outfit chips, and a paged grid whose tile size is fitted in JS
   (avatar_picker.js layoutGrid) to the space left. ---- */
.av-page { height: 100vh; height: 100dvh; min-height: 0; display: flex; flex-direction: column; }
.av-bar { flex: none; position: relative; }
.av-main { flex: 1 1 0; min-height: 0; width: 100%; padding: 14px 18px; grid-template-rows: minmax(0, 1fr); align-items: stretch; }
.av-stage { position: static; min-height: 0; gap: 10px; justify-content: center; }
.av-frame { width: min(440px, 100%, max(160px, calc(100dvh - 372px))); height: auto; flex: none; }
.av-panel { min-height: 0; display: flex; flex-direction: column; padding: 12px 14px 12px; }
.av-filters { flex: none; gap: 6px; padding-bottom: 10px; }
.av-panel .av-chip { min-height: 36px; padding: 0 12px; }
.av-countrow { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; margin: 6px 0 6px; }
.av-countrow .av-count { margin: 0; }
.av-pager { display: flex; align-items: center; gap: 8px; }
.av-pager[hidden] { display: none; }
.av-pbtn {
  min-width: 44px; min-height: 38px; padding: 0 10px; border-radius: 12px; cursor: pointer; font: 700 1.25rem/1 "Crimson Text", Georgia, serif;
  background: linear-gradient(180deg, #f3e2c0, #d4b070); border: 2px solid #8a6a2a; color: var(--ink); box-shadow: 0 3px 0 #5a3a18;
  -webkit-tap-highlight-color: transparent;
}
.av-pbtn:disabled { opacity: 0.4; cursor: default; }
.av-pbtn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.av-pnum { min-width: 3.2em; text-align: center; font-weight: 700; color: #5a4030; }
.av-grid { flex: 1 1 0; min-height: 0; overflow: hidden; align-content: start; justify-content: center; gap: 8px;
  grid-template-columns: repeat(var(--av-cols, 5), var(--av-tile, 118px)); touch-action: pan-y; }
.av-tile { padding: 4px; gap: 3px; }
.av-tile img { width: 100%; }
.av-tlab { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-grid.nolab .av-tlab { display: none; }
.av-tile.saved::after { top: 6px; right: 6px; width: 20px; height: 20px; font-size: 0.7rem; }

@media (max-width: 760px) {
  .av-main { display: flex; flex-direction: column; padding: 8px 10px 10px; gap: 8px; }
  .av-stage {
    flex: none; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 12px; row-gap: 6px; align-items: center;
    grid-template-areas: "frame plate" "frame name" "act act" "status status";
  }
  .av-frame { grid-area: frame; width: clamp(96px, 30vw, 136px); max-width: none; padding: 5px; border-radius: 14px; }
  .av-preview { border-radius: 9px; }
  .av-plate { grid-area: plate; margin: 0; min-width: 0; padding: 3px 10px 4px; align-self: end; text-align: left; border-width: 2px; }
  .av-plate h2 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .av-plate p { font-size: 0.92rem; }
  .av-namebox { grid-area: name; gap: 2px; align-self: start; }
  .av-nlab { display: none; }
  .av-stage .av-ninput { min-height: 44px; font-size: 1.05rem; padding: 0 10px; }
  .av-stage .av-dice { flex-basis: 46px; min-height: 44px; font-size: 1.3rem; }
  .av-nerr { min-height: 1.15em; font-size: 0.88rem; line-height: 1.15; }
  .av-actions { grid-area: act; }
  .av-stage .av-btn { min-height: 48px; }
  .av-status { grid-area: status; font-size: 0.95rem; line-height: 1.2; min-height: 1.2em; }
  .av-panel { flex: 1 1 0; padding: 8px 8px 8px; }
  .av-filters { gap: 5px; padding-bottom: 8px; }
  .av-frow { flex-direction: row; align-items: center; gap: 6px; }
  .av-flab { flex: 0 0 50px; font-size: 0.82rem; }
  .av-panel .av-chip { min-height: 36px; padding: 0 11px; font-size: 0.95rem; }
  .av-countrow { min-height: 38px; margin: 4px 0; }
  .av-grid { gap: 6px; }
  .av-tile { padding: 3px; border-radius: 10px; }
  .av-tile img { border-radius: 7px; }
  .av-tlab { font-size: 0.78rem; }
}
/* racebeat_v1 (Brandon 6:36 PM): one short line above the Folk (race) chips */
.av-raceline { margin: 0; font: italic 600 clamp(0.82rem, 2.4vw, 0.95rem)/1.3 Georgia, serif; color: var(--wood-d); text-align: center; }
/* night1 (Brandon 10:31 PM): first-study cards line up: same art box, figure centered on one bottom baseline,
   name + line on the same rows in all three cards (the line row is 3 lines tall in every card) */
.fh-screen.step-class .fh-card { display: grid; grid-template-rows: minmax(0, 1fr) auto 3.7em; justify-items: center; align-items: start; }
.fh-screen.step-class .fh-art { width: 100%; height: 100%; align-self: stretch; container-type: size; }
.fh-screen.step-class .fh-art img:not(.fh-icon) { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: auto; max-width: none; height: min(96cqh, calc(100cqw / var(--fh-ar, 0.5))); max-height: none; object-fit: contain; }
.fh-screen.step-class .fh-name { align-self: end; }
.fh-screen.step-class .fh-line { font-size: clamp(0.82rem, 3.3vw, 1.05rem); line-height: 1.2; text-align: center; overflow: hidden; }
