@font-face {
  font-family: "Magnus Notes Hand";
  src: url("./assets/MagnusNotesHand-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

:root {
  color-scheme: light;
  --page: #f3f0e8;
  --paper: #faf8f1;
  --paper-deep: #f4f0e6;
  --graphite: #191a1d;
  --muted: #62605b;
  --line: #c9c4b9;
  --line-soft: rgba(101, 96, 86, 0.2);
  --ink: #18356d;
  --rust: #b74b2c;
  --rust-dark: #8f331c;
  --focus: #2d66cc;
  --rule-blue: rgba(81, 133, 174, 0.26);
  --rule-red: rgba(187, 87, 71, 0.27);
  --editor-width: 38.6%;
  --preview-size: 48px;
  --preview-leading: 1.6;
  --line-step: 76.8px;
  --radius-sm: 4px;
  --radius-md: 10px;
  --shadow-paper: 0 14px 28px rgba(56, 48, 35, 0.12), 0 2px 5px rgba(56, 48, 35, 0.16);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--graphite);
  background-color: var(--page);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.055'/%3E%3C/svg%3E");
}

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

button {
  color: inherit;
}

button,
input[type="range"] {
  touch-action: manipulation;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  min-height: 92px;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  border-bottom: 1px solid var(--line);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 22px;
}

.brand h1 {
  margin: 0;
  color: #122744;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 3vw, 2.65rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.brand-divider {
  width: 1px;
  height: 52px;
  flex: 0 0 auto;
  background: #868178;
}

.brand p {
  margin: 0;
  font-family: Georgia, "Songti SC", "Noto Serif CJK SC", serif;
  font-size: clamp(1.35rem, 2vw, 1.8rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 22px;
}

.action-button {
  min-height: 52px;
  padding: 0 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--rust);
  border-radius: var(--radius-sm);
  color: var(--rust-dark);
  background: rgba(250, 248, 241, 0.45);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.action-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.action-button:hover {
  color: #fffaf3;
  background: var(--rust);
}

.action-button:active {
  transform: translateY(1px);
}

.workspace {
  position: relative;
  min-height: 740px;
  display: grid;
  grid-template-columns: var(--editor-width) minmax(0, 1fr);
}

.editor-pane,
.preview-pane {
  min-width: 0;
  padding: 28px 32px 34px;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.editor-pane h2,
.preview-pane h2 {
  margin: 0 0 18px;
  font-family: Georgia, "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.section-heading {
  min-height: 25px;
  margin-bottom: 18px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
}

.section-heading h2 {
  margin-bottom: 0;
}

.font-status {
  margin: 0;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.76rem;
  white-space: nowrap;
}

.font-status[data-state="ready"] {
  color: var(--ink);
}

.font-status[data-state="error"] {
  color: var(--rust-dark);
  font-weight: 700;
}

#editor {
  width: 100%;
  min-height: 420px;
  flex: 1 1 420px;
  resize: vertical;
  padding: 24px 20px;
  border: 1px solid #9b968c;
  border-radius: 7px;
  outline: 3px solid transparent;
  outline-offset: 1px;
  color: #202225;
  background: rgba(255, 253, 247, 0.52);
  box-shadow: inset 0 1px 2px rgba(54, 48, 38, 0.06);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 1.12rem;
  line-height: 1.65;
  letter-spacing: 0.01em;
  caret-color: var(--rust);
  transition: border-color 160ms ease, outline-color 160ms ease, background-color 160ms ease;
}

#editor:focus {
  border-color: var(--focus);
  outline-color: rgba(45, 102, 204, 0.22);
  background: rgba(255, 253, 247, 0.82);
}

.editor-meta {
  padding: 13px 4px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
}

#supportMessage[data-warning="true"] {
  color: var(--rust-dark);
  font-weight: 600;
}

.controls {
  border-top: 1px solid var(--line-soft);
}

.control-row {
  min-height: 104px;
  display: grid;
  grid-template-columns: 66px minmax(130px, 1fr) 64px 24px;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.control-row label {
  font-family: Georgia, "Songti SC", serif;
  font-size: 1.02rem;
  font-weight: 700;
}

.range-wrap {
  position: relative;
  min-width: 0;
  padding-bottom: 28px;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--rust) 0 var(--range-progress, 33%), #d4d0c8 var(--range-progress, 33%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -7px;
  appearance: none;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--rust);
  box-shadow: 0 0 0 1px rgba(109, 45, 26, 0.35);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: #d4d0c8;
}

input[type="range"]::-moz-range-progress {
  height: 5px;
  border-radius: 999px;
  background: var(--rust);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--rust);
  box-shadow: 0 0 0 1px rgba(109, 45, 26, 0.35);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 5px;
  border-radius: 5px;
}

