:root {
  --bg: #07070d;
  --panel: rgba(16, 16, 28, 0.72);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e9e7f5;
  --muted: #8d8aa8;
  --accent: #b18cff;
  --accent2: #5fd4ff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #1a1430 0%, #0b0a16 55%, var(--bg) 100%);
  color: var(--text);
  font: 14px/1.4 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stars {
  position: fixed; inset: 0; pointer-events: none; opacity: .55;
  background-image:
    radial-gradient(1px 1px at 12% 20%, #fff8, transparent),
    radial-gradient(1px 1px at 72% 12%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 40% 75%, #c9b8ff88, transparent),
    radial-gradient(1px 1px at 85% 64%, #fff7, transparent),
    radial-gradient(1px 1px at 25% 88%, #9fe6ff77, transparent),
    radial-gradient(1px 1px at 58% 38%, #fff5, transparent),
    radial-gradient(1.5px 1.5px at 92% 30%, #ffd9a077, transparent),
    radial-gradient(1px 1px at 5% 55%, #fff6, transparent);
  background-size: 600px 600px;
  animation: drift 120s linear infinite;
}
@keyframes drift { to { background-position: 600px 300px; } }
#graph { position: fixed; inset: 0; }

.panel {
  position: fixed; z-index: 5;
  background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
.btn {
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  color: white; border: 0; border-radius: 10px; padding: 8px 14px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: transform .15s, box-shadow .15s, opacity .15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 18px #8f6bff66; }
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { background: rgba(255,255,255,.06); border: 1px solid var(--border); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
a.btn[hidden] { display: none; }
label.btn { display: inline-flex; align-items: center; }

/* Top bar */
#topbar {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 10;
  display: flex; gap: 12px; align-items: center;
  padding: 8px 10px 8px 16px;
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 14px;
}
.brand { font-weight: 800; letter-spacing: .5px; font-size: 16px; white-space: nowrap; }
.brand span { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .logo { color: var(--accent); -webkit-text-fill-color: var(--accent); }
.search-wrap { position: relative; }
#search {
  width: 360px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: rgba(0,0,0,.35); color: var(--text);
  font: inherit; outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #b18cff33; }
#suggestions {
  position: absolute; top: 42px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: #14121f; border: 1px solid var(--border); border-radius: 10px;
  max-height: 380px; overflow-y: auto; display: none;
}
#suggestions li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
#suggestions li.active, #suggestions li:hover { background: #ffffff12; }
#suggestions img { width: 44px; height: 32px; object-fit: cover; border-radius: 5px; }
#suggestions .t { color: var(--muted); font-size: 12px; }

/* Breadcrumbs */
#crumbs {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center;
  max-width: 60vw; font-size: 12px; color: var(--muted);
}
#crumbs .crumb { padding: 3px 9px; border-radius: 20px; background: rgba(255,255,255,.05); border: 1px solid var(--border); cursor: pointer; }
#crumbs .crumb:hover { color: var(--text); border-color: var(--accent); }
#crumbs .crumb.current { color: var(--text); border-color: #b18cff88; cursor: default; }

/* Card panel */
#card-panel { top: 110px; left: 18px; width: 290px; max-height: calc(100vh - 220px); overflow-y: auto; padding: 14px; }
#card-view img.card { width: 100%; border-radius: 4.75% / 3.5%; box-shadow: 0 8px 30px rgba(0,0,0,.6); display: block; }
#card-view h2 { margin: 12px 0 2px; font-size: 17px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
#card-view .mana img { width: 15px; height: 15px; vertical-align: -2px; margin-left: 1px; }
#card-view .type { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
#card-view h4 { margin: 12px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.tag { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; margin: 5px 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 4px; box-shadow: 0 0 8px currentColor; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 10.5px; padding: 2px 7px; border-radius: 10px; background: #3fc46a22; color: #8be8a8; border: 1px solid #3fc46a44; }
.badge.off { background: transparent; color: #66637c; border-color: #ffffff12; text-decoration: line-through; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.card-actions a { color: var(--accent2); font-size: 12.5px; align-self: center; text-decoration: none; }
.loading { color: var(--muted); padding: 30px 0; text-align: center; }
.muted { color: var(--muted); font-size: 12.5px; }

/* Controls */
#controls { top: 110px; right: 18px; width: 250px; padding: 12px 14px; font-size: 13px; max-height: calc(100vh - 220px); overflow-y: auto; }
#controls h3 { margin: 6px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
#controls .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
#controls .row.check { justify-content: flex-start; }
#controls select { background: #0c0b16; color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 4px 6px; font: inherit; }
#controls input[type=range] { flex: 1; accent-color: var(--accent); }
#legend .chip {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; cursor: pointer; user-select: none;
}
#legend .chip:hover { background: #ffffff0d; }
#legend .chip.off { opacity: .3; }
#legend .bar { width: 18px; height: 3px; border-radius: 2px; box-shadow: 0 0 6px currentColor; }

/* Tray */
#tray {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; gap: 12px; align-items: center; padding: 10px 12px;
  max-width: calc(100vw - 40px);
  background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 14px;
}
.tray-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); white-space: nowrap; }
#tray-cards { display: flex; gap: 6px; overflow-x: auto; max-width: 52vw; min-height: 38px; align-items: center; }
#tray-cards .hint { color: #66637c; font-size: 12.5px; white-space: nowrap; }
.tray-card { position: relative; flex: none; cursor: pointer; }
.tray-card img { width: 52px; height: 38px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); display: block; }
.tray-card .x {
  position: absolute; top: -6px; right: -6px; width: 17px; height: 17px; border-radius: 50%;
  background: #2a2540; color: #fff; font-size: 11px; line-height: 17px; text-align: center; display: none;
}
.tray-card:hover .x { display: block; }

#disclaimer { position: fixed; bottom: 6px; left: 12px; right: 12px; text-align: center; font-size: 10.5px; color: #5d5a75; z-index: 4; pointer-events: none; }

/* Graph tooltips */
.float-tooltip-kap { display: none !important; }
#tip { position: fixed; top: 0; left: 0; z-index: 50; pointer-events: none; display: none; }
.tip {
  background: rgba(14, 12, 24, .96); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; max-width: 340px; color: var(--text); font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6);
}
/* Hover card: large, sharp image with the explanation beside it */
.tip.node-tip { display: flex; gap: 14px; align-items: flex-start; max-width: none; padding: 10px; }
.tip img.card-img {
  width: min(320px, calc((100vh - 60px) * 0.716)); /* card aspect ratio, never taller than the window */
  aspect-ratio: 488 / 680; border-radius: 4.75% / 3.5%; display: block; flex: none;
  box-shadow: 0 6px 24px rgba(0,0,0,.6);
}
.tip .side { width: 270px; font-size: 13.5px; }
.tip .side .why { margin-top: 0; }
.tip .hint { margin-top: 10px; }
.tip .why { margin-top: 8px; }
.tip .why-row { margin: 6px 0; }
.tip .head { font-weight: 600; display: flex; gap: 7px; align-items: flex-start; }
.tip q { display: block; color: var(--muted); font-style: italic; margin: 3px 0 0 16px; quotes: "“" "”"; }
.tip .card-name { color: #fff; }
.tip img.sym { width: 13px; height: 13px; vertical-align: -2px; display: inline; }

/* How-to-read key */
#controls h3 .sub { text-transform: none; letter-spacing: 0; font-weight: 400; color: #66637c; }
.howto { font-size: 12.5px; color: #c9c6dc; margin-bottom: 14px; }
.howto-row { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 9px; }
.howto b { color: #fff; }
.sample-lines { display: flex; flex-direction: column; gap: 3px; width: 26px; flex: none; padding-top: 4px; }
.sample-lines i { display: block; height: 3px; border-radius: 2px; }
.sample-node {
  position: relative; width: 26px; height: 26px; flex: none; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.35); background: linear-gradient(135deg, #3a3150, #1d1830);
}
.sample-node .pip { position: absolute; bottom: -4px; }
.sample-node .pip:first-child { left: 5px; }
.sample-node .pip:last-child { left: 13px; }
.pip { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid #0b0a16; vertical-align: -1px; }
.pips-key { display: block; margin-top: 4px; color: var(--muted); font-size: 11.5px; }
.pips-key .pip { margin-left: 4px; }
.pips-key .pip:first-child { margin-left: 0; }
.howto-tip { color: var(--muted); font-size: 11.5px; }
#legend .chip .lbl { flex: 1; }
#legend .chip .n { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
#legend .chip.absent { opacity: .45; }

/* Tray: synergies between tray cards */
.core-pair { background: rgba(255,255,255,.04); border: 1px solid var(--border); border-radius: 10px; padding: 7px 9px; margin: 6px 0; }
.core-pair .names { font-weight: 600; font-size: 12.5px; margin-bottom: 2px; }
.tip .explain { color: var(--muted); margin: 3px 0 0 16px; }
.tip .explain b { color: #cfcbe6; font-weight: 600; }
.tip .limit { color: #ffcf70; font-size: 12px; margin: 4px 0 0 16px; }

/* Back / forward */
.nav-btns { display: flex; gap: 4px; }
.btn.icon { padding: 6px 11px; font-size: 16px; line-height: 1; }

/* Card rules text with linked terms */
#card-view .oracle { font-size: 12.5px; line-height: 1.5; color: #d9d6ea; background: rgba(255,255,255,.03); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
#card-view .oracle .sym, #card-view .type .sym { width: 13px; height: 13px; vertical-align: -2px; }
.h4-hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: #66637c; }
a.rl { color: var(--accent2); text-decoration: underline dotted; text-underline-offset: 2px; cursor: pointer; }
a.rl:hover { color: #fff; }

/* Rules panel (replaces the filters panel while open) */
#rules-panel { top: 110px; right: 18px; width: 420px; max-height: calc(100vh - 220px); display: flex; flex-direction: column; padding: 12px 14px; z-index: 7; }
#rules-panel[hidden] { display: none; }
.rules-head { display: flex; gap: 8px; }
#rules-search { flex: 1; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: rgba(0,0,0,.35); color: var(--text); font: inherit; outline: none; }
#rules-search:focus { border-color: var(--accent); }
#rules-results { list-style: none; margin: 6px 0 0; padding: 4px; display: none; background: #14121f; border: 1px solid var(--border); border-radius: 8px; max-height: 240px; overflow-y: auto; }
#rules-results li { padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
#rules-results li:hover { background: #ffffff12; }
#rules-body { overflow-y: auto; margin-top: 10px; font-size: 13px; line-height: 1.5; padding-right: 4px; }
.rule-crumbs { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
a.crumb-rl { color: var(--muted); cursor: pointer; }
a.crumb-rl:hover { color: var(--text); }
.rule-title { margin: 2px 0 10px; font-size: 16px; }
.rule { margin: 0 0 9px; padding: 6px 8px; border-radius: 8px; color: #d9d6ea; }
.rule .num { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 4px; }
.rule.hl { background: rgba(177,140,255,.14); outline: 1px solid rgba(177,140,255,.4); }
.rule .ex { margin-top: 5px; color: var(--muted); font-size: 12.5px; }
.rule-list div { padding: 3px 0; font-size: 12.5px; color: #cfcbe6; }
#rules-foot { margin-top: 8px; font-size: 10.5px; color: #5d5a75; }

/* Card finder */
#finder { top: 110px; left: 330px; right: 290px; bottom: 100px; display: flex; flex-direction: column; padding: 12px 14px; z-index: 8; }
#finder[hidden] { display: none; }
.finder-head { display: flex; gap: 8px; }
#finder-q { flex: 1; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: rgba(0,0,0,.35); color: var(--text); font: inherit; outline: none; }
#finder-q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #b18cff33; }
#finder select { background: #0c0b16; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; font: inherit; }
.finder-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0; min-height: 24px; }
#finder-count { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.fchip { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; padding: 3px 9px; margin: 0 6px 4px 0; border-radius: 20px; background: rgba(177,140,255,.14); border: 1px solid rgba(177,140,255,.35); cursor: pointer; }
.fchip.kw { background: rgba(198,255,61,.1); border-color: rgba(198,255,61,.35); }
.fchip.text { background: rgba(255,255,255,.06); border-color: var(--border); }
.fchip b { color: var(--muted); font-weight: 400; }
.fchip:hover b { color: #fff; }
#finder-scroll { overflow-y: auto; flex: 1; }
#finder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.fcard { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 4.75% / 3.5%; transition: transform .12s; }
.fcard:hover { transform: translateY(-3px) scale(1.02); }
.fcard img { width: 100%; aspect-ratio: 488 / 680; border-radius: 4.75% / 3.5%; display: block; background: #1a1728; }
.fcard.added { outline: 2px solid var(--accent); }
#finder-sentinel { height: 1px; }
#finder-empty { padding: 30px; text-align: center; }
#suggestions li.find-all { color: var(--accent2); font-size: 13px; border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; }
a.rl.find { color: #ffcf70; }

/* Saved decks */
#decks-panel { bottom: 100px; left: 50%; transform: translateX(-50%); width: 520px; max-height: calc(100vh - 230px); overflow-y: auto; padding: 12px 14px; z-index: 9; }
#decks-panel[hidden] { display: none; }
.decks-head { display: flex; justify-content: space-between; align-items: center; }
.decks-head h3 { margin: 0; font-size: 15px; }
.deck-save { display: flex; gap: 8px; margin: 10px 0 6px; }
.deck-save input, #import-text { flex: 1; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: rgba(0,0,0,.35); color: var(--text); font: inherit; outline: none; }
#import-text { width: 100%; resize: vertical; margin-top: 8px; font-size: 12.5px; }
#deck-msg { min-height: 18px; font-size: 12.5px; color: var(--accent2); margin-bottom: 6px; }
#deck-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.deck-row { display: flex; gap: 6px; align-items: center; padding: 7px 9px; border-radius: 10px; border: 1px solid var(--border); background: rgba(255,255,255,.03); }
.deck-row.current { border-color: rgba(177,140,255,.5); background: rgba(177,140,255,.08); }
.deck-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.deck-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-info .muted { font-size: 11.5px; }
.deck-row .btn { padding: 5px 10px; font-size: 12.5px; }
.deck-import summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.muted.small { font-size: 11px; margin-top: 8px; }

/* Playtest */
#playtest { top: 110px; left: 330px; right: 290px; bottom: 100px; display: flex; flex-direction: column; padding: 12px 16px; z-index: 8; background: rgba(21, 19, 31, .97); }
#playtest[hidden] { display: none; }
.pt-head { display: flex; justify-content: space-between; align-items: center; }
.pt-head h3 { margin: 0; font-size: 15px; }
#pt-content { overflow-y: auto; flex: 1; margin-top: 8px; }
.pt-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.pt-tab { background: none; border: 0; color: var(--muted); font: inherit; padding: 7px 12px; cursor: pointer; border-bottom: 2px solid transparent; }
.pt-tab.on { color: var(--text); border-bottom-color: var(--accent); }
.pt-summary { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.pt-summary b { color: var(--text); }
.pt-warn { font-size: 12.5px; color: #ffcf70; margin: 4px 0; }
.pt-note { font-size: 12.5px; margin: 8px 0; }
.pt-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.pt-stat { margin-left: auto; font-size: 13px; color: var(--muted); }
.pt-stat b { color: var(--text); }
.pt-toggle { font-size: 12.5px; color: var(--muted); display: inline-flex; gap: 5px; align-items: center; }
.pt-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.pt-card { padding: 0; border: 0; background: none; border-radius: 4.75% / 3.5%; cursor: default; }
.pt-card img { width: 130px; aspect-ratio: 488 / 680; border-radius: 4.75% / 3.5%; display: block; background: #1a1728; }
.pt-row.small .pt-card img { width: 84px; }
.pt-card.pickable { cursor: pointer; transition: transform .12s; }
.pt-card.pickable:hover { transform: translateY(-4px); }
.pt-card.dim img { opacity: .45; }
.pt-zone-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-top: 6px; }
.pt-log { font-size: 12.5px; color: #cfcbe6; margin-top: 6px; }
.pt-log summary { cursor: pointer; color: var(--muted); }
.pt-log div { white-space: pre; }
.pt-tiles { display: flex; gap: 10px; margin: 6px 0 12px; }
.tile { flex: 1; background: rgba(255,255,255,.03); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.tile-n { font-size: 22px; font-weight: 700; }
.tile-l { font-size: 11.5px; color: var(--muted); }
.pt-chart-title { font-weight: 600; font-size: 13px; margin: 10px 0 2px; }
.pt-chart { width: 100%; max-width: 560px; display: block; }
.pt-chart .ax { fill: #8d8aa8; font-size: 10px; }
.pt-chart .val { fill: #e9e7f5; font-size: 11px; font-weight: 600; }
.pt-odds-form { font-size: 13px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.pt-odds-form select { background: #0c0b16; color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 3px 6px; font: inherit; max-width: 240px; }
.pt-hero { display: flex; align-items: baseline; gap: 10px; margin: 8px 0 2px; }
.hero-n { font-size: 32px; font-weight: 800; }
.pt-table { font-size: 12px; margin-top: 4px; }
.pt-table summary { cursor: pointer; color: var(--muted); }
.pt-table table { border-collapse: collapse; margin-top: 4px; }
.pt-table td, .pt-table th { padding: 3px 8px; border-bottom: 1px solid var(--border); text-align: center; font-weight: 400; }
.pt-empty { padding: 30px; text-align: center; }
#pt-tip { position: absolute; display: none; pointer-events: none; background: rgba(14,12,24,.96); border: 1px solid var(--border); border-radius: 8px; padding: 5px 9px; font-size: 12px; white-space: nowrap; z-index: 2; }
.toc-ch { margin: 12px 0 4px; font-weight: 700; font-size: 14px; }
.toc-sec { padding: 2px 0 2px 12px; font-size: 12.5px; color: #cfcbe6; }
.fcard.selected { outline: 3px solid var(--accent); outline-offset: 2px; }
.graph-btn { width: 100%; margin-bottom: 10px; }

/* Deck builder */
#builder { top: 110px; left: 330px; right: 290px; bottom: 100px; display: flex; flex-direction: column; padding: 12px 16px; z-index: 8; background: rgba(21, 19, 31, .97); }
#builder[hidden] { display: none; }
#bd-scroll { overflow-y: auto; flex: 1; }
.bd-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.bd-field { font-size: 12.5px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.bd-field select, .bd-field input { background: #0c0b16; color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; font: inherit; }
.bd-field input[type=number] { width: 80px; }
.bd-label { font-size: 12.5px; color: var(--muted); }
.bd-color { background: rgba(255,255,255,.04); border: 1px solid var(--border); border-radius: 50%; padding: 5px; cursor: pointer; opacity: .45; }
.bd-color.on { opacity: 1; border-color: var(--accent); box-shadow: 0 0 0 2px #b18cff55; }
.bd-color img { width: 20px; height: 20px; display: block; }
.bd-seed { display: flex; gap: 12px; align-items: center; }
.bd-seed img { width: 90px; height: 66px; object-fit: cover; border-radius: 8px; }
.bd-busy { padding: 30px; text-align: center; }
.bd-head { display: flex; gap: 16px; margin: 8px 0 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.bd-cmd { width: 170px; border-radius: 4.75% / 3.5%; cursor: pointer; }
.bd-title { font-size: 18px; font-weight: 700; }
.bd-meta { color: var(--muted); font-size: 12.5px; margin: 4px 0 8px; }
.bd-meta .sym { width: 14px; height: 14px; vertical-align: -2px; }
.bd-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.bd-actions .btn { padding: 6px 11px; font-size: 12.5px; }
.bd-group { margin-bottom: 12px; }
.bd-gt { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; }
.bd-card { display: grid; grid-template-columns: 44px 30px minmax(120px, 1.1fr) 1.4fr; gap: 8px; align-items: center; padding: 3px 6px; border-radius: 7px; cursor: pointer; font-size: 12.5px; }
.bd-card:hover { background: rgba(255,255,255,.05); }
.bd-card img { width: 44px; height: 32px; object-fit: cover; border-radius: 5px; }
.bd-q { color: var(--muted); text-align: right; }
.bd-why { color: var(--muted); font-size: 12px; }
#disclaimer a { color: #8d8aa8; pointer-events: auto; }
@media (max-width: 1240px) { #api-btn .lbl { display: none; } }   /* keep the toolbar on one line: icon only */

/* Loading screen */
#loader { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #1a1430 0%, #0b0a16 55%, #07070d 100%); transition: opacity .5s ease; }
#loader.done { opacity: 0; pointer-events: none; }
.ld-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(320px, 80vw); }
.ld-orbit { width: 120px; height: 120px; overflow: visible; }
.ld-ring { animation: ld-spin 9s linear infinite; transform-origin: 0 0; }
.ld-ring line { stroke-width: 2.5; stroke-linecap: round; opacity: .75; }
.ld-ring circle { filter: drop-shadow(0 0 4px currentColor); }
.ld-core { fill: #a487ff; stroke: #fff; stroke-opacity: .85; stroke-width: 2; animation: ld-pulse 1.8s ease-in-out infinite; transform-origin: 0 0; }
@keyframes ld-spin { to { transform: rotate(360deg); } }
@keyframes ld-pulse { 0%, 100% { transform: scale(1); filter: drop-shadow(0 0 6px #b18cff); } 50% { transform: scale(1.12); filter: drop-shadow(0 0 16px #b18cff); } }
.ld-brand { font-weight: 800; font-size: 22px; letter-spacing: .3px; }
.ld-brand span { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ld-brand .logo { color: var(--accent); -webkit-text-fill-color: var(--accent); }
.ld-status { color: var(--muted); font-size: 13.5px; min-height: 20px; text-align: center; }
.ld-bar { width: 100%; height: 4px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden; }
.ld-fill { height: 100%; width: 4%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .25s ease; }
@media (prefers-reduced-motion: reduce) {
  .ld-ring, .ld-core { animation: none; }
  #loader { transition: none; }
}
/* Smaller loading states */
.loading-line { color: var(--muted); font-size: 12.5px; font-style: italic; }
a.brand { color: var(--text); text-decoration: none; cursor: pointer; }
a.brand:hover .logo { filter: drop-shadow(0 0 6px var(--accent)); }

/* ---------- Phone layout (desktop unaffected) ---------- */
#menu-btn, #menu, .sheet-head, .sheet-close, .tip-name { display: none; }
.tip-actions { display: flex; gap: 8px; margin-top: 10px; }

@media (max-width: 760px) {
  body { font-size: 14px; }
  /* Top bar: logo mark, search, menu */
  #topbar { left: 8px; right: 8px; top: 8px; transform: none; gap: 8px; padding: 6px 8px; border-radius: 12px; }
  #topbar .brand { font-size: 0; }                 /* hide the words, keep the ✦ mark */
  #topbar .brand .logo { font-size: 20px; }
  #topbar .nav-btns, #random, .rand-more, #find-btn, #rules-btn, #api-btn { display: none; }
  .search-wrap { flex: 1; min-width: 0; }
  #search { width: 100%; font-size: 16px; padding: 8px 10px; }   /* 16px stops iOS zooming into the field */
  #suggestions { top: 40px; }
  #menu-btn { display: inline-flex; flex: none; }
  #crumbs, #disclaimer { display: none; }

  /* ☰ menu */
  #menu { display: none; position: fixed; top: 60px; right: 8px; z-index: 30; min-width: 220px; flex-direction: column; padding: 6px;
    background: #15131f; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.6); }
  body.menu-open #menu { display: flex; }
  #menu button, #menu a { text-align: left; background: none; border: 0; color: var(--text); font: inherit; font-size: 15px; padding: 11px 12px; border-radius: 8px; text-decoration: none; cursor: pointer; }
  #menu button:active, #menu a:active { background: #ffffff14; }
  #menu a { color: var(--muted); font-size: 14px; }

  /* Card panel -> bottom sheet: collapsed shows only the header row */
  #card-panel { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 64px; overflow: hidden; padding: 0 14px;
    border-radius: 16px 16px 0 0; transition: max-height .25s ease; z-index: 9; }
  body.sheet-open #card-panel { max-height: 78vh; overflow-y: auto; padding-bottom: 20px; }
  .sheet-head { display: flex; align-items: center; gap: 10px; height: 64px; cursor: pointer; position: sticky; top: 0; background: #15131f; margin: 0 -14px 6px; padding: 0 14px; z-index: 1; }
  .sheet-head img { width: 54px; height: 40px; object-fit: cover; border-radius: 7px; flex: none; }
  .sheet-title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sheet-sub { display: block; font-weight: 400; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
  .sheet-chev { color: var(--muted); transition: transform .2s; }
  body.sheet-open .sheet-chev { transform: rotate(180deg); }
  #card-view img.card { max-width: 240px; margin: 0 auto; }

  /* Filters & legend, and the deck tray: hidden until opened from the menu, then a bottom sheet */
  #controls, #tray { display: none; }
  body.show-controls #controls, body.show-tray #tray { display: flex; flex-direction: column; left: 0; right: 0; bottom: 0; top: auto; width: auto;
    transform: none; max-height: 75vh; overflow-y: auto; border-radius: 16px 16px 0 0; z-index: 12; padding: 14px 16px 22px; }
  body.show-controls #controls { display: block; }
  .sheet-close { display: inline-flex; position: absolute; top: 10px; right: 10px; z-index: 2; }
  body.show-tray #tray { align-items: stretch; gap: 10px; }
  #tray-cards { max-width: none; flex-wrap: wrap; }
  #tray .btn { width: 100%; }
  #tray .tray-label { font-size: 13px; }

  /* Tap preview (the tooltip) -> bottom sheet with actions */
  #tip { left: 0; right: 0; bottom: 0; top: auto; transform: none !important; pointer-events: auto; z-index: 20; }
  #tip .tip { max-width: none; border-radius: 16px 16px 0 0; padding: 12px 14px 18px; max-height: 70vh; overflow-y: auto; }
  #tip .tip.node-tip { gap: 12px; }
  #tip .tip img.card-img { width: 110px; }
  #tip .tip .side { width: auto; flex: 1; min-width: 0; font-size: 13px; }
  .tip-name { display: block; font-weight: 700; font-size: 15px; margin-bottom: 4px; }
  #tip .tip .hint { display: none; }

  /* Full-screen panels */
  #finder, #builder, #playtest, #rules-panel { top: 64px; left: 0; right: 0; bottom: 0; width: auto; max-height: none; border-radius: 16px 16px 0 0; padding: 10px 12px; }
  #decks-panel { left: 0; right: 0; bottom: 0; width: auto; transform: none; max-height: 85vh; border-radius: 16px 16px 0 0; }
  .finder-head { flex-wrap: wrap; }
  #finder-q { flex: 1 1 100%; font-size: 16px; }
  #finder-role, #finder-sort { flex: 1; min-width: 0; }
  .finder-meta { flex-direction: column; align-items: flex-start; gap: 4px; }
  #finder-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .pt-card img { width: 96px; }
  .pt-row.small .pt-card img { width: 64px; }
  .pt-stat { margin-left: 0; width: 100%; }
  .pt-tiles { flex-wrap: wrap; }
  .bd-head { flex-direction: column; }
  .bd-cmd { width: 140px; }
  .bd-card { grid-template-columns: 40px 28px 1fr; }
  .bd-why { grid-column: 3; font-size: 11.5px; }
  .bd-row { gap: 8px; }
  .deck-row { flex-wrap: wrap; }
  .deck-info { flex: 1 1 100%; }
  #search, #finder-q, .deck-save input, #rules-search, .bd-field input, .bd-field select { font-size: 16px; }
}

@media (max-width: 760px) {
  /* leave room for the card bar at the bottom */
  #finder, #builder, #playtest, #rules-panel { bottom: 64px; border-radius: 16px; }
  /* preview sheet: actions wrap, close button pinned top-right */
  #tip .tip { position: relative; }
  .tip-actions { flex-wrap: wrap; }
  .tip-actions [data-tip-act=close] { position: absolute; top: 8px; right: 8px; }
  .tip-name { padding-right: 44px; }
}

/* known combos (Commander Spellbook) */
.badge.gc { background: #ff8a3d22; color: #ffb37f; border-color: #ff8a3d55; }
.combo-row { margin: 6px 0; font-size: 13px; line-height: 1.35; }
.combo-row .card-link { color: var(--text, #e8e6f3); cursor: pointer; border-bottom: 1px dotted #ff8a3d88; }
.combo-row .card-link:hover { color: #ffb37f; }
.combo-row a[target] , .bd-combos a { color: #b9a6ff; }
.h4-hint a { color: #8f86b8; }
.bd-check { flex-direction: row !important; align-items: center; gap: 6px; }
.bd-combos { margin: 4px 0 8px; font-size: 12.5px; }
.bd-combos summary { cursor: pointer; color: #ffb37f; }
.bd-combo { margin: 4px 0 0 14px; }

/* random card: kind menu */
.rand-wrap { position: relative; display: inline-flex; }
.rand-wrap #random { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.rand-more { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; padding-left: 7px; padding-right: 7px; }
#random-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; min-width: 220px; background: #12101f; border: 1px solid var(--border); border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px #0008; }
#random-menu button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 7px 10px; border-radius: 7px; font: inherit; font-size: 13px; cursor: pointer; }
#random-menu button:hover { background: #ffffff10; }
#random-menu button.on { color: #c9b8ff; }
#random-menu button.on::after { content: ' ✓'; }
#random-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
#random-menu .muted { padding: 6px 10px 2px; }
#finder-random:disabled { opacity: .4; cursor: default; }

/* commander build plans */
.plan-text { font-size: 13px; line-height: 1.45; color: var(--text); }
.plan-keys { font-size: 12.5px; line-height: 1.6; margin: 6px 0 8px; }
.plan-keys .card-link { color: #c9b8ff; cursor: pointer; }
.plan-keys .card-link:hover { text-decoration: underline; }
.bd-plan { color: var(--text); font-size: 13px; line-height: 1.4; }
.btn.small { font-size: 12px; padding: 4px 10px; }

/* check a deck */
#ck-text { width: 100%; box-sizing: border-box; margin: 8px 0; background: #0c0b16; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.ck-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 4px 22px; }
.ck-row { font-size: 13px; line-height: 1.5; margin: 2px 0; }
.ck-row .sym { width: 14px; height: 14px; vertical-align: -2px; }
.ck-ok { color: #6fdc8c; font-weight: 700; }
.ck-warn { color: #ffc24d; font-weight: 700; }
.ck-curve { display: flex; gap: 6px; align-items: flex-end; height: 92px; }
.ck-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 26px; font-size: 11px; color: var(--muted); }
.ck-bar { width: 18px; background: #9a78f0; border-radius: 4px 4px 0 0; min-height: 2px; }
.ck-col b { font-weight: 500; color: #8f8aa8; }
#bd-result .card-link { color: #c9b8ff; cursor: pointer; }
#bd-result .card-link:hover { text-decoration: underline; }
.tile-n.warn { color: #ffc24d; }
