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

/* ─── Theme ─── */
:root {
  --bg: #0c0a09;
  --bg-alt: #141110;
  --bg-card: #1a1614;
  --text: #e3d7c8;
  --text-muted: #7a6e62;
  --accent: #c9955a;
  --accent-dim: #a07850;
  --green: #7aad6a;
  --border: #2d2721;
  --text-shadow: #c9955a;
  --font-display: 'Fraunces', 'Palatino', serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --glow: rgba(201, 149, 90, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
}
[data-theme="light"] {
  --bg: #f2ece2;
  --bg-alt: #ece4d8;
  --bg-card: #faf6ef;
  --text: #1a1510;
  --text-muted: #7a6e62;
  --accent: #a67c52;
  --accent-dim: #c49a6e;
  --green: #6a9e5a;
  --border: #ddd6cc;
  --text-shadow: #8a7a6a;
  --glow: rgba(166, 124, 82, 0.06);
}

/* ─── Sacred geometry pattern ─── */
body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 20% 50%, var(--glow) 0%, transparent 50%),
    radial-gradient(circle at 80% 50%, var(--glow) 0%, transparent 50%),
    repeating-conic-gradient(var(--border) 0%, transparent 0.0001%, transparent 0.5%, var(--border) 0.5%, transparent 0.5001%);
  background-size: 100% 100%, 100% 100%, 120px 120px;
  opacity: 0.3;
}
body::after {
  content: '';
  position: fixed; inset: 0; pointer-events: none;
  z-index: 9999; opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

/* ─── Theme toggle ─── */
.theme-toggle {
  background: none; border: none;
  box-shadow: 0 0 0 1px var(--border);
  color: var(--text-muted); width: 44px; height: 44px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; transition: box-shadow 0.3s, color 0.3s, transform 0.3s;
  flex-shrink: 0; margin-left: 0.5rem; position: relative;
}
.theme-toggle::before {
  content: ''; position: absolute; inset: -4px; border-radius: 50%;
}
.theme-toggle:hover { box-shadow: 0 0 0 1px var(--accent); color: var(--accent); transform: rotate(15deg); }
.theme-toggle:active { transform: rotate(15deg) scale(0.92); }
.theme-icon::before { content: '☽'; }
[data-theme="light"] .theme-icon::before { content: '☀'; }

/* ─── Base ─── */
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body); background: var(--bg);
  color: var(--text); line-height: 1.6; min-height: 100vh;
  font-weight: 300;
}
::selection { background: var(--accent); color: var(--bg); }

/* ─── Cursor glow ─── */
.cursor-glow {
  position: fixed; width: 600px; height: 600px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201,149,90,0.05) 0%, transparent 70%);
  pointer-events: none; z-index: 1;
  transform: translate(-50%, -50%); will-change: transform;
}

/* ─── Navigation ─── */
nav {
  position: relative; z-index: 10; padding: 1rem 2rem;
  display: flex; justify-content: space-between; align-items: center;
  background: rgba(12,10,9,0.6); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
[data-theme="light"] nav { background: rgba(242,236,226,0.7); }
nav::after {
  content: '';
  position: absolute; bottom: -1px; left: 10%; right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.3;
}
.logo {
  font-family: var(--font-display); font-size: 1.15rem; font-weight: 400;
  font-variation-settings: 'SOFT' 100; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--text); text-decoration: none;
  min-height: 44px; display: inline-flex; align-items: center;
}
.logo em { font-style: italic; color: var(--accent); }
.nav-links { display: flex; gap: 1rem; list-style: none; }
.nav-links a {
  font-size: 0.65rem; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--text-muted); text-decoration: none;
  transition: color 0.3s; position: relative; padding: 0.5rem 0.6rem;
  min-height: 44px; display: flex; align-items: center;
}
.nav-links a::after {
  content: ''; position: absolute; bottom: 0; left: 50%; right: auto;
  width: 0; height: 1px;
  background: var(--accent); transition: width 0.3s var(--ease-out), left 0.3s var(--ease-out);
}
.nav-links a:hover { color: var(--text); }
.nav-links a:hover::after { width: calc(100% - 1.2rem); left: 0.6rem; }
.nav-links a:active { transform: scale(0.97); }
.nav-links a.active { color: var(--accent); }
.nav-links a.active::after { width: calc(100% - 1.2rem); left: 0.6rem; }

