/* Adaptive layouts. Every rule is under html.adapt or a touch/a11y hook so the desktop 1280×800 stage is unchanged.
   Keyword words are clipped off the desktop tokens and shown only in the adaptive layout. */
.tok .kwlab, .gbadge .kwlab { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

html.adapt { --ad-ink: #f3e6c4; --ad-dim: #c9b48a; }
html.adapt #stage {
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--ad-hud, 48px) var(--ad-rival, 56px) minmax(0, 1fr) var(--ad-you, 64px) var(--ad-hand, 164px);
  grid-template-areas: "hud" "rival" "field" "you" "hand";
  box-shadow: none;
}
html.adapt #stage > * { inset: auto; }
html.adapt #topbar, html.adapt #field, html.adapt #hand, html.adapt #endzone { position: relative !important; }
html.adapt #props { z-index: 1; display: none; }
html.adapt #hud { grid-area: hud; position: relative; left: auto; right: auto; top: auto; height: auto; z-index: 40; padding: 0 8px; display: flex; align-items: center; justify-content: flex-end; }
html.adapt #btn-menu { min-width: 48px; min-height: 48px; padding: 0 14px; font-size: 14px; }
html.adapt #rhand { position: absolute; left: 12px; top: 8px; width: auto; height: 0; display: flex; z-index: 5; }
html.adapt #rhand .back { position: relative; left: auto !important; top: auto; width: 22px; height: 16px; margin: 0 -8px; }
html.adapt #hz1 { grid-area: rival; position: relative; }
html.adapt #field { grid-area: field; position: relative; inset: auto; min-height: 0; z-index: 7; display: flex; flex-direction: column; justify-content: center; gap: var(--ad-gap, 6px); padding: 0 8px; overflow: hidden; }
html.adapt #hz0 { grid-area: you; position: relative; }
html.adapt #hand { grid-area: hand; position: relative; }
html.adapt .hz, html.adapt #hz0, html.adapt #hz1 { position: relative !important; transform: none !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; width: 100%; height: 100%; min-height: 0; margin: 0; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 6px; z-index: 8; padding: 0 8px; box-sizing: border-box; overflow: hidden; align-self: stretch; }
html.adapt .hz .portrait { position: relative; left: auto; top: auto !important; margin: 0; width: min(72px, calc(100% - 4px)); height: calc(100% - 6px); max-height: 96px; flex: none; }
html.adapt .hz .nm, html.adapt #hz1 .nm { position: relative; left: auto; top: auto !important; transform: none; min-width: 0; max-width: 28vw; font-size: 13px; white-space: normal; line-height: 1.05; }
html.adapt .hz .heart, html.adapt #hz1 .heart { position: relative; left: auto; top: auto !important; margin: 0; width: 48px; height: 44px; flex: none; }
html.adapt .hz .faith, html.adapt #hz1 .faith { position: relative; right: auto; top: auto !important; width: auto; max-width: none; min-width: 4.6rem; flex: 0 0 auto; text-align: left; margin: 0; overflow: visible; }
html.adapt .hz .faith .fl { letter-spacing: .08em; font-size: 11px; }
html.adapt .hz .faith .fn { font-size: 18px; white-space: nowrap; }
html.adapt .hz .power, html.adapt #hz1 .power { position: relative; left: auto; top: auto !important; margin: 0; width: 48px; height: 48px; min-width: 48px; min-height: 48px; flex: none; }
html.adapt .hz .power .pl { display: none; }
html.adapt .hz .seals, html.adapt #hz0 .seals, html.adapt #hz1 .seals { position: relative; left: auto; top: auto !important; margin: 0; width: auto; height: 36px; }
html.adapt #field::before, html.adapt #field::after { display: none; }
html.adapt #row0, html.adapt #row1 { position: relative !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; width: 100%; height: var(--ad-tok-h, 88px); flex: 0 0 auto; margin: 0; gap: var(--ad-gap, 6px); overflow: hidden; }
html.adapt .tok { width: var(--ad-tok, 64px); height: var(--ad-tok-h, 88px); overflow: hidden; }
html.adapt .tok .tbody { position: absolute; inset: auto; top: 0; left: 0; width: var(--ad-tok, 64px); height: var(--ad-tok, 64px); }
html.adapt .tok .tring, html.adapt .tok .tart { width: var(--ad-tok, 64px); height: var(--ad-tok, 64px); border-radius: 50%; }
html.adapt .tok .tname { max-width: var(--ad-tok, 64px); font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; max-height: 1.2em; bottom: 0; display: block; -webkit-line-clamp: 1; }
html.adapt .tok .stat { width: 22px; height: 22px; min-width: 22px; font-size: 12px; bottom: calc(100% - var(--ad-tok, 64px) + 2px); }
html.adapt .tok .stat.atk { left: 0; }
html.adapt .tok .stat.hp { right: 0; }
html.adapt .tok .tkw { top: 0; left: 0; right: 0; width: auto; transform: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 100%; }
html.adapt .tok .tkw i, html.adapt .gbadge { width: auto; min-width: 16px; height: auto; min-height: 16px; padding: 1px 3px; display: inline-flex; align-items: center; gap: 2px; }
html.adapt .tok .kwlab, html.adapt .gbadge .kwlab { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; font-family: Cinzel, serif; font-size: 8px; font-weight: 700; letter-spacing: .02em; line-height: 1; color: #2a1606; }
html.adapt #hand { left: auto; bottom: auto; width: 100%; height: 100%; display: flex; flex-direction: row; align-items: stretch; gap: 8px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-padding-inline: 12px; -webkit-overflow-scrolling: touch; padding: 4px 10px; box-sizing: border-box; z-index: 20; }
html.adapt #hand .card { position: relative !important; left: auto !important; bottom: auto !important; flex: 0 0 var(--ad-card-w, 112px); width: var(--ad-card-w, 112px); height: 100% !important; max-height: 100%; scroll-snap-align: center; transform: none !important; margin: 0; overflow: hidden; }
html.adapt #hand .card .c-in { inset: 5px 5px 4px; }
html.adapt #hand .card .c-head { height: auto; min-height: 22px; max-height: 2.6em; padding: 1px 4px 0 30px; }
html.adapt #hand .card .c-name { font-size: 12px; line-height: 1.05; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
html.adapt #hand .card .c-art { height: 28%; min-height: 28px; }
html.adapt #hand .card .c-type { height: 14px; font-size: 8px; }
html.adapt #hand .card .c-text { font-size: 11px; line-height: 1.12; padding: 2px 4px 20px; overflow: hidden; }
html.adapt #hand .card .c-cost { left: 2px; top: 2px; width: 26px; height: 26px; font-size: 13px; }
html.adapt #hand .card .c-stats { left: 4px; right: 4px; bottom: 3px; }
html.adapt #hand .card .stat { min-width: 26px; height: 22px; font-size: 14px; }
html.adapt #hand .card.playable { box-shadow: 0 0 0 2px rgba(255, 220, 140, .9); }
html.adapt #hz0 { padding-right: 168px; }
html.adapt #endzone { grid-area: you; position: relative; right: auto; bottom: auto; top: auto; width: auto; height: 100%; z-index: 12; display: flex; flex-direction: row; align-items: center; justify-content: flex-end; margin: 0 8px 0 0; pointer-events: none; }
html.adapt #endzone * { pointer-events: auto; }
html.adapt #btn-end { width: 168px; min-width: 48px; min-height: 48px; height: 48px; padding: 0 8px; box-sizing: border-box; }
html.adapt #banner { position: fixed; left: calc(var(--safe-left, 0px) + 76px); top: var(--safe-top, 0px); height: var(--ad-hud, 48px); margin: 0; display: flex; align-items: center; z-index: 45; pointer-events: none; max-width: calc(100vw - 230px); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; letter-spacing: .08em; }
html.adapt[data-bp="tablet"] .tok .tname, html.adapt[data-bp="expanded"] .tok .tname, html.adapt[data-bp="fold"] .tok .tname { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 11px; line-height: 1.05; max-height: 2.3em; text-overflow: unset; }
html.adapt #deck0, html.adapt #deck1 { position: absolute; width: 40px; height: 32px; left: 8px; right: auto; z-index: 6; }
html.adapt #deck1 { top: calc(var(--ad-hud, 48px) + 4px); }
html.adapt #deck0 { bottom: calc(var(--ad-hand, 164px) + 8px); top: auto; }
html.adapt #preview, html.touchplay #preview { display: none !important; }
html.adapt #histw { display: none; }
html.adapt #logdrawer { top: var(--ad-hud, 48px); }
html.adapt .tok.aimpick .tbody, html.adapt .hz.aimpick .portrait { outline: 3px solid #fff1c4; outline-offset: 2px; }
html.adapt .qbanner, html.adapt .hz.q-left .qbanner { position: relative; left: auto; top: auto; margin: 0; transform: none; width: min(132px, 24vw); max-height: 100%; overflow: hidden; padding: 2px 6px; flex: 0 1 132px; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
html.adapt .qbanner .qn { position: static; font-size: 12px; line-height: 1; white-space: nowrap; }
/* Phone landscape: heroes and End Turn share the top bar. Servant plaques use the full row width. */
html.compact-land #stage {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 168px auto;
  grid-template-rows: var(--ad-hud, 48px) minmax(0, 1fr) var(--ad-hand, 96px);
  grid-template-areas: "rival you end menu" "field field field field" "hand hand hand hand";
}
html.compact-land #hz1 { grid-area: rival; padding-left: 42px; }
html.compact-land #hz1 .portrait, html.compact-land #hz0 .portrait { left: 0 !important; margin: 0 !important; position: relative !important; }
html.compact-land #hz0 { grid-area: you; padding-right: 2px; }
html.compact-land #endzone { grid-area: end; width: 168px; margin: 0; justify-content: center; }
html.compact-land #hud { grid-area: menu; justify-content: center; padding: 0 4px; }
html.compact-land #field { grid-area: field; padding: 2px 6px 2px 42px; }
html.compact-land #hand { grid-area: hand; }
html.compact-land #banner { display: none; }
html.compact-land #deck1 { top: 6px; left: 4px; width: 34px; height: 28px; }
html.compact-land #deck0 { top: auto; bottom: calc(var(--ad-hand, 96px) + 6px); left: 4px; width: 34px; height: 28px; }
html.compact-land .hz { gap: 4px; padding: 0 2px; overflow: hidden; justify-content: flex-start; }
html.compact-land #hz0 .portrait, html.compact-land #hz1 .portrait { width: 36px; height: 36px; max-height: 36px; flex: none; }
html.compact-land #hz0 .heart, html.compact-land #hz1 .heart { width: 36px; height: 34px; flex: none; }
html.compact-land .hz .nm { flex: 1 1 32px; min-width: 32px; max-width: 96px; font-size: 11px; max-height: 2.4em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0; }
html.compact-land .hz .nm small { display: none; }
html.compact-land .hz .faith { min-width: 0; flex: none; }
html.compact-land .hz .faith .fl { font-size: 0; line-height: 0; }
html.compact-land .hz .faith .fn { font-size: 15px; line-height: 1.2; }
html.compact-land .hz .faith .pips { display: none; }
html.compact-land .hz .seals, html.compact-land .hz .rels, html.compact-land .hz .wardb { display: none; }
html.compact-land .qbanner { flex: 0 0 52px; width: 52px; padding: 2px; align-items: stretch; }
html.compact-land .qbanner .qh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
html.compact-land .qbanner .qn { font-size: 13px; text-align: center; }
html.compact-land .qbanner .qbar { width: 100%; }
html.compact-land #row0, html.compact-land #row1 { height: auto; flex: 1 1 0; min-height: 0; align-items: stretch; gap: var(--ad-gap, 4px); overflow: hidden; }
html.compact-land .tok { flex: 1 1 0 !important; width: auto; min-width: 0; height: 100%; overflow: hidden; }
html.compact-land .tok .tbody { inset: 0; width: auto; height: auto; }
html.compact-land .tok .tring { inset: 0; width: auto; height: auto; border-radius: 8px; }
html.compact-land .tok .tart { position: absolute; left: 2px; right: 2px; top: 2px; bottom: calc(var(--ad-name, 22px)); width: auto; height: auto; border-radius: 6px; overflow: hidden; }
html.compact-land .tok .tart .pic { width: 100%; height: 100%; object-fit: cover; object-position: 50% 16%; transform: none; border-radius: 0; }
html.compact-land .tok .tart::after { border-radius: 6px; }
html.compact-land .tok .tname, html.compact-land .tok .tname.tn2 { position: absolute; left: 1px; right: 1px; bottom: 0; transform: none; min-width: 0; max-width: none; width: auto; margin: 0; padding: 1px 2px; font-size: 10.5px; line-height: 1.05; letter-spacing: 0; white-space: normal; text-overflow: clip; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; max-height: calc(var(--ad-name, 22px)); border-radius: 2px; }
html.compact-land .tok .stat { width: 22px; height: 22px; min-width: 22px; font-size: 12px; bottom: calc(var(--ad-name, 22px) + 1px); }
html.compact-land .tok .stat.atk { left: 2px; }
html.compact-land .tok .stat.hp { right: 2px; }
html.compact-land .tok .tkw { top: 2px; left: 2px; right: 24px; height: 16px; flex-wrap: nowrap; overflow: hidden; }
html.compact-land .tok .tkw i:not(:first-child) .kwlab, html.compact-land .gbadge .kwlab { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
html.compact-land .tok .kwlab { font-size: 9px; }
html.compact-land #hand .card .c-text, html.compact-land #hand .card .c-type { display: none; }
html.compact-land #hand .card .c-art { display: block; height: 22px; min-height: 0; }
html.compact-land #hand .card .c-name { font-size: 12px; letter-spacing: 0; -webkit-line-clamp: 2; }
html.compact-land #hand .card .c-head { min-height: 0; max-height: 2.6em; padding-top: 2px; }
html.compact-land #hand .card .c-cost { width: 26px; height: 26px; font-size: 14px; }
html.compact-land #hand .card .c-stats { bottom: 3px; }
html.compact-land #hand .card .stat { min-width: 24px; height: 22px; font-size: 14px; }
html.compact-land .aimbar { top: auto; bottom: var(--safe-bottom, 0px); min-height: 48px; }
html.compact-land .aimbar .sheet-btn { min-width: 96px; min-height: 48px; }
html.adapt .qbanner .qt { display: none; }
html.adapt .qbanner .qh { font-size: 9px; min-height: 0; padding-right: 18px; }

html.adapt[data-bp="tablet"] .hz .portrait,
html.adapt[data-bp="expanded"] .hz .portrait,
html.adapt[data-bp="fold"] .hz .portrait { width: 96px; height: 96px; max-height: none; }
html.adapt[data-bp="tablet"] .hz .power,
html.adapt[data-bp="expanded"] .hz .power,
html.adapt[data-bp="fold"] .hz .power { width: 64px; height: 64px; }
html.adapt[data-bp="tablet"] .hz .heart,
html.adapt[data-bp="expanded"] .hz .heart,
html.adapt[data-bp="fold"] .hz .heart { width: 64px; height: 56px; }
html.adapt[data-bp="tablet"] .hz .nm,
html.adapt[data-bp="expanded"] .hz .nm,
html.adapt[data-bp="fold"] .hz .nm { font-size: 16px; max-width: 24vw; }
html.adapt[data-bp="tablet"] .tok .tname,
html.adapt[data-bp="expanded"] .tok .tname,
html.adapt[data-bp="fold"] .tok .tname { font-size: 12px; }
html.adapt[data-bp="tablet"] .tok .kwlab,
html.adapt[data-bp="expanded"] .tok .kwlab,
html.adapt[data-bp="fold"] .tok .kwlab { font-size: 10px; }
html.adapt[data-bp="tablet"] #hand .card .c-name,
html.adapt[data-bp="expanded"] #hand .card .c-name,
html.adapt[data-bp="fold"] #hand .card .c-name { font-size: 15px; }
html.adapt[data-bp="tablet"] #hand .card .c-text,
html.adapt[data-bp="expanded"] #hand .card .c-text,
html.adapt[data-bp="fold"] #hand .card .c-text { font-size: 13px; }

.sheet, .aimbar, .rotatehint, .exitask { font-family: "Cormorant Garamond", "Palatino Linotype", Palatino, serif; color: #f6ecd4; }
.sheet[hidden], .aimbar[hidden], .exitask[hidden] { display: none !important; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; display: flex; gap: 12px; max-height: min(72vh, 560px); padding: 12px 12px calc(12px + var(--safe-bottom, 0px)); background: linear-gradient(180deg, rgba(42, 18, 14, .98), rgba(12, 6, 4, .98)); border-top: 2px solid #c9a35a; box-shadow: 0 -18px 40px rgba(0, 0, 0, .55); }
.sheet-card { flex: 0 0 148px; overflow: auto; max-height: 100%; }
.sheet-card .card { position: relative !important; left: auto !important; bottom: auto !important; transform: none !important; width: 140px; height: 210px; overflow: visible; }
.sheet-card .card .c-name { white-space: normal; -webkit-line-clamp: unset; display: block; overflow: visible; }
.sheet-body { flex: 1 1 auto; min-width: 0; overflow: auto; }
.sheet-body h2 { margin: 0 0 4px; font-family: Cinzel, "Times New Roman", serif; font-size: 1.35rem; letter-spacing: .04em; color: #f3e2ae; }
.sheet-meta { margin: 0 0 6px; color: #e7d7a4; font-size: 1rem; }
.sheet-body p { margin: 0 0 8px; font-size: 1.05rem; line-height: 1.35; }
.sheet-body ul { margin: 0 0 8px; padding-left: 1.1rem; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-btn { min-width: var(--ad-ctrl-w, 112px); min-height: 48px; padding: 0 14px; border-radius: 8px; border: 1px solid #c9a35a; background: #2a140e; color: #f6ecd4; font: 700 1rem/1 Cinzel, serif; letter-spacing: .04em; }
.sheet-btn.primary { background: linear-gradient(180deg, #8d1d2b, #4c0d16); color: #fff6df; }
.sheet-btn:disabled { opacity: .45; }
.aimbar { position: fixed; left: max(8px, var(--safe-left, 0px)); right: max(8px, var(--safe-right, 0px)); bottom: calc(var(--ad-hand, 164px) + var(--safe-bottom, 0px) + 8px); z-index: 70; display: flex; align-items: center; gap: 8px; padding: 8px; background: rgba(16, 8, 6, .94); border: 1px solid #c9a35a; border-radius: 10px; }
.aimbar p { flex: 1 1 auto; margin: 0; font-size: 1rem; }
html.rotate-hint.match-on #rotatehint, html.short-gate.match-on #shortgate { display: flex; }
html.rotate-hint.match-on #endzone, html.short-gate.match-on #endzone, html.rotate-hint.match-on #hud, html.short-gate.match-on #hud { z-index: 72; }
html.short-gate .shortgate { padding-right: 196px; }
.rotatehint { display: none; position: fixed; left: 0; right: 0; top: var(--ad-hud, 48px); bottom: 0; z-index: 65; align-items: center; justify-content: center; padding: 24px; text-align: center; background: rgba(8, 4, 3, .82); }
.rotatehint h2 { font-family: Cinzel, serif; color: #f3e2ae; margin: 0 0 8px; }
.rotatehint p { max-width: 28rem; margin: 0 auto; font-size: 1.15rem; line-height: 1.4; }
.exitask { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .62); padding: 20px; }
.exitask > div { max-width: 28rem; background: #1a0c09; border: 1px solid #c9a35a; padding: 18px; }
.exitask h2 { font-family: Cinzel, serif; margin: 0 0 8px; color: #f3e2ae; }

html.adapt #mainmenu, html.adapt #title, html.adapt #arenascreen, html.adapt #builder { overflow: auto; padding-top: calc(12px + var(--safe-top, 0px)); padding-bottom: calc(18px + var(--safe-bottom, 0px)); padding-left: var(--safe-left, 0px); padding-right: var(--safe-right, 0px); }
html.adapt #mainmenu .mm-in { width: min(440px, 92vw); }
html.adapt #mainmenu .mm-logo h1 { font-size: clamp(28px, 10vw, 64px); letter-spacing: .05em; padding-left: .05em; }
html.adapt #mainmenu .mm-logo .tag { letter-spacing: .22em; padding-left: .22em; font-size: clamp(11px, 3.2vw, 16px); }
html.adapt .mm-btn, html.adapt .langopt, html.adapt .db-btn, html.adapt #t-back, html.adapt #t-next, html.adapt #ar-back, html.adapt #ar-go { min-height: 48px; min-width: 48px; }
html.adapt #title .heroes, html.adapt #builder .db-main { display: flex; flex-direction: column; }
html.adapt[data-bp="tablet"] #builder .db-main, html.adapt[data-bp="expanded"] #builder .db-main, html.adapt[data-bp="fold"] #builder .db-main { flex-direction: row; align-items: stretch; }
html.adapt #cardsmodal .modal, html.adapt #helpmodal .modal, html.adapt #setmodal .modal, html.adapt #creditsmodal .modal { max-height: calc(100vh - var(--safe-top, 0px) - var(--safe-bottom, 0px) - 16px); overflow: auto; width: min(960px, calc(100vw - 16px)); }
html.adapt[data-bp="tablet"] #cardsmodal .modal, html.adapt[data-bp="expanded"] #cardsmodal .modal, html.adapt[data-bp="fold"] #cardsmodal .modal { width: min(1100px, calc(100vw - 24px)); }
html.adapt #cardgrid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
html.adapt #gamemenu { max-height: calc(100vh - var(--safe-top, 0px) - 64px); overflow: auto; }
html.adapt #gamemenu button, html.adapt .gm-it { min-height: 48px; }

@media (prefers-reduced-motion: reduce) {
  html.adapt *, html.adapt *::before, html.adapt *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (prefers-contrast: more) {
  html.adapt .tok .tname, html.adapt .tok .tkw i, html.adapt .sheet, html.adapt #btn-end, html.adapt .sheet-btn { outline: 2px solid #fff8e0; }
  html.adapt .tok .stat { box-shadow: 0 0 0 2px #fff; }
}
html.reduce-motion #rotatehint, html.reduce-motion .sheet { animation: none; }

@media (max-width: 520px) {
  .sheet { flex-direction: column; }
  .sheet-card { flex-basis: auto; display: flex; justify-content: center; }
}
