/* =============================================
   RuamCalc – Shared Stylesheet (Mobile-First + SEO)
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700;800&family=Inter:wght@400;600;700;800&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --primary:      #6C63FF;
  --primary-dark: #5A52D9;
  --secondary:    #00D4AA;
  --accent:       #FF6584;
  --bg:           #0F0F1A;
  --surface:      #1A1A2E;
  --surface2:     #16213E;
  --border:       rgba(108,99,255,.25);
  --text:         #E8E8F0;
  --text-muted:   #8888A8;
  --radius:       16px;
  --radius-sm:    10px;
  --shadow:       0 8px 32px rgba(0,0,0,.45);
  --transition:   .25s cubic-bezier(.4,0,.2,1);
  --nav-h:        64px;
}

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

html { scroll-behavior: smooth; font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Sarabun', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.3; }
h1 { font-size: clamp(1.6rem, 5vw, 2.8rem); }
h2 { font-size: clamp(1.25rem, 3.5vw, 2rem); }
h3 { font-size: clamp(1rem, 2.5vw, 1.35rem); }
p  { color: var(--text-muted); }
a  { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--secondary); }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.section { padding: 4rem 0; }

/* ---------- Gradient Text ---------- */
.gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* =============================================
   NAVBAR
   ============================================= */
.navbar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(15,15,26,.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  height: var(--nav-h);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  gap: 1rem;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.nav-logo .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* Desktop nav links */
.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.nav-links a {
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color var(--transition);
  padding: .3rem 0;
  border-bottom: 2px solid transparent;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

/* ---------- Hamburger Button ---------- */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: border-color var(--transition);
}

.hamburger:hover { border-color: var(--primary); }

.hamburger span {
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition);
  display: block;
}

.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; width: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- Mobile Nav Drawer ---------- */
.mobile-nav {
  position: fixed;
  top: var(--nav-h);
  left: 0;
  right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem 1.5rem;
  display: none;
  flex-direction: column;
  gap: .25rem;
  z-index: 199;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: slideDown .2s ease;
}

.mobile-nav.open { display: flex; }

.mobile-nav a {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 500;
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  text-decoration: none;
  display: block;
}

.mobile-nav a:hover,
.mobile-nav a.active {
  background: rgba(108,99,255,.12);
  color: var(--primary);
}

/* =============================================
   HERO
   ============================================= */
.hero {
  padding: 5rem 0 3rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  height: 100vw;
  max-width: 800px;
  background: radial-gradient(ellipse at center,
    rgba(108,99,255,.18) 0%,
    transparent 70%);
  pointer-events: none;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: rgba(108,99,255,.15);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: .4rem 1.1rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 1.5rem;
  letter-spacing: .04em;
}

.hero h1 { margin-bottom: 1.25rem; }

.hero p.subtitle {
  max-width: 560px;
  margin: 0 auto 2.5rem;
  font-size: 1.05rem;
  color: var(--text-muted);
}

/* =============================================
   CALCULATOR GRID
   ============================================= */
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1.25rem;
  padding: 1rem 0;
}

.calc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
  gap: .65rem;
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.calc-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(108,99,255,.06), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.calc-card:hover,
.calc-card:focus-visible { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--primary); outline: none; }
.calc-card:hover::before,
.calc-card:focus-visible::before { opacity: 1; }

.card-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
}

.card-title  { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.card-desc   { font-size: .87rem; color: var(--text-muted); line-height: 1.6; }
.card-arrow  {
  margin-top: auto;
  padding-top: .85rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: .3rem;
  transition: gap var(--transition);
}
.calc-card:hover .card-arrow { gap: .6rem; }

/* Icon colours */
.icon-purple { background: rgba(108,99,255,.18); }
.icon-green  { background: rgba(0,212,170,.18);  }
.icon-red    { background: rgba(255,101,132,.18); }
.icon-blue   { background: rgba(59,130,246,.18);  }
.icon-yellow { background: rgba(245,158,11,.18);  }
.icon-pink   { background: rgba(236,72,153,.18);  }

/* =============================================
   CALCULATOR PAGE LAYOUT
   ============================================= */
.calc-page { padding: 2.5rem 0 5rem; }

.calc-page-header { text-align: center; margin-bottom: 2rem; }
.calc-page-header h1 { margin-bottom: .6rem; }
.calc-page-header p  { max-width: 560px; margin: 0 auto; font-size: 1rem; }

/* Two-column on desktop, single on mobile */
.calc-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ---------- Calculator Box ---------- */
.calc-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.calc-box h2 {
  font-size: 1.1rem;
  margin-bottom: 1.35rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
}

/* ---------- Form Elements ---------- */
.form-group { margin-bottom: 1.1rem; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
  letter-spacing: .02em;
  text-transform: uppercase;
}

input[type="number"],
input[type="text"],
input[type="email"],
input[type="date"],
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  min-height: 48px;           /* touch target */
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,.2);
}

