*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gold-0: #fffbf0;
  --gold-1: #fef3c7;
  --gold-2: #fde68a;
  --gold-3: #f59e0b;
  --gold-4: #d97706;
  --gold-5: #92400e;
  --ink: #1a1006;
  --ink-muted: #6b5a3e;
  --surface: #fffdf7;
  --surface-2: #fff8e7;
  --border: #e8d5a3;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(92,60,10,.10);
  --shadow-lg: 0 12px 48px rgba(92,60,10,.16);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--gold-0);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── NOISE TEXTURE OVERLAY ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ── DECORATIVE HEADER ── */
header {
  position: relative;
  text-align: center;
  padding: 3.5rem 1.5rem 2rem;
  overflow: hidden;
}

header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 80px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-3), transparent);
}

.site-badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-family: 'DM Mono', monospace;
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--gold-4);
  background: var(--gold-1);
  border: 1px solid var(--border);
  padding: .3rem .8rem;
  border-radius: 100px;
  margin-bottom: 1.2rem;
}

.site-badge svg { width: 12px; height: 12px; }

.hero-illustration {
  width: min(320px, 72vw);
  height: auto;
  margin: 0 auto 1rem;
  display: block;
  filter: drop-shadow(0 10px 16px rgba(146, 64, 14, 0.18));
}

h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -.02em;
  color: var(--ink);
  margin-bottom: .75rem;
}

h1 em {
  font-style: italic;
  color: var(--gold-4);
}

header p {
  max-width: 520px;
  margin: 0 auto;
  color: var(--ink-muted);
  font-size: .95rem;
  line-height: 1.7;
}

/* ── LIVE PRICE TICKER ── */
.ticker-bar {
  background: var(--ink);
  color: var(--gold-2);
  font-family: 'DM Mono', monospace;
  font-size: .78rem;
  padding: .55rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
  letter-spacing: .04em;
}

.ticker-item { display: flex; align-items: center; gap: .5rem; }

.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #22c55e;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.8); }
}

.price-up { color: #86efac; }
.price-down { color: #fca5a5; }
.price-neutral { color: var(--gold-2); }

/* ── MAIN LAYOUT ── */
main {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  display: grid;
  gap: 1.5rem;
}

/* ── CARD ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  animation: slideUp .5s cubic-bezier(.16,1,.3,1) both;
}

.card:nth-child(2) { animation-delay: .08s; }
.card:nth-child(3) { animation-delay: .16s; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-corner {
  position: absolute;
  top: -20px; right: -20px;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-1) 0%, transparent 70%);
  pointer-events: none;
}

.card-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.card-title svg {
  width: 18px; height: 18px;
  color: var(--gold-3);
  flex-shrink: 0;
}

/* ── FORM GRID ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
}

.field { display: flex; flex-direction: column; gap: .45rem; }

label {
  font-size: .78rem;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

input, select {
  font-family: 'DM Mono', monospace;
  font-size: 1rem;
  padding: .7rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus {
  border-color: var(--gold-3);
  box-shadow: 0 0 0 3px rgba(245,158,11,.15);
}

input.error { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.12); }

.error-msg {
  font-size: .75rem;
  color: #ef4444;
  display: none;
}

.error-msg.visible { display: block; }

/* Karat buttons */
.karat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .5rem;
  margin-bottom: 1rem;
}

.karat-btn {
  font-family: 'DM Mono', monospace;
  font-size: .82rem;
  font-weight: 500;
  padding: .55rem .2rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-muted);
  cursor: pointer;
  transition: all .18s;
  text-align: center;
}

.karat-btn:hover {
  border-color: var(--gold-3);
  color: var(--gold-4);
  background: var(--gold-1);
}

.karat-btn.active {
  background: var(--gold-3);
  border-color: var(--gold-3);
  color: white;
  box-shadow: 0 2px 8px rgba(245,158,11,.35);
}

.purity-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .75rem;
}

.purity-row label { white-space: nowrap; margin-bottom: 0; }

.purity-row input { max-width: 110px; }

.purity-row span {
  font-family: 'DM Mono', monospace;
  font-size: .9rem;
  color: var(--ink-muted);
}