.range-limits {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.76rem;
}

.control-row output {
  min-height: 40px;
  padding: 7px 8px;
  display: grid;
  place-items: center;
  border: 1px solid #9f9a90;
  border-radius: var(--radius-sm);
  background: rgba(255, 253, 247, 0.6);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.96rem;
}

.unit {
  color: #383733;
  font-size: 0.9rem;
}

.divider-handle {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: var(--editor-width);
  width: 21px;
  height: 52px;
  padding: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  transform: translate(-50%, -50%);
  border: 1px solid #aaa59c;
  border-radius: 10px;
  color: #4b4945;
  background: var(--paper);
  box-shadow: 0 2px 5px rgba(41, 37, 31, 0.1);
  cursor: col-resize;
}

.divider-handle span {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}

.divider-handle:hover,
.divider-handle:focus-visible {
  color: var(--rust);
  border-color: var(--rust);
}

.divider-handle:focus-visible {
  outline: 3px solid rgba(45, 102, 204, 0.22);
  outline-offset: 2px;
}

.preview-pane {
  display: flex;
  flex-direction: column;
}

.preview-sheet {
  position: relative;
  min-height: 640px;
  flex: 1 1 auto;
  overflow: auto;
  border: 1px solid #d0cbbf;
  border-radius: var(--radius-md);
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, transparent 67px, var(--rule-red) 68px, transparent 69px),
    repeating-linear-gradient(to bottom, transparent 0 calc(var(--line-step) - 1px), var(--rule-blue) calc(var(--line-step) - 1px) var(--line-step));
  box-shadow: var(--shadow-paper);
  isolation: isolate;
}

.preview-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  border-radius: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='150'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  opacity: 0.5;
}

#previewText {
  min-height: 100%;
  margin: 0;
  padding: calc(var(--line-step) + 12px) 48px 72px 96px;
  color: var(--ink);
  font-family: "Magnus Notes Hand", cursive;
  font-size: var(--preview-size);
  font-weight: 400;
  font-style: normal;
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "liga" 1;
  line-height: var(--preview-leading);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-rendering: geometricPrecision;
}

.mobile-note {
  min-height: 68px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  color: #45433f;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
}

.mobile-note svg {
  width: 22px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.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: 1000px) {
  :root {
    --editor-width: 42%;
  }

  .topbar {
    padding-inline: 24px;
  }

  .brand {
    gap: 16px;
  }

  .brand-divider {
    height: 42px;
  }

  .topbar-actions {
    gap: 10px;
  }

  .action-button {
    min-height: 46px;
    padding-inline: 18px;
  }

  .editor-pane,
  .preview-pane {
    padding-inline: 24px;
  }

  .control-row {
    grid-template-columns: 58px minmax(96px, 1fr) 56px 20px;
    gap: 10px;
  }

  #previewText {
    padding-right: 34px;
    padding-left: 88px;
  }
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 18px;
  }

  .topbar-actions {
    width: 100%;
  }

  .action-button {
    flex: 1 1 0;
  }

  .workspace {
    min-height: 0;
    display: block;
  }

  .editor-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #editor {
    min-height: 300px;
    flex-basis: 300px;
  }

  .divider-handle {
    display: none;
  }

  .preview-sheet {
    min-height: 620px;
  }
}

@media (max-width: 560px) {
  .topbar,
  .editor-pane,
  .preview-pane {
    padding-right: 18px;
    padding-left: 18px;
  }

  .brand {
    width: 100%;
    align-items: flex-start;
    gap: 12px;
  }

  .brand h1 {
    font-size: clamp(1.7rem, 8vw, 2rem);
    white-space: normal;
  }

  .brand-divider {
    height: 36px;
  }

  .brand p {
    padding-top: 3px;
    font-size: 1rem;
    white-space: normal;
  }

  .action-button {
    min-height: 44px;
    padding-inline: 12px;
    font-size: 0.9rem;
  }

  .editor-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .control-row {
    min-height: 112px;
    grid-template-columns: 48px minmax(90px, 1fr) 52px;
  }

  .control-row .unit {
    display: none;
  }

  .preview-sheet {
    min-height: 520px;
    background-image:
      linear-gradient(to right, transparent 47px, var(--rule-red) 48px, transparent 49px),
      repeating-linear-gradient(to bottom, transparent 0 calc(var(--line-step) - 1px), var(--rule-blue) calc(var(--line-step) - 1px) var(--line-step));
  }

  #previewText {
    padding-right: 24px;
    padding-left: 66px;
  }

  .mobile-note {
    align-items: flex-start;
    text-align: left;
  }
}

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