/* Commander Forge — mobile-first dark theme */
:root {
  --bg: #12141c;
  --card: #1b1e29;
  --card2: #232736;
  --text: #eef0f6;
  --muted: #9aa3b8;
  --accent: #e8b64c;
  --accent2: #7fb3e8;
  --good: #6fce7e;
  --bad: #e86a6a;
  --border: #2e3348;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
.app-header {
  padding: 20px 16px 8px;
  text-align: center;
}
.app-header h1 { margin: 0; font-size: 28px; letter-spacing: .3px; }
.tagline { color: var(--muted); margin: 4px 0 0; }
main { max-width: 720px; margin: 0 auto; padding: 8px 12px 24px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
h2 { margin: 0 0 12px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.opt-label { display: block; font-weight: 600; margin: 14px 0 6px; }

/* Search */
.search-wrap { position: relative; }
#commander-input {
  width: 100%;
  font-size: 17px;
  padding: 14px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  outline: none;
}
#commander-input:focus { border-color: var(--accent); }
.search-results {
  position: absolute;
  z-index: 20;
  left: 0; right: 0;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 4px;
  max-height: 340px;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.result-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--border);
  color: var(--text); padding: 10px; cursor: pointer; font-size: 15px;
}
.result-row:last-child { border-bottom: none; }
.result-row:active { background: #2c3049; }
.result-row img { width: 40px; height: 56px; object-fit: cover; border-radius: 4px; background: #333; }
.result-row .r-name { font-weight: 600; display: block; }
.result-row .r-sub { color: var(--muted); font-size: 13px; display: block; }

/* Commander detail */
.commander-detail { display: flex; gap: 14px; margin-top: 14px; align-items: flex-start; }
.commander-detail img { width: 120px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.commander-detail h3 { margin: 0 0 4px; font-size: 18px; }
.commander-detail .type-line { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.oracle { font-size: 14px; white-space: pre-wrap; margin: 0; }
.edhrec-rank { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* Segmented controls */
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  min-height: 52px;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.seg button.active { border-color: var(--accent); background: #33291a; color: var(--accent); }
.seg-sub { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
#bracket-seg button { min-height: 48px; font-size: 17px; }

select#win-style {
  width: 100%;
  font-size: 16px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
}
.big-btn {
  width: 100%;
  margin-top: 16px;
  min-height: 56px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #1a1405;
  cursor: pointer;
}
.big-btn:disabled { opacity: .5; cursor: wait; }
.tcg-btn { background: #ff5c1a; color: #fff; }
.tcg-btn:active { background: #e04d12; }
.ghost-btn {
  flex: 1;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .big-btn { margin-top: 0; }
.actions p { flex-basis: 100%; margin: 4px 0 0; }

/* Deck stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.source-badge {
  display: inline-block; margin-top: 10px; padding: 4px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 700;
  background: #1e3a26; color: var(--good);
}
.source-badge.local { background: #3a2a1e; color: var(--accent); }
.source-badge.shared { background: #1e2a3a; color: #9ecfff; }
.curve { margin-top: 14px; }
.curve-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 13px; }
.curve-row .cl { width: 22px; color: var(--muted); text-align: right; }
.curve-row .bar { height: 14px; background: var(--accent2); border-radius: 4px; min-width: 2px; }
.curve-row .cv { color: var(--muted); }

/* Validation */
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { padding: 5px 0; font-size: 15px; }
.check-list .ok { color: var(--good); font-weight: 700; }
.check-list .fail { color: var(--bad); font-weight: 700; }

/* Notices */
.notice {
  background: #3a2a1e; border: 1px solid #6b4d1f; color: #f0d9a8;
  border-radius: 10px; padding: 12px 14px; margin: 12px 0; font-size: 14px;
}

/* Deck groups */
.group { margin: 12px 0; }
.group > h3 {
  margin: 0; padding: 10px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; cursor: pointer; user-select: none;
  display: flex; justify-content: space-between;
}
.group > h3 .count { color: var(--muted); font-weight: 400; }
.group ul { list-style: none; margin: 6px 0 0; padding: 0; }
.card-row {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  padding: 10px 12px; margin: 4px 0; cursor: pointer; font-size: 15px;
}
.card-row:active { background: #2c3049; }
.card-row .c-name { flex: 1; min-width: 0; }
.card-row .c-type { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-row .c-price { color: var(--muted); font-size: 14px; white-space: nowrap; }
.card-row .c-price.gc { color: var(--accent); font-weight: 700; }

/* Mana pips */
.pip {
  display: inline-block; min-width: 20px; height: 20px; line-height: 20px;
  text-align: center; border-radius: 50%; font-size: 12px; font-weight: 700;
  margin-right: 2px; vertical-align: middle; padding: 0 3px;
  background: #555; color: #fff;
}
.pip-W { background: #e8ddb0; color: #4a3f1a; }
.pip-U { background: #6ea8dc; color: #0c2a4a; }
.pip-B { background: #777; color: #eee; }
.pip-R { background: #e07856; color: #fff; }
.pip-G { background: #6aa84f; color: #fff; }
.pip-C { background: #999; color: #222; }
.pip-X { background: #444; color: #ddd; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-box {
  position: relative; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; max-width: 480px; width: 100%;
  max-height: 86vh; overflow-y: auto;
}
.modal-close {
  position: absolute; top: 10px; right: 10px; width: 36px; height: 36px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--card2);
  color: var(--text); font-size: 16px; cursor: pointer;
}
.modal-box img { width: 100%; max-width: 260px; display: block; margin: 0 auto 12px; border-radius: 12px; }
.modal-box h3 { margin: 0 0 4px; font-size: 19px; padding-right: 36px; }
.modal-box .type-line { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
.modal-box .oracle { font-size: 15px; }
.modal-box .m-price { margin-top: 12px; font-size: 15px; color: var(--muted); }

/* Saved decks */
.saved-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--card2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); padding: 12px; margin: 6px 0; cursor: pointer; text-align: left; font-size: 15px;
}
.saved-row .s-name { flex: 1; font-weight: 600; }
.saved-row .s-meta { color: var(--muted); font-size: 13px; }
.saved-row .s-del { color: var(--bad); background: none; border: none; font-size: 17px; cursor: pointer; padding: 4px 8px; }

footer { max-width: 720px; margin: 0 auto; padding: 0 16px 32px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Saved-deck export / import */
.actions-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.actions-row .ghost-btn { flex: 1; min-width: 140px; }
#import-box { margin-top: 10px; }
#import-text {
  width: 100%; box-sizing: border-box; min-height: 90px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text);
  font-size: 14px; padding: 10px; margin-bottom: 8px;
}
.saved-row:disabled { opacity: 0.55; }

/* Partner picker */
.partner-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  background: #2a3350; color: var(--accent2);
  border-radius: 999px; padding: 2px 8px; vertical-align: 2px;
  white-space: nowrap;
}
#partner-section { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
#partner-section h3 { margin: 0 0 4px; font-size: 16px; }
#partner-input {
  width: 100%;
  font-size: 16px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  outline: none;
}
#partner-input:focus { border-color: var(--accent); }
.partner-chip {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-top: 10px; font-size: 15px;
}

/* Deck editing */
.card-row-wrap { display: flex; gap: 6px; align-items: stretch; }
.card-row-wrap .card-row { flex: 1; min-width: 0; }
.edit-btn {
  flex: 0 0 44px; min-height: 44px; align-self: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card2); color: var(--text); font-size: 17px; cursor: pointer;
}
.edit-btn:active { background: #2c3049; }
.source-badge.edited { background: #2a2140; color: #c9a7ff; }
.notice.warn { background: #3a1e1e; border-color: #6b2f2f; color: #f0c9a8; }
#add-input, #swap-search {
  width: 100%; font-size: 16px; padding: 12px; margin-top: 10px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text); outline: none;
}
#swap-search { margin-top: 12px; }
#add-input:focus, #swap-search:focus { border-color: var(--accent); }
#share-box { flex-basis: 100%; margin-top: 4px; }
#share-link {
  width: 100%; font-size: 13px; padding: 10px; box-sizing: border-box;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text); outline: none;
}
#share-link:focus { border-color: var(--accent); }
#share-box .ghost-btn { margin-top: 8px; }
.swap-results { margin-top: 6px; max-height: 260px; overflow-y: auto; }

/* Playtester */
.pt-zone { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pt-card {
  width: 84px; background: none; border: none; padding: 0; cursor: pointer;
  text-align: center; color: var(--text); font-size: 12px; font-family: inherit;
}
.pt-card img { width: 84px; height: 117px; object-fit: cover; border-radius: 8px; background: #333; display: block; }
.pt-card .pt-cname { display: block; margin-top: 4px; line-height: 1.25; }
.pt-card.tapped { opacity: .55; }
.pt-card.tapped img { transform: rotate(8deg); }
.pt-card.selected { outline: 2px solid var(--accent); border-radius: 8px; }
.pt-tapped-tag { display: block; font-size: 10px; font-weight: 700; color: var(--accent); }
.pt-name-only {
  display: block; width: 84px; min-height: 60px; padding: 8px 4px;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px;
}
.pt-btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.pt-btn-row .ghost-btn { flex: 1; min-width: 110px; }
.mini-btn {
  min-height: 40px; padding: 6px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card2);
  color: var(--text); font-size: 15px; cursor: pointer;
}
.pt-bf-menu { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.pt-bf-menu #pt-bf-name { flex: 1; font-weight: 600; min-width: 120px; }
.pt-bf-menu .ghost-btn { flex: 0 0 auto; min-height: 40px; padding: 6px 14px; }
.sim-results { margin-top: 12px; }
.sim-results p { margin: 6px 0; }
