:root {
  --bg: #18241d;
  --bg-strong: #101711;
  --ink: #2a2418;
  --muted: #746b5a;
  --line: #b59a62;
  --panel: #f4ead3;
  --panel-strong: #e4d3ae;
  --panel-soft: #fbf5e7;
  --green: #2d6d45;
  --green-soft: #d8e6cf;
  --amber: #b47b24;
  --red: #ad443b;
  --blue: #2f5f86;
  --shadow: 0 14px 30px rgba(7, 12, 8, 0.26);
}

body[data-theme="dark"] {
  --bg: #0e1510;
  --bg-strong: #090d0a;
  --ink: #f3ead4;
  --muted: #b7aa8f;
  --line: #6c5b34;
  --panel: #1c241d;
  --panel-strong: #263022;
  --panel-soft: #141b15;
  --green: #9acb83;
  --green-soft: #273d29;
  --amber: #d7a84c;
  --red: #e06c62;
  --blue: #80add4;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(180deg, var(--bg), var(--bg-strong));
  background-size:
    34px 34px,
    34px 34px,
    auto;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  transition:
    background 160ms ease,
    color 160ms ease;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 20px));
  margin: 0 auto;
  padding: 14px 0;
}

.topbar {
  align-items: end;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 12px;
  color: #f7efd9;
}

.topbar-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

.section-label {
  color: #d5c195;
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.deck-status {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  display: flex;
  gap: 8px;
  padding: 8px 10px;
}

.theme-toggle {
  background: #e7d3a0;
  border: 1px solid #c7a75a;
  border-radius: 8px;
  color: #2a2418;
  cursor: pointer;
  font-weight: 760;
  min-height: 34px;
  padding: 0 10px;
}

.theme-toggle:hover {
  opacity: 0.88;
}

.mode-switch {
  background: rgba(244, 234, 211, 0.12);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  padding: 4px;
}

.mode-button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: #e7d8b5;
  cursor: pointer;
  font-weight: 780;
  min-height: 28px;
  padding: 0 10px;
}

.mode-button.active {
  background: #e7d3a0;
  color: #2a2418;
}

.help-menu {
  position: relative;
}

.help-button {
  align-items: center;
  background: rgba(244, 234, 211, 0.12);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #f7efd9;
  cursor: help;
  display: inline-flex;
  font-size: 14px;
  font-weight: 900;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.help-button:hover,
.help-button:focus-visible {
  background: #e7d3a0;
  color: #2a2418;
  outline: 0;
}

.help-popover {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  display: none;
  font-size: 12px;
  line-height: 1.35;
  padding: 12px;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(330px, calc(100vw - 24px));
  z-index: 120;
}

.help-popover strong,
.help-popover span {
  display: block;
}

.help-popover span {
  color: var(--muted);
  margin-top: 2px;
}

.help-popover ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-left: 18px;
}

.help-menu:hover .help-popover,
.help-menu:focus-within .help-popover {
  display: block;
}

.status-item {
  min-width: 54px;
}

.status-value {
  display: block;
  font-size: 19px;
  font-weight: 780;
  line-height: 1;
}

.status-label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 3px;
}

.workspace {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 300px;
  margin-bottom: 12px;
}