/* ─── Hamburger ─── */
.nav-toggle {
  display: none; background: none; border: none; cursor: pointer;
  width: 44px; height: 44px; padding: 10px; position: relative;
  flex-shrink: 0; z-index: 20;
}
.nav-toggle span {
  display: block; width: 24px; height: 2px;
  background: var(--text); margin: 5px 0;
  transition: transform 0.3s var(--ease-out), opacity 0.3s;
  border-radius: 1px;
}
.nav-open .nav-toggle span:nth-child(1) { transform: rotate(45deg) translate(5px, 6px); }
.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.nav-open .nav-toggle span:nth-child(3) { transform: rotate(-45deg) translate(5px, -6px); }

/* ─── Drawer backdrop ─── */
.nav-drawer-bg {
  display: none;
}

@media (max-width: 820px) {
  .nav-toggle { display: block; }

  .nav-drawer-bg {
    display: block; position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5); z-index: 14;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s var(--ease-out);
  }
  .nav-open .nav-drawer-bg { opacity: 1; pointer-events: auto; }

  .nav-links {
    position: fixed; top: 0; left: 0;
    width: min(300px, 80vw); height: 100vh;
    flex-direction: column; align-items: stretch;
    gap: 0; overflow-y: auto;
    background: var(--bg-alt);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
    z-index: 16;
    transform: translateX(-100%);
    transition: transform 0.35s var(--ease-out);
    margin: 0; padding: 5rem 0 2rem;
    list-style: none;
  }
  [data-theme="light"] .nav-links { background: var(--bg-alt); }
  .nav-open .nav-links { transform: translateX(0); }
  html.nav-open { overflow: hidden; }

  .nav-links a {
    font-size: 0.95rem; padding: 1rem 1.5rem; min-height: 52px;
    width: 100%; text-align: left; justify-content: flex-start;
    gap: 0.75rem;
    border-left: 2px solid transparent;
    transition: border-color 0.3s, background 0.3s, color 0.3s;
  }
  .nav-links a:hover { background: var(--bg-card); border-left-color: var(--accent-dim); }
  .nav-links a.active { border-left-color: var(--accent); }
  .nav-links a::after { display: none; }

  .nav-open .theme-toggle { z-index: 20; }
}

/* ─── Layout ─── */
main {
  position: relative; z-index: 2; max-width: 1000px; margin: 0 auto;
  padding: 3rem 2.5rem 5rem;
}

/* ─── Hero ─── */
.hero {
  margin-bottom: 3.5rem;
  position: relative;
}
.hero::after {
  content: '';
  display: block; width: 3rem; height: 1px; margin-top: 1.5rem;
  background: var(--accent); opacity: 0.4;
}
.hero-label {
  font-size: 0.6rem; letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 400; margin-bottom: 0.75rem;
}
h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 4.5vw, 3.5rem);
  font-weight: 300; font-variation-settings: 'SOFT' 70;
  line-height: 1.0; letter-spacing: -0.03em; margin-bottom: 1rem;
}
h1 em { font-style: italic; color: var(--accent); }
.hero-desc {
  font-size: 0.85rem; color: var(--text-muted);
  max-width: 55ch; font-weight: 300; line-height: 1.7;
}

/* ─── Input area ─── */
.calc-section {
  background: var(--bg-card); border: none;
  box-shadow: 0 0 0 1px var(--border), 0 4px 24px rgba(0,0,0,0.15);
  border-radius: var(--radius);
  padding: 2.5rem; margin-bottom: 2.5rem;
}
.calc-section-row {
  display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap;
}
.calc-section-row .field-group { flex: 1; min-width: 200px; }
.calc-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2rem;
}
.field-group { display: flex; flex-direction: column; gap: 0.5rem; }
.field-group.full { grid-column: 1 / -1; }
.field-group label {
  font-size: 0.65rem; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 400;
}
.input-row { display: flex; gap: 0; }
.input-row input {
  flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--border); border-right: none;
  padding: 0.85rem 1.2rem; font-family: var(--font-body); font-size: 0.9rem;
  color: var(--text); outline: none; transition: border-color 0.3s, box-shadow 0.3s;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.input-row input:only-child { border-right: 1px solid var(--border); border-radius: var(--radius-sm); }
