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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --border-color: #30363d;
  --border-light: #484f58;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-primary: #58a6ff;
  --accent-hover: #79b8ff;
  --success-color: #3fb950;
  --success-bg: rgba(63, 185, 80, 0.15);
  --warning-color: #d29922;
  --warning-bg: rgba(210, 153, 34, 0.15);
  --error-color: #f85149;
  --error-bg: rgba(248, 81, 73, 0.15);
  --gradient-accent: linear-gradient(135deg, #58a6ff 0%, #a371f7 100%);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at top left, rgba(88, 166, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(163, 113, 247, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at center, rgba(56, 139, 253, 0.03) 0%, transparent 70%);
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 40px;
  padding: 32px 0;
  position: relative;
}

.header::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(63, 185, 80, 0.1) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.header h1 {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #2ea043 0%, #3fb950 35%, #56d364 65%, #7ee787 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  letter-spacing: -1px;
  text-shadow: 0 0 80px rgba(63, 185, 80, 0.3);
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  from {
    filter: drop-shadow(0 0 20px rgba(46, 160, 67, 0.2));
  }
  to {
    filter: drop-shadow(0 0 30px rgba(126, 231, 135, 0.3));
  }
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* Sticky Header */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  padding: 16px 32px 4px 32px;
  margin-left: -24px;
  margin-right: -24px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-radius: 0 0 16px 16px;
}

/* Stats Bar */
.stats-bar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 24px;
  margin-bottom: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-value.positive {
  color: var(--success-color);
}

.stat-value.negative {
  color: var(--error-color);
}

.stat-value.neutral {
  color: var(--text-primary);
}

.stat.target input {
  width: 100%;
  max-width: 120px;
  padding: 8px 12px;
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.stat.target input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

/* Progress Bar */
.progress-container {
  position: relative;
  height: 12px;
  background: var(--bg-primary);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  border: 1px solid var(--border-color);
}

.progress-bar {
  height: 100%;
  transition: width 0.4s ease;
  background: var(--accent-primary);
}

.progress-bar.bonus {
  background: #a371f7;
}

.progress-label {
  position: absolute;
  right: 0;
  top: -24px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Deck Controls */
.deck-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.btn {
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-secondary);
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  margin-bottom: 20px;
  flex-wrap: wrap;
  position: relative;
  z-index: 50;
  overflow: visible;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 280px;
  z-index: 100;
  overflow: visible;
}

.search-box input {
  width: 100%;
  padding: 12px 40px 12px 16px;
  font-size: 0.9rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.search-box .btn-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.2s;
}

.search-box .btn-icon:hover {
  color: var(--text-primary);
}

/* Autocomplete dropdown */
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  max-height: 320px;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 4px;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.autocomplete-list.hidden {
  display: none;
}

.autocomplete-item {
  padding: 12px 14px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background-color 0.15s;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--bg-hover);
}

.autocomplete-item-name {
  font-weight: 600;
  color: var(--text-primary);
}

.autocomplete-item-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Consolas', monospace;
}

.autocomplete-item-stats {
  font-size: 0.75rem;
  color: var(--accent-primary);
  font-weight: 500;
}

/* Filter Toggle Button (hidden on desktop) */
.filter-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.filter-toggle:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.filter-toggle-icon {
  transition: transform 0.3s ease;
}

.filter-toggle.expanded .filter-toggle-icon {
  transform: rotate(180deg);
}

/* Filter Groups Container */
.filter-groups {
  display: contents;
}

/* Filter Groups */
.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.filter-group select {
  padding: 8px 12px;
  font-size: 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.2s;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.filter-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}

.filter-count.has-filter {
  color: var(--accent-primary);
  font-weight: 600;
}

/* Section Title */
.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 32px 0 16px 0;
  padding-left: 4px;
}

