/* ========================================
   Md2Pdf — Refined Light Design System
   Warm ivory canvas, ink type, champagne gold,
   paper-white preview surface for PDF fidelity.
   ======================================== */

/* ----------------------------------------
   0. Self-hosted Display Serif
   Playfair Display (SIL OFL 1.1) — latin + latin-ext only, 119 KiB total.
   Self-hosted so the app keeps working offline and never calls Google.
   CJK and Devanagari glyphs fall through to the system serif stack.
   ---------------------------------------- */
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/playfair-display-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/playfair-display-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Playfair Display";
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/playfair-display-italic-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Playfair Display";
  font-style: italic;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/playfair-display-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ----------------------------------------
   1. Design Tokens
   ---------------------------------------- */
:root {
  color-scheme: light;

  /* Warm ivory canvas */
  --canvas: #faf8f3;
  --canvas-deep: #f3efe6;
  --surface: #ffffff;
  --surface-warm: #fffdf8;

  /* Champagne gold */
  --gold: #a8874e;
  --gold-light: #d9c193;
  --gold-bright: #ecd9ae;
  --gold-deep: #7d5f28;
  --gold-glow: rgba(168, 135, 78, 0.2);

  /* Surfaces + hairlines (ink-based on light) */
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.92);
  --hairline: rgba(35, 30, 18, 0.1);
  --hairline-strong: rgba(35, 30, 18, 0.18);

  /* Text */
  --text: #2b2820;
  --text-strong: #17150f;
  --text-muted: #645f53;
  --text-faint: #6e6858;
  --danger: #b2402c;
  --danger-soft: rgba(178, 64, 44, 0.08);
  --success: #4a7c4f;

  /* Paper (preview surface — kept white for PDF export) */
  --paper: #ffffff;
  --paper-ink: #1b1a17;
  --paper-ink-soft: #55534d;
  --paper-line: #e6e2d8;

  /* Radii */
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 9px;
  --radius-pill: 999px;

  /* Shadows — warm, low-opacity, layered */
  --shadow-sm: 0 1px 2px rgba(35, 28, 15, 0.05);
  --shadow: 0 14px 32px -22px rgba(35, 28, 15, 0.32);
  --shadow-lg: 0 34px 70px -38px rgba(35, 28, 15, 0.38);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", "Noto Sans KR", "Noto Sans JP", "Noto Sans SC", "Noto Sans Devanagari",
    Arial, sans-serif;
  --font-display: "Playfair Display", "Iowan Old Style", "Palatino Linotype", Palatino,
    Georgia, "Noto Serif KR", "Noto Serif JP", "Noto Serif SC", "Noto Serif Devanagari",
    serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;

  /* Motion */
  --ease: cubic-bezier(0.22, 0.68, 0.32, 1);
  --dur: 220ms;

  /* Layout */
  --header-h: 68px;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--canvas);
  background-image:
    radial-gradient(1200px 680px at 50% -14%, rgba(214, 190, 143, 0.28), transparent 64%),
    radial-gradient(820px 560px at 92% 4%, rgba(176, 190, 214, 0.16), transparent 62%),
    radial-gradient(1000px 760px at 4% 100%, rgba(214, 190, 143, 0.14), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Paper grain — keeps the large ivory areas from reading as flat digital white */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23g)' opacity='0.045'/%3E%3C/svg%3E");
}

::selection {
  background: rgba(168, 135, 78, 0.24);
  color: var(--text-strong);
}

:focus-visible {
  outline: 1px solid var(--gold-deep);
  outline-offset: 3px;
  border-radius: 4px;
}

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

button {
  background: none;
  border: none;
  cursor: pointer;
}

svg {
  display: block;
  flex-shrink: 0;
}

code,
kbd,
pre {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
}

.view {
  width: 100%;
}

/* ----------------------------------------
   3. Language Selector
   ---------------------------------------- */
.lang-selector-wrapper {
  position: absolute;
  top: clamp(16px, 3vw, 32px);
  right: clamp(16px, 3vw, 32px);
  z-index: 20;
}

.lang-selector {
  position: relative;
}

.lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px 9px 13px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--glass);
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}

.lang-trigger:hover,
.lang-selector.open .lang-trigger {
  color: var(--text-strong);
  border-color: var(--hairline-strong);
  background: var(--glass-strong);
}

.lang-flag {
  font-size: 0.95rem;
  line-height: 1;
}

.lang-name {
  white-space: nowrap;
}

