:root {
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #20231f;
  background: #f5f5f2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(16px, 3.5vw, 52px);
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: min(1440px, 100%);
  min-height: min(820px, calc(100vh - 7vw));
  min-height: min(820px, calc(100svh - 7vw));
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid #e5e6e1;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 20px 60px rgb(24 28 21 / 4%);
}

.panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 24px;
}

.input-panel {
  border-right: 1px solid #e9eae6;
  background: #fbfbfa;
}

.panel-heading {
  display: flex;
  align-items: center;
  min-height: 34px;
}

.panel-heading h1,
.panel-heading h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#latex-editor {
  min-height: 0;
  flex: 1;
  margin-top: 20px;
  overflow: hidden;
}

#latex-editor .cm-editor {
  height: 100%;
  background: transparent;
  color: #343934;
  font-size: 13px;
  line-height: 1.8;
}

#latex-editor .cm-scroller,
#latex-editor .cm-content {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

#latex-editor .cm-scroller {
  overflow: auto;
}

#latex-editor .cm-content {
  min-height: 100%;
  padding: 0 0 24px;
  caret-color: #343934;
}

#latex-editor .cm-line {
  padding: 0;
}

#latex-editor .cm-gutters {
  border: 0;
  background: transparent;
  color: #b0b5ad;
  font-size: 11px;
}

#latex-editor .cm-gutterElement {
  min-width: 24px;
  padding: 0 12px 0 0;
}

#latex-editor .cm-activeLine {
  background: rgb(47 57 44 / 3%);
}

#latex-editor .cm-selectionBackground,
#latex-editor .cm-focused .cm-selectionBackground {
  background: #dfe5da;
}

#latex-editor .cm-focused {
  outline: 2px solid #87927f;
  outline-offset: 3px;
  border-radius: 2px;
}

#latex-editor .cm-math-mode {
  color: #394d62;
}

#latex-editor .cm-latex-command {
  color: #7561a8;
  font-weight: 500;
}

#latex-editor .cm-environment-command {
  color: #47735c;
  font-weight: 600;
}

#latex-editor .cm-environment-name {
  color: #9a7440;
  font-weight: 500;
}

#latex-editor .cm-math-delimiter {
  color: #747c72;
}

#latex-editor .cm-latex-comment {
  color: #9a9e96;
  font-style: italic;
}

.output-panel {
  background: #fff;
}

.output-heading-row,
.actions,
.scale-row {
  display: flex;
  align-items: center;
}

.output-heading-row {
  justify-content: space-between;
  gap: 16px;
}

.actions {
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #e6e8e3;
  border-radius: 7px;
  background: #fff;
  color: #424840;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.icon-button:hover:not(:disabled) {
  border-color: #c9cec5;
  background: #f7f8f5;
  color: #161a16;
}

.icon-button:focus-visible,
select:focus-visible,
input:focus-visible,
#latex-editor .cm-focused {
  outline: 2px solid #87927f;
  outline-offset: 2px;
}

.icon-button:disabled {
  color: #b8bcb5;
  cursor: default;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

#export-format {
  height: 34px;
  padding: 0 25px 0 10px;
  border: 1px solid #e6e8e3;
  border-radius: 7px;
  background-color: #fff;
  color: #424840;
  font-size: 12px;
  cursor: pointer;
}

.scale-row {
  gap: 12px;
  margin-top: 21px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eff0ed;
  color: #737970;
  font-size: 12px;
}

.scale-row label {
  flex: 0 0 auto;
}

.scale-row input {
  width: min(140px, 24vw);
  height: 3px;
  accent-color: #666f61;
  cursor: pointer;
}

.scale-row output {
  min-width: 38px;
  color: #454b43;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.render-stage {
  display: flex;
  min-height: 240px;
  flex: 1;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 30px 10px;
  color: #20231f;
  font-size: 100%;
  text-align: center;
}

.render-stage mjx-container[display="true"] {
  display: block;
  margin: 0.8em 0 !important;
}

.render-stage mjx-container {
  max-width: 100%;
}

.status {
  min-height: 18px;
  color: #777d74;
  font-size: 11px;
  line-height: 18px;
}

.status[data-error="true"] {
  color: #9c433b;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

@media (max-width: 760px) {
  body {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    min-height: calc(100svh - 24px);
  }

  .panel {
    min-height: 42svh;
    padding: 18px;
  }

  .input-panel {
    border-right: 0;
    border-bottom: 1px solid #e9eae6;
  }

  #latex-editor {
    min-height: 170px;
  }

  .render-stage {
    min-height: 190px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