.input-row input::placeholder { color: var(--text-muted); opacity: 0.35; }
.input-row input:focus { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.input-row button {
  background: var(--accent); border: 1px solid var(--accent);
  padding: 0.85rem 1.4rem; cursor: pointer; color: var(--bg); font-size: 1rem;
  transition: background 0.3s; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.input-row button:hover { background: var(--accent-dim); }
.input-row button:active { transform: scale(0.97); }
.input-row button svg { width: 18px; height: 18px; }
.input-row select {
  flex: 1; min-width: 0;
  background: var(--bg); border: 1px solid var(--border);
  padding: 0.85rem 1.2rem;
  font-family: var(--font-body); font-size: 0.9rem;
  color: var(--text); outline: none;
  transition: border-color 0.3s; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.input-row select:only-child { border-radius: var(--radius-sm); }
.input-row select option { background: var(--bg-card); color: var(--text); }

/* ─── Buttons ─── */
.btn-sm {
  background: transparent; border: none;
  box-shadow: 0 0 0 1px var(--border);
  color: var(--text-muted); font-family: var(--font-body);
  font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 0.75rem 1.5rem; cursor: pointer; min-height: 44px;
  transition: border-color 0.3s, color 0.3s; white-space: nowrap; border-radius: 6px;
}
.btn-sm:hover { box-shadow: 0 0 0 1px var(--accent); color: var(--text); }
.btn-sm:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent); border: none;
  box-shadow: 0 0 0 1px var(--accent);
  padding: 0.85rem 2.5rem; cursor: pointer; color: var(--bg);
  font-family: var(--font-body); font-size: 0.82rem;
  letter-spacing: 0.1em; text-transform: uppercase;
  transition: background 0.3s, transform 0.3s; margin-top: 0.5rem;
  display: inline-flex; align-items: center; gap: 0.5rem;
  border-radius: var(--radius-sm);
}
.btn-primary:hover { background: var(--accent-dim); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.97); }

/* ─── Result ─── */
.result { display: none; }
.result.show {
  display: block;
  animation: fadeUp 0.5s var(--ease-out) forwards;
}
.error-msg {
  background: rgba(180,60,60,0.1); border: 1px solid rgba(180,60,60,0.25);
  color: #d88; padding: 1rem 1.5rem; font-size: 0.82rem;
  margin-bottom: 1.5rem; display: none; border-radius: var(--radius-sm);
}
.loading {
  text-align: center; padding: 3rem; color: var(--text-muted);
  font-size: 0.82rem; display: none;
}
.loading .spinner {
  display: inline-block; width: 24px; height: 24px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin-bottom: 0.75rem;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Layer cards ─── */
.layer {
  background: var(--bg-card); border: none;
  box-shadow: 0 0 0 1px var(--border), 0 2px 16px rgba(0,0,0,0.08);
  border-radius: var(--radius);
  padding: 2rem; margin-bottom: 2rem;
}
.layer-tag {
  font-size: 0.55rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--accent); font-weight: 400; margin-bottom: 0.25rem;
}
.layer-title {
  font-family: var(--font-display); font-size: 1.3rem; font-weight: 300;
  font-variation-settings: 'SOFT' 70; margin-bottom: 1.25rem;
  letter-spacing: -0.02em;
}
.layer-title small { font-size: 0.75rem; color: var(--text-muted); font-weight: 300; }
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;
}

/* ─── Num items ─── */
.num-item {
  padding: 0.75rem 0; border-bottom: 1px solid var(--border);
}
.num-item:last-child { border: none; }
.num-item-label {
  font-size: 0.58rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 400; margin-bottom: 0.15rem;
}
.num-item-value {
  font-family: var(--font-display); font-size: 1.6rem; font-weight: 300;
  font-variation-settings: 'SOFT' 60; color: var(--accent); line-height: 1.15;
}
.num-item-value .sub {
  font-size: 0.8rem; color: var(--text); font-family: var(--font-body);
  font-weight: 300; margin-left: 0.3rem;
}
.num-item-desc {
  font-size: 0.78rem; color: var(--text-muted); font-weight: 300; line-height: 1.5;
  margin-top: 0.2rem;
}

/* ─── Tags ─── */
.tag {
  display: inline-block; font-size: 0.58rem; letter-spacing: 0.12em;
  text-transform: uppercase; padding: 0.2rem 0.6rem;
  border: 1px solid var(--border); color: var(--text-muted); margin-right: 0.35rem;
  margin-bottom: 0.35rem; border-radius: 4px;
}
.tag.accent { border-color: var(--accent); color: var(--accent); }
.tag.green { border-color: var(--green); color: var(--green); }
.shadow-text { color: var(--text-shadow); }
.green-text { color: var(--green); }
.accent-text { color: var(--accent); }

/* ─── Key quote ─── */
.key-quote {
  margin-top: 1rem; padding: 1rem 1.25rem;
  border-left: 2px solid var(--accent); background: var(--bg);
  font-style: italic; font-size: 0.85rem; color: var(--accent); font-weight: 300;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ─── Footer ─── */
footer {
  position: relative; z-index: 2;
  border-top: 1px solid var(--border);
  padding: 1.5rem 2.5rem;
  text-align: center;
  font-size: 0.68rem; color: var(--text-muted); font-weight: 300;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ─── Action bar ─── */
.action-bar {
  display: flex; gap: 0.75rem; justify-content: center;
  flex-wrap: wrap; margin-top: 1.5rem; margin-bottom: 2.5rem;
}

/* ─── Toast ─── */
.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--accent); color: var(--bg); padding: 0.6rem 1.5rem;
  font-size: 0.75rem; z-index: 99999; opacity: 0;
  transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out); pointer-events: none;
  border-radius: 6px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Devata grid ─── */
