:root {
  --bg: #121212;
  --text: #e0e0e0;
  --border: #333;
  --header: #1e1e1e;
  --green: #3cb371;
  --blue: #4d88ff;
  --red: #ff4d4d;
  --primary: var(--blue);
  --success: var(--green);
  --error: var(--red);
  --text-muted: #999;
}

/* Light mode theme */
body.light-mode {
  --bg: #f9f9f9;
  --text: #222;
  --border: #ccc;
  --header: #eee;
  --green: #388e3c;
  --blue: #1976d2;
  --red: #d32f2f;
  --primary: var(--blue);
  --success: var(--green);
  --error: var(--red);
  --text-muted: #666;
}

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

body {
  margin: 0;
  padding: 2rem;
  background-color: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
  padding: 2rem;
  background: var(--header);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.header-content .title {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--primary);
}

.icon {
  font-size: 2rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.update-section {
  text-align: right;
}

.update-btn {
  background-color: var(--header);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.update-btn:hover:not(:disabled) {
  background-color: var(--primary);
  color: white;
}

.update-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-icon {
  transition: transform 0.2s ease;
}

.update-btn.loading .btn-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.last-updated {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--header);
  padding: 1.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: center;
  transition: transform 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

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

/* Loading */
.loading {
  text-align: center;
  padding: 3rem;
  background: var(--header);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

/* Error Message */
.error-message {
  background: rgba(255, 77, 77, 0.1);
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.error-content {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.error-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.error-content h3 {
  color: var(--red);
  margin-bottom: 0.5rem;
}

/* Table */
.table-container {
  background: var(--header);
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
}

.table-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.cache-info {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 0.25rem 0.75rem;
  background: rgba(77, 191, 255, 0.1);
  border-radius: 6px;
  border: 1px solid rgba(77, 191, 255, 0.3);
}

.table-wrapper {
  overflow-x: auto;
}

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

.price-table th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid var(--border);
}

.price-table td {
  padding: 1rem 1.5rem;
  border: 1px solid var(--border);
  vertical-align: middle;
}

.price-table tbody tr {
  transition: background-color 0.2s ease;
}

.price-table tbody tr:hover {
  background: rgba(77, 191, 255, 0.05);
}

.rank-cell {
  font-weight: 600;
  color: var(--primary);
  width: 60px;
}

.rank-cell.top-3 {
  color: var(--green);
}

.item-cell {
  max-width: 200px;
}

.item-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.item-id {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.materials-cell {
  min-width: 120px;
}

.material-amount {
  font-weight: 600;
  color: var(--text);
}

.material-boxes {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.cost-column {
  color: var(--success);
  font-weight: 600;
  min-width: 120px;
}

.price-cell {
  font-family: 'SF Mono', 'Monaco', 'Cascadia Code', monospace;
  font-weight: 500;
}

/* Night Mode Toggle - matching your existing style */
#night-toggle {
  position: fixed;
  bottom: 20px;
  right: 60px;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--header);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  z-index: 1000;
  transition: background-color 0.3s, color 0.3s;
}

#night-toggle:hover {
  background-color: var(--primary);
  color: white;
}

/* Corner Image - matching your existing style */
#cornerImage {
  position: fixed;
  bottom: 80px;
  left: 44px;
  width: 115px;
  height: auto;
  z-index: 1000;
}

/* Mobile spacing fix */
@media (max-width: 800px) and (orientation: portrait),
       (max-height: 550px) and (orientation: landscape) {
  .mobile-spacer {
    height: 225px;
  }
}

/* Hide Icon on mobile */
@media (max-width: 768px) {
  #cornerImage {
    display: none;
  }
}

/* Responsive */
@media (max-width: 768px) {
  body {
    padding: 1rem;
  }
  
  .container {
    padding: 0;
  }
  
  .header {
    flex-direction: column;
    gap: 1.5rem;
    text-align: center;
  }
  
  .update-section {
    text-align: center;
  }
  
  .header-content .title {
    font-size: 2rem;
    justify-content: center;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .table-header {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .price-table th,
  .price-table td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }
}