:root {
  --bg: #f5f2eb;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #fffdf9;
  --text: #161512;
  --muted: #777268;
  --line: rgba(22, 21, 18, 0.09);
  --gold: #b98a29;
  --gold-dark: #805d16;
  --gold-soft: #f1e7cc;
  --success: #237452;
  --danger: #a04635;
  --shadow: 0 22px 60px rgba(38, 32, 21, 0.075);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 6%, rgba(185, 138, 41, 0.10), transparent 27rem),
    radial-gradient(circle at 92% 18%, rgba(255, 255, 255, 0.95), transparent 32rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 36px;
}

.brand {
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--text);
  color: #f3d986;
  font-family: "Manrope", sans-serif;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.brand strong,
.brand small { display: block; }
.brand strong { font-family: "Manrope", sans-serif; font-size: 17px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }

.market-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.58);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(12px);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bcae91;
  box-shadow: 0 0 0 4px rgba(188,174,145,.14);
}

.market-pill[data-state="live"] .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(35,116,82,.12); }
.market-pill[data-state="error"] .status-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(160,70,53,.12); }

.hero-grid {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  gap: 18px;
}

.hero-card,
.control-card,
.result-card,
.table-section,
.market-reference,
.manual-card {
  border: 1px solid rgba(255,255,255,.75);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero-card {
  min-height: 310px;
  padding: 34px;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(140deg, rgba(255,255,255,.92), rgba(248,241,222,.83)),
    var(--surface);
  display: flex;
  flex-direction: column;
}

.eyebrow {
  color: var(--gold-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.price-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 7px;
  margin: 19px 0 14px;
}

.price-line .currency {
  font-family: "Manrope", sans-serif;
  font-size: clamp(24px, 3vw, 38px);
  font-weight: 600;
  color: var(--gold-dark);
}

.price-line strong {
  font-family: "Manrope", sans-serif;
  font-size: clamp(48px, 7.4vw, 82px);
  line-height: 1;
  letter-spacing: -.065em;
  font-weight: 600;
}

.price-line .unit { color: var(--muted); font-size: 13px; }

.price-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  border: 0;
  padding: 7px 0;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.text-button:hover { color: var(--gold-dark); }
.text-button.loading .refresh-icon { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.formula-chip {
  margin-top: auto;
  padding-top: 26px;
}

.formula-chip span {
  display: inline-flex;
  max-width: 100%;
  border: 1px solid rgba(185,138,41,.14);
  background: rgba(255,255,255,.55);
  border-radius: 999px;
  padding: 9px 12px;
  color: #625b4e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.control-card {
  padding: 34px;
  border-radius: var(--radius-xl);
  background: rgba(24, 23, 20, .97);
  color: #fff;
}

.control-card .eyebrow { color: #d4b96d; }
.control-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.control-heading h1 {
  max-width: 360px;
  margin: 10px 0 0;
  font-family: "Manrope", sans-serif;
  font-size: clamp(26px, 3.3vw, 40px);
  line-height: 1.05;
  letter-spacing: -.04em;
  font-weight: 600;
}

.percent-badge {
  min-width: 78px;
  height: 78px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #d6b858, #a87a1c);
  color: #17140d;
  font-family: "Manrope", sans-serif;
  font-size: 20px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
}

.percent-control { margin-top: 54px; display: grid; grid-template-columns: 1fr 105px; align-items: center; gap: 18px; }
input[type="range"] { width: 100%; accent-color: #d2b35c; }

.input-wrap {
  height: 50px;
  display: flex;
  align-items: center;
  border-radius: 14px;
  background: rgba(255,255,255,.085);
  border: 1px solid rgba(255,255,255,.10);
  overflow: hidden;
}

.input-wrap input {
  min-width: 0;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  padding: 0 5px 0 14px;
  background: transparent;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}
.input-wrap span { padding-right: 13px; color: #bdb8ad; }

.hint { margin: 28px 0 0; color: #a8a39a; line-height: 1.55; font-size: 12px; }

.result-card {
  margin-top: 18px;
  padding: 27px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, #f0e0b8, #f8f1df);
  box-shadow: 0 18px 48px rgba(91,67,20,.09);
}

.result-card h2 { margin: 7px 0 0; font-family: "Manrope", sans-serif; font-size: clamp(27px, 4vw, 44px); letter-spacing: -.045em; }
.result-card h2 small { color: #6f644f; font-size: 12px; letter-spacing: 0; font-weight: 500; }
.result-context { text-align: right; }
.result-context span, .result-context strong { display: block; }
.result-context span { color: #786a4e; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.result-context strong { margin-top: 5px; font-family: "Manrope", sans-serif; font-size: 16px; }

.table-section {
  margin-top: 18px;
  padding: 32px;
  border-radius: var(--radius-xl);
  background: var(--surface);
}

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.section-heading h2 { margin: 7px 0 0; font-family: "Manrope", sans-serif; font-size: 28px; letter-spacing: -.04em; }
.section-heading p { max-width: 330px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: right; }

.karat-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 24px;
}

.karat-card {
  min-width: 0;
  padding: 16px 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.57);
  text-align: center;
  transition: .2s ease;
}
.karat-card:hover { transform: translateY(-2px); border-color: rgba(185,138,41,.28); }
.karat-card strong { display: block; font-family: "Manrope", sans-serif; font-size: 20px; }
.karat-card span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.karat-card b { display: block; margin-top: 12px; color: var(--gold-dark); font-family: "Manrope", sans-serif; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.karat-card.featured { background: #1b1a17; border-color: #1b1a17; color: #fff; }
.karat-card.featured span { color: #aaa69d; }
.karat-card.featured b { color: #efd37b; }

.desktop-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
td { font-size: 13px; }
td:last-child, th:last-child { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
.karat-label { font-weight: 700; }
.price-cell { font-family: "Manrope", sans-serif; font-weight: 700; }

.market-reference {
  margin-top: 18px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.58);
}
.market-reference summary {
  list-style: none;
  cursor: pointer;
  padding: 22px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.market-reference summary::-webkit-details-marker { display: none; }
.market-reference summary strong { display: block; margin-top: 5px; font-family: "Manrope", sans-serif; font-size: 15px; }
.chevron { font-size: 21px; transition: transform .2s ease; }
.market-reference[open] .chevron { transform: rotate(180deg); }
.tradingview-wrap { padding: 0 18px 18px; }
.tradingview-wrap tv-single-ticker { display: block; width: 100%; min-height: 100px; }
.tv-placeholder { padding: 24px; border-radius: 15px; background: rgba(0,0,0,.035); color: var(--muted); font-size: 12px; }

.manual-card {
  margin-top: 18px;
  padding: 26px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-radius: var(--radius-lg);
  background: #fff3e9;
}
.manual-card h3 { margin: 6px 0 5px; font-family: "Manrope", sans-serif; font-size: 19px; }
.manual-card p { margin: 0; color: var(--muted); font-size: 12px; }
.manual-input { min-width: 190px; }
.manual-input span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.manual-input input { width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 13px; background: white; padding: 0 13px; outline: none; font-weight: 700; }
.manual-input input:focus { border-color: rgba(185,138,41,.65); box-shadow: 0 0 0 4px rgba(185,138,41,.08); }

footer {
  padding: 30px 4px 4px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}
footer p { margin: 0; max-width: 610px; }
footer span { text-align: right; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 15px;
  border-radius: 999px;
  background: #1a1916;
  color: white;
  box-shadow: 0 15px 40px rgba(0,0,0,.18);
  font-size: 12px;
  transition: .22s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; }
  .karat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 640px) {
  .page-shell { width: min(100% - 20px, 1180px); padding-top: 13px; }
  .topbar { margin-bottom: 20px; }
  .brand-mark { width: 41px; height: 41px; border-radius: 13px; }
  .market-pill { max-width: 48%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hero-card, .control-card { padding: 25px 22px; border-radius: 24px; }
  .hero-card { min-height: 275px; }
  .price-meta { align-items: flex-start; }
  .price-meta > span { max-width: 65%; }
  .control-heading h1 { font-size: 30px; }
  .percent-badge { min-width: 67px; height: 67px; border-radius: 18px; }
  .percent-control { margin-top: 38px; grid-template-columns: 1fr 95px; }
  .result-card { padding: 22px; align-items: flex-start; flex-direction: column; }
  .result-context { text-align: left; }
  .table-section { padding: 24px 18px; border-radius: 24px; }
  .section-heading { align-items: flex-start; flex-direction: column; margin-bottom: 20px; }
  .section-heading p { text-align: left; }
  .karat-grid { grid-template-columns: repeat(2, 1fr); }
  .desktop-table-wrap { display: none; }
  .manual-card { align-items: stretch; flex-direction: column; }
  footer { flex-direction: column; }
  footer span { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; }
}
