@font-face {
  font-family: "berkeley";
  src: url("berkeley.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-canvas: #ffffff;
  --bg-default: #ffffff;
  --bg-subtle: #f6f8fa;
  --bg-muted: #eaeef2;
  --bg-inset: #eff2f5;
  --fg-default: #1f2328;
  --fg-muted: #656d76;
  --fg-subtle: #6e7781;
  --border-default: #d0d7de;
  --border-muted: #d8dee4;
  --border-subtle: rgba(31, 35, 40, 0.15);
  --accent: #0969da;
  --accent-fg: #0550ae;
  --accent-muted: rgba(84, 174, 255, 0.4);
  --accent-subtle: #ddf4ff;
  --success: #1a7f37;
  --success-muted: rgba(74, 194, 107, 0.4);
  --success-subtle: #dafbe1;
  --attention: #9a6700;
  --attention-muted: rgba(212, 167, 44, 0.4);
  --attention-subtle: #fff8c5;
  --danger: #d1242f;
  --danger-muted: rgba(255, 129, 130, 0.4);
  --danger-subtle: #ffebe9;
  --done: #8250df;
  --done-muted: rgba(194, 151, 255, 0.4);
  --done-subtle: #fbefff;
  --sponsors: #bf3989;
  --sponsors-muted: rgba(255, 128, 200, 0.4);
  --sponsors-subtle: #ffeff7;
  --neutral-muted: rgba(175, 184, 193, 0.2);
  --code-bg: rgba(175, 184, 193, 0.2);
  --shadow: 0 1px 0 rgba(31, 35, 40, 0.04);
  --shadow-md: 0 3px 6px rgba(140, 149, 159, 0.15);
  --shadow-lg: 0 8px 24px rgba(140, 149, 159, 0.2);
  --brand: #5c6bc0;
}

[data-theme="dark"] {
  --bg-canvas: #0d1117;
  --bg-default: #0d1117;
  --bg-subtle: #161b22;
  --bg-muted: #21262d;
  --bg-inset: #010409;
  --fg-default: #e6edf3;
  --fg-muted: #8b949e;
  --fg-subtle: #6e7681;
  --border-default: #30363d;
  --border-muted: #21262d;
  --border-subtle: rgba(240, 246, 252, 0.1);
  --accent: #2f81f7;
  --accent-fg: #58a6ff;
  --accent-muted: rgba(56, 139, 253, 0.4);
  --accent-subtle: rgba(56, 139, 253, 0.15);
  --success: #3fb950;
  --success-muted: rgba(46, 160, 67, 0.4);
  --success-subtle: rgba(46, 160, 67, 0.15);
  --attention: #d29922;
  --attention-muted: rgba(187, 128, 9, 0.4);
  --attention-subtle: rgba(187, 128, 9, 0.15);
  --danger: #f85149;
  --danger-muted: rgba(248, 81, 73, 0.4);
  --danger-subtle: rgba(248, 81, 73, 0.15);
  --done: #a371f7;
  --done-muted: rgba(163, 113, 247, 0.4);
  --done-subtle: rgba(163, 113, 247, 0.15);
  --sponsors: #db61a2;
  --sponsors-muted: rgba(219, 97, 162, 0.4);
  --sponsors-subtle: rgba(219, 97, 162, 0.15);
  --neutral-muted: rgba(110, 118, 129, 0.4);
  --code-bg: rgba(110, 118, 129, 0.4);
  --shadow: 0 0 transparent;
  --shadow-md: 0 3px 6px #010409;
  --shadow-lg: 0 8px 24px #010409;
}

[data-theme="dimmed"] {
  --bg-canvas: #22272e;
  --bg-default: #22272e;
  --bg-subtle: #2d333b;
  --bg-muted: #373e47;
  --bg-inset: #1c2128;
  --fg-default: #adbac7;
  --fg-muted: #768390;
  --fg-subtle: #636e7b;
  --border-default: #444c56;
  --border-muted: #373e47;
  --border-subtle: rgba(205, 217, 229, 0.1);
  --accent: #539bf5;
  --accent-fg: #6cb6ff;
  --accent-muted: rgba(65, 132, 228, 0.4);
  --accent-subtle: rgba(65, 132, 228, 0.15);
  --success: #57ab5a;
  --success-muted: rgba(70, 149, 74, 0.4);
  --success-subtle: rgba(70, 149, 74, 0.15);
  --attention: #c69026;
  --attention-muted: rgba(174, 124, 20, 0.4);
  --attention-subtle: rgba(174, 124, 20, 0.15);
  --danger: #e5534b;
  --danger-muted: rgba(229, 83, 75, 0.4);
  --danger-subtle: rgba(229, 83, 75, 0.15);
  --done: #986ee2;
  --done-muted: rgba(152, 110, 226, 0.4);
  --done-subtle: rgba(152, 110, 226, 0.15);
  --sponsors: #c96198;
  --sponsors-muted: rgba(201, 97, 152, 0.4);
  --sponsors-subtle: rgba(201, 97, 152, 0.15);
  --neutral-muted: rgba(99, 110, 123, 0.4);
  --code-bg: rgba(99, 110, 123, 0.4);
  --shadow: 0 0 transparent;
  --shadow-md: 0 3px 6px #1c2128;
  --shadow-lg: 0 8px 24px #1c2128;
}

html {
  font-size: 16px;
}

body {
  font-family: "berkeley", ui-monospace, monospace;
  background: var(--bg-canvas);
  color: var(--fg-default);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s ease, color 0.2s ease;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

header a {
    color: inherit;
    text-decoration: none;
}

header h1 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

header h1 strong {
  color: var(--brand);
}

header h1 svg {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--brand);
}

header nav {
  display: flex;
  gap: 0.5rem;
}

header nav button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--bg-default);
  color: var(--fg-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

header nav button:hover {
  background: var(--bg-muted);
  color: var(--fg-default);
  border-color: var(--fg-muted);
}

header nav button:active {
  transform: scale(0.96);
}

header nav button svg {
  width: 1rem;
  height: 1rem;
}

header nav button[data-action="theme"] svg {
  display: none;
}

[data-theme="light"] header nav button[data-action="theme"] svg[data-icon="sun"],
:root:not([data-theme]) header nav button[data-action="theme"] svg[data-icon="sun"] {
  display: block;
}

[data-theme="dark"] header nav button[data-action="theme"] svg[data-icon="moon"] {
  display: block;
}

[data-theme="dimmed"] header nav button[data-action="theme"] svg[data-icon="github-alt"] {
  display: block;
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

main > section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

main > section[aria-label="editor"] {
  border-right: 1px solid var(--border-default);
}

main > section[aria-label="editor"] textarea {
  flex: 1;
  width: 100%;
  padding: 1.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--fg-default);
  background: var(--bg-default);
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
}

main > section[aria-label="editor"] textarea::placeholder {
  color: var(--fg-subtle);
}

main > section[aria-label="preview"] {
  background: var(--bg-default);
  overflow-y: auto;
}

main > section[aria-label="preview"] article {
  padding: 2rem;
  max-width: 980px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

article > *:first-child {
  margin-top: 0 !important;
}

article > *:last-child {
  margin-bottom: 0 !important;
}

article h1,
article h2,
article h3,
article h4,
article h5,
article h6 {
  margin-top: 1.5em;
  margin-bottom: 1rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--fg-default);
}

article h1 {
  font-size: 2em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border-muted);
}

