* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4fc3f7;
  --accent: #66bb6a;
  --bg: #0f0f1a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, var(--bg) 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  color: #e0e0e0;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2.5rem;
  color: #fff;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: #a0a0a0;
  font-size: 1.1rem;
}

h2 {
  color: #fff;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

/* Search Section */
.search-section {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 2rem;
  margin-bottom: 2rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-bar input {
  flex: 1;
  padding: 0.8rem 1.2rem;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transition: border-color 0.3s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
}

.search-bar input::placeholder {
  color: #888;
}

.search-bar button {
  padding: 0.8rem 2rem;
  background: var(--primary);
  color: #1a1a2e;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s, transform 0.1s;
}

.search-bar button:hover {
  background: #81d4fa;
  transform: translateY(-1px);
}

.search-bar button:active {
  transform: translateY(0);
}

/* Mode Selector */
.mode-selector {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mode-option {
  cursor: pointer;
}

.mode-option input[type="radio"] {
  display: none;
}

.mode-label {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  font-size: 0.9rem;
  color: #aaa;
  transition: all 0.3s;
}

.mode-option input[type="radio"]:checked + .mode-label {
  background: rgba(79, 195, 247, 0.2);
  border-color: var(--primary);
  color: var(--primary);
}

.mode-option:hover .mode-label {
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

.foil-text {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.1), rgba(255, 105, 180, 0.1));
}

.mode-option input[type="radio"]:checked + .foil-text {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.3), rgba(255, 105, 180, 0.2));
  border-color: #ffd700;
  color: #ffd700;
}

.loading {
  text-align: center;
  padding: 1rem;
  color: var(--primary);
  font-style: italic;
}

.error {
  text-align: center;
  padding: 1rem;
  color: #ef5350;
  background: rgba(239, 83, 80, 0.1);
  border-radius: 8px;
}

.hidden {
  display: none;
}

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.card-item {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  min-width: 0;
}

.card-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.card-item.foil-card {
  border-color: rgba(255, 215, 0, 0.4);
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.05), rgba(255, 105, 180, 0.05), rgba(100, 200, 255, 0.05));
}

.card-image {
  width: 100%;
  max-width: 200px;
  height: auto;
  border-radius: 8px;
  margin-bottom: 0.8rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.card-image.foil-img {
  box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
  position: relative;
}

/* Foil holographic shimmer effect — animated overlay style */
.foil-shimmer-wrap {
  position: relative;
  display: inline-block;
  overflow: hidden;
  border-radius: 8px;
}
.foil-shimmer-wrap img {
  display: block;
}
.foil-shimmer-wrap::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><defs><linearGradient id="g" x1="0%25" y1="0%25" x2="100%25" y2="100%25"><stop offset="0%25" style="stop-color:rgb(255,0,128);stop-opacity:0.3"/><stop offset="16%25" style="stop-color:rgb(255,200,0);stop-opacity:0.3"/><stop offset="33%25" style="stop-color:rgb(0,255,100);stop-opacity:0.3"/><stop offset="50%25" style="stop-color:rgb(0,150,255);stop-opacity:0.3"/><stop offset="66%25" style="stop-color:rgb(128,0,255);stop-opacity:0.3"/><stop offset="83%25" style="stop-color:rgb(255,100,200);stop-opacity:0.3"/><stop offset="100%25" style="stop-color:rgb(255,200,0);stop-opacity:0.3"/></linearGradient></defs><rect fill="url(%23g)" width="200" height="200"/></svg>');
  background-size: 300% 300%;
  mix-blend-mode: color-dodge;
  opacity: 0.55;
  z-index: 1;
  pointer-events: none;
  animation: foilGradient 4s ease infinite;
}
@keyframes foilGradient {
  0% { background-position: 0% 0%; }
  25% { background-position: 100% 0%; }
  50% { background-position: 100% 100%; }
  75% { background-position: 0% 100%; }
  100% { background-position: 0% 0%; }
}

/* Surge Foil — Three.js WebGL shader overlay (see surge-foil.js) */
.surge-foil-wrap {
  position: relative;
  display: inline-block;
  overflow: hidden;
  border-radius: 8px;
}
.surge-foil-wrap img {
  display: block;
}