.devata-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem;
  padding: 0.75rem 0; border-top: 1px solid var(--border); margin-top: 0.75rem;
}
.devata-item {
  padding: 0.75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg);
}
.devata-label {
  font-size: 0.55rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 400; margin-bottom: 0.25rem;
}
.devata-name {
  font-family: var(--font-display); font-size: 1rem; font-weight: 500;
  color: var(--accent); font-variation-settings: 'SOFT' 80;
}
.devata-detail {
  font-size: 0.7rem; color: var(--text-muted); font-weight: 300; margin-top: 0.15rem;
}

/* ─── Table wrappers (shared) ─── */
.table-responsive {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin-bottom: 2rem;
}
.table-responsive::-webkit-scrollbar { height: 4px; }
.table-responsive::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.table-wrap {
  background: var(--bg-card); border: none;
  box-shadow: 0 0 0 1px var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem; margin-bottom: 2rem;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.table-wrap::-webkit-scrollbar { height: 4px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.table-header {
  font-family: var(--font-display); font-size: 1rem; font-weight: 400;
  font-variation-settings: 'SOFT' 80; margin-bottom: 1rem;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font-size: 0.6rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 400;
  text-align: left; padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.5rem 0.75rem; font-size: 0.82rem;
  border-bottom: 1px solid var(--border); color: var(--text-muted);
}
.data-table tr:hover td { color: var(--text); }
.yoga-list { list-style: none; padding: 0; }
.yoga-list li {
  padding: 0.5rem 0.75rem; font-size: 0.82rem;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}
.yoga-list li:last-child { border: none; }

/* ─── Responsive ─── */
@media (max-width: 820px) {
  nav { padding: 0.75rem 1.5rem; }
  main { padding: 2rem 1.25rem 3rem; }
  .calc-section { padding: 1.25rem; }
  .layer { padding: 1.25rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .table-wrap { padding: 1rem; }
  .hero-label { font-size: 0.55rem; }
  .hero-desc { font-size: 0.82rem; }
}
@media (max-width: 600px) {
  .hero { margin-bottom: 2rem; }
  h1 { margin-bottom: 0.75rem; }
  .hero-desc { max-width: 100%; }
  .input-row input { font-size: 0.82rem; padding: 0.7rem 1rem; }
  .input-row button { padding: 0.7rem 1rem; min-width: 44px; min-height: 44px; }
  .calc-grid { grid-template-columns: 1fr; }
  .layer-title { font-size: 1.1rem; }
  .num-item-value { font-size: 1.3rem; }
  .key-quote { font-size: 0.8rem; }
  .table-wrap { padding: 0.75rem; }
  .data-table { min-width: 500px; }
  .devata-grid { grid-template-columns: 1fr; }
  .num-item-desc { font-size: 0.75rem; }
  .tag { font-size: 0.55rem; }
  .num-item-label { font-size: 0.55rem; }
  .data-table th { font-size: 0.55rem; padding: 0.4rem 0.5rem; }
  .data-table td { font-size: 0.75rem; padding: 0.4rem 0.5rem; }
}
@media (max-width: 400px) {
  main { padding: 1.5rem 1rem 2rem; }
  .calc-section { padding: 1rem; }
  .layer { padding: 1rem; }
  .calc-section-row .field-group { min-width: 140px; }
  .input-row input { font-size: 0.78rem; padding: 0.6rem 0.8rem; }
  .input-row button { padding: 0.6rem 0.8rem; }
  .sys-code { font-size: 1.3rem; }
}
@media (pointer: coarse) {
  .nav-links a { min-height: 48px; }
  .tag { padding: 0.3rem 0.7rem; min-height: 36px; }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Print ─── */
@media print {
  body::before, body::after, .cursor-glow { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
  .calc-section { display: none !important; }
  nav, footer, .action-bar, .toast, .theme-toggle, .nav-toggle { display: none !important; }
  .result { display: block !important; }
  .layer { border-color: #ccc !important; background: #fff !important; }
  .num-item { border-color: #eee !important; }
  .key-quote { background: #f5f5f5 !important; border-color: #999 !important; }
  .table-wrap { border-color: #ccc !important; background: #fff !important; }
}