.lang-chevron {
  width: 13px;
  height: 13px;
  opacity: 0.6;
  transition: transform var(--dur) var(--ease);
}

.lang-selector.open .lang-chevron {
  transform: rotate(180deg);
  opacity: 1;
  color: var(--gold-deep);
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 186px;
  padding: 6px;
  display: grid;
  gap: 2px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease),
    visibility var(--dur);
}

.lang-selector.open .lang-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.lang-option:hover {
  background: var(--canvas-deep);
  color: var(--text-strong);
}

.lang-option.active {
  color: var(--gold-deep);
  background: rgba(168, 135, 78, 0.12);
}

.lang-option.active .lang-flag {
  filter: drop-shadow(0 0 5px var(--gold-glow));
}

/* ----------------------------------------
   4. Landing View
   ---------------------------------------- */
.landing-view {
  position: relative;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto;
  align-content: safe center;
  justify-items: center;
  padding: clamp(68px, 8vh, 96px) clamp(18px, 4vw, 40px) clamp(40px, 7vh, 80px);
}

/* Soft spotlight behind the hero so the ivory canvas has a light source */
.landing-view::before {
  content: "";
  position: absolute;
  inset: -18% -12% auto;
  height: min(720px, 82vh);
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    48% 46% at 50% 42%,
    rgba(214, 190, 143, 0.3),
    transparent 72%
  );
}

.landing-container {
  position: relative;
  z-index: 1;
  width: min(100%, 900px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(22px, 3.6vh, 40px);
}

.landing-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(15px, 2.2vh, 24px);
  text-align: center;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 18px 6px 7px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--glass);
  color: var(--gold-deep);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

.brand-icon {
  width: 30px;
  height: 30px;
  padding: 4px;
  border-radius: 8px;
  color: var(--gold-deep);
  background: linear-gradient(145deg, var(--gold-bright), rgba(168, 135, 78, 0.16));
  box-shadow: inset 0 0 0 1px rgba(168, 135, 78, 0.28);
}

.brand-text {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--text-faint);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.hero-eyebrow::before,
.hero-eyebrow::after {
  content: "";
  width: clamp(20px, 5vw, 52px);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(168, 135, 78, 0.55));
}

.hero-eyebrow::after {
  background: linear-gradient(90deg, rgba(168, 135, 78, 0.55), transparent);
}

.landing-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.7rem, 7.8vw, 5rem);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text-strong);
  text-wrap: balance;
}

.gradient-text {
  background: linear-gradient(102deg, var(--gold-deep) 0%, var(--gold) 42%, #c19a52 72%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-style: italic;
  letter-spacing: -0.02em;
}

.landing-subtitle {
  max-width: 48ch;
  color: var(--text-muted);
  font-size: clamp(0.96rem, 1.5vw, 1.08rem);
  line-height: 1.72;
  text-wrap: pretty;
}

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 13px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--glass);
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.pill svg {
  width: 12px;
  height: 12px;
  color: var(--gold-deep);
  opacity: 0.9;
}

.pill:hover {
  color: var(--text-strong);
  border-color: rgba(168, 135, 78, 0.4);
  box-shadow: var(--shadow-sm);
}

/* Gold hairline ornament with a lozenge centre */
.ornament {
  display: flex;
  align-items: center;
  width: min(100%, 620px);
  color: var(--gold);
}

.ornament::before,
.ornament::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(168, 135, 78, 0.4), transparent);
}

.ornament-mark {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin: 0 16px;
  transform: rotate(45deg);
  background: linear-gradient(135deg, var(--gold-bright), var(--gold-deep));
  box-shadow: 0 0 10px var(--gold-glow);
}

/* ----------------------------------------
   5. Drop Zone
   ---------------------------------------- */
.drop-zone-wrapper {
  width: min(100%, 760px);
}

.drop-zone {
  position: relative;
  width: 100%;
  padding: clamp(26px, 4.4vh, 46px) clamp(22px, 4vw, 44px);
  border: 1px dashed rgba(168, 135, 78, 0.55);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 253, 248, 0.6));
  box-shadow: var(--shadow);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}

.drop-zone:hover,
.drop-zone.drag-over,
.drop-zone.is-dragging {
  transform: translateY(-2px);
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(250, 246, 236, 0.86));
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(168, 135, 78, 0.28);
}

.drop-zone.is-dragging {
  animation: goldPulse 1.6s ease-in-out infinite;
}

