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

:root {
  --bg: #0a0a0b;
  --surface: #131316;
  --surface-2: #1a1a1f;
  --surface-3: #222228;
  --border: #2a2a32;
  --border-hover: #3a3a44;
  --text: #ededef;
  --text-secondary: #8e8e96;
  --text-muted: #5a5a64;
  --accent: #c084fc;
  --accent-dim: #a855f7;
  --accent-glow: rgba(168, 85, 247, 0.15);
  --green: #4ade80;
  --green-dim: rgba(74, 222, 128, 0.1);
  --red: #f87171;
  --blue: #60a5fa;
  --orange: #fb923c;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 80px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.header {
  text-align: center;
  margin-bottom: 48px;
}

.header .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-glow);
  border: 1px solid rgba(168, 85, 247, 0.25);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 100px;
  margin-bottom: 16px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header h1 {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header p {
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: 8px;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  padding: 32px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.live-dot.active {
  background: var(--green);
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
  animation: pulse-dot 2s ease-in-out infinite;
}

.live-dot.fetching {
  background: var(--orange);
  animation: pulse-dot 0.8s ease-in-out infinite;
}

.live-dot.error {
  background: var(--red);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.live-age {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0;
  text-transform: none;
  margin-left: auto;
}

/* ── Inputs ── */
.field {
  margin-bottom: 16px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

.field input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Button ── */
.btn {
  width: 100%;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-dim), #7c3aed);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  margin-top: 8px;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Status ── */
.status {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 12px;
  min-height: 20px;
}

.status.error {
  color: var(--red);
}

.status .spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ── Results ── */
.results {
  width: 100%;
  max-width: 520px;
  display: none;
}

.results.visible {
  display: block;
  animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.results .card {
  margin-bottom: 16px;
}

/* ── Market Prices ── */
.prices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.price-item {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}

.price-item .item-icon {
  font-size: 22px;
  margin-bottom: 6px;
}

.price-item .item-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.price-item .item-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.price-item .item-source {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Summary row ── */
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.summary-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.summary-row:first-child {
  padding-top: 0;
}

.summary-label {
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-label .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.summary-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Profit highlight ── */
.profit-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
  width: 100%;
  max-width: 520px;
}

.profit-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.profit-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.profit-amount {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
}

.profit-amount.positive {
  color: var(--green);
}

.profit-amount.negative {
  color: var(--red);
}

.profit-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.profit-sub span {
  font-weight: 600;
}

.profit-sub .positive {
  color: var(--green);
}

.profit-sub .negative {
  color: var(--red);
}

/* ── Attribution ── */
.attribution {
  margin-top: 40px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.attribution a {
  color: var(--accent);
  text-decoration: none;
}

.attribution a:hover {
  text-decoration: underline;
}

.kofi-btn {
  display: inline-flex;
  align-items: center;
  background: #c0392b;
  color: #fff !important;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 100px;
  text-decoration: none !important;
  transition: opacity 0.2s;
  vertical-align: middle;
}

.kofi-btn:hover {
  opacity: 0.85;
  text-decoration: none !important;
}

/* ── Copy buttons ── */
.summary-value-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-btn {
  background: none;
  border: none;
  padding: 0 0 0 6px;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.copy-btn:hover {
  opacity: 1;
}

.copy-btn img {
  width: 15px;
  height: 15px;
  display: block;
  filter: invert(1);
}

.copy-btn.copied img {
  filter: invert(74%) sepia(60%) saturate(400%) hue-rotate(90deg) brightness(110%);
}

.copy-check {
  font-size: 13px;
  font-weight: 700;
  color: var(--green);
  line-height: 1;
}

/* ── Override toggle ── */
.override-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  cursor: pointer;
  user-select: none;
}

.override-toggle span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.toggle {
  width: 36px;
  height: 20px;
  border-radius: 100px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}

.toggle.on {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

.toggle.on::after {
  transform: translateX(16px);
  background: #fff;
}

.override-fields {
  display: none;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.override-fields.visible {
  display: block;
}

.field-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 4px;
}

/* ── Progress bar ── */
.fetch-progress {
  width: 100%;
  max-width: 520px;
  height: 3px;
  background: var(--surface-3);
  border-radius: 100px;
  margin-bottom: 12px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}

.fetch-progress.visible {
  opacity: 1;
}

.fetch-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 100px;
  transition: width 0.4s ease;
}

/* ── Refresh button ── */
.refresh-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
}

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

.refresh-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.refresh-icon {
  display: inline-block;
  transition: transform 0.5s;
}

.refresh-icon.spinning {
  animation: spin 0.8s linear infinite;
}

/* ── Responsive ── */
@media (max-width: 560px) {
  body {
    padding: 20px 12px 60px;
  }
  .card {
    padding: 20px 16px;
  }
  .header {
    margin-bottom: 28px;
  }
  .header h1 {
    font-size: 26px;
  }
  .header p {
    font-size: 14px;
  }
  .prices-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }
  .price-item {
    padding: 10px 6px;
  }
  .price-item .item-icon {
    font-size: 18px;
  }
  .price-item .item-price {
    font-size: 14px;
  }
  .price-item .item-name {
    font-size: 10px;
  }
  .profit-section {
    padding: 20px 16px;
  }
  .profit-amount {
    font-size: 32px;
  }
  .summary-value {
    font-size: 14px;
  }
}