.card-item .card-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.3rem;
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-item .card-set {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 0.3rem;
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-item .card-condition {
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 0.5rem;
  text-align: center;
}

.card-item .foil-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: linear-gradient(135deg, #ffd700, #ff69b4);
  color: #1a1a2e;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.card-item .card-price {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.8rem;
  text-align: center;
}

.card-item .add-btn {
  width: 100%;
  padding: 0.6rem;
  background: var(--accent);
  color: #1a1a2e;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s;
}

.card-item .add-btn:hover {
  background: #81c784;
}

/* Market Section */
.market-section {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 2rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.market-summary {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 1rem 1.5rem;
  background: rgba(102, 187, 106, 0.1);
  border: 1px solid rgba(102, 187, 106, 0.3);
  border-radius: 10px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.total-value {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.total-value span:first-child {
  font-size: 1rem;
  color: #aaa;
}

#totalValue {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

.card-count {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-count span:first-child {
  color: #aaa;
}

#cardCount {
  font-weight: 600;
  color: #fff;
}

.clear-btn {
  margin-left: auto;
  padding: 0.5rem 1.2rem;
  background: rgba(239, 83, 80, 0.2);
  color: #ef5350;
  border: 1px solid rgba(239, 83, 80, 0.4);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.3s;
}

.clear-btn:hover {
  background: rgba(239, 83, 80, 0.4);
}

/* Market List */
.market-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.market-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  transition: background 0.2s;
}

.market-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.market-item-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
}

.market-item-thumb {
  width: 40px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.market-item-name {
  font-weight: 500;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.market-foil-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  background: linear-gradient(135deg, #ffd700, #ff69b4);
  color: #1a1a2e;
  border-radius: 8px;
  font-weight: 700;
}

.market-item-set {
  font-size: 0.8rem;
  color: #888;
}

.market-item-qty {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.market-item-qty button {
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.market-item-qty button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.market-item-qty span {
  min-width: 24px;
  text-align: center;
  font-weight: 500;
}

.market-item-price {
  font-weight: 600;
  color: var(--accent);
  min-width: 80px;
  text-align: right;
}

.market-item .remove-btn {
  margin-left: 1rem;
  padding: 0.3rem 0.6rem;
  background: transparent;
  color: #ef5350;
  border: 1px solid rgba(239, 83, 80, 0.4);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background 0.3s;
}

.market-item .remove-btn:hover {
  background: rgba(239, 83, 80, 0.2);
}

.empty-market {
  text-align: center;
  padding: 2rem;
  color: #666;
  font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 0.8rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  h2 {
    font-size: 1.2rem;
  }

  .search-section {
    padding: 1rem;
    border-radius: 10px;
  }

  .search-bar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .search-bar input {
    width: 100%;
  }

  .search-bar button {
    width: 100%;
    padding: 0.8rem;
  }

  .search-bar select {
    width: 100%;
    padding: 0.7rem;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.6rem;
  }

  .card-item {
    padding: 0.6rem;
  }

  .card-item .card-name {
    font-size: 0.8rem;
  }

  .card-item .card-set {
    font-size: 0.7rem;
  }

  .card-name {
    font-size: 0.85rem;
  }

  .market-summary {
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
  }

  .market-summary button {
    width: 100%;
    padding: 0.8rem;
  }

  .clear-btn {
    margin-left: 0;
  }

  .market-item {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .market-item-info {
    width: 100%;
  }

  .buyer-row {
    flex-direction: column;
    gap: 0.3rem;
  }

  .buyer-row input {
    width: 100%;
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding: 1rem;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }
}

/* Touch-friendly: minimum tap target 44px */
@media (hover: none) and (pointer: coarse) {
  button, .tab-btn, .nav-link, .add-btn, .primary-btn, .secondary-btn, .sell-btn {
    min-height: 44px;
    min-width: 44px;
  }

  input, select, textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 44px;
  }

  .card-item .add-btn {
    padding: 0.7rem;
    font-size: 0.9rem;
  }
}

/* Lightbox - click to enlarge card images */
.lightbox-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  z-index: 3000;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox-overlay.active { display: flex; }
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.lightbox-overlay .foil-shimmer-wrap {
  border-radius: 12px;
}
.lightbox-overlay .foil-shimmer-wrap img {
  border-radius: 12px;
}
.lightbox-overlay .surge-foil-wrap {
  border-radius: 12px;
}
.lightbox-overlay .surge-foil-wrap img {
  border-radius: 12px;
}
.card-img-clickable { cursor: zoom-in; }

/* Stage tracker connector line */
.stage-tracker { position: relative; }
.stage-tracker::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 5%;
  right: 5%;
  height: 2px;
  background: rgba(255,255,255,0.15);
  z-index: 0;
  pointer-events: none;
}
.stage-step { z-index: 1; }
.stage-dot { position: relative; z-index: 1; }
