:root {
  --bg: #0f0c13; --panel: #17151b; --panel2: #231e27; --line: #4d4755;
  --text: #eee6eef3; --muted: #aa9caf; --accent: #844aa5; --bad: #e19591; --ok: #3fb950;
  --floor: #171618; --gc: #e0b43c;
  --overlay: rgba(255, 255, 255, .08); --overlay-line: rgba(255, 255, 255, .28); --hairline: rgba(255, 255, 255, .05);
  --floor-glow: rgba(255, 255, 255, .062); --floor-glow-end: rgba(255, 255, 255, .01); --floor-line: rgba(255, 255, 255, .082);
  --ghost: #3d3a41; --ghost-line: #6a6570; --text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
  --pop-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  --card-r: 4.5% / 3.2%;        /* corner radius of card images */
  --card-ar: 488 / 680;         /* Scryfall card aspect ratio */
  --pv-w: calc(52vh * 0.7176);  /* preview card width the builder's left column is sized around */
  color-scheme: dark;
}

/* Light theme: Settings > Dark mode unticked sets data-theme="light" on <html>. */
:root[data-theme="light"] {
  --bg: #f4f1f6; --panel: #ffffff; --panel2: #ece6f0; --line: #cdc4d4;
  --text: #1f1a24; --muted: #6b6172; --accent: #844aa5; --bad: #b3261e; --ok: #1a7f37;
  --floor: #e8e5eb; --gc: #9a6b00;
  --overlay: rgba(0, 0, 0, .05); --overlay-line: rgba(0, 0, 0, .25); --hairline: rgba(0, 0, 0, .07);
  --floor-glow: rgba(0, 0, 0, .04); --floor-glow-end: rgba(0, 0, 0, .01); --floor-line: rgba(0, 0, 0, .1);
  --ghost: #f3f0f6; --ghost-line: #b8afc0; --text-shadow: none;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, sans-serif; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
button, select, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
button { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
button.cmd-card { display: block; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* Buttons drawn as plain text or icons, without the default chrome. */
.side-nav-item, .opts-btn, .nav, .card-menu button, .deck-table th button, .tile-art { border: 0; background: none; }

/* Inline SVG icons are stroked in the current text colour. */
.menu-btn svg, .side-nav svg, .x-btn svg, .sort-icon, .plus-icon { stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.menu-btn svg, .side-nav svg, .x-btn svg { stroke-width: 1.6; }
.logo { height: 1.2em; width: auto; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.msg { color: var(--muted); margin: 8px 0; }
.msg.err, .sync.err, .status .bad, .danger { color: var(--bad); }
.status .ok { color: var(--ok); }

/* topbar */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { display: flex; align-items: center; font-size: 20px; line-height: 1; margin: 0; color: var(--accent); }
.topbar h1 a, .side-nav-brand { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }

/* Trim the text box to cap height..baseline so flex centering lines the logo up with the letters,
   not with the font's ascender/descender space. (Chromium/Safari; others fall back to box centering.) */
.brand-text { display: block; line-height: 1; text-box: trim-both cap alphabetic; }
.spacer { flex: 1; }
.topbar label { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.deck-title { position: relative; top: -.065em; font-weight: 400; font-size: 20px; line-height: 1.2; max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Your own deck: the name is an inline input that looks like plain text until hovered or focused. */
body:not(.shared) #deckTitle, body.shared #deckNameInput { display: none; }

/* Inputs can't use text-box trimming, and the system font's ascender/descender space leaves the letters
   ~0.065em below the box centre, so shift the text up by that much (box size unchanged) to line up with the logo. */
.deck-name-input { font-size: 20px; line-height: 1.2; padding: calc(3px - .065em) 8px calc(3px + .065em); margin-left: -9px; border-color: transparent; background: none; min-width: 6ch; max-width: 50vw; text-overflow: ellipsis; }
.deck-name-input:hover { border-color: var(--line); }
.deck-name-input:focus { border-color: var(--accent); background: var(--panel2); outline: none; }
#homeSortDir { min-width: 34px; padding-left: 8px; padding-right: 8px; margin-left: -6px; align-self: stretch; }
.sort-icon { width: 18px; height: 18px; stroke-width: 1.8; }
.sync { color: var(--muted); font-size: 14.4px; }

/* Hamburger button left of the logo; opens the full-height side panel (#sideNav). */
.menu-btn { width: 36px; height: 36px; padding: 0; flex: none; border-color: transparent; background: none; }
.menu-btn[aria-expanded="true"] { background: var(--panel2); border-color: var(--line); }
.menu-btn svg { width: 20px; height: 20px; }
dialog.side-nav { position: fixed; inset: 0 auto 0 0; margin: 0; width: min(300px, 85vw); height: 100%; max-height: none; max-width: none; padding: 0; border: 0; border-right: 1px solid var(--line); border-radius: 0; box-shadow: 8px 0 32px rgba(0,0,0,.5); }
dialog.side-nav[open] { display: flex; animation: side-nav-in .22s cubic-bezier(.2,.7,.2,1); }
@keyframes side-nav-in { from { transform: translateX(-100%); } }
.side-nav-inner { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 10px 10px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); overflow-y: auto; }
.side-nav-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 10px 6px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.side-nav-brand { font-size: 20px; font-weight: 700; color: var(--accent); }
.side-nav-item { justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 6px; text-align: left; }
.side-nav-item:hover:not(:disabled), .side-nav-item:focus-visible { background: var(--panel2); outline: none; }
.side-nav-item svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.side-nav-spacer { flex: 1; }

/* layout */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: min(40vw, calc(var(--pv-w) + 56px)) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 10px; padding: 10px; }
.deck { grid-column: 2; grid-row: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-y: auto; padding: 12px; min-height: 0; }
.box-title, .curve-title { font-weight: 700; text-transform: uppercase; font-size: 14.4px; letter-spacing: .06em; color: var(--muted); }
.box-title { margin-bottom: 8px; }
.identity, .curve-title span { text-transform: none; letter-spacing: 0; }
.identity { margin-left: 8px; }

/* preview: card panel shared by the builder (#preview) and the landing list view (#homePreview) */
.preview { position: relative; display: flex; grid-row: 1 / span 2; }
.preview-empty { flex: 1; color: var(--muted); text-align: center; margin-top: 40px; }
.preview img.art { width: 100%; border-radius: 5% / 4.5%; display: block; }
.preview .pv { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.preview .pv-art { position: relative; flex: 0 0 auto; align-self: center; width: min(75%, calc(var(--pv-w) * 0.9)); }
.preview .flip { position: absolute; left: 8px; bottom: 8px; width: auto; margin: 0; }
.preview .pv-text { flex: 1; min-height: 0; display: flex; flex-direction: column; align-self: center; width: min(100%, calc(var(--pv-w) + 32px)); }
.preview .pv-text-inner { flex: 1; min-height: 0; overflow-y: auto; }
.preview .print-btn { position: absolute; right: 8px; bottom: 8px; display: none; height: 30px; padding: 2px 10px; font-size: 14px; line-height: 1; }
.preview .pv-art:hover .print-btn { display: inline-flex; }

/* Card text block shared by every preview, including the new-deck dialog's. */
.pv h2 { margin: 0 0 2px; font-size: 18px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pv .type { color: var(--muted); margin-bottom: 8px; }
.pv .rules { background: var(--panel2); border-radius: 6px; padding: 8px 10px; }
.pv .rules p { margin: 0 0 6px; white-space: pre-wrap; }
.pv .rules p:last-child { margin: 0; }
.pv dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; }
.pv dt { color: var(--muted); }
.pv dd { margin: 0; }
.flip { margin-top: 8px; width: 100%; }
.sym { height: 1.05em; width: 1.05em; vertical-align: -0.15em; margin: 0 1px; }

/* commander slots */
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px dashed var(--line); border-radius: 6px; padding: 6px 8px; min-height: 36px; }
.slot.filled { border-style: solid; cursor: pointer; }
.slot.filled.sel { border-color: var(--accent); outline: 1px solid var(--accent); }
.slot .nm { flex: 1; font-weight: 600; }
.slot .label { color: var(--muted); font-size: 14.4px; }
.slot button { padding: 2px 8px; }
.slot .x-btn { width: 26px; height: 26px; padding: 0; flex: none; }
.x-btn svg { width: 10px; height: 10px; }

.status { margin: 10px 0; padding: 6px 10px; border-radius: 6px; background: var(--panel2); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.gc { color: var(--gc); font-size: 14.4px; cursor: help; }

/* deck rows and tiles */
.group h3 { margin: 12px 0 4px; font-size: 15.6px; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 2px; }
.row { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 4px; cursor: default; }
.row:hover { background: var(--panel2); }
.row .qty { width: 24px; text-align: right; color: var(--muted); }
.row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .cost { white-space: nowrap; }
.row .price { width: 56px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .set { color: var(--muted); font-size: 12px; }
.row.illegal .nm { color: var(--bad); text-decoration: line-through; }
.row.sel { background: var(--panel2); outline: 1px solid var(--accent); }
.row.top { outline: 1px solid var(--accent); }
.row button, .tile .acts button { padding: 0 7px; line-height: 20px; }
.row .acts, .tile .acts { display: none; gap: 3px; }
.row:hover .acts, .tile:hover .acts { display: flex; }

.view-list2 .items { columns: 2; column-gap: 12px; }
.view-list2 .row { break-inside: avoid; }
.view-grid-s { --cw: 90px; } .view-grid-m { --cw: 130px; } .view-grid-l { --cw: 190px; }
.view-grid-s .items, .view-grid-m .items, .view-grid-l .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--cw), 1fr)); gap: 8px; padding-top: 6px; }
.stacked .items { gap: 0 8px; padding-bottom: calc(var(--cw) * 1.4); }
.tile { position: relative; min-width: 0; }
.tile img { width: 100%; display: block; border-radius: var(--card-r); }
.tile.illegal img { outline: 2px solid var(--bad); }
.tile.sel img, .stacked .tile:hover img { box-shadow: 0 0 0 2px var(--accent); }
.tile .tq { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.75); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 13px; }
.tile .acts { position: absolute; bottom: 4px; right: 4px; }
.tile .acts button { background: rgba(0,0,0,.8); }
.stacked .tile { height: 28px; }
.stacked .tile:hover { z-index: 2; }
.stacked .tile .acts { top: 4px; bottom: auto; }

/* floating menus: card options in the builder, deck options on the landing page */
.card-menu { position: fixed; z-index: 1000; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px; box-shadow: var(--pop-shadow); }
.card-menu button { text-align: left; justify-content: flex-start; white-space: nowrap; }
.card-menu button:hover, .card-menu button:focus-visible { background: var(--panel2); outline: none; }
.deck-menu { padding: 3px; min-width: 110px; }
.deck-menu button { font-size: 14px; padding: 5px 10px; border-radius: 4px; }

/* view options */
.view-h { margin: 8px 0 0; font-size: 15.6px; color: var(--muted); }
.view-opt { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.view-opt input { width: auto; }

/* search */
.searchbar { position: sticky; top: -12px; z-index: 5; margin: -12px -12px 10px; padding: 12px 12px 8px; background: var(--panel); }
.searchbar input { width: 100%; padding: 9px 12px; }
.drop { display: none; position: absolute; left: 12px; right: 12px; top: calc(100% - 6px); max-height: 60vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 4px 6px; box-shadow: var(--pop-shadow); }
.drop.open { display: block; }
.drop .msg:empty { display: none; }
#searchResults .row { cursor: pointer; }
#searchResults .row.owned { opacity: .45; cursor: not-allowed; }
#moreBtn { display: block; margin: 10px auto 0; }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: min(760px, 92vw); max-height: 85vh; padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog[open] { display: flex; flex-direction: column; gap: 8px; }
dialog.wide { width: 94vw; max-width: 2000px; height: 80vh; }
#viewDialog { width: min(320px, 94vw); }
#appSettingsDialog, #authDialog { width: min(460px, 94vw); }
#settingsDialog { width: min(520px, 94vw); }
#aboutDialog { width: min(560px, 94vw); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.foot-actions { display: flex; gap: 6px; flex-shrink: 0; }
dialog input { width: 100%; }
dialog textarea { width: 100%; height: 50vh; resize: vertical; font: 15.6px/1.5 Consolas, monospace; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
#settingsDialog textarea { height: auto; }
.apply { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.tabs button.active { border-color: var(--accent); background: var(--panel); }
.cmd-grid { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.cmd-card { background: none; border: 1px solid transparent; padding: 4px; text-align: center; }
.cmd-card img { width: 100%; border-radius: var(--card-r); display: block; }
.cmd-card:hover, .cmd-card.cur { border-color: var(--accent); }
#printDialog .cmd-grid { flex: 1; min-height: 0; align-content: start; }
.pcap { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* new deck */
.new-body { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.new-body > div { overflow-y: auto; min-height: 0; min-width: 0; }
.new-results { padding: 2px; }
.new-preview { background: var(--panel2); border-radius: 8px; padding: 10px; }
.new-preview .pv { display: flex; flex-direction: row-reverse; gap: 10px; height: 100%; min-height: 0; }
.new-preview .pv-art { flex: 0 1 45%; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; }
.new-preview img.art { width: auto; max-width: 100%; max-height: 100%; min-height: 0; object-fit: contain; border-radius: var(--card-r); display: block; }
.new-preview .flip { flex-shrink: 0; }
.new-preview .pv-text { flex: 1; min-width: 0; overflow-y: auto; overflow-wrap: anywhere; }
.new-preview h2 { font-size: 19.2px; flex-wrap: wrap; align-items: normal; }
.new-preview .type { margin-bottom: 6px; }
.new-preview .rules { background: var(--panel); padding: 6px 8px; }
.new-preview dl { margin-top: 8px; }

/* settings / account */
.about { overflow-y: auto; line-height: 1.55; }
.about p { margin: 0 0 12px; }
.about-tag { font-size: 22px; font-weight: 700; color: var(--accent); }
.about-tag strong { font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.about-fine { margin-top: 18px !important; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.about-fine a { color: inherit; }
.setting-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; cursor: pointer; }
.setting-row input[type="checkbox"] { width: 18px; height: 18px; margin: 0; padding: 0; accent-color: var(--accent); cursor: pointer; }
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; }
#shareBox select { width: 100%; }
.auth-alt { display: flex; gap: 8px; flex-wrap: wrap; }
.auth-alt button { flex: 1; }

/* landing page */
body.home #builder, body.home .builder-only, body:not(.home) #home, body:not(.home) .home-only { display: none; }
.home-page { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; background: var(--floor); }
/* Only the chosen landing view is shown. */
.home-page:not([data-view="carousel"]) .home-inner, .home-page:not([data-view="gallery"]) .gallery-view, .home-page:not([data-view="list"]) .list-view { display: none; }
.home-inner { width: 100%; display: flex; align-items: stretch; }
.carousel-wrap { --w: max(180px, min(58vw, calc((100vh - 80px) / 2.23))); --h: calc(var(--w) * 1.393); --top: calc(var(--h) * 0.1 + 24px);
  /* Card top edge: vertically centered in the stage, but never higher than --top and always leaving at least
     half a card of floor below for the deck info. Percentages resolve against the stage height at each use. */
  --card-top: max(var(--top), min(50% - var(--h) / 2, 100% - var(--h) * 1.5));
  position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }

  /* The stage fills the page height: cards sit at --card-top and the floor runs from under them to the bottom. */
.carousel { position: relative; flex: 1 0 auto; min-height: calc(var(--h) * 1.5 + var(--top)); overflow: hidden; perspective: calc(var(--w) * 3.7); perspective-origin: 50% calc(var(--card-top) + var(--h)); background: var(--floor); touch-action: pan-y; }
.carousel::after { content: ''; position: absolute; left: 0; right: 0; top: calc(var(--card-top) + var(--h)); bottom: 0; background: linear-gradient(var(--floor-glow), var(--floor-glow-end) 45%, transparent); border-top: 1px solid var(--floor-line); pointer-events: none; z-index: 100; }


/* z-index is not transitioned: restack() in app.js sets it each frame from the cards' real positions. */
.slide { position: absolute; top: var(--card-top); left: 50%; width: var(--w); margin-left: calc(var(--w) / -2); cursor: pointer; will-change: transform; filter: brightness(.6); transition: transform .45s cubic-bezier(.2,.7,.2,1), filter .45s; user-select: none; -webkit-user-drag: none; }
.carousel.resizing .slide { transition: none; }
.slide.sel { filter: none; }
.slide .cover, .tile-art img, .tile-art .blank { width: 100%; aspect-ratio: var(--card-ar); object-fit: cover; display: block; }
.slide .cover { border-radius: var(--card-r); }

/* Opaque mirror that fades to the floor color, so overlapping reflections occlude rather than blend. */
.slide .refl { position: absolute; top: 100%; left: 0; width: 100%; aspect-ratio: var(--card-ar); transform: scaleY(-1); border-radius: var(--card-r); overflow: hidden; pointer-events: none; background: var(--floor); }
.slide .refl img { width: 100%; height: 100%; object-fit: cover; display: block; filter: brightness(.6) blur(2px); transform: scale(1.04); }
.slide .refl::after { content: ''; position: absolute; inset: 0; background: linear-gradient(var(--floor) 42%, color-mix(in srgb, var(--floor) 60%, transparent)); }

/* Empty deck face: a dashed outline where the commander art would be. */
.blank { background: var(--panel); border: 2px dashed var(--line); }
.refl .blank { width: 100%; height: 100%; }
.refl .blank, .tile-art .blank { border-radius: inherit; }
/* Empty-state "create a deck" card: the carousel's selected slot and the gallery's only tile. */

.slide.placeholder .cover.blank, .tile-art.placeholder { display: flex; align-items: center; justify-content: center; text-align: center; padding: 0 10%; line-height: 1.35; color: var(--muted); background: var(--overlay); border-color: var(--overlay-line); }
.slide.placeholder .cover.blank { font-size: calc(var(--w) * .065); transition: border-color .2s, color .2s; }
.slide.placeholder:hover .cover.blank, .slide.placeholder:focus-visible .cover.blank, .tile-art.placeholder:hover, .tile-art.placeholder:focus-visible { border-color: var(--accent); color: var(--text); }
.slide.placeholder:focus-visible { outline: none; }

/* Decorative empty decks beside the empty-state placeholder; not interactive. */
.slide.ghost { pointer-events: none; cursor: default; }

/* Side slides are dimmed by brightness(.6), so this lighter grey lands as a dark grey on screen. */
.slide.ghost .blank { background: var(--ghost); border-color: var(--ghost-line); }
.plus-icon { width: 28%; height: auto; stroke-width: 1.5; }
.deck-info { position: absolute; left: 0; right: 0; padding-left: calc(var(--w) * .16); top: calc(var(--card-top) + var(--h)); bottom: 0; z-index: 250; text-align: left; display: flex; align-items: center; pointer-events: none; text-shadow: var(--text-shadow); }
.deck-info .info-text { display: flex; flex-direction: column; gap: calc(var(--w) * .013); min-width: 0; }
.deck-info .title { font-weight: 700; font-size: calc(var(--w) * .09); margin-bottom: calc(var(--w) * .013); }
.deck-info .meta { font-size: calc(var(--w) * .06); }
.deck-info .lbl, .deck-info .title.muted { color: var(--muted); }
.deck-info .title-row { display: flex; align-items: center; gap: calc(var(--w) * .04); margin-bottom: calc(var(--w) * .013); }
.deck-info .title-row .title { margin-bottom: 0; min-width: 0; overflow-wrap: anywhere; }

/* "⋯" deck options button, used in every landing view; the menu it opens is the shared .deck-menu. */
.opts-btn { flex-shrink: 0; font-size: 20px; line-height: 1; padding: .05em .3em; color: var(--muted); }
.opts-btn:hover, .opts-btn[aria-expanded="true"] { color: var(--text); background: var(--overlay); }
.deck-info .opts-btn { font-size: calc(var(--w) * .07); pointer-events: auto; text-shadow: inherit; }
.nav { position: absolute; top: calc(var(--card-top) + var(--h) / 2); transform: translateY(-50%); z-index: 300; width: 48px; height: 48px; padding: 0; display: flex; align-items: center; justify-content: center; font-size: 48px; line-height: 1; border-radius: 0; color: var(--muted); }
.nav:hover:not(:disabled) { color: var(--text); }
#prevBtn { left: 16px; } #nextBtn { right: 16px; }

/* Gallery: an album-style grid of commander covers. */
.gallery-view { flex: 1; align-self: flex-start; display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 15vw, 220px), 1fr)); gap: 28px 20px; padding: 24px; }
.tile-art { display: block; width: 100%; padding: 0; border-radius: var(--card-r); overflow: hidden; transition: transform .2s, box-shadow .2s; }
.tile-art:hover, .tile-art:focus-visible { transform: translateY(-4px); box-shadow: 0 10px 24px rgba(0, 0, 0, .55); outline: none; }
.tile-art.placeholder { aspect-ratio: var(--card-ar); border: 2px dashed var(--overlay-line); }
.tile-art.placeholder:hover, .tile-art.placeholder:focus-visible { transform: none; box-shadow: none; }
.tile-row { display: flex; align-items: flex-start; gap: 6px; margin-top: 8px; }
.tile-text { flex: 1; min-width: 0; }
.tile-name, .tile-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-name { font-weight: 600; }
.tile-sub { color: var(--muted); font-size: 13px; }

/* List: commander preview on the left (like the deck builder), a sortable table of decks on the right. */
.list-view { flex: 1; min-width: 0; display: grid; grid-template-columns: min(40vw, calc(var(--pv-w) + 56px)) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 10px; padding: 10px; background: var(--bg); }
#homePreview { grid-row: auto; }
.deck-table-wrap { padding: 0; overflow: auto; }
.deck-table { width: 100%; border-collapse: collapse; font-size: 14.4px; }
.deck-table th { position: sticky; top: 0; z-index: 1; padding: 0; background: var(--panel); border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.deck-table th button { width: 100%; justify-content: flex-start; gap: 4px; padding: 10px 12px; border-radius: 0; color: var(--muted); font-weight: 600; }
.deck-table th button:hover, .deck-table th[aria-sort="ascending"] button, .deck-table th[aria-sort="descending"] button { color: var(--text); }
.deck-table td { padding: 8px 12px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
.deck-table tbody tr[data-i] { cursor: pointer; }
.deck-table tbody tr[data-i]:hover td, .deck-table tbody tr.sel td { background: var(--panel2); }
.deck-table tbody tr.sel td:first-child { box-shadow: inset 3px 0 var(--accent); }
.deck-table .c-name { font-weight: 600; white-space: normal; min-width: 140px; }
.deck-table .c-commander { white-space: normal; min-width: 160px; }
.deck-table .c-bracket { text-align: center; }
.deck-table th.c-bracket button { justify-content: center; }
.deck-table .c-cost { text-align: right; font-variant-numeric: tabular-nums; }
.deck-table th.c-cost button { justify-content: flex-end; }
.deck-table .c-created, .deck-table .c-recent { color: var(--muted); }
.deck-table .c-opts { width: 1%; padding: 0 6px; text-align: right; }
.deck-table .list-empty { padding: 24px 12px; color: var(--muted); text-align: center; white-space: normal; }

/* bottom tray: mana curve and test hand */
.tray { grid-column: 2; grid-row: 2; --th: clamp(170px, 27vh, 250px); display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; }
.tray[data-tab="curve"] #hand, .tray[data-tab="hand"] #curve, .tray.collapsed .tray-body,
.tray[data-tab="curve"] .hand-actions, .tray.collapsed .hand-actions { display: none; }
.tray-head { display: flex; align-items: center; gap: 12px; }
.tray-head .hand-actions { margin-left: auto; }
.tray-head .tabs button, .hand-actions button, .tray-toggle { height: 30px; padding: 0 10px; font-size: 14.3px; line-height: 1; }
.tray[data-tab="curve"] .tray-toggle, .tray.collapsed .tray-toggle { margin-left: auto; }
.tray.collapsed .tray-toggle { transform: rotate(180deg); }
.tray-body { display: flex; height: var(--th); }
.curve { display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; min-width: 0; }
.curve-title { display: flex; flex-direction: row; align-items: center; gap: 10px; min-height: 28px; }
.curve-title span { font-weight: 400; }
.bars { display: flex; gap: 8px; flex: 1; min-width: 0; min-height: 96px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bar .track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; padding-top: 18px; }
.bar .fill { position: relative; width: 70%; min-height: 2px; background: var(--accent); border-radius: 3px 3px 0 0; transition: height .25s; }
.bar .cnt { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 14.4px; }
.bar .lbl { font-size: 14.4px; color: var(--muted); }
.hand { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.hand-actions { display: flex; align-items: center; gap: 8px; }
.hand-info { color: var(--muted); font-size: 14.4px; }
.hand-cards { display: flex; flex: 1; min-height: 0; overflow: hidden; align-items: flex-start; }
.hc { position: relative; flex: 0 0 auto; }
.hc + .hc { margin-left: var(--gap, 6px); }
.hc img { height: var(--ch, clamp(120px, 20vh, 190px)); display: block; border-radius: 5% / 4.5%; }
.hand-empty { color: var(--muted); align-self: center; }

/* read-only shared deck page */
.shared-only { display: none; }
body.shared .shared-only { display: inline-block; }
body.shared .desc.shared-only { display: none; }
body.shared .desc.shared-only:not(:empty) { display: block; white-space: pre-wrap; color: var(--muted); margin: 8px 0 0; }
body.shared #settingsBtn, body.shared #listBtn, body.shared .searchbar, body.shared .slot:not(.filled),
body.shared .slot button, body.shared .row .acts, body.shared .tile .acts { display: none; }

@media (max-width: 700px) {
  .carousel-wrap { --w: max(150px, min(58vw, calc((100vh - 140px) / 2.23))); }
  .nav { font-size: 36px; width: 36px; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .gallery-view { gap: 20px 14px; padding: 16px; }
  .new-preview .pv { height: auto; flex-direction: column; }
  .new-preview .pv-art { flex: none; }
  .new-preview img.art { max-height: 35vh; }
  .new-preview .pv-text { overflow: visible; }
}

@media (max-width: 1000px) {
  body { height: auto; min-height: 100vh; min-height: 100dvh; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; }
  .preview, .deck, .tray { grid-column: 1; grid-row: auto; }
  .list-view { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; align-self: flex-start; }
  #homePreview { order: 2; } /* table first on narrow screens, commander preview below it */
  .preview .pv-art { width: min(90%, 54vw); }
  .panel { max-height: 80vh; }
}

@media (prefers-reduced-motion: reduce) {
  dialog.side-nav[open], .slide, .tile-art { animation: none; transition: none; }
  .tile-art:hover, .tile-art:focus-visible { transform: none; }
}