/* iOS date fix */
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.6); cursor: pointer; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .8rem 1.6rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 48px;            /* touch target */
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  width: 100%;
  padding: .9rem;
  box-shadow: 0 4px 14px rgba(108,99,255,.4);
}

.btn-primary:hover,
.btn-primary:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(108,99,255,.5);
  outline: none;
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 100%;
  margin-top: .65rem;
}

.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Result Box ---------- */
.result-box {
  background: linear-gradient(135deg, rgba(108,99,255,.12), rgba(0,212,170,.08));
  border: 1px solid rgba(108,99,255,.3);
  border-radius: var(--radius-sm);
  padding: 1.35rem;
  margin-top: 1.35rem;
  display: none;
  animation: fadeIn .35s ease;
}

.result-box.show { display: block; }

.result-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: .25rem;
}

.result-value {
  font-size: 1.9rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  word-break: break-all;
}

.result-breakdown {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  font-size: .87rem;
}

.breakdown-row span:first-child { color: var(--text-muted); }
.breakdown-row span:last-child  { font-weight: 600; color: var(--text); text-align: right; }

/* ---------- Info Panel ---------- */
.info-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.info-box h2 { font-size: .98rem; color: var(--text); margin-bottom: .7rem; }

.info-box p, .info-box li {
  font-size: .88rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.info-box ul, .info-box ol {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.formula-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  font-family: 'Courier New', monospace;
  font-size: .85rem;
  color: var(--secondary);
  margin: .65rem 0;
  word-break: break-word;
  overflow-x: auto;
}

/* =============================================
   OTHER CALCULATORS SECTION
   ============================================= */
.other-calcs { padding: 3rem 0; }
.other-calcs h2 { text-align: center; margin-bottom: 1.5rem; }

/* =============================================
   STATS BAR
   ============================================= */
.stats-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 0;
}

.stats-bar .container {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 1.25rem;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label { font-size: .78rem; color: var(--text-muted); }

/* =============================================
   FEATURES GRID
   ============================================= */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}

.feature-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  transition: border-color var(--transition);
}

.feature-item:hover { border-color: var(--primary); }
.feature-icon { font-size: 1.65rem; margin-bottom: .65rem; }
.feature-item h3 { font-size: .9rem; color: var(--text); margin-bottom: .35rem; }
.feature-item p  { font-size: .83rem; }

/* =============================================
   FOOTER
   ============================================= */
.footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 2rem 0;
}

.footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-links {
  display: flex;
  gap: 1.25rem;
  list-style: none;
  flex-wrap: wrap;
}

.footer-links a { font-size: .83rem; color: var(--text-muted); }
.footer-links a:hover { color: var(--primary); }
.footer-copy { font-size: .78rem; color: var(--text-muted); }

/* =============================================
   BREADCRUMB
   ============================================= */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  color: var(--text-muted);
  padding: .75rem 0;
  flex-wrap: wrap;
}

.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .current { color: var(--primary); font-weight: 500; }

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate-in { animation: fadeIn .5s ease both; }

/* =============================================
   RESPONSIVE – TABLET  ≤ 900px
   ============================================= */
@media (max-width: 900px) {
  .calc-wrapper { grid-template-columns: 1fr; }

  .info-panel { order: 2; }
}

/* =============================================
   RESPONSIVE – MOBILE  ≤ 640px
   ============================================= */
@media (max-width: 640px) {
  /* Show hamburger, hide desktop links */
  .hamburger  { display: flex; }
  .nav-links  { display: none; }

  /* Hero */
  .hero { padding: 3.5rem 0 2rem; }
  .hero p.subtitle { font-size: .95rem; }

  /* Calculator grid = 1 column */
  .calc-grid { grid-template-columns: 1fr; }

  /* Calc box */
  .calc-box { padding: 1.25rem; }

  /* Feature grid = 1 column */
  .feature-grid { grid-template-columns: 1fr 1fr; }

  /* Stats bar */
  .stats-bar .container { gap: 1rem; }
  .stat-value { font-size: 1.25rem; }

  /* Result value smaller font */
  .result-value { font-size: 1.5rem; }

  /* Footer stacked */
  .footer .container { flex-direction: column; align-items: flex-start; }
  .footer-links { gap: 1rem; }

  /* Calc page spacing */
  .calc-page { padding: 1.5rem 0 4rem; }
  .other-calcs { padding: 2rem 0; }
  .section { padding: 3rem 0; }
}

/* =============================================
   RESPONSIVE – VERY SMALL  ≤ 380px
   ============================================= */
@media (max-width: 380px) {
  .feature-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.45rem; }
}

/* =============================================
   ACCESSIBILITY
   ============================================= */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

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

/* Dark scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
