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

:root,
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --btn-primary-text: #0d1117;
  --drop-bg: #1c2128;
  --preview-bg: #0d1117;
  --code-bg: #161b22;
  --blockquote-border: #3d444d;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --radius: 8px;
  --header-h: 56px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --btn-primary-text: #ffffff;
  --drop-bg: #f6f8fa;
  --preview-bg: #ffffff;
  --code-bg: #f6f8fa;
  --blockquote-border: #d0d7de;
}

html {
  color-scheme: light dark;
}

[data-theme="dark"] {
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* Header */

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-h);
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.header__logo {
  width: 22px;
  height: 22px;
  display: block;
  object-fit: contain;
}

.header__title {
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header__filename {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4375rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn--primary {
  background: var(--accent);
  color: var(--btn-primary-text);
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--icon {
  padding: 0.4375rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn--icon:hover {
  color: var(--text);
  background: var(--drop-bg);
}

.icon {
  width: 18px;
  height: 18px;
  display: block;
}

[data-theme="dark"] .icon--sun { display: block; }
[data-theme="dark"] .icon--moon { display: none; }
[data-theme="light"] .icon--sun { display: none; }
[data-theme="light"] .icon--moon { display: block; }

/* Main */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Dropzone */

.dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  margin: 1.5rem;
  border: 2px dashed var(--border);
  border-radius: calc(var(--radius) * 1.5);
  background: var(--drop-bg);
  transition: border-color 0.2s, background 0.2s;
}

.dropzone--active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--drop-bg));
}

.dropzone__content {
  text-align: center;
  max-width: 420px;
}

.dropzone__icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  color: var(--text-muted);
}

.dropzone__title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.dropzone__text {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
}

.dropzone__hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  opacity: 0.85;
}

/* Preview */

.preview {
  flex: 1;
  overflow: auto;
  padding: 2rem 0;
  background: var(--preview-bg);
}

/* Markdown body — GitHub-inspired */

.markdown-body {
  width: 80%;
  margin: 0 auto;
  font-size: 1rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.75em;
  font-weight: 600;
  line-height: 1.25;
}

.markdown-body h1 { font-size: 2em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin-top: 0;
  margin-bottom: 1em;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body code {
  padding: 0.2em 0.4em;
  font-size: 0.875em;
  font-family: var(--font-mono);
  background: var(--code-bg);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.markdown-body pre {
  padding: 1rem;
  overflow: auto;
  font-size: 0.875rem;
  line-height: 1.45;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.markdown-body pre code {
  padding: 0;
  background: none;
  border: none;
  font-size: inherit;
}

.markdown-body blockquote {
  padding: 0 1em;
  color: var(--text-muted);
  border-left: 4px solid var(--blockquote-border);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 2em;
}

.markdown-body li + li {
  margin-top: 0.25em;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.markdown-body th,
.markdown-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.markdown-body th {
  font-weight: 600;
  background: var(--surface);
}

.markdown-body tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}

.markdown-body hr {
  height: 1px;
  margin: 1.5em 0;
  background: var(--border);
  border: 0;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* Footer */

.footer {
  padding: 0.75rem 1.25rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.footer p {
  margin: 0;
}

.footer__link {
  color: var(--accent);
  text-decoration: none;
}

.footer__link:hover {
  text-decoration: underline;
}

.footer__credit {
  margin: 0.375rem 0 0;
  font-size: 0.6875rem;
  opacity: 0.85;
}

/* Responsive */

@media (max-width: 600px) {
  .header__filename {
    display: none;
  }

  .markdown-body {
    width: 92%;
  }

  .dropzone {
    margin: 1rem;
    padding: 1.5rem;
  }
}
