:root {
  color-scheme: light dark;

  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #111827;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --border-focus: #3b82f6;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-text: #ffffff;
  --primary-subtle-bg: #eff6ff;
  --primary-subtle-border: #bfdbfe;

  --success-bg: #f0fdf4;
  --success-text: #166534;
  --success-border: #bbf7d0;

  --danger-bg: #fef2f2;
  --danger-text: #991b1b;
  --danger-border: #fecaca;

  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,.10), 0 1px 2px -1px rgba(0,0,0,.10);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -2px rgba(0,0,0,.10);

  --radius: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #1a1d24;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #2d3340;
    --border-focus: #60a5fa;

    --primary: #60a5fa;
    --primary-hover: #93c5fd;
    --primary-text: #0f1117;
    --primary-subtle-bg: rgba(96,165,250,.10);
    --primary-subtle-border: #1d4ed8;

    --success-bg: #052e16;
    --success-text: #86efac;
    --success-border: #166534;

    --danger-bg: #450a0a;
    --danger-text: #fca5a5;
    --danger-border: #7f1d1d;

    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.35);
    --shadow: 0 1px 3px 0 rgba(0,0,0,.45), 0 1px 2px -1px rgba(0,0,0,.45);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.45), 0 2px 4px -2px rgba(0,0,0,.45);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Decorative top glow */
.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 80% 40% at 50% -10%, rgba(59,130,246,.14), transparent);
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .page-bg {
    background: radial-gradient(ellipse 80% 40% at 50% -10%, rgba(96,165,250,.10), transparent);
  }
}

main {
  width: min(900px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 80px;
}

/* ── Header ── */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 20px;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.logo-icon {
  width: 18px;
  height: 18px;
}

header {
  margin-bottom: 36px;
}

h1 {
  font-size: 3.25rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.1;
  margin-bottom: 12px;
}

header > p {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* ── Flash messages ── */
.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 0.9rem;
  animation: slide-in 0.2s ease-out;
}

.message svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Upload card ── */
.upload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* Drop zone */
.drop-zone {
  display: block;
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s, box-shadow 0.15s;
  margin-bottom: 16px;
}

.drop-zone:hover,
.drop-zone:focus-within {
  border-color: var(--primary);
  background: var(--primary-subtle-bg);
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-subtle-bg);
  transform: scale(1.01);
  box-shadow: 0 0 0 4px rgba(59,130,246,.18);
}

.drop-zone-content {
  pointer-events: none;
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: var(--text-secondary);
  transition: color 0.15s, transform 0.15s;
}

.drop-zone:hover .upload-icon,
.drop-zone:focus-within .upload-icon {
  color: var(--primary);
  transform: translateY(-3px);
}

.upload-icon--active {
  color: var(--primary);
  transform: translateY(-4px);
}

.drop-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.drop-subtitle {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.browse-link {
  color: var(--primary);
  font-weight: 500;
}

.drop-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

#file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Selected file indicator */
.file-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--success-border);
  border-radius: var(--radius);
  background: var(--success-bg);
  color: var(--success-text);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 16px;
  animation: slide-in 0.2s ease-out;
}

.file-selected svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.file-selected span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  min-height: unset;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--success-text);
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s, background 0.15s;
}

.clear-btn:hover {
  opacity: 1;
  background: rgba(0,0,0,.08);
}

/* Convert button */
.convert-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-text);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}

.convert-btn:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.convert-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.convert-btn[data-loading] {
  opacity: 0.8;
  pointer-events: none;
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Result card ── */
.result-card {
  margin-top: 32px;
  animation: fade-up 0.3s ease-out;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.result-title {
  min-width: 0;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.result-badge svg {
  width: 13px;
  height: 13px;
}

.result-filename {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  color: var(--text);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn-secondary svg {
  width: 15px;
  height: 15px;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
}

/* ── Tabs ── */
.view-tabs {
  display: inline-flex;
  gap: 3px;
  padding: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.view-tabs button {
  min-height: 34px;
  padding: 0 16px;
  border: none;
  border-radius: calc(var(--radius) - 3px);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.view-tabs button:hover {
  color: var(--text);
  background: var(--surface);
}

.view-tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ── Preview ── */
.preview {
  min-height: 56vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.7;
  box-shadow: var(--shadow-sm);
}

.preview > :first-child { margin-top: 0; }
.preview > :last-child  { margin-bottom: 0; }

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  margin: 1.5rem 0 0.6rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.preview h1 { font-size: 1.75rem; }
.preview h2 {
  font-size: 1.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}
.preview h3 { font-size: 1.15rem; }

.preview p,
.preview ul,
.preview ol,
.preview blockquote,
.preview pre,
.preview table {
  margin: 0 0 1rem;
}

.preview ul,
.preview ol {
  padding-left: 1.5rem;
}

.preview li + li {
  margin-top: 0.25rem;
}

.preview a {
  color: var(--primary);
  text-decoration: none;
}

.preview a:hover { text-decoration: underline; }

.preview pre {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg);
}

.preview code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.preview :not(pre) > code {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  background: var(--bg);
}

.preview blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 1rem;
  color: var(--text-secondary);
  font-style: italic;
}

.preview table {
  width: 100%;
  border-collapse: collapse;
}

.preview th {
  background: var(--bg);
  font-weight: 600;
}

.preview th, .preview td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.preview tbody tr:hover > td {
  background: rgba(59,130,246,.04);
}

/* ── Textarea ── */
textarea {
  display: block;
  width: 100%;
  min-height: 56vh;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  font: 0.9rem/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  tab-size: 2;
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.20);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  main {
    width: calc(100% - 24px);
    padding: 32px 0 56px;
  }

  .upload-card { padding: 16px; }

  h1 { font-size: 2rem; }

  header > p { font-size: 1rem; }

  .drop-zone { padding: 32px 16px; }

  .result-header { flex-direction: column; align-items: flex-start; }

  .actions { width: 100%; }

  .btn-secondary { flex: 1; justify-content: center; }

  .view-tabs { display: flex; width: 100%; }

  .view-tabs button { flex: 1; }
}