@keyframes goldPulse {
  0%,
  100% {
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(168, 135, 78, 0.24);
  }
  50% {
    box-shadow: var(--shadow-lg), 0 0 0 7px rgba(168, 135, 78, 0.12);
  }
}

.drop-zone-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}

.drop-icon {
  width: 54px;
  height: 54px;
  padding: 11px;
  border-radius: 50%;
  color: var(--gold-deep);
  background: linear-gradient(145deg, rgba(236, 217, 174, 0.55), rgba(168, 135, 78, 0.1));
  box-shadow: inset 0 0 0 1px rgba(168, 135, 78, 0.24);
  transition: transform var(--dur) var(--ease);
}

.drop-zone:hover .drop-icon {
  transform: translateY(-3px);
}

.drop-main {
  font-size: clamp(1.04rem, 2vw, 1.3rem);
  line-height: 1.5;
  color: var(--text-strong);
  text-wrap: balance;
}

.drop-main strong {
  color: var(--gold-deep);
  font-weight: 600;
}

.drop-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.btn-ghost {
  padding: 2px 7px;
  margin: 0 2px;
  border-radius: 6px;
  color: var(--gold-deep);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgba(168, 135, 78, 0.45);
  text-underline-offset: 3px;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease),
    text-decoration-color var(--dur) var(--ease);
}

.btn-ghost:hover {
  color: #5f4718;
  background: rgba(168, 135, 78, 0.14);
  text-decoration-color: currentColor;
}

.drop-formats {
  font-size: 0.78rem;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.drop-formats code {
  padding: 2px 7px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--canvas-deep);
  color: var(--text-muted);
  font-size: 0.72rem;
}

.drag-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(253, 251, 246, 0.92);
  backdrop-filter: blur(6px);
  color: var(--gold-deep);
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), visibility var(--dur);
}

.drag-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drag-overlay svg {
  width: 46px;
  height: 46px;
}

/* ----------------------------------------
   6. Trust Bar
   ---------------------------------------- */
.trust-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px clamp(14px, 3vw, 34px);
  padding-top: clamp(4px, 1vh, 10px);
}

.trust-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.trust-item svg {
  width: 14px;
  height: 14px;
  color: var(--gold);
  opacity: 0.95;
}

/* ----------------------------------------
   7. SEO Content (crawlable copy + FAQ)
   ---------------------------------------- */
.seo-section {
  width: 100%;
  max-width: 900px;
  margin-top: clamp(36px, 6vh, 64px);
  padding-top: clamp(32px, 4.5vh, 52px);
  border-top: 1px solid var(--hairline);
}

.seo-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.seo-heading {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1.25;
  letter-spacing: -0.015em;
  color: var(--text-strong);
  text-align: center;
  text-wrap: balance;
}

.seo-intro {
  max-width: 68ch;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.75;
  text-align: center;
  text-wrap: pretty;
}

.seo-subheading {
  margin-top: clamp(20px, 3vh, 34px);
  color: var(--text-faint);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-align: center;
}

.seo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(248px, 1fr));
  gap: 12px;
}

.seo-card {
  padding: 18px 20px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.seo-card:hover {
  border-color: rgba(168, 135, 78, 0.42);
  background: var(--glass-strong);
  box-shadow: var(--shadow);
}

.seo-card h4 {
  margin-bottom: 7px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold-deep);
}

.seo-card p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.65;
}

.seo-usecases {
  display: grid;
  gap: 8px;
  max-width: 68ch;
  margin: 0 auto;
  padding: 0;
  list-style: none;
}

.seo-usecases li {
  position: relative;
  padding-left: 22px;
  color: var(--text-muted);
  font-size: 0.87rem;
  line-height: 1.7;
}

.seo-usecases li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.72em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.8;
}

.faq-list {
  display: grid;
  gap: 8px;
  max-width: 78ch;
  margin: 0 auto;
}

.faq-item {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease);
}

.faq-item[open] {
  border-color: rgba(168, 135, 78, 0.42);
  background: var(--glass-strong);
}

.faq-item summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  color: var(--text-strong);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  transition: color var(--dur) var(--ease);
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::after {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1px solid var(--gold);
  border-bottom: 1px solid var(--gold);
  transform: rotate(45deg) translateY(-2px);
  transition: transform var(--dur) var(--ease);
}

.faq-item[open] summary::after {
  transform: rotate(225deg) translateY(-2px);
}

.faq-item summary:hover {
  color: var(--gold-light);
}

.faq-item p {
  padding: 0 18px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.7;
}

.noscript-note {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--glass);
}

.noscript-note h2 {
  margin-bottom: 10px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.5rem;
}

.noscript-note p {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.7;
}

/* ----------------------------------------
   8. Editor View — Header
   ---------------------------------------- */
.editor-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.editor-header {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 clamp(14px, 2.6vw, 26px);
  border-bottom: 1px solid var(--hairline);
  background: rgba(250, 248, 243, 0.86);
  backdrop-filter: blur(16px);
}

.btn-home {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 15px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--glass);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.btn-home svg {
  width: 16px;
  height: 16px;
  color: var(--gold-deep);
}

.btn-home:hover {
  transform: translateX(-2px);
  color: var(--text-strong);
  border-color: rgba(168, 135, 78, 0.45);
  background: rgba(168, 135, 78, 0.08);
}

.editor-title {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}

.editor-title h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46ch;
}

.file-badge {
  flex-shrink: 0;
  padding: 3px 9px;
  border: 1px solid rgba(168, 135, 78, 0.32);
  border-radius: var(--radius-pill);
  background: rgba(168, 135, 78, 0.1);
  color: var(--gold-deep);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  max-width: 26ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 9px;
}

/* Segmented layout toggle (checkbox in disguise) */
.view-toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 34px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--glass);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}

.view-toggle:hover {
  color: var(--text-strong);
  border-color: var(--hairline-strong);
  background: var(--glass-strong);
}

.view-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.view-toggle svg {
  position: absolute;
  width: 17px;
  height: 17px;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.view-toggle .icon-horizontal {
  opacity: 1;
}

.view-toggle .icon-vertical {
  opacity: 0;
  transform: scale(0.8);
}

.view-toggle:has(input:checked) .icon-horizontal {
  opacity: 0;
  transform: scale(0.8);
}

.view-toggle:has(input:checked) .icon-vertical {
  opacity: 1;
  transform: scale(1);
}

.view-toggle:has(input:focus-visible) {
  outline: 1px solid var(--gold-deep);
  outline-offset: 3px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 17px;
  border: 1px solid rgba(168, 135, 78, 0.55);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #f0e3c4 0%, #dcbe86 52%, #c39c53 100%);
  color: #241b08;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  box-shadow: 0 8px 20px -12px rgba(125, 95, 40, 0.4);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    filter var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.btn-primary svg {
  width: 16px;
  height: 16px;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow: 0 14px 28px -12px rgba(125, 95, 40, 0.45);
}

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

.btn-primary:disabled {
  background: transparent;
  border-color: var(--hairline);
  color: var(--text-faint);
  box-shadow: none;
  cursor: not-allowed;
}

/* ----------------------------------------
   9. Split Layout
   ---------------------------------------- */
.split-container {
  --editor-flex: 50%;
  flex: 1;
  min-height: 0;
  display: flex;
  padding: clamp(12px, 1.8vw, 20px);
}

.split-container.layout-vertical {
  flex-direction: column;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--glass-strong);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.editor-pane {
  flex: 0 0 var(--editor-flex, 50%);
}

.preview-pane {
  flex: 1 1 0%;
}

.pane-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 clamp(12px, 1.8vw, 18px);
  border-bottom: 1px solid var(--hairline);
}

.pane-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
}

.pane-title svg {
  width: 14px;
  height: 14px;
  color: var(--gold);
  opacity: 0.85;
}

.pane-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-faint);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.stat span:first-child {
  color: var(--gold-deep);
  font-weight: 600;
}

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

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.checkbox-inline input {
  width: 15px;
  height: 15px;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Resizer */
.split-resizer {
  position: relative;
  flex: 0 0 10px;
  align-self: stretch;
  display: grid;
  place-items: center;
  cursor: col-resize;
  touch-action: none;
  border-radius: 6px;
}

.split-resizer::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  width: 1px;
  transform: translateX(-50%);
  background: var(--hairline);
  transition: background var(--dur) var(--ease), width var(--dur) var(--ease);
}

.split-resizer::after {
  content: "";
  width: 2px;
  height: 36px;
  border-radius: 2px;
  background: var(--gold);
  opacity: 0.4;
  transition: opacity var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.split-resizer:hover::before,
.split-resizer:focus-visible::before,
.split-resizer.is-active::before {
  width: 2px;
  background: rgba(168, 135, 78, 0.7);
}

.split-resizer:hover::after,
.split-resizer:focus-visible::after,
.split-resizer.is-active::after {
  opacity: 1;
  box-shadow: 0 0 12px var(--gold-glow);
}

.split-resizer:focus-visible {
  outline: 1px solid var(--gold-deep);
  outline-offset: -1px;
}

.split-resizer.is-active {
  cursor: grabbing;
}

.layout-vertical .split-resizer {
  flex: 0 0 10px;
  width: 100%;
  cursor: row-resize;
}

.layout-vertical .split-resizer::before {
  inset: 50% 0 auto 0;
  width: auto;
  height: 1px;
  transform: translateY(-50%);
}

.layout-vertical .split-resizer:hover::before,
.layout-vertical .split-resizer:focus-visible::before,
.layout-vertical .split-resizer.is-active::before {
  width: auto;
  height: 2px;
}

.layout-vertical .split-resizer::after {
  width: 36px;
  height: 2px;
}

/* ----------------------------------------
   10. Editor + Preview Content
   ---------------------------------------- */
.editor-textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: clamp(16px, 2.2vw, 24px);
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.78;
  caret-color: var(--gold-deep);
  tab-size: 2;
}

.editor-textarea::placeholder {
  color: var(--text-faint);
}

.editor-textarea::selection {
  background: rgba(168, 135, 78, 0.2);
}

.preview-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: clamp(14px, 2.2vw, 22px);
  scroll-behavior: smooth;
}

.preview-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-faint);
  text-align: center;
}

.preview-placeholder svg {
  width: 58px;
  height: 58px;
  opacity: 0.28;
}

.preview-placeholder p {
  font-size: 0.92rem;
}

.placeholder-hint {
  font-size: 0.64rem !important;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.7;
}

/* ----------------------------------------
   11. Rendered Markdown (paper surface)
   ---------------------------------------- */
.markdown-body {
  padding: clamp(20px, 3vw, 40px);
  border-radius: var(--radius-lg);
  background: var(--paper);
  color: var(--paper-ink);
  font-size: 15px;
  line-height: 1.75;
  box-shadow: 0 18px 44px -30px rgba(35, 28, 15, 0.4);
  overflow-wrap: break-word;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.6em 0 0.6em;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.01em;
  color: var(--paper-ink);
}

.markdown-body h1 {
  font-size: 1.9rem;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--paper-line);
}

.markdown-body h2 {
  font-size: 1.5rem;
  padding-bottom: 0.28em;
  border-bottom: 1px solid var(--paper-line);
}

.markdown-body h3 {
  font-size: 1.22rem;
}
.markdown-body h4 {
  font-size: 1.05rem;
}
.markdown-body h5 {
  font-size: 0.95rem;
}
.markdown-body h6 {
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-ink-soft);
}

.markdown-body p {
  margin: 1em 0;
}

.markdown-body a {
  color: #8a6a2f;
  text-decoration: underline;
  text-decoration-color: rgba(138, 106, 47, 0.4);
  text-underline-offset: 2px;
}

.markdown-body a:hover {
  color: #6d5222;
  text-decoration-color: currentColor;
}

.markdown-body strong {
  font-weight: 700;
  color: #100f0d;
}

.markdown-body ul,
.markdown-body ol {
  margin: 1em 0;
  padding-left: 1.5em;
}

.markdown-body li {
  margin: 0.4em 0;
}

.markdown-body li::marker {
  color: #a9822f;
}

.markdown-body blockquote {
  margin: 1.2em 0;
  padding: 0.3em 0 0.3em 1.1em;
  border-left: 3px solid #c8a96a;
  color: var(--paper-ink-soft);
  font-style: italic;
}

.markdown-body code {
  padding: 0.15em 0.4em;
  border-radius: 5px;
  background: rgba(27, 26, 23, 0.06);
  color: #7a5c22;
  font-size: 0.88em;
}

.markdown-body pre {
  margin: 1.2em 0;
  padding: 1em 1.1em;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  background: #f6f4ee;
  overflow-x: auto;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: #26241f;
  font-size: 0.85rem;
  line-height: 1.65;
}

