:root {
  --bg: #15171c;
  --surface: #1e2129;
  --surface-2: #262a34;
  --border: #333845;
  --text: #e6e8ec;
  --text-dim: #9aa0ad;
  --accent: #c9922e;
  --accent-soft: rgba(201, 146, 46, 0.15);
  --win: #4caf72;
  --loss: #d35b5b;
  --radius: 12px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Ensure the `hidden` attribute always wins over display rules. */
[hidden] {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* Profile header */
.profile {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 32px;
}

.avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8a5f1a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.profile-meta {
  flex: 1;
}

.username {
  font-size: 26px;
  font-weight: 700;
}

.handle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 16px;
}

.profile-stats {
  display: flex;
  gap: 32px;
}

.profile-stat {
  display: flex;
  flex-direction: column;
}

.profile-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.profile-stat-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header h2 {
  font-size: 20px;
}

.filters {
  display: flex;
  gap: 8px;
}

/* Extra breathing room under the deck format filters, above the grid. */
.decks-section .filters {
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.filter-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Deck grid */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.deck-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.deck-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.deck-name {
  font-size: 17px;
  font-weight: 600;
}

.deck-format {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.deck-form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}

.form-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 2px;
}

.form-pill {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.form-W { background: var(--win); }
.form-L { background: var(--loss); }

.rating-delta {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
}
.rating-up { color: var(--win); }
.rating-down { color: var(--loss); }
.rating-flat { color: var(--text-dim); }

.deck-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.deck-stat {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.deck-stat-value {
  display: block;
  font-size: 18px;
  font-weight: 700;
}

.deck-stat-label {
  font-size: 11px;
  color: var(--text-dim);
}

/* Win rate bar */
.winrate {
  display: flex;
  align-items: center;
  gap: 10px;
}

.winrate-bar {
  flex: 1;
  height: 8px;
  background: var(--loss);
  border-radius: 999px;
  overflow: hidden;
}

.winrate-fill {
  height: 100%;
  background: var(--win);
  border-radius: 999px;
}

.winrate-label {
  font-size: 13px;
  font-weight: 600;
  min-width: 42px;
  text-align: right;
}

/* Refresh button */
.refresh-btn {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.refresh-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.refresh-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Status banner */
.status {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 24px;
  font-size: 14px;
  border: 1px solid var(--border);
}
.status.loading {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.status.error {
  background: rgba(211, 91, 91, 0.12);
  border-color: var(--loss);
  color: #e88;
}
.status.info {
  background: var(--surface);
  color: var(--text-dim);
}

/* Empty state */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px;
  color: var(--text-dim);
}

/* Player lookup */
.lookup-section {
  margin-bottom: 32px;
}
.lookup-section h2 {
  font-size: 20px;
  margin-bottom: 12px;
}
.lookup-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.lookup-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.lookup-input:focus {
  outline: none;
  border-color: var(--accent);
}
.lookup-btn {
  background: var(--accent);
  border: none;
  color: #15171c;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}
.lookup-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.lookup-result:empty {
  display: none;
}

/* Player card (lookup result) */
.player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  gap: 20px;
  align-items: center;
}
.player-card .avatar {
  width: 64px;
  height: 64px;
  font-size: 22px;
}
.player-card-info {
  flex: 1;
}
.player-card-name {
  font-size: 20px;
  font-weight: 700;
}
.player-card-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.player-card-stats {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.player-card-stat {
  display: flex;
  flex-direction: column;
}
.player-card-stat b {
  font-size: 18px;
  color: var(--accent);
}
.player-card-stat span {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Clickable deck cards */
.deck-card {
  cursor: pointer;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: 20px;
}
.modal-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover {
  color: var(--text);
}
.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
}

/* Rating chart */
.chart-wrap {
  margin-bottom: 24px;
}
.chart-title {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.rating-chart {
  width: 100%;
  height: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.chart-empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* Match history list */
.match-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.match-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
}
.match-result {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
}
.match-opponent {
  font-weight: 500;
}
.match-meta {
  font-size: 12px;
  color: var(--text-dim);
}
.match-rating {
  font-size: 13px;
  font-weight: 600;
  min-width: 48px;
  text-align: right;
}

/* Rating section (main profile) */
.rating-section {
  margin-bottom: 32px;
}
.rating-section .section-header {
  margin-bottom: 16px;
}

/* Player comparison (vs you) */
.compare {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.compare-head {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.compare-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.compare-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.cmp-label {
  color: var(--text-dim);
}
.cmp-theirs {
  font-weight: 700;
}
.cmp-mine {
  color: var(--text-dim);
  font-size: 12px;
}
.cmp-better { color: var(--win); }
.cmp-worse { color: var(--loss); }
.cmp-flat { color: var(--text); }

/* Format breakdown */
.breakdown-section {
  margin-bottom: 32px;
}
.breakdown-section h2 {
  font-size: 20px;
  margin-bottom: 16px;
}
.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.breakdown-row {
  display: grid;
  grid-template-columns: 160px 1fr 150px;
  align-items: center;
  gap: 14px;
}
.breakdown-name {
  font-size: 14px;
  font-weight: 500;
}
.breakdown-bar {
  height: 20px;
  background: var(--loss);
  border-radius: 6px;
  overflow: hidden;
}
.breakdown-fill {
  height: 100%;
  background: var(--win);
  border-radius: 6px;
}
.breakdown-figures {
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
}
.breakdown-figures b {
  color: var(--text);
}
.breakdown-row.clickable {
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 8px;
  margin: 0 -8px;
  transition: background 0.12s ease;
}
.breakdown-row.clickable:hover {
  background: var(--surface);
}

/* Deck controls (search + sort) */
.deck-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}
.deck-search {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  min-width: 180px;
}
.deck-search:focus {
  outline: none;
  border-color: var(--accent);
}
.deck-sort {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.deck-sort:focus {
  outline: none;
  border-color: var(--accent);
}

/* "View decklist" affordance on deck cards */
.deck-cardcount {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
}

/* Decklist in modal */
.decklist {
  margin-bottom: 24px;
}
.decklist-columns {
  columns: 2;
  column-gap: 24px;
}
.decklist-group {
  break-inside: avoid;
  margin-bottom: 16px;
}
.decklist-group h4 {
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.decklist-card {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.decklist-qty {
  color: var(--text-dim);
  margin-right: 8px;
}
.decklist-loading {
  color: var(--text-dim);
  font-size: 13px;
  padding: 12px 0;
}

/* Vim hint mode */
#hint-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}
.hint-label {
  position: absolute;
  background: var(--accent);
  color: #15171c;
  font-weight: 700;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 5px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.5px;
  transform: translate(-2px, -2px);
}
.hint-label .hint-done {
  opacity: 0.4;
}

/* Keyboard help hint */
.kbd-help {
  position: fixed;
  bottom: 12px;
  right: 16px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  z-index: 50;
}
.kbd-help kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-family: ui-monospace, monospace;
  font-size: 10px;
}

/* Head-to-head opponents */
.opponents-section {
  margin-bottom: 32px;
}
.opponent-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}
.opponent-row {
  display: grid;
  grid-template-columns: 1fr 90px 120px 56px;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.opponent-name {
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.opponent-record {
  font-size: 13px;
  color: var(--text-dim);
}
.opponent-record b {
  color: var(--text);
}
.opponent-bar {
  height: 8px;
  background: var(--loss);
  border-radius: 999px;
  overflow: hidden;
}
.opponent-fill {
  height: 100%;
  background: var(--win);
  border-radius: 999px;
}
.opponent-winrate {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}
.opponent-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
  text-align: center;
}

/* Clickable opponent rows */
.opponent-row {
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.opponent-row:hover {
  border-color: var(--accent);
}

/* Opponent detail breakdown (in modal) */
.oppfmt-group {
  margin-bottom: 20px;
}
.oppfmt-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.oppfmt-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}
.oppfmt-record {
  font-size: 13px;
  color: var(--text-dim);
}
.oppfmt-record b {
  color: var(--text);
}
.oppdeck-row {
  display: grid;
  grid-template-columns: 1fr 120px 110px;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
}
.oppdeck-name {
  font-size: 14px;
}
.oppdeck-record {
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
}

/* Opponent list controls */
.opponent-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap;
}

/* Unified checkbox control for deck + opponent sections.
   Styled as a pill; uses visibility (not display) toggling so showing/hiding
   it never shifts the search/sort controls beside it. */
.control-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
}
.control-check:hover {
  border-color: var(--accent);
  color: var(--text);
}
.control-check input {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
/* Keep the slot occupied when hidden so sibling controls don't move. */
.control-check[hidden] {
  display: inline-flex !important;
  visibility: hidden;
  pointer-events: none;
}

/* Opponent list caption */
.opponent-caption {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* Deleted-decks badge + tooltip */
.deleted-badge,
.unmatched-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 7px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  position: relative;
  vertical-align: middle;
}
.deleted-badge {
  background: var(--loss);
}
.unmatched-badge {
  background: var(--accent);
  color: #15171c;
}
.deleted-badge:hover::after,
.deleted-badge:focus::after,
.unmatched-badge:hover::after,
.unmatched-badge:focus::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  background: #000;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
/* Suppress the native tooltip so only the styled one shows. */
.deleted-badge:hover,
.deleted-badge:focus,
.unmatched-badge:hover,
.unmatched-badge:focus {
  outline: none;
}

/* Explanation blocks in the deck modal (replace the decklist). */
.deleted-explanation {
  background: rgba(211, 91, 91, 0.1);
  border: 1px solid var(--loss);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}
.unmatched-explanation {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

/* Deck modal: per-deck opponents + toggle buttons */
/* Per-deck match breakdown (2-0 / 2-1 / 1-2 / 0-2 + win rates) */
.deck-breakdown {
  margin-bottom: 24px;
}
.breakdown-rates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.breakdown-rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.breakdown-rate-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.breakdown-rate-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.breakdown-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 8px;
  padding: 10px 6px;
}
.breakdown-cell.breakdown-win {
  border-left-color: var(--win);
}
.breakdown-cell.breakdown-loss {
  border-left-color: var(--loss);
}
.breakdown-score {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.breakdown-count {
  font-size: 18px;
  font-weight: 700;
}
.breakdown-pct {
  font-size: 12px;
  color: var(--text-dim);
}
.breakdown-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.deck-opponents {
  margin-bottom: 24px;
}
.deck-opp-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.deck-opp-row {
  display: grid;
  grid-template-columns: 1fr 120px 110px;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
}
.deck-opp-name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-opp-record {
  font-size: 13px;
  color: var(--text-dim);
  text-align: right;
}

/* Generic toggle button (show more / show decklist) */
.toggle-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.toggle-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Space the decklist section from the content above it. */
.decklist {
  margin-top: 8px;
}
.decklist .toggle-btn {
  margin-bottom: 12px;
}

/* Full-screen decklist view */
.deck-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 150;
  display: flex;
  flex-direction: column;
}
.deck-view-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.back-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.deck-view-title {
  font-size: 22px;
}
.deck-view-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}
.deck-view-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 48px;
}
.deck-view-loading {
  color: var(--text-dim);
  font-size: 15px;
  padding: 40px;
  text-align: center;
}

/* Card image grid */
.cardgrid-section {
  margin-bottom: 32px;
}
.cardgrid-section h3 {
  font-size: 15px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.card-tile {
  position: relative;
  aspect-ratio: 488 / 680; /* standard MTG card ratio */
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}
.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.card-qty {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Deck view: view-mode toggle */
.view-toggle {
  margin-left: auto;
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.view-toggle-btn {
  background: var(--surface);
  border: none;
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
}
.view-toggle-btn:hover {
  color: var(--text);
}
.view-toggle-btn.active {
  background: var(--accent);
  color: #15171c;
  font-weight: 600;
}

/* Stacks mode: piles laid out as columns, cards overlapping vertically. */
.deck-view-body.mode-stacks {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 24px;
}
.mode-stacks .cardgrid-section {
  width: 200px;
  margin-bottom: 0;
}
.card-stack {
  display: flex;
  flex-direction: column;
}
.card-tile.stacked {
  width: 100%;
  /* marginTop (overlap) + zIndex are set inline per card in JS */
}
.card-tile.stacked:hover {
  /* Raise the hovered card above its neighbours so it shows fully.
     z-index only — no margin change — so the pile doesn't reflow. */
  z-index: 999 !important;
}
/* In stacks mode the quantity pill sits top-right (name strip is at top). */
.mode-stacks .card-qty {
  top: 6px;
  bottom: auto;
}

/* Mana curve histogram (deck view) */
.mana-curve {
  width: 100%;
  flex-basis: 100%;
  margin-bottom: 28px;
}
.curve-bars {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 120px;
  padding: 4px 0;
}
.curve-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}
.curve-count {
  font-size: 12px;
  color: var(--text-dim);
  height: 16px;
  line-height: 16px;
}
.curve-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.curve-bar {
  width: 70%;
  min-height: 2px;
  background: linear-gradient(180deg, var(--accent), #8a5f1a);
  border-radius: 5px 5px 0 0;
  transition: height 0.2s ease;
}
.curve-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* Head-to-head block in player lookup card */
.h2h-overall {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}
.h2h-record {
  font-size: 22px;
  font-weight: 700;
}
.h2h-sub {
  font-size: 12px;
  color: var(--text-dim);
}
.h2h-formats {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.h2h-fmt-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.h2h-fmt-name {
  color: var(--text-dim);
}
.h2h-none {
  font-size: 13px;
  color: var(--text-dim);
}

/* Clickable deck rows inside the format popup */
.opponent-row.clickable-row {
  cursor: pointer;
}
.opponent-row.clickable-row:hover {
  border-color: var(--accent);
}

/* Main navigation */
.main-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-btn:hover {
  color: var(--text);
}
.nav-btn.active {
  background: var(--accent);
  color: #15171c;
  border-color: var(--accent);
}

/* Cards page */
.cards-intro {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 16px;
  max-width: 640px;
}
.card-color-section {
  margin-bottom: 28px;
}
.card-color-head {
  font-size: 16px;
  margin-bottom: 12px;
  padding-left: 10px;
  border-left: 4px solid var(--border);
}
.card-color-head.bucket-w { border-left-color: #f8f6d8; }
.card-color-head.bucket-u { border-left-color: #a6c7e8; }
.card-color-head.bucket-b { border-left-color: #b0a7bd; }
.card-color-head.bucket-r { border-left-color: #e49185; }
.card-color-head.bucket-g { border-left-color: #93c296; }
.card-color-head.bucket-m { border-left-color: var(--accent); }
.card-color-head.bucket-c { border-left-color: #c9c6c0; }
.card-color-head.bucket-l { border-left-color: #9a8866; }

.card-stat-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.card-stat-row {
  display: grid;
  grid-template-columns: 1fr 90px 120px 48px;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
}
.card-stat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-stat-decks {
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
}
.card-stat-wr {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  z-index: 50;
}
.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}
.login-title {
  font-size: 22px;
  margin-bottom: 6px;
}
.login-sub {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 24px;
}
.login-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.login-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
  outline: none;
  transition: border-color 0.15s ease;
}
.login-input:focus {
  border-color: var(--accent);
}
.login-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #15171c;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.login-btn:hover:not(:disabled) {
  opacity: 0.9;
}
.login-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.login-error {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--loss);
  background: rgba(211, 91, 91, 0.12);
  border: 1px solid rgba(211, 91, 91, 0.4);
}

/* ---------- Profile header actions (refresh + logout) ---------- */
.profile-actions {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.logout-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.logout-btn:hover:not(:disabled) {
  border-color: var(--loss);
  color: var(--loss);
}
.logout-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ---------- Account switcher ---------- */
.account-switcher {
  position: relative;
}
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.account-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.account-btn-caret {
  font-size: 10px;
  opacity: 0.8;
}
.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.account-menu-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}
.account-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}
.account-menu-item:hover:not(:disabled) {
  background: var(--surface-2);
}
.account-menu-item:disabled {
  cursor: default;
}
.account-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.account-menu-item.active .account-dot {
  background: var(--win);
}
.account-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-item-tag {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.account-menu-add {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.account-menu-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Cancel button on the login screen (shown only when adding an account) */
.login-cancel {
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.login-cancel:hover {
  border-color: var(--text);
  color: var(--text);
}

/* ---------- Settings menu (top-right) ---------- */
.settings-menu {
  position: relative;
  margin-left: auto; /* push to the far right of the nav bar */
}
.settings-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 999px;
  font-size: 17px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.settings-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  z-index: 45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.settings-panel-title {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.settings-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
}
.settings-row + .settings-row {
  border-top: 1px solid var(--border);
}
.settings-row input[type='checkbox'] {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.settings-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-row-label {
  font-size: 14px;
  color: var(--text);
}
.settings-row-hint {
  font-size: 12px;
  color: var(--text-dim);
}
/* Dim the self-match toggle when combining is off (it only applies combined). */
.settings-row.disabled {
  opacity: 0.5;
}
.settings-row.disabled input {
  pointer-events: none;
}

/* --- MagicWeb web port adjustments --- */
/* Keep the login card clear of the shared sticky nav. */
.login-screen { padding-top: 72px; }
.login-note {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 20px;
  line-height: 1.4;
}