.lower-grid {
  grid-template-columns: minmax(520px, 1fr) minmax(300px, 380px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.panel-heading {
  align-items: start;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 40%);
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
}

.panel .section-label {
  color: var(--muted);
}

.advanced-panel {
  margin-bottom: 12px;
}

.deck-preview-panel {
  margin-bottom: 12px;
}

.deck-preview-content {
  overflow: hidden;
}

.deck-preview-groups {
  align-items: end;
  display: flex;
  gap: 12px;
  min-height: 118px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 4px 10px;
}

.preview-group {
  display: flex;
  flex: 0 0 auto;
  min-width: 0;
}

.preview-card-grid {
  align-items: end;
  display: flex;
  isolation: isolate;
  padding-right: 44px;
}

.preview-card {
  aspect-ratio: 5 / 7;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(12, 14, 8, 0.16);
  cursor: zoom-in;
  flex: 0 0 74px;
  margin-right: -42px;
  overflow: hidden;
  position: relative;
  transition:
    transform 120ms ease,
    z-index 120ms ease;
}

.preview-card:hover,
.preview-card:focus-visible {
  outline: 0;
  transform: translateY(-8px);
  z-index: 20;
}

.preview-card img,
.preview-placeholder {
  height: 100%;
  width: 100%;
}

.preview-card img {
  display: block;
  object-fit: cover;
}

.preview-placeholder {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  font-weight: 800;
  justify-content: center;
  line-height: 1.25;
  padding: 10px;
  text-align: center;
}

.preview-quantity {
  background: #315f3b;
  border: 1px solid #244c30;
  border-radius: 0;
  bottom: 0;
  color: #f7efd9;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  left: 0;
  overflow: hidden;
  padding: 4px 5px;
  position: absolute;
  right: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.floating-card-preview {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.34);
  overflow: hidden;
  pointer-events: none;
  position: fixed;
  width: min(260px, 72vw);
  z-index: 100;
}

.floating-card-preview img,
.floating-card-preview .preview-placeholder {
  display: block;
  height: auto;
  width: 100%;
}

.search-layout {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
}

.search-column,
.deck-column {
  min-width: 0;
}

.search-box {
  display: grid;
  gap: 7px;
}

.set-filter {
  margin-bottom: 12px;
  max-width: 520px;
  position: relative;
}

.search-box span,
.deck-list-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.search-box input {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.set-filter-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.set-token-input {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 36px;
  padding: 4px 7px;
}

.set-token-input:focus-within {
  border-color: var(--blue);
}

.set-token-input input {
  background: transparent;
  border: 0;
  color: var(--ink);
  flex: 1 1 104px;
  min-height: 26px;
  min-width: 86px;
  outline: 0;
  padding: 2px;
}

.selected-set-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.set-tag {
  background: #315f3b;
  border: 1px solid #244c30;
  border-radius: 999px;
  color: #f7efd9;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  min-height: 24px;
  padding: 0 8px;
}

.set-tag::after {
  content: " x";
}

.set-suggestions {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  left: 0;
  margin-top: 0;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 8;
}

.set-suggestions:empty {
  display: none;
}

.set-suggestion {
  align-items: baseline;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-height: 34px;
  padding: 7px 9px;
  text-align: left;
}

.set-suggestion span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.set-suggestions .empty-state {
  padding: 10px;
}

.search-meta {
  color: var(--muted);
  font-size: 12px;
  margin: 7px 0;
}

.search-results,
.deck-list {
  display: grid;
  gap: 7px;
  max-height: 320px;
  overflow: auto;
  padding-right: 4px;
}

.card-result,
.deck-card {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  padding: 7px;
}

.card-thumb {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  height: 56px;
  object-fit: cover;
  width: 40px;
}

.card-placeholder {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  font-weight: 800;
  justify-content: center;
}

.card-name {
  display: block;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card-details {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  margin-top: 2px;
}

.add-card-button,
.quantity-button {
  background: #315f3b;
  border: 1px solid #244c30;
  border-radius: 7px;
  color: #f7efd9;
  cursor: pointer;
  font-weight: 800;
  min-height: 30px;
  padding: 0 9px;
}

.deck-list-heading {
  align-items: baseline;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.basic-land-builder {
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
  padding-bottom: 10px;
}

.deck-card {
  grid-template-columns: minmax(0, 1fr) auto;
}

.basic-land-input {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 760;
  gap: 7px;
}

.basic-land-input input {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 8px;
  width: 100%;
}

.quantity-control {
  align-items: center;
  display: inline-flex;
  gap: 7px;
}

.quantity-control strong {
  min-width: 24px;
  text-align: center;
}

.quantity-button {
  min-height: 30px;
  min-width: 30px;
  padding: 0;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  padding: 10px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.ghost-button {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  min-height: 30px;
  padding: 0 9px;
}

.ghost-button:hover {
  background: var(--panel-strong);
}

.curve-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(7, minmax(70px, 1fr));
}

.options-panel {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  padding: 10px;
}

.options-heading {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.options-heading span {
  color: var(--muted);
  font-size: 13px;
}

.range-editor {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.range-row {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 38px 1fr 1fr;
  padding: 9px;
}

.range-row label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.range-row span {
  display: block;
  margin-bottom: 3px;
}

.range-row input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 32px;
  padding: 6px;
  width: 100%;
}

.curve-card,
.color-row {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.curve-card {
  padding: 8px;
}

.curve-label {
  align-items: baseline;
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.curve-label strong {
  font-size: 15px;
}

.range-text {
  color: var(--muted);
  font-size: 12px;
}

.number-control {
  display: grid;
  gap: 6px;
}

.field-label {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 760;
  margin-bottom: 4px;
}

.number-control input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 32px;
  padding: 6px;
  width: 100%;
}

.number-control input:disabled,
.color-row input:disabled,
.nonbasic-row input:disabled {
  color: var(--muted);
  opacity: 0.8;
}

.color-row label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 760;
  gap: 5px;
  line-height: 1.2;
}

.chart-wrap {
  margin-top: 12px;
  overflow: hidden;
}

canvas {
  border: 1px solid color-mix(in srgb, var(--line), transparent 35%);
  border-radius: 8px;
  display: block;
  height: auto;
  max-width: 100%;
}

.recommendation-list {
  display: grid;
  gap: 7px;
}

.recommendation {
  background: var(--panel-soft);
  border: 1px solid color-mix(in srgb, var(--line), transparent 30%);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  padding: 8px 9px;
}

.recommendation.cut {
  border-left-color: var(--red);
}

.recommendation.add {
  border-left-color: var(--blue);
}

.recommendation.warn {
  border-left-color: var(--amber);
}

.recommendation strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}

.recommendation span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.land-grid {
  display: grid;
  gap: 8px;
}

.nonbasic-row {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 92px;
  padding: 9px;
}

.nonbasic-row strong {
  display: block;
  font-size: 13px;
}

.nonbasic-row span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-top: 2px;
}

.color-row {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(110px, 1.1fr) minmax(100px, 1fr) minmax(120px, 1fr) 66px;
  padding: 9px;
}

.color-chip {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  font-weight: 800;
  gap: 8px;
}

.mana-dot {
  align-items: center;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100%;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.mana-W {
  background-image: url("https://svgs.scryfall.io/card-symbols/W.svg");
}

.mana-U {
  background-image: url("https://svgs.scryfall.io/card-symbols/U.svg");
}

.mana-B {
  background-image: url("https://svgs.scryfall.io/card-symbols/B.svg");
}

.mana-R {
  background-image: url("https://svgs.scryfall.io/card-symbols/R.svg");
}

.mana-G {
  background-image: url("https://svgs.scryfall.io/card-symbols/G.svg");
}

.mana-C {
  background-image: url("https://svgs.scryfall.io/card-symbols/C.svg");
}

.color-row input,
.nonbasic-row input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 32px;
  padding: 6px 7px;
  width: 100%;
}

.percent-pill {
  background: var(--green-soft);
  border-radius: 999px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  justify-self: end;
  padding: 7px 9px;
  white-space: nowrap;
}

.land-results {
  display: grid;
  gap: 7px;
}

.land-result {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  padding: 7px 0;
}

.land-result:first-child {
  padding-top: 0;
}

.land-result:last-child {
  border-bottom: 0;
}

.land-name {
  color: var(--muted);
  font-size: 13px;
}

.land-count {
  font-size: 24px;
  font-weight: 820;
}

.formula-note {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 9px;
  padding: 9px;
}

.app-footer {
  align-items: center;
  color: #d5c195;
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 10px;
  justify-content: center;
  padding: 8px 0 4px;
}

.app-footer a {
  color: #f7efd9;
  font-weight: 800;
  text-decoration: none;
}

.app-footer a:hover,
.app-footer a:focus-visible {
  text-decoration: underline;
}

@media (max-width: 860px) {
  .topbar,
  .workspace,
  .lower-grid {
    display: block;
  }

  .topbar-tools {
    justify-content: flex-start;
    margin-top: 10px;
  }

  .deck-status {
    display: grid;
    flex: 1 1 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 2px;
    width: 100%;
  }

  .search-layout {
    grid-template-columns: 1fr;
  }

  .panel {
    margin-bottom: 12px;
  }

  .curve-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .deck-preview-groups {
    min-height: 104px;
  }

  .range-editor {
    grid-template-columns: 1fr;
  }

  .color-row {
    align-items: stretch;
    grid-template-columns: minmax(110px, 1fr) 1fr;
  }

  .nonbasic-row {
    grid-template-columns: minmax(0, 1fr) 82px;
  }

  .percent-pill {
    justify-self: start;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 12px, 1180px);
    padding: 8px 0;
  }

  h1 {
    font-size: 25px;
  }

  .section-label {
    font-size: 9px;
  }

  .topbar-tools {
    gap: 6px;
  }

  .mode-switch,
  .help-menu,
  .theme-toggle {
    flex: 1 1 auto;
  }

  .help-button {
    width: 100%;
  }

  .help-popover {
    left: 0;
    right: auto;
  }

  .mode-button,
  .theme-toggle {
    font-size: 12px;
  }

  .deck-status {
    gap: 4px;
    padding: 6px;
  }

  .status-item {
    min-width: 0;
  }

  .status-value {
    font-size: 17px;
  }

  .status-label {
    font-size: 10px;
  }

  .panel {
    padding: 10px;
  }

  .panel-heading {
    align-items: center;
  }

  .curve-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-result {
    grid-template-columns: 34px minmax(0, 1fr) auto;
  }

  .card-thumb {
    height: 48px;
    width: 34px;
  }

  .deck-card {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .preview-card {
    flex-basis: 62px;
    margin-right: -34px;
  }

  .floating-card-preview {
    width: min(220px, 82vw);
  }

  .quantity-control {
    justify-content: flex-end;
  }

  .color-row {
    grid-template-columns: 1fr;
  }

  .nonbasic-row {
    grid-template-columns: 1fr;
  }

  .search-results,
  .deck-list {
    max-height: 260px;
  }
}