.markdown-body table {
  width: 100%;
  margin: 1.2em 0;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.markdown-body th,
.markdown-body td {
  padding: 9px 12px;
  border: 1px solid var(--paper-line);
  text-align: left;
}

.markdown-body th {
  background: #f4f1e9;
  font-weight: 700;
}

.markdown-body tbody tr:nth-child(even) td {
  background: rgba(27, 26, 23, 0.028);
}

.markdown-body hr {
  margin: 2em 0;
  border: none;
  border-top: 1px solid var(--paper-line);
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  margin: 1.2em 0;
  border-radius: var(--radius);
}

.markdown-body .task-list-item {
  list-style: none;
  display: flex;
  align-items: flex-start;
  gap: 9px;
}

.markdown-body .task-list-item input[type="checkbox"] {
  margin-top: 0.42em;
  accent-color: #8a6a2f;
}

.markdown-body .katex-display {
  margin: 1.2em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.2em 0;
}

.markdown-body .katex {
  color: var(--paper-ink);
}

.markdown-body .mermaid {
  margin: 1.5em 0;
  text-align: center;
}

.markdown-body .mermaid svg {
  max-width: 100%;
  height: auto;
}

.markdown-body .mermaid-error {
  padding: 14px 16px;
  border: 1px solid rgba(178, 64, 44, 0.35);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: #932f1d;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: left;
  white-space: pre-wrap;
}

/* ----------------------------------------
   12. Loading Overlay
   ---------------------------------------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(250, 248, 243, 0.86);
  backdrop-filter: blur(8px);
}

.loading-spinner svg {
  width: 54px;
  height: 54px;
  color: var(--gold);
}

.loading-text {
  color: var(--text-strong);
  font-size: 0.92rem;
  letter-spacing: 0.08em;
}

.loading-progress {
  width: min(260px, 62vw);
  height: 2px;
  border-radius: 2px;
  background: var(--canvas-deep);
  overflow: hidden;
}

.loading-bar {
  width: 0;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  transition: width 380ms var(--ease);
}

/* ----------------------------------------
   13. Toasts
   ---------------------------------------- */
.toast-container {
  position: fixed;
  bottom: clamp(16px, 4vh, 32px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(88vw, 460px);
  padding: 11px 18px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  color: var(--text-strong);
  font-size: 0.86rem;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  animation: toastIn 340ms var(--ease);
}

.toast::before {
  content: "";
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

.toast.error {
  border-color: rgba(178, 64, 44, 0.4);
}

.toast.error::before {
  background: var(--danger);
}

.toast.leaving {
  animation: toastOut 280ms var(--ease) forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* ----------------------------------------
   14. Responsive
   ---------------------------------------- */
@media (max-width: 1100px) {
  .landing-title {
    font-size: clamp(2.3rem, 6.6vw, 3.6rem);
  }
}

@media (max-width: 900px) {
  .editor-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .split-container,
  .split-container.layout-vertical {
    flex-direction: column;
    overflow-y: auto;
  }

  .editor-pane {
    flex: 0 0 auto;
    height: 46vh;
  }

  .preview-pane {
    flex: 0 0 auto;
    height: 46vh;
  }

  .split-resizer {
    display: none;
  }
}

@media (max-width: 680px) {
  :root {
    --header-h: auto;
  }

  .editor-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .editor-title {
    order: 3;
    flex: 1 0 100%;
    justify-content: flex-start;
  }

  .editor-actions {
    margin-left: auto;
  }

  .btn-home-text {
    display: none;
  }

  .btn-home {
    padding: 9px 11px;
  }

  .landing-title {
    font-size: clamp(2.1rem, 9.4vw, 3rem);
  }

  .trust-bar {
    gap: 10px 18px;
  }

  .editor-pane,
  .preview-pane {
    height: 52vh;
  }
}

@media (max-width: 480px) {
  .landing-view {
    padding-top: 84px;
  }

  .feature-pills {
    gap: 6px;
  }

  .drop-zone {
    padding: 30px 18px;
    border-radius: var(--radius-lg);
  }

  .toast-container {
    left: 12px;
    right: 12px;
    transform: none;
    align-items: stretch;
  }

  .toast {
    max-width: none;
  }

  .markdown-body {
    padding: 20px 16px;
  }
}

/* ----------------------------------------
   15. Motion + Print
   ---------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body {
    background: #fff;
  }

  .bg-canvas,
  .landing-view,
  .editor-header,
  .editor-pane,
  .split-resizer,
  .loading-overlay,
  .toast-container,
  .pane-header {
    display: none !important;
  }

  .editor-view,
  .split-container,
  .pane,
  .preview-content {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
  }

  .markdown-body {
    box-shadow: none;
    padding: 0;
  }
}