/* ── CALCULATE BTN ── */
.calc-btn {
  width: 100%;
  padding: 1rem;
  margin-top: 1.75rem;
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .01em;
  color: white;
  background: linear-gradient(135deg, var(--gold-3) 0%, var(--gold-4) 100%);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s, opacity .18s;
  box-shadow: 0 4px 20px rgba(245,158,11,.4);
}

.calc-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(245,158,11,.5);
}

.calc-btn:active { transform: translateY(0); }

/* ── RESULT CARD ── */
.result-card {
  display: none;
  background: linear-gradient(135deg, var(--ink) 0%, #2d1a06 100%);
  border: 1px solid #3d2a0a;
  border-radius: var(--radius);
  padding: 2rem;
  color: white;
  animation: resultPop .5s cubic-bezier(.16,1,.3,1) both;
}

.result-card.visible { display: block; }

@keyframes resultPop {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: scale(1); }
}

.result-label {
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold-2);
  margin-bottom: .4rem;
  opacity: .8;
}

.result-value {
  font-family: 'Playfair Display', serif;
  font-size: clamp(2.4rem, 6vw, 3.5rem);
  font-weight: 900;
  line-height: 1;
  color: var(--gold-2);
  letter-spacing: -.02em;
  margin-bottom: .2rem;
}

.result-sub {
  font-family: 'DM Mono', monospace;
  font-size: .8rem;
  color: #a8895a;
}

.result-breakdown {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .75rem;
}

.breakdown-item {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 10px;
  padding: .85rem 1rem;
}

.breakdown-item .bl { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #a8895a; margin-bottom: .3rem; }
.breakdown-item .bv { font-family: 'DM Mono', monospace; font-size: .95rem; font-weight: 500; color: var(--gold-1); }

/* ── INFO SECTION ── */
.info-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.info-section h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.info-section h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 700;
  margin: 1.25rem 0 .5rem;
  color: var(--gold-4);
}

.info-section p, .info-section li {
  font-size: .9rem;
  line-height: 1.75;
  color: var(--ink-muted);
}

.info-section ul { padding-left: 1.2rem; }
.info-section li { margin-bottom: .35rem; }

.karat-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: .75rem;
  font-size: .85rem;
}

.karat-table th {
  text-align: left;
  padding: .5rem .75rem;
  background: var(--gold-1);
  color: var(--gold-5);
  font-weight: 500;
  letter-spacing: .04em;
  font-size: .75rem;
  text-transform: uppercase;
}

.karat-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink-muted);
  font-family: 'DM Mono', monospace;
}

.karat-table tr:last-child td { border-bottom: none; }

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: .8rem;
  color: var(--ink-muted);
  border-top: 1px solid var(--border);
  position: relative; z-index: 1;
}

footer a { color: var(--gold-4); text-decoration: none; }

/* ── SPINNER ── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(245,158,11,.3);
  border-top-color: var(--gold-3);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  background: var(--ink);
  color: var(--gold-1);
  font-family: 'DM Mono', monospace;
  font-size: .8rem;
  padding: .7rem 1.2rem;
  border-radius: 10px;
  border: 1px solid var(--gold-5);
  box-shadow: var(--shadow-lg);
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all .3s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ── CURRENCY SELECT ── */
.currency-strip {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.currency-strip label {
  margin-bottom: 0;
  flex-shrink: 0;
}

.currency-strip select {
  max-width: 120px;
  font-size: .85rem;
  padding: .45rem .75rem;
}

/* ── MOBILE ── */
@media (max-width: 540px) {
  .card { padding: 1.4rem; }
  .karat-grid { grid-template-columns: repeat(5, 1fr); gap: .35rem; }
  .karat-btn { font-size: .72rem; padding: .5rem .1rem; }
  .result-breakdown { grid-template-columns: 1fr 1fr; }
  header { padding: 2.5rem 1rem 1.5rem; }
  .hero-illustration { width: min(250px, 78vw); margin-bottom: .85rem; }
}

/* ── REFRESH COUNTDOWN ── */
.refresh-info {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-family: 'DM Mono', monospace;
  font-size: .72rem;
  color: #a8895a;
}

.countdown-bar-wrap {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,.08);
  border-radius: 2px;
  overflow: hidden;
  max-width: 100px;
}

.countdown-bar {
  height: 100%;
  background: var(--gold-3);
  transition: width 1s linear;
  border-radius: 2px;
}