:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --accent: #7c3aed;
  --success: #059669;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
}

[data-theme='dark'] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #1f2937;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-soft: rgba(56, 189, 248, 0.14);
  --accent: #a78bfa;
  --success: #34d399;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --warn-border: rgba(245, 158, 11, 0.35);
  --warn-text: #fcd34d;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.32);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 62px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.format-guide {
  font-size: 0.79rem;
  line-height: 1.45;
  color: var(--muted);
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 8px 11px;
  margin-bottom: 12px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-select, .icon-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:hover, .lang-select:hover {
  border-color: var(--primary);
}

/* Category Tabs (Big Tabs) & Sub-Tabs (Small Tabs) — wrap cleanly in all 6 languages */
.tabs-shell {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.big-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 0;
}

.big-tab {
  padding: 7px 13px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 0.87rem;
  color: var(--muted);
  white-space: nowrap;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.big-tab:hover { color: var(--text); background: var(--surface-2); }
.big-tab.active {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

.sub-tabs-wrap {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.sub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 10px 0;
}

.sub-tab {
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all 0.15s ease;
}
.sub-tab:hover { border-color: var(--primary); color: var(--text); }
.sub-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
[data-theme='dark'] .sub-tab.active { color: #0b1120; }

@media (max-width: 640px) {
  .big-tabs, .sub-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Main Workspace */
.main-content {
  padding: 26px 0 56px;
}

.hero-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.hero-head h1 {
  margin: 0 0 6px;
  font-size: clamp(1.45rem, 2.5vw, 2rem);
  letter-spacing: -0.025em;
}

.hero-desc {
  margin: 0;
  color: var(--muted);
  max-width: 720px;
}

.badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge.verified {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  color: var(--success);
}

/* Calculator Split Grid */
.calc-grid {
  display: grid;
  grid-template-columns: minmax(310px, 410px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .calc-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

/* Unit Pills */
.unit-pills {
  display: inline-flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--border);
}

.unit-pill {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.unit-pill.active {
  background: var(--primary);
  color: #fff;
}
[data-theme='dark'] .unit-pill.active { color: #0b1120; }

/* Inputs & Grouped Rows */
.mode-switch-row {
  margin-bottom: 14px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.field-groups {
  display: grid;
  gap: 12px;
}

.field-group {
  background: color-mix(in srgb, var(--surface-2) 48%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.group-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 9px;
}

.group-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  display: inline-block;
}
.group-dot.dot-a { background: #10b981; }
.group-dot.dot-b { background: #f43f5e; }

.fields-row {
  display: grid;
  gap: 9px;
}
.fields-row.cols-1 { grid-template-columns: 1fr; }
.fields-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.3;
  word-break: break-word;
}

.field input,
.quick-input,
.field-select,
.dataset-input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.96rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-weight: 600;
}
.field input:focus,
.quick-input:focus,
.field-select:focus,
.dataset-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.dataset-input {
  resize: vertical;
  min-height: 76px;
  line-height: 1.5;
}

.quick-input {
  padding: 11px 12px;
  font-size: 0.98rem;
}

.input-tip {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

@keyframes flashFill {
  0% { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
  100% { border-color: var(--border); box-shadow: none; }
}
.flash-fill {
  animation: flashFill 0.65s ease-out;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
[data-theme='dark'] .btn-primary { color: #0b1120; }

.calc-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  font-size: 0.86rem;
  font-weight: 600;
}

/* Primary Result Box */
.result-banner {
  background: linear-gradient(135deg, var(--primary-soft), color-mix(in srgb, var(--accent) 10%, transparent));
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.result-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.result-number {
  font-size: clamp(1.8rem, 3.2vw, 2.5rem);
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--primary);
  line-height: 1.2;
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.result-unit {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
}

.metric-label {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
}

.metric-value {
  font-size: 0.98rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, monospace;
  margin-top: 2px;
}

/* Canvas Visualizer */
.visual-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

#visualCanvas {
  display: block;
  width: 100%;
  height: 330px;
}

.visual-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  flex-wrap: wrap;
}

/* Formula & Step-by-Step */
.section-stack {
  display: grid;
  gap: 18px;
  margin-top: 20px;
}

.formula-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.98rem;
  font-weight: 700;
  overflow-x: auto;
  margin-bottom: 14px;
}

.steps-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.step-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
[data-theme='dark'] .step-num { color: #0b1120; }

.step-title {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.step-expr {
  display: block;
  font-size: 0.9rem;
  font-family: ui-monospace, SFMono-Regular, monospace;
  word-break: break-word;
  margin-top: 2px;
}

.latex-bar {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.latex-code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

/* Disclaimer & Ad Slot */
.disclaimer-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 11px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  font-size: 0.84rem;
}

.ad-slot {
  margin: 22px 0;
  min-height: 90px;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: var(--surface);
}

/* Embed & FAQ */
.embed-textarea {
  width: 100%;
  min-height: 66px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.8rem;
  resize: vertical;
}

.faq-list {
  display: grid;
  gap: 10px;
}

.faq-item {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px 16px;
  background: var(--surface-2);
}

.faq-item summary {
  font-weight: 700;
  cursor: pointer;
}

.faq-item p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Home Grid */
.home-hero {
  text-align: center;
  padding: 24px 0 32px;
}

.home-hero h1 {
  font-size: clamp(1.8rem, 3.6vw, 2.7rem);
  margin: 0 0 10px;
  letter-spacing: -0.03em;
}

.home-hero p {
  color: var(--muted);
  max-width: 660px;
  margin: 0 auto;
  font-size: 1.05rem;
}

.cat-section {
  margin-top: 30px;
}

.cat-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.22rem;
  margin: 0 0 14px;
}

.cat-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.calc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 16px;
}

.calc-link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.calc-link-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
}

.card-thumb {
  position: relative;
  width: 88px;
  height: 70px;
  flex-shrink: 0;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-thumb svg {
  width: 100%;
  height: 100%;
  display: block;
}

.card-dim-pill {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
}

.card-copy {
  min-width: 0;
}

.calc-link-card h3 {
  margin: 0 0 5px;
  font-size: 1rem;
  line-height: 1.3;
}
.calc-link-card p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 26px 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 16px;
  font-weight: 600;
}
.footer-links a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.legal-doc {
  max-width: 780px;
  margin: 0 auto;
  padding: 28px 30px;
}
.legal-doc h1 { margin-top: 0; }
.legal-doc h2 { margin-top: 24px; font-size: 1.1rem; }
.legal-doc p { color: var(--muted); }

.contact-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Clean Embed Mode */
body.embed-mode .site-header,
body.embed-mode .tabs-shell,
body.embed-mode .sub-tabs-wrap,
body.embed-mode .site-footer,
body.embed-mode .embed-section,
body.embed-mode .faq-section,
body.embed-mode .related-section,
body.embed-mode .ad-slot {
  display: none !important;
}
body.embed-mode .main-content {
  padding: 14px 0;
}
