:root {
  color-scheme: light;
  --page-bg: #f5f0e8;
  --panel-bg: #fffaf3;
  --accent: #23433a;
  --accent-soft: #d7e4dd;
  --border: #8b7f70;
  --text: #1f1b18;
  --muted: #534a42;
  --focus: #a83b12;
  --shadow: rgba(31, 27, 24, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page-bg: #13100f;
    --panel-bg: #1c1816;
    --accent: #b7d7c9;
    --accent-soft: #2b342f;
    --border: #6f665d;
    --text: #f2ebe1;
    --muted: #d1c4b8;
    --focus: #f28d49;
    --shadow: rgba(0, 0, 0, 0.38);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.92), transparent 45%),
    linear-gradient(180deg, #efe7da 0%, var(--page-bg) 100%);
}

main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

footer {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  color: var(--muted);
}

footer a {
  color: inherit;
}

h1,
h2 {
  color: var(--accent);
}

h1 {
  margin-bottom: 0.5rem;
  font-size: clamp(2rem, 5vw, 3.5rem);
}

p,
li {
  max-width: 68ch;
}

.editor-panel,
.output-panel,
dialog {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  box-shadow: 0 0.8rem 2rem var(--shadow);
}

.editor-panel,
.output-panel {
  padding: 1rem;
  margin-top: 1rem;
}

label,
button {
  font: inherit;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 20rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: #fff;
  color: inherit;
  resize: vertical;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0;
}

.dlButtons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0 0;
}

button {
  padding: 0.8rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fffaf3;
  cursor: pointer;
}

#helpButton,
#downloadMarkdown,
#downloadText,
#downloadHtml,
dialog button {
  background: var(--accent-soft);
  color: var(--text);
}

button:hover,
button:focus-visible {
  filter: brightness(1.03);
}

textarea:focus-visible,
button:focus-visible,
#renderedOutput:focus-visible,
dialog:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.status-message {
  min-height: 1.5rem;
  margin: 0.5rem 0 1rem;
  color: var(--muted);
}

#statusMessage {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#renderedOutput {
  min-height: 16rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.75);
}

#renderedOutput.is-shifting > * {
  animation: outputFadeIn 220ms ease-out;
}

#renderedOutput.is-shifting .drift-word {
  display: inline-block;
  animation: ghostDrift 650ms ease-out both;
  animation-delay: calc(var(--drift-index, 0) * 22ms);
}

#renderedOutput :first-child {
  margin-top: 0;
}

#renderedOutput a {
  color: #0d4f8f;
}

#renderedOutput code {
  padding: 0.08rem 0.3rem;
  border-radius: 0.25rem;
  background: #ece4d6;
}

@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(circle at top, rgba(90, 107, 98, 0.14), transparent 38%),
      linear-gradient(180deg, #171311 0%, var(--page-bg) 100%);
  }

  textarea {
    background: #141110;
    color: var(--text);
  }

  #renderedOutput {
    background: rgba(18, 15, 14, 0.9);
  }

  #renderedOutput a {
    color: #8dc2ff;
  }

  #renderedOutput code {
    background: #312926;
  }
}

dialog {
  width: min(40rem, calc(100vw - 2rem));
  padding: 1rem 1rem 1.25rem;
}

dialog::backdrop {
  background: rgba(31, 27, 24, 0.55);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 0.5rem;
}

@keyframes ghostDrift {
  0% {
    opacity: 0.15;
    transform: translate(var(--drift-x, 0.2rem), var(--drift-y, -0.15rem)) rotate(var(--drift-rotate, 1deg));
    filter: blur(1px);
  }

  55% {
    opacity: 0.95;
    transform: translate(calc(var(--drift-x, 0.2rem) * -0.35), calc(var(--drift-y, -0.15rem) * -0.25)) rotate(calc(var(--drift-rotate, 1deg) * -0.35));
    filter: blur(0.2px);
  }

  100% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg);
    filter: blur(0);
  }
}

@keyframes outputFadeIn {
  0% {
    opacity: 0.4;
  }

  100% {
    opacity: 1;
  }
}

@media (max-width: 48rem) {
  main {
    padding: 1rem 0.75rem 2rem;
  }

  textarea {
    min-height: 16rem;
  }

  .actions {
    flex-direction: column;
  }

  .dlButtons {
    flex-direction: column;
  }
}
