: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);
}

.site-heading {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.site-logo {
  width: clamp(2.5rem, 5vw, 3.5rem);
  height: auto;
  flex: 0 0 auto;
  padding: 0.35rem;
  border: 1px solid var(--accent);
  border-radius: 0.9rem;
  background: var(--accent-soft);
}

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

.editor-panel,
.output-panel,
.reference-panel {
  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,
select {
  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;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
}

.dlButtons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  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 {
  background: var(--accent-soft);
  color: var(--text);
}

.reference-panel {
  margin-top: 1rem;
  padding: 1rem;
}

.reference-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent);
}

.reference-copy {
  margin-top: 1rem;
}

.reference-copy code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.reference-example-list {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

.reference-example-list li {
  margin: 0 0 0.55rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.72);
}

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

textarea:focus-visible,
button:focus-visible,
select:focus-visible,
#renderedOutputRegion:focus-visible,
.reference-panel summary: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;
}

#renderedOutputRegion {
  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;
}

#renderedOutput pre,
#renderedOutput table {
  overflow-x: auto;
}

#renderedOutput pre {
  padding: 0.9rem 1rem;
  border-radius: 0.7rem;
  background: rgba(236, 228, 214, 0.75);
}

#renderedOutput blockquote {
  margin-inline: 0;
  padding-inline: 1rem 0;
  border-left: 0.3rem solid var(--border);
  color: var(--muted);
}

#renderedOutput img {
  max-width: 100%;
  height: auto;
}

#renderedOutput input[type="checkbox"] {
  inline-size: 1rem;
  block-size: 1rem;
  margin-right: 0.55rem;
  accent-color: var(--accent);
}

#renderedOutput li.task-list-item {
  list-style: none;
  margin-left: -1.4rem;
  padding-left: 0.25rem;
}

#renderedOutput ul:has(> li.task-list-item) {
  padding-left: 1.6rem;
}

#renderedOutput table {
  width: 100%;
  border-collapse: collapse;
}

#renderedOutput th,
#renderedOutput td {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}

#renderedOutput th {
  background: rgba(215, 228, 221, 0.55);
}

@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: transparent;
  }

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

  #renderedOutput a {
    color: #8dc2ff;
  }

  #renderedOutput code {
    background: #312926;
  }

  .reference-example-list li,
  #renderedOutput pre {
    background: rgba(28, 24, 22, 0.96);
  }

  #renderedOutput th {
    background: rgba(43, 52, 47, 0.82);
  }
}

@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;
  }

  .site-heading {
    gap: 0.65rem;
  }

  textarea {
    min-height: 16rem;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .dlButtons {
    flex-direction: column;
    align-items: stretch;
  }
}