/* Deck Table */
.deck-table-container {
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.deck-table {
  width: 100%;
  border-collapse: collapse;
}

.deck-table thead {
  background: var(--bg-tertiary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.deck-table th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  letter-spacing: 0.5px;
}

.deck-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.deck-table tbody tr {
  transition: background-color 0.15s;
}

.deck-table tbody tr:hover {
  background: var(--bg-hover);
}

.deck-table tbody tr:last-child td {
  border-bottom: none;
}

/* Column widths */
.col-num {
  width: 50px;
  text-align: center;
}

.col-name {
  width: 240px;
}

.col-ability {
  min-width: 320px;
}

.col-cost {
  width: 90px;
  text-align: center;
  white-space: nowrap;
}

.col-dbs {
  width: 80px;
  text-align: center;
}

/* Row number */
.row-num {
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Card Select Dropdown */
.card-select {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.card-select:hover {
  border-color: var(--border-light);
}

.card-select option,
.card-select optgroup {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Ability text */
.ability-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-height: 4em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ability-text.empty {
  font-style: italic;
  color: var(--text-muted);
}

/* Cost and DBS cells */
.cost-value,
.dbs-value {
  font-weight: 600;
  text-align: center;
  display: block;
  font-variant-numeric: tabular-nums;
}

.dbs-value {
  color: var(--accent-primary);
}

.cost-value.empty,
.dbs-value.empty {
  color: var(--text-muted);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 28px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  width: 90%;
  max-width: 520px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.modal-content h2 {
  margin-bottom: 20px;
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-content textarea {
  width: 100%;
  height: 200px;
  padding: 14px;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 0.85rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  resize: vertical;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}

.modal-content textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.modal-content textarea::placeholder {
  color: var(--text-muted);
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Responsive */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .container {
    padding: 16px;
  }

  .sticky-header {
    margin-left: -16px;
    margin-right: -16px;
    padding: 16px 20px 20px 20px;
    border-radius: 0 0 12px 12px;
  }

  .header {
    margin-bottom: 24px;
    padding: 20px 0;
  }

  .header h1 {
    font-size: 2rem;
  }

  .header::before {
    width: 300px;
    height: 300px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .deck-table-container {
    overflow-x: auto;
    border-radius: 8px;
  }

  .deck-table {
    min-width: 700px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  .search-box {
    min-width: auto;
  }

  .filter-toggle {
    display: flex;
  }

  .filter-groups {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
    margin-top: 0;
  }

  .filter-groups.expanded {
    max-height: 300px;
    opacity: 1;
    margin-top: 12px;
  }

  .filter-group {
    justify-content: space-between;
  }

  .filter-count {
    margin-left: 0;
    text-align: center;
    padding-top: 4px;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 12px;
  }

  .sticky-header {
    margin-left: -12px;
    margin-right: -12px;
    padding: 14px 16px 18px 16px;
    border-radius: 0 0 10px 10px;
  }

  /* Header mobile */
  .header {
    margin-bottom: 20px;
    padding: 16px 0;
  }

  .header h1 {
    font-size: 1.6rem;
    letter-spacing: -0.5px;
  }

  .header::before {
    width: 250px;
    height: 250px;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  /* Stats mobile */
  .stats-bar {
    padding: 16px;
    border-radius: 10px;
    margin-bottom: 14px;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }

  .stat {
    text-align: center;
    gap: 4px;
  }

  .stat-label {
    font-size: 0.6rem;
  }

  .stat-value {
    font-size: 1rem;
  }

  .stat.target input {
    max-width: 70px;
    padding: 5px 6px;
    font-size: 0.9rem;
  }

  .progress-container {
    height: 6px;
  }

  .progress-label {
    top: -20px;
    font-size: 0.7rem;
  }

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

  .btn {
    padding: 10px 12px;
    font-size: 0.75rem;
    justify-content: center;
    border-radius: 6px;
  }

  /* Filter mobile */
  .filter-bar {
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 14px;
    gap: 10px;
  }

  .search-box {
    min-width: auto;
  }

  .search-box input {
    padding: 10px 36px 10px 12px;
    font-size: 0.85rem;
    border-radius: 6px;
  }

  .filter-group {
    flex-wrap: wrap;
    gap: 6px;
  }

  .filter-group label {
    font-size: 0.7rem;
    min-width: 50px;
  }

  .filter-group select {
    flex: 1;
    padding: 8px 10px;
    font-size: 0.8rem;
    min-width: 0;
  }

  .filter-count {
    font-size: 0.75rem;
  }

  /* Autocomplete mobile */
  .autocomplete-list {
    max-height: 250px;
  }

  .autocomplete-item {
    padding: 10px 12px;
  }

  .autocomplete-item-name {
    font-size: 0.9rem;
  }

  .autocomplete-item-id,
  .autocomplete-item-stats {
    font-size: 0.7rem;
  }

  /* Table mobile - card layout */
  .deck-table-container {
    border-radius: 12px;
    overflow: visible;
    background: transparent;
    border: none;
  }

  .deck-table {
    display: block;
    min-width: 0;
  }

  .deck-table thead {
    display: none;
  }

  .deck-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px;
  }

  .deck-table tbody tr {
    display: block;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    position: relative;
  }

  .deck-table tbody tr:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-light);
  }

  .deck-table td {
    display: block;
    padding: 0;
    border: none;
  }

  /* Row number - top left badge */
  .deck-table td:nth-child(1) {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .row-num {
    width: 28px;
    height: 28px;
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    line-height: 28px;
  }

  /* Card select - main element */
  .deck-table td:nth-child(2) {
    margin-bottom: 12px;
    padding-left: 44px;
  }

  .card-select {
    padding: 12px 32px 12px 14px;
    font-size: 0.9rem;
    background-position: right 10px center;
    border-radius: 8px;
  }

  /* Stats row - cost and DBS inline */
  .deck-table td:nth-child(4),
  .deck-table td:nth-child(5) {
    display: inline-block;
    margin-top: 4px;
    margin-right: 10px;
    margin-bottom: 12px;
  }

  .cost-value,
  .dbs-value {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
  }

  .cost-value::before {
    content: 'Hot Dog Cost:';
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.75rem;
  }

  .dbs-value::before {
    content: 'DBS:';
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.75rem;
  }

  .dbs-value {
    color: var(--accent-primary);
  }

  .cost-value.empty,
  .dbs-value.empty {
    display: none;
  }

  /* Ability text - full width below */
  .deck-table td:nth-child(3) {
    order: 3;
  }

  .ability-text {
    font-size: 0.85rem;
    line-height: 1.6;
    max-height: none;
    color: var(--text-secondary);
    padding: 14px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
  }

  .ability-text.empty {
    display: none;
  }

  /* Modal mobile */
  .modal-content {
    padding: 20px;
    border-radius: 12px;
    margin: 12px;
    width: calc(100% - 24px);
  }

  .modal-content h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
  }

  .modal-content textarea {
    height: 150px;
    padding: 12px;
    font-size: 0.8rem;
  }

  .modal-buttons {
    gap: 8px;
  }

  .modal-buttons .btn {
    padding: 10px 16px;
  }
}

/* Extra small devices */
@media (max-width: 400px) {
  .container {
    padding: 8px;
  }

  .sticky-header {
    margin-left: -8px;
    margin-right: -8px;
    padding: 12px 12px 16px 12px;
    border-radius: 0 0 8px 8px;
  }

  .header h1 {
    font-size: 1.4rem;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .stat-label {
    font-size: 0.55rem;
  }

  .stat-value {
    font-size: 0.85rem;
  }

  .stat.target input {
    max-width: 60px;
    padding: 4px 5px;
    font-size: 0.8rem;
  }

  .deck-controls {
    grid-template-columns: 1fr 1fr;
  }

  .deck-controls .btn:last-child {
    grid-column: span 2;
  }

  .filter-bar {
    padding: 10px;
  }

  .deck-table tbody tr {
    padding: 14px;
  }

  .row-num {
    width: 26px;
    height: 26px;
    font-size: 0.7rem;
    line-height: 26px;
  }

  .deck-table td:nth-child(1) {
    top: 14px;
    left: 14px;
  }

  .deck-table td:nth-child(2) {
    padding-left: 40px;
    margin-bottom: 10px;
  }

  .card-select {
    font-size: 0.85rem;
    padding: 10px 28px 10px 12px;
  }

  .cost-value,
  .dbs-value {
    padding: 5px 10px;
    font-size: 0.8rem;
  }

  .ability-text {
    font-size: 0.8rem;
    padding: 12px;
  }
}
