:root {
  --bg: #0c0c0d;
  --panel: #151517;
  --panel-2: #1d1d20;
  --line: #303036;
  --text: #f4f1ea;
  --muted: #a5a3a8;
  --accent: #ffcc66;
  --accent-ink: #231806;
  --danger: #ff7878;
  --success: #78d9a6;
  --radius: 18px;
  --shadow: 0 18px 60px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgba(255,204,102,.10), transparent 28rem),
    radial-gradient(circle at 90% 20%, rgba(255,255,255,.035), transparent 24rem),
    var(--bg);
}

button, select, textarea, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 max(24px, calc((100vw - 1240px)/2));
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(12,12,13,.84);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { color: var(--text); text-decoration: none; font-size: 1.15rem; font-weight: 850; letter-spacing: -.03em; }
.topbar-copy { color: var(--muted); font-size: .88rem; padding-left: 16px; border-left: 1px solid var(--line); }

.shell { width: min(1240px, calc(100% - 32px)); margin: 30px auto 64px; }
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent 120px), var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero { display: grid; grid-template-columns: 1fr auto; gap: 28px; align-items: end; padding: 34px; margin-bottom: 20px; }
.hero h1 { margin: 8px 0 10px; font-size: clamp(2rem, 5vw, 4.25rem); line-height: .98; max-width: 840px; letter-spacing: -.055em; }
.lede { color: #c5c2c5; max-width: 850px; font-size: 1.05rem; line-height: 1.65; margin: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; font-weight: 850; color: var(--accent); }
.hero-badge { min-width: 150px; padding: 18px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); text-align: center; }
.hero-badge span { display: block; }
.badge-number { font-size: 2.2rem; font-weight: 900; letter-spacing: -.07em; }
.hero-badge span:last-child { font-size: .78rem; font-weight: 800; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .72fr); gap: 20px; }
.input-panel, .settings-panel, .results-panel, .preview-panel { padding: 26px; }
.results-panel, .preview-panel { margin-top: 20px; }
h2 { margin: 7px 0 18px; font-size: 1.35rem; letter-spacing: -.03em; }
.section-head { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.text-button { border: 0; background: transparent; color: var(--accent); font-weight: 750; padding: 8px 0; }
.text-button:hover { text-decoration: underline; }

.moxfield-import { margin: 2px 0 18px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,204,102,.035); }
.url-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.url-row input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 11px; background: #0f0f11; color: var(--text); padding: 0 13px; outline: none; }
.url-row input:focus { border-color: #777780; box-shadow: 0 0 0 3px rgba(255,255,255,.055); }
.import-options { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 11px; color: var(--muted); font-size: .76rem; }
.import-options label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.import-options input { accent-color: var(--accent); }
.moxfield-meta { min-height: 18px; margin-top: 9px; color: var(--muted); font-size: .76rem; line-height: 1.4; }
.moxfield-meta.success { color: var(--success); }
.moxfield-meta.error { color: var(--danger); }
.or-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: #77777d; font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.or-divider::before, .or-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }

.drop-zone {
  display: flex;
  min-height: 116px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  border: 1px dashed #4b4b51;
  border-radius: 14px;
  background: rgba(255,255,255,.025);
  transition: .15s ease;
  margin-bottom: 18px;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: rgba(255,204,102,.07); }
.drop-title { font-weight: 800; }
.drop-subtitle { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.field-label { display: block; color: #d7d4d7; font-size: .86rem; font-weight: 750; margin-bottom: 8px; }
textarea {
  width: 100%;
  min-height: 290px;
  resize: vertical;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #0f0f11;
  color: var(--text);
  line-height: 1.55;
  outline: none;
}
textarea:focus, select:focus { border-color: #777780; box-shadow: 0 0 0 3px rgba(255,255,255,.055); }
.format-hint { margin: 10px 2px 0; color: var(--muted); font-size: .79rem; line-height: 1.55; }
code { color: #e9d6ab; }
.action-row { display: flex; gap: 10px; margin-top: 18px; }
.button {
  border: 1px solid var(--line);
  border-radius: 11px;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 850;
  color: var(--text);
  background: var(--panel-2);
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(1.06); }
.button.ghost:hover { background: #26262b; }
.button:disabled { opacity: .38; cursor: not-allowed; filter: none; }
.button.full { width: 100%; margin-top: 16px; }
.status-box { min-height: 22px; margin-top: 14px; font-size: .85rem; color: var(--muted); }
.status-box.error { color: var(--danger); }
.status-box.success { color: var(--success); }

.setting-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.setting-grid label > span { display: block; font-size: .77rem; font-weight: 800; color: var(--muted); margin: 0 0 7px 2px; }
select {
  width: 100%; min-height: 43px; border: 1px solid var(--line); border-radius: 10px; background: #101012; color: var(--text); padding: 0 11px; outline: none;
}
.check-row { display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding: 13px 0; border-bottom: 1px solid rgba(255,255,255,.065); align-items: start; }
.check-row input { margin: 3px 0 0; accent-color: var(--accent); width: 16px; height: 16px; }
.check-row strong, .check-row small { display: block; }
.check-row strong { font-size: .9rem; }
.check-row small { color: var(--muted); margin-top: 3px; line-height: 1.4; }
.metrics { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 18px; }
.metrics div { background: #101012; border: 1px solid var(--line); border-radius: 10px; text-align: center; padding: 12px 6px 10px; }
.metrics span { display: block; font-weight: 900; font-size: 1.25rem; }
.metrics small { display: block; color: var(--muted); margin-top: 2px; font-size: .7rem; }
.print-note { margin: 12px 4px 0; color: var(--muted); font-size: .77rem; line-height: 1.5; }

.results-head { align-items: center; }
.muted { color: var(--muted); font-size: .82rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 14px; }
.card-grid.empty-state { min-height: 180px; display: grid; place-items: center; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { color: var(--text); margin-bottom: 5px; }
.card-item { position: relative; background: #101012; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.card-item img { display: block; width: 100%; aspect-ratio: 63.5 / 88.9; object-fit: cover; background: #222; }
.card-meta { padding: 10px; }
.card-name { font-size: .78rem; font-weight: 850; line-height: 1.25; min-height: 2.5em; }
.card-printing { color: var(--muted); font-size: .69rem; margin-top: 4px; text-transform: uppercase; letter-spacing: .05em; }
.qty-pill { position: absolute; top: 7px; left: 7px; min-width: 30px; height: 30px; display: grid; place-items: center; border-radius: 999px; background: rgba(10,10,11,.84); border: 1px solid rgba(255,255,255,.2); font-weight: 900; font-size: .78rem; backdrop-filter: blur(8px); }

.sheet-wrap { overflow-x: auto; padding: 18px; border-radius: 14px; background: #0d0d0f; border: 1px solid var(--line); }
.sheet { width: min(100%, 720px); aspect-ratio: 8.5 / 11; margin: 0 auto; background: white; padding: 2.3%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 1px; box-shadow: 0 12px 50px rgba(0,0,0,.35); }
.sheet.a4 { aspect-ratio: 210 / 297; }
.sheet-card { position: relative; min-width: 0; min-height: 0; display: flex; justify-content: center; align-items: center; overflow: hidden; }
.sheet-card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sheet-watermark { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; overflow: hidden; }
.sheet-watermark span { transform: rotate(-35deg); color: rgba(255,255,255,.52); text-shadow: 0 1px 3px rgba(0,0,0,.75); font-size: clamp(9px, 2.2vw, 22px); font-weight: 950; letter-spacing: .14em; }
.sheet-placeholder { min-height: 240px; display: grid; place-items: center; color: var(--muted); }

footer { width: min(900px, calc(100% - 36px)); margin: 0 auto 44px; color: #77777d; text-align: center; font-size: .76rem; line-height: 1.55; }

@media (max-width: 820px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .hero-badge { width: fit-content; }
  .topbar-copy { display: none; }
  .section-head { align-items: start; }
}
@media (max-width: 520px) {
  .url-row { grid-template-columns: 1fr; }
  .url-row .button { width: 100%; }
  .shell { width: min(100% - 18px, 1240px); margin-top: 12px; }
  .hero, .input-panel, .settings-panel, .results-panel, .preview-panel { padding: 18px; }
  .setting-grid { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* v2 print-order, custom-card, and bleed controls */
.bleed-control {
  display: grid;
  grid-template-columns: 1fr 120px;
  align-items: center;
  gap: 10px;
  padding: 12px 0 2px;
}
.bleed-control > span { color: var(--muted); font-size: .78rem; font-weight: 800; }

.card-item.ignored-card { opacity: .58; }
.card-item.ignored-card img { filter: grayscale(.7); }
.custom-pill, .ignored-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  padding: 5px 7px;
  border-radius: 999px;
  font-size: .58rem;
  font-weight: 950;
  letter-spacing: .08em;
  background: rgba(10,10,11,.86);
  border: 1px solid rgba(255,255,255,.2);
  backdrop-filter: blur(7px);
}
.ignored-pill { top: 38px; color: #d0ccd0; }
.custom-pill { color: var(--accent); }
.custom-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.065);
}
.custom-controls select { min-height: 34px; font-size: .7rem; }
.mini-button {
  min-height: 34px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #1b1b1f;
  color: var(--text);
  font-size: .7rem;
  font-weight: 850;
}
.mini-button:hover { background: #25252a; }

.sheet-card.outer-bleed-card { overflow: visible; }
.sheet-card.outer-bleed-card::before {
  content: '';
  position: absolute;
  top: var(--bleed-top, 0px);
  bottom: var(--bleed-bottom, 0px);
  left: var(--bleed-left, 0px);
  right: var(--bleed-right, 0px);
  background: #000;
  z-index: 0;
}
.sheet-card.outer-bleed-card img,
.sheet-card.outer-bleed-card .sheet-watermark { position: relative; z-index: 2; }
.sheet-card .sheet-watermark { z-index: 4; }
.sheet-card.custom-sheet-card::after {
  content: 'CUSTOM';
  position: absolute;
  z-index: 4;
  right: 5px;
  bottom: 5px;
  padding: 3px 5px;
  border-radius: 5px;
  background: rgba(0,0,0,.72);
  color: rgba(255,255,255,.85);
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .08em;
}
.sheet-card.blank-card { box-shadow: none; background: transparent; overflow: hidden; }

@media (max-width: 520px) {
  .bleed-control { grid-template-columns: 1fr; }
}

/* Explicit opt-in controls */
.toggle-setting {
  display: grid;
  gap: 7px;
}
.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #101012;
  color: var(--text);
  font-size: .8rem;
  font-weight: 800;
}
.inline-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
select:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* v3 deck naming, commander priority, and square print-slot fixes */
.setting-grid input[type="text"] {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101012;
  color: var(--text);
  padding: 0 11px;
  outline: none;
}
.setting-grid input[type="text"]:focus,
.setting-grid select:focus {
  border-color: rgba(255, 204, 102, .7);
  box-shadow: 0 0 0 3px rgba(255, 204, 102, .08);
}
.locked-rule {
  cursor: default;
}
.locked-dot {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #111;
  font-size: 10px;
  font-weight: 950;
}
/* Printable slots are always rectangular. A black backing lives only inside
   the physical card boundary so transparent/rounded source corners never
   reveal white paper. Optional gap/outer bleed remains separately toggleable. */
.sheet-card {
  border-radius: 0 !important;
  background: #000;
}
.sheet-card img {
  border-radius: 0 !important;
  object-fit: cover;
}
.sheet-card.blank-card {
  background: transparent;
}
