:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #64748b;
  --paper: #f3f7fc;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --line: #d9e5f2;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #dbeafe;
  --accent-faint: #eff6ff;
  --error: #dc2626;
  --shadow: 0 12px 32px rgba(30, 64, 175, 0.08);
  font-family:
    "Segoe UI Variable", "Segoe UI", Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(59, 130, 246, 0.14), transparent 30rem),
    radial-gradient(circle at 96% 14%, rgba(14, 165, 233, 0.11), transparent 28rem),
    linear-gradient(180deg, #f8fbff 0%, var(--paper) 100%);
}

button,
select,
.latex-input {
  font: inherit;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 1.75rem 2rem 2.5rem;
}

.hero {
  margin-bottom: 22px;
  padding: 8px 4px 18px;
  border-bottom: 1px solid rgba(147, 197, 253, 0.7);
}

.step-number {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin: 0;
  color: #0b2559;
  background: linear-gradient(90deg, #0f172a 0%, #1d4ed8 82%);
  font-size: clamp(1.85rem, 2.3vw, 2.65rem);
  font-weight: 750;
  line-height: 1.04;
  letter-spacing: -0.035em;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.input-card,
.result-card {
  min-width: 0;
  border: 1px solid rgba(191, 219, 254, 0.72);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.input-card {
  padding: 24px;
}

.section-heading,
.card-header,
.input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.section-heading {
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.section-heading h2,
.card-header h2 {
  margin: 3px 0 0;
  color: #172554;
  font-size: 1.05rem;
  font-weight: 720;
}

.example-picker {
  display: grid;
  min-width: 0;
  flex: 1 1 22rem;
  gap: 6px;
  color: #475569;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-width: 0;
  padding: 10px 36px 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  text-transform: none;
}

select:focus {
  border-color: #60a5fa;
  outline: 0;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.latex-input {
  display: block;
  width: 100%;
  min-height: 54px;
  max-height: 180px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  resize: none;
  overflow-y: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  color: #1d2b3f;
  background: var(--surface-soft);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.98rem;
  line-height: 1.4;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.latex-input:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.input-actions {
  margin-top: 18px;
}

.hint {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.error-message {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid #fecaca;
  border-radius: 9px;
  color: #b91c1c;
  background: #fef2f2;
  font-size: 0.82rem;
  line-height: 1.45;
}

.error-message[hidden] {
  display: none;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 19px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.24);
  cursor: pointer;
  font-weight: 750;
  transition:
    background 120ms ease,
    transform 120ms ease;
}

button:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.3);
  transform: translateY(-2px);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "input text"
    "latex rendered";
  align-items: stretch;
  gap: 1.5rem;
}

.workspace-grid > * {
  min-width: 0;
}

.workspace-input {
  grid-area: input;
}

.workspace-text {
  grid-area: text;
}

.workspace-latex {
  grid-area: latex;
}

.workspace-rendered {
  grid-area: rendered;
}

.result-card {
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.card-header {
  justify-content: flex-start;
  margin-bottom: 16px;
}

.card-header .step-number {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #bfdbfe;
  border-radius: 50%;
  background: var(--accent-faint);
}

.card-header p:not(.step-number) {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.preview-surface {
  min-height: 140px;
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
}

.math-preview {
  display: grid;
  min-height: 240px;
  place-items: center;
  background:
    linear-gradient(145deg, #ffffff 0%, #f5f9ff 100%);
  font-size: 1.1rem;
  text-align: center;
}

.converted-source {
  margin: 0;
  color: #243248;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.rendered-output {
  color: #111827;
  font-family: inherit;
  font-size: 1.08rem;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rendered-output .style-bold {
  font-weight: 700;
}

.rendered-output .style-italic {
  font-style: italic;
}

.rendered-output .style-superscript {
  vertical-align: super;
  font-size: 0.72em;
}

.rendered-output .style-subscript {
  vertical-align: sub;
  font-size: 0.72em;
}

.card-note {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.45;
}

.converted-card .preview-surface,
.rendered-card .preview-surface {
  min-height: 14rem;
  flex: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 60rem) {
  .page-shell {
    width: 100%;
    padding: 1rem;
  }

  .workspace-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "input"
      "latex"
      "text"
      "rendered";
  }

  .hero,
  .section-heading,
  .input-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .hero {
    padding: 4px 2px 18px;
  }

  .example-picker,
  select {
    width: 100%;
  }

  .input-card,
  .result-card {
    border-radius: 15px;
  }

  .input-card {
    padding: 20px;
  }

  button {
    justify-content: center;
    width: 100%;
  }
}

