/* ═══════════════════════════════════════════
   FIRST DANCE — Design System v2
   Black Russian · Snow · Cinnabar
═══════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;1,6..72,400&family=IBM+Plex+Mono:wght@400;500;600;700&family=Noto+Sans+Thai:wght@400;500;600;700&display=swap');

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: auto; }

/* ── TOKENS ── */
:root {
  --black:   #0e0e0e;
  --snow:    #fdfdf9;
  --red:     #eb5939;
  --red-dim: rgba(235,89,57,.12);
  --red-mid: rgba(235,89,57,.25);

  --bg:      var(--snow);
  --fg:      var(--black);
  --border:  rgba(14,14,14,.15); /* Slightly darker for better visibility */
  --border2: rgba(14,14,14,.08);
  --surface: #f5f5f0;
  --muted:   rgba(14,14,14,.7); /* Darker muted for readability */
  --dim:     rgba(14,14,14,.35);

  /* Font roles: */
  --f-display:  'Inter', 'Noto Sans Thai', sans-serif;
  --f-thai:     'Noto Sans Thai', 'Inter', sans-serif;
  --f-editorial:'Newsreader', 'Noto Sans Thai', serif;
  --f-mono:     'IBM Plex Mono', 'Noto Sans Thai', monospace;

  --radius-sm: 6px;
  --radius:    12px;
  --radius-lg: 20px;
  --ease:      cubic-bezier(.16,1,.3,1);
}

/* ── BASE ── */
body {
  font-family: var(--f-thai);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  padding: 0 24px 80px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  font-size: 16px;
  line-height: 1.5;
}
::selection { background: var(--red); color: var(--snow); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--dim); border-radius: 2px; }

/* ── NAV ── */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 18px;
  max-width: 1100px; margin: 0 auto;
  border-bottom: 1px solid var(--border);
}
.nav-brand { display: flex; align-items: center; gap: 10px; }
.nav-mark {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--black);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.nav-name {
  font-family: var(--f-display);
  font-size: 14px; font-weight: 700;
  color: var(--black);
}
.nav-sub {
  font-family: var(--f-mono);
  font-size: 11px; color: var(--muted);
  margin-top: 1px;
}
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  font-size: 14px; font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid transparent;
  transition: all .2s var(--ease);
}
.nav-links a:hover { color: var(--fg); border-color: var(--border); }
.nav-links a.active {
  background: var(--black); color: var(--snow);
  border-color: var(--black);
}
.nav-links a.cta {
  background: var(--red); color: var(--snow) !important;
  border-color: var(--red) !important;
}

/* ── WRAP ── */
.wrap { max-width: 1100px; margin: 0 auto; }

/* ── HERO ── */
.hero { padding: 56px 0 44px; }
.hero-eyebrow {
  font-family: var(--f-mono);
  font-size: 13px; font-weight: 600;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 16px;
}
.hero h1 {
  font-family: var(--f-editorial);
  font-size: clamp(40px, 5.5vw, 72px);
  font-weight: 400; /* Thicker */
  line-height: 1.05;
  margin-bottom: 18px;
  color: var(--black);
}
.hero h1 em {
  font-style: italic;
  color: var(--red);
}
.hero-desc {
  font-family: var(--f-thai);
  font-size: 18px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.6;
  max-width: 480px;
  margin-bottom: 12px;
}
.hero-meta {
  font-family: var(--f-mono);
  font-size: 13px;
  color: var(--muted);
}

/* ── SECTION LABEL ── */
.section-label {
  font-family: var(--f-mono);
  font-size: 12px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 32px 0 16px;
  display: flex; align-items: center; gap: 12px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── CARD ── */
.card {
  background: var(--snow);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
}
.card-title {
  font-family: var(--f-thai);
  font-size: 20px; font-weight: 700;
  color: var(--black);
  margin-bottom: 5px;
  line-height: 1.3;
}
.card-sub {
  font-family: var(--f-thai);
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ── SETTINGS BAR ── */
.settings-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 24px;
}
.settings-bar-label {
  font-family: var(--f-mono);
  font-size: 12px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px;
}
.settings-bar-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
}
.settings-grid .field label { white-space: nowrap; font-size: 11px; letter-spacing: 0; }

/* ── FORM FIELD ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label {
  font-family: var(--f-mono);
  font-size: 12px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}
.field input, .field select {
  font-family: var(--f-mono);
  font-size: 15px; font-weight: 600;
  color: var(--black);
  background: var(--snow);
  border: 1.5px solid rgba(14,14,14,.25); /* More visible border */
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.field select { cursor: pointer; font-family: var(--f-thai); }
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-dim);
}
.field.accent label { color: var(--red); }
.field.accent input { border-color: var(--red-mid); color: var(--red); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%230e0e0e' opacity='.6' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }

/* ── RESULTS ── */
.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 16px;
}
.res-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border2);
  gap: 10px;
}
.res-row:last-child { border-bottom: none; }
.res-label {
  font-family: var(--f-thai);
  font-size: 15px; font-weight: 500;
  color: var(--muted);
  flex-shrink: 0;
  line-height: 1.4;
}
.res-val {
  font-family: var(--f-mono);
  font-size: 16px; font-weight: 700;
  color: var(--black);
  text-align: right;
  white-space: nowrap;
}
.res-val.vr  { color: var(--red); }
.res-row.hi  { background: rgba(235,89,57,.08); }
.res-row.hi .res-label { font-weight: 700; color: var(--black); }
.res-divider { height: 1px; background: var(--border); }

/* ── BIG NUMBER ── */
.big-num {
  font-family: var(--f-editorial);
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 500;
  line-height: 1;
  color: var(--black);
}
.big-num.red { color: var(--red); }

/* ── STAT BOXES ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 16px; }
.stat-box { background: var(--snow); padding: 18px 14px; text-align: center; }
.stat-val { font-family: var(--f-mono); font-size: 22px; font-weight: 700; color: var(--black); margin-bottom: 6px; }
.stat-val.red { color: var(--red); }
.stat-lbl { font-family: var(--f-mono); font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; line-height: 1.4; }

/* ── TABLE ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  font-family: var(--f-mono);
  padding: 12px 14px;
  text-align: left;
  color: var(--muted);
  font-size: 12px; font-weight: 700;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border2);
  font-size: 14px;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }
.mono { font-family: var(--f-mono); font-weight: 600; }
.mono.red { color: var(--red); }

/* ── TAGS ── */
.tag {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 4px;
  font-family: var(--f-mono);
  font-size: 12px; font-weight: 600;
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--border);
}
.tag.red { background: var(--red-dim); color: var(--red); border-color: var(--red-mid); }

/* ── FORMULA ── */
.formula-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.f-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.f-step { font-family: var(--f-mono); font-size: 12px; font-weight: 700; color: var(--red); text-transform: uppercase; margin-bottom: 8px; }
.f-title { font-family: var(--f-editorial); font-size: 18px; font-weight: 500; margin-bottom: 8px; color: var(--black); line-height: 1.3; }
.f-code { font-family: var(--f-mono); font-size: 13px; color: var(--black); background: var(--snow); border: 1px solid var(--border); border-radius: 4px; padding: 10px; line-height: 1.7; margin-bottom: 8px; word-break: break-all; }
.f-desc { font-family: var(--f-thai); font-size: 14px; color: var(--muted); line-height: 1.65; }

/* ── BUTTON ── */
.btn {
  font-family: var(--f-display);
  font-size: 14px; font-weight: 700;
  padding: 10px 20px;
  border-radius: 99px;
  border: 1.5px solid transparent;
  transition: all .2s var(--ease);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-solid { background: var(--black); color: var(--snow); border-color: var(--black); }
.btn-solid:hover { background: var(--red); border-color: var(--red); }
.btn-outline { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-outline:hover { border-color: var(--black); }
.btn-red { background: var(--red); color: var(--snow); border-color: var(--red); }
.btn-red:hover { opacity: .9; }

/* ── TOGGLE TABS ── */
.tab-bar {
  display: flex; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px;
  width: fit-content;
  margin-bottom: 20px;
}
.tab-btn {
  font-family: var(--f-display);
  font-size: 14px; font-weight: 600;
  padding: 8px 20px;
  border-radius: 99px;
  border: none; background: transparent;
  color: var(--muted);
  transition: all .2s var(--ease);
}
.tab-btn.active { background: var(--black); color: var(--snow); }

/* ── CONVERTER ── */
.converter-box {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}
.conv-side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.conv-label {
  font-family: var(--f-mono);
  font-size: 12px; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.conv-mid {
  display: flex; align-items: center; justify-content: center;
  padding-top: 40px;
}
.conv-arrow {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--black);
  color: var(--snow);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  border: none;
  transition: background .2s;
}
.conv-arrow:hover { background: var(--red); }
.conv-result {
  font-family: var(--f-editorial);
  font-size: 32px; font-weight: 500;
  color: var(--black);
  line-height: 1;
  margin-top: 12px;
  margin-bottom: 6px;
}
.conv-result-label {
  font-family: var(--f-mono);
  font-size: 13px; color: var(--muted);
}
@media (max-width: 640px) {
  .converter-box { grid-template-columns: 1fr; }
  .conv-mid { padding-top: 0; transform: rotate(90deg); }
}

/* ── 2 COL ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 780px) { .two-col { grid-template-columns: 1fr; } }

/* ── FOOTER ── */
.footer {
  font-family: var(--f-mono);
  font-size: 12px; color: var(--dim);
  text-align: center;
  padding: 32px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer a { color: var(--muted); text-decoration: none; font-weight: 600; }
.footer a:hover { color: var(--red); }
