/* App shell (nav.js): persistent navigation and responsive page layouts for every screen outside a
   match. Loaded last. Phones get a bottom tab bar (Marvel Snap); from 900px wide a left rail
   (MTG Arena / Hearthstone desktop), which grows labels beside the icons from 1280px. Content screens
   get a readable centred column; the home screen spreads into three columns on desktop. */

/* ---------- frame ---------- */
body.nav-on { display: flex; flex-direction: column; }
body.nav-on #app { flex: 1; min-height: 0; height: auto; width: 100%; max-width: none; padding-bottom: 0; }
#nav { flex: none; display: flex; position: relative; z-index: 30; background: var(--deep); box-shadow: 0 -3px 0 var(--ink), inset 0 3px 0 var(--rimlo);
  padding: 0 max(4px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left, 0px)); font-family: var(--pixel); }
#nav[hidden] { display: none; }
.nv-brand { display: none; }
.nv-tab { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 58px;
  background: none; border: 0; padding: 0; color: var(--dim); font-size: 13px; letter-spacing: .05em; cursor: pointer; }
.nv-tab svg { width: 24px; height: 24px; shape-rendering: crispEdges; }
.nv-tab.on { color: var(--gold); }
.nv-tab.on::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; background: var(--gold); box-shadow: 0 0 10px rgba(242,193,78,.6); }
.nv-tab:active { background: rgba(255,255,255,.04); }
.nv-dot { position: absolute; top: 9px; left: calc(50% + 10px); width: 8px; height: 8px; background: var(--gold); box-shadow: 0 0 0 2px var(--ink); }
/* The deck editor brings its own bottom bar on phones. */
@media (max-width: 899px) { body[data-screen="deckedit"] #nav { display: none; } }

@media (min-width: 900px) {
  body.nav-on { flex-direction: row; }
  #nav { order: -1; flex-direction: column; width: 96px; padding: max(12px, env(safe-area-inset-top, 0px)) 0 12px max(0px, env(safe-area-inset-left, 0px));
    box-shadow: 3px 0 0 var(--ink), inset -3px 0 0 var(--rimlo); gap: 4px; }
  .nv-brand { display: flex; flex-direction: column; align-items: center; padding: 6px 4px 16px; text-align: center; }
  .nv-brand small { font-size: 11px; letter-spacing: .25em; color: var(--gold); opacity: .8; }
  .nv-brand b { font-weight: 400; font-size: 15px; color: var(--cream); margin-top: 2px; }
  .nv-tab { flex: none; height: 76px; font-size: 14px; gap: 6px; }
  .nv-tab svg { width: 28px; height: 28px; }
  .nv-tab.on { background: linear-gradient(90deg, rgba(242,193,78,.14), transparent); }
  .nv-tab.on::before { top: 12px; bottom: 12px; left: 0; right: auto; width: 4px; height: auto; }
  .nv-dot { top: 12px; left: calc(50% + 12px); }
}
@media (min-width: 1280px) {
  #nav { width: 212px; padding-inline: 12px; }
  .nv-brand { align-items: flex-start; padding: 8px 12px 22px; text-align: left; }
  .nv-brand small { font-size: 11px; }
  .nv-brand b { font-size: 22px; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
  .nv-tab { flex-direction: row; justify-content: flex-start; gap: 14px; height: 54px; padding: 0 14px; font-size: 17px; }
  .nv-tab svg { width: 24px; height: 24px; }
  .nv-tab.on::before { top: 10px; bottom: 10px; left: -12px; }
  .nv-dot { top: 50%; left: auto; right: 14px; margin-top: -4px; }
}

/* ---------- sub-tabs (收藏 / 日志 / 我) ---------- */
.subtabs { position: sticky; top: -10px; z-index: 6; display: flex; gap: 6px; margin: -10px calc(-1 * var(--sx, 0px)) 0; padding: 10px var(--sx, 0px) 8px;
  background: linear-gradient(var(--night) 80%, transparent); overflow-x: auto; scrollbar-width: none; flex: none; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button { flex: none; font: inherit; font-size: 15px; color: var(--dim); background: var(--deep); border: 0; padding: 9px 16px; cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--rimlo); white-space: nowrap; }
.subtabs .sub-act { margin-left: auto; font-size: 14px; padding: 6px 12px; }
.subtabs button.on { color: var(--ink); background: var(--gold); box-shadow: inset 0 -3px 0 var(--goldlo); }
/* Root screens of an area: no back arrow, and the sub-tabs already name the page. */
.nav-root > .topbar > .icon-btn[data-act="home"] { display: none; }
.nav-root:has(> .subtabs) > .topbar > h2 { display: none; }
.nav-root:has(> .subtabs) > .topbar:not(:has(> :not(h2):not([data-act="home"]))) { display: none; }
.nav-root:has(> .subtabs) > .topbar { justify-content: flex-end; }

/* ---------- content screens: readable centred column ---------- */
section.in-shell:not(#title) { --mx: 760px; --sx: max(16px, calc((100% - var(--mx)) / 2)); padding-inline: var(--sx); padding-bottom: 24px; }
#decks.in-shell, #deckpick.in-shell, #heroes.in-shell { --mx: 1100px; }
#codex.in-shell { --mx: 1280px; }
#ladder.in-shell, #profile.in-shell { --mx: 900px; }
#deckedit.in-shell { --mx: 1400px; }
@media (min-width: 900px) {
  section.in-shell:not(#title) { padding-top: 22px; }
  .subtabs { top: -22px; margin-top: -22px; padding-top: 22px; }
  .subtabs button { font-size: 16px; padding: 10px 20px; }
  section.in-shell .topbar h2 { font-size: 30px; }
  #codex.in-shell .codex { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  #codex.in-shell .codex button { font-size: 14px; }
  #codex.in-shell .codex button div { height: 150px; }
  #rules.in-shell .rules { font-size: 16px; line-height: 1.7; }
  .qs-q { padding: 14px 16px; }
}

/* Big screens: the pixel UI was drawn for phones, so scale the content pages up rather than leave
   12px type on a 27" monitor. The duel and the deck editor size themselves and are left alone. */
@media (min-width: 1200px) and (min-height: 760px) {
  #decks.in-shell, #codex.in-shell, #deckpick.in-shell, #heroes.in-shell, #quests.in-shell, #ladder.in-shell,
  #collroad.in-shell, #profile.in-shell, #rules.in-shell { zoom: 1.25; }
}
@media (min-width: 1700px) and (min-height: 1000px) {
  #decks.in-shell, #codex.in-shell, #deckpick.in-shell, #heroes.in-shell, #quests.in-shell, #ladder.in-shell,
  #collroad.in-shell, #profile.in-shell, #rules.in-shell { zoom: 1.5; }
}
@media (min-width: 700px) and (max-width: 1199px) and (min-height: 900px) {
  #decks.in-shell, #codex.in-shell, #deckpick.in-shell, #heroes.in-shell, #quests.in-shell, #ladder.in-shell,
  #collroad.in-shell, #profile.in-shell, #rules.in-shell { zoom: 1.2; }
}
/* Night Patrol has no nav (a mode, like Hearthstone's adventures) but gets the same readable column. */
@media (min-width: 900px) { #app > section.np { padding-inline: max(16px, calc((100% - 960px) / 2)); } }

/* ---------- home: the hall + Play panel ---------- */
#title.hall.in-shell { padding-bottom: 12px; }
.hm-side { position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.hm-side .qs-card { display: none; }
.hm-play { position: relative; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.hm-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hm-chips > button { height: 54px; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 0 8px; color: var(--cream); text-align: left; }
#title.hall .hm-chips .lg-btn .lg-emb { width: 30px; height: 30px; flex: none; }
.hm-chips .lg-btn > span { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.hm-chips .lg-btn > span b { font-weight: 400; font-size: 12px; color: var(--dim); }
#title.hall .hm-chips .lg-btn > span small { display: block !important; font-size: 14px; color: var(--cream); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hm-chips .lg-btn .lg-stars { display: none; }
.hm-deck .pic { flex: none; width: 34px; height: 34px; background: var(--deep) center 20% / cover; box-shadow: 0 0 0 2px var(--ink); }
.hm-deck .txt { flex: 1; display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.hm-deck small { font-size: 12px; color: var(--dim); }
.hm-deck b { font-weight: 400; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hm-deck em { flex: none; font-style: normal; font-size: 12px; color: var(--gold); }
/* English names run long on a phone's half-width chip: the art names the deck, the chip just says Deck (backlog #87). */
@media (max-width: 599px) { .hm-deck.en b { display: none; } .hm-deck.en small { font-size: 14px; color: var(--cream); } }
.hm-go { height: 66px; font-size: 26px; }
.hm-go.teach, .hm-go.hm-ranked { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.hm-go.hm-ranked small { font-size: 13px; opacity: .85; margin-top: 3px; }
/* 今晚值班 (duty.js): today's three things on phones, three cells in one row; desktop has the quests panel. */
.hm-duty { display: grid; gap: 6px; padding: 8px; background: rgba(14,19,44,.78); box-shadow: inset 0 0 0 2px var(--rimlo), var(--frame); }
.hm-duty .dt-h { font-weight: 400; font-size: 13px; color: var(--gold); }
.hm-duty ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.dt-row { width: 100%; min-height: 44px; display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 6px; align-items: center;
  padding: 5px 6px; border: 0; background: rgba(255,255,255,.04); color: var(--cream); font: inherit; text-align: left; cursor: pointer; box-shadow: inset 0 0 0 1px var(--rimlo); }
.dt-row > span { font-size: 13px; line-height: 1.15; }
.dt-row > small { grid-column: 2; font-size: 12px; color: var(--gold); line-height: 1.2; }
.dt-row.ok > span { color: var(--dim); }
.dt-box { grid-row: 1 / span 2; width: 14px; height: 14px; display: grid; place-items: center; font-style: normal; font-size: 12px; line-height: 1;
  box-shadow: inset 0 0 0 2px var(--dim); color: var(--teal); }
.dt-row.ok .dt-box { box-shadow: inset 0 0 0 2px var(--teal); }
.dt-row:focus-visible, .dt-row:hover { box-shadow: inset 0 0 0 1px var(--gold); }
.hm-duty .dt-done { margin: 0; font-size: 13px; color: var(--teal); }
@media (min-width: 900px) { .hm-duty { display: none; } }
.hm-second { height: 44px; font-size: 16px; }
/* Past the deck menu the other modes fold into this one entry and a sheet (ui.js modesSheet). */
.hm-more { position: relative; height: 44px; font-size: 15px; color: var(--cream); }
.hm-sheet h4 { color: var(--gold); }
.hm-list { display: grid; gap: 8px; }
.hm-list > button { position: relative; width: 100%; min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 12px; font-size: 16px; line-height: 1.2; color: var(--cream); }
.hm-list > button small { font-size: 12px; color: var(--gold); }
.hm-list > .fd-locked { flex-direction: row; gap: 8px; color: var(--dim); }
.hm-modes { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; }
.hm-modes small { font-size: 12px; color: var(--dim); margin-right: 2px; }
.hm-modes .ghost-btn { font-size: 13px; padding: 5px 12px; color: var(--cream); }
#title.hall .hm-side .hl-feed ul { max-height: calc(2 * 1.45em + 4px); }
/* A phone with the shift list up: the feed is one quiet line, no panel of its own (scorecard 11-04 6-3). Scrolls for the rest. */
@media (max-width: 599px) {
  #title.hall:has(.hm-duty) .hm-side .hl-feed { padding: 2px 10px; background: none; border: 0; text-shadow: 0 1px 2px #000; }
  #title.hall:has(.hm-duty) .hm-side .hl-feed h3 { display: none; }
  #title.hall:has(.hm-duty) .hm-side .hl-feed ul { max-height: 1.45em; gap: 0; }
  #title.hall:has(.hm-duty) .hm-side .hl-feed li > :last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
}

/* Tablets held upright: a centred panel instead of edge-to-edge buttons, and room for the quests. */
@media (min-width: 600px) and (max-width: 899px) and (min-height: 800px) {
  .hm-side, .hm-play { width: min(100%, 560px); margin-inline: auto; }
  .hm-side { margin-top: 8px; }
  .hm-side .qs-card { display: grid; gap: 6px; width: 100%; padding: 10px; text-align: left; font: inherit; color: inherit; cursor: pointer;
    background: rgba(14,19,44,.78); border: 0; box-shadow: inset 0 0 0 2px var(--rimlo), var(--frame); }
  .qs-card > .qs-top { position: relative; padding-right: 14px; }
  .qs-card > .qs-top b { color: var(--gold); }
  .qs-card .qs-q { padding: 6px 10px; gap: 3px; }
  .qs-card .qs-bot { min-height: 0; }
  .hm-go { height: 72px; }
  #title.hall:has(.hm-duty) .hm-side .qs-card { display: none; }
}
@media (min-width: 900px) {
  /* The modes sheet opens over the Play panel, not across the whole window. */
  .hl-sheet:has(.hm-sheet) { align-items: flex-end; padding: 0 24px 20px 0; }
  .hm-sheet { width: 360px; }
  #title.hall.in-shell { display: grid; padding: 20px 24px 20px; gap: 0 24px;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(300px, 360px);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "hud hud ." "stats floor ." "side floor play"; }
  #title.hall .bg::after { background: linear-gradient(90deg, rgba(8,10,26,.85) 0%, rgba(8,10,26,.25) 30%, rgba(8,10,26,.05) 50%, rgba(8,10,26,.3) 70%, rgba(8,10,26,.88) 100%),
    linear-gradient(180deg, rgba(8,10,26,.7) 0%, transparent 25%, transparent 70%, rgba(8,10,26,.8) 100%); }
  #title .hl-hud { grid-area: hud; padding-right: 0; }
  #title .hl-stats { grid-area: stats; align-self: start; }
  #title .hl-floor { grid-area: floor; min-height: 0; }
  .hm-side { grid-area: side; align-self: end; gap: 12px; }
  .hm-side .qs-card { display: grid; gap: 8px; width: 100%; padding: 12px; text-align: left; font: inherit; color: inherit; cursor: pointer;
    background: rgba(14,19,44,.78); border: 0; box-shadow: inset 0 0 0 2px var(--rimlo), var(--frame); }
  .qs-card > .qs-top { position: relative; padding-right: 14px; }
  .qs-card > .qs-top b { font-size: 16px; color: var(--gold); }
  .qs-card > .qs-top .qs-dot { top: 2px; right: 0; }
  .qs-card .qs-q { padding: 8px 10px; gap: 4px; }
  .qs-card .qs-q .qs-top b { font-size: 13px; }
  .qs-card .qs-bot { min-height: 0; }
  .qs-card:hover { box-shadow: inset 0 0 0 2px var(--gold), var(--frame); }
  #title.hall .hm-side .hl-feed { padding: 12px; }
  #title.hall .hm-side .hl-feed ul { max-height: calc(5 * 1.45em + 16px); font-size: 13px; }
  .hm-play { grid-area: play; align-self: end; margin: 0; gap: 10px; padding: 14px; background: rgba(14,19,44,.82); box-shadow: inset 0 0 0 2px var(--rimlo), var(--frame); }
  .hm-chips { grid-template-columns: 1fr; }
  .hm-chips > button { height: 60px; }
  .hm-go { height: 76px; font-size: 30px; }
  #title .corner { top: 20px; right: 24px; bottom: auto; left: auto; }
  #title.hall h1.hl-title { font-size: 44px; }
  .hl-med { width: 88px; height: 88px; }
}
/* Short landscape phones and small laptops: keep the Play panel on screen. */
@media (min-width: 900px) and (max-height: 700px) {
  .hm-side .qs-card .qs-q:nth-child(n+3) { display: none; }
  .hm-go { height: 60px; }
}
@media (max-width: 899px) and (orientation: landscape) and (max-height: 520px) {
  #title.hall.in-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 40%); grid-template-rows: auto minmax(0, 1fr) auto; column-gap: 16px;
    grid-template-areas: "hud play" "floor play" "side play"; }
  #title .hl-stats { display: none; }
  #title .hl-hud { grid-area: hud; } #title .hl-floor { grid-area: floor; } .hm-side { grid-area: side; } .hm-play { grid-area: play; align-self: end; }
  .nv-tab { height: 46px; flex-direction: row; gap: 8px; }
}