article h2 {
  font-size: 1.5em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border-muted);
}

article h3 {
  font-size: 1.25em;
}

article h4 {
  font-size: 1em;
}

article h5 {
  font-size: 0.875em;
}

article h6 {
  font-size: 0.85em;
  color: var(--fg-muted);
}

article p {
  margin-top: 0;
  margin-bottom: 1rem;
  line-height: 1.6;
}

article a {
  color: var(--accent-fg);
  text-decoration: none;
}

article a:hover {
  text-decoration: underline;
}

article strong {
  font-weight: 600;
}

article em {
  font-style: italic;
}

article del {
  text-decoration: line-through;
}

article sub,
article sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

article sup {
  top: -0.5em;
}

article sub {
  bottom: -0.25em;
}

article ins {
  text-decoration: underline;
}

article code {
  font-family: "berkeley", ui-monospace, monospace;
  font-size: 0.85em;
  padding: 0.2em 0.4em;
  background: var(--code-bg);
  border-radius: 6px;
}

article pre {
  margin-top: 0;
  margin-bottom: 1rem;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.45;
  background: var(--bg-subtle);
  border-radius: 6px;
}

article pre code {
  padding: 0;
  background: transparent;
  font-size: 1em;
  border-radius: 0;
}

article blockquote {
  margin: 0 0 1rem;
  padding: 0 1em;
  color: var(--fg-muted);
  border-left: 0.25em solid var(--border-default);
}

article blockquote > :first-child {
  margin-top: 0;
}

article blockquote > :last-child {
  margin-bottom: 0;
}

article ul,
article ol {
  margin-top: 0;
  margin-bottom: 1rem;
  padding-left: 2em;
}

article ul ul,
article ul ol,
article ol ol,
article ol ul {
  margin-top: 0;
  margin-bottom: 0;
}

article li {
  margin-top: 0.25em;
}

article li + li {
  margin-top: 0.25em;
}

article li > p {
  margin-top: 1em;
}

article li > ul,
article li > ol {
  margin-top: 0.25em;
}

article ul:has(> li > input[type="checkbox"]) {
  list-style: none;
  padding-left: 0;
}

article li:has(> input[type="checkbox"]) {
  margin-left: 0;
}

article li > input[type="checkbox"] {
  margin-right: 0.5em;
  vertical-align: middle;
  accent-color: var(--accent);
}

article hr {
  height: 0.25em;
  margin: 1.5rem 0;
  padding: 0;
  background-color: var(--border-default);
  border: 0;
  border-radius: 2px;
}

article table {
  width: max-content;
  max-width: 100%;
  margin-bottom: 1rem;
  border-spacing: 0;
  border-collapse: collapse;
  overflow: auto;
  display: block;
}

article table th,
article table td {
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--border-default);
}

article table th {
  font-weight: 600;
  background: var(--bg-subtle);
}

article table tr {
  background: var(--bg-default);
  border-top: 1px solid var(--border-muted);
}

article table tr:nth-child(2n) {
  background: var(--bg-subtle);
}

article img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  box-sizing: content-box;
  background-color: var(--bg-default);
}

article details {
  margin-bottom: 1rem;
}

article details summary {
  cursor: pointer;
  font-weight: 600;
}

article details summary:hover {
  color: var(--accent-fg);
}

article blockquote:has(> p:first-child > strong:first-child) p:first-child {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

article [data-alert] {
  margin-bottom: 1rem;
  padding: 1rem;
  border-radius: 6px;
  border: 1px solid;
  border-left-width: 4px;
}

article [data-alert] > p:first-child {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

article [data-alert] > p:first-child svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

article [data-alert] > p:last-child {
  margin-bottom: 0;
}

article [data-alert="note"] {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

article [data-alert="note"] > p:first-child {
  color: var(--accent-fg);
}

article [data-alert="tip"] {
  background: var(--success-subtle);
  border-color: var(--success);
}

article [data-alert="tip"] > p:first-child {
  color: var(--success);
}

article [data-alert="important"] {
  background: var(--done-subtle);
  border-color: var(--done);
}

article [data-alert="important"] > p:first-child {
  color: var(--done);
}

article [data-alert="warning"] {
  background: var(--attention-subtle);
  border-color: var(--attention);
}

article [data-alert="warning"] > p:first-child {
  color: var(--attention);
}

article [data-alert="caution"] {
  background: var(--danger-subtle);
  border-color: var(--danger);
}

article [data-alert="caution"] > p:first-child {
  color: var(--danger);
}

article section[data-footnotes] {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-default);
  font-size: 0.875em;
  color: var(--fg-muted);
}

article section[data-footnotes] ol {
  padding-left: 1.5em;
}

article sup a[data-footnote-ref] {
  font-size: 0.75em;
  font-weight: 600;
  color: var(--accent-fg);
  text-decoration: none;
  padding: 0 0.2em;
}

article sup a[data-footnote-ref]::before {
  content: "[";
}

article sup a[data-footnote-ref]::after {
  content: "]";
}

article a[data-footnote-backref] {
  font-size: 0.75em;
  text-decoration: none;
}

article kbd {
  display: inline-block;
  padding: 0.2em 0.4em;
  font-size: 0.85em;
  font-family: "berkeley", ui-monospace, monospace;
  line-height: 1;
  color: var(--fg-default);
  vertical-align: middle;
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: 6px;
  box-shadow: inset 0 -1px 0 var(--border-muted);
}

article pre .keyword { color: var(--danger); }
article pre .string { color: var(--accent-fg); }
article pre .comment { color: var(--fg-muted); }
article pre .number { color: var(--done); }
article pre .function { color: var(--done); }

article:empty::before {
  content: "your preview will appear here...";
  color: var(--fg-subtle);
  font-style: italic;
}

@media (max-width: 800px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  main > section[aria-label="editor"] {
    border-right: none;
    border-bottom: 1px solid var(--border-default);
  }

  main > section[aria-label="preview"] article {
    padding: 1.25rem;
  }
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--fg-subtle);
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: var(--accent-muted);
}
