:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-2: #1e2a4a;
  --primary: #0f3460;
  --accent: #e94560;
  --accent-soft: #ff6b81;
  --text: #eee;
  --text-muted: #9aa3b8;
  --border: #2a3656;
  --radius: 12px;
  --ok: #3ddc97;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #233356 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(26, 26, 46, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.5px;
  background: var(--accent);
  color: #fff;
  padding: 6px 9px;
  border-radius: 9px;
  white-space: nowrap;
}
.topbar h1 { font-size: 1.05rem; font-weight: 600; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.version { font-size: 0.72rem; color: var(--text-muted); }

/* Main */
#app {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 18px 40px;
  display: flex;
  flex-direction: column;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .1s;
  user-select: none;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: var(--surface-2); transform: scale(1.01); }
.dz-icon { font-size: 3rem; margin-bottom: 14px; }
.dz-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 8px; }
.dz-sub { color: var(--text-muted); font-size: 0.85rem; }

/* Progress */
#progress-view { text-align: center; padding: 60px 20px; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#progress-text { color: var(--text-muted); margin-bottom: 16px; }
.progress-bar {
  height: 8px; background: var(--surface); border-radius: 999px;
  overflow: hidden; max-width: 320px; margin: 0 auto;
}
#progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  border-radius: 999px; transition: width .25s ease;
}

/* Result */
.result-head {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
.file-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.file-name { font-weight: 600; font-size: 1rem; word-break: break-all; }
.file-stats { font-size: 0.78rem; color: var(--text-muted); }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  padding: 9px 14px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  background: none; border: none; color: var(--text-muted);
  padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* Panels */
#panel-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
#panel-preview h1, #panel-preview h2, #panel-preview h3 { margin: 1em 0 .5em; line-height: 1.3; }
#panel-preview h1 { font-size: 1.6rem; }
#panel-preview h2 { font-size: 1.3rem; }
#panel-preview h3 { font-size: 1.1rem; }
#panel-preview p { margin: 0 0 .9em; }
#panel-preview ul, #panel-preview ol { margin: 0 0 .9em 1.4em; }
#panel-preview li { margin-bottom: .3em; }
#panel-preview code {
  background: var(--bg); padding: 1px 5px; border-radius: 5px;
  font-size: 0.9em;
}
#panel-preview a { color: var(--accent-soft); }
#panel-preview > *:first-child { margin-top: 0; }

#raw-output {
  width: 100%; min-height: 420px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; resize: vertical;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.85rem; line-height: 1.55;
  white-space: pre;
}

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ok); color: #062b1d; font-weight: 600;
  padding: 10px 18px; border-radius: 999px; font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 50;
}

/* Footer */
.foot {
  text-align: center; color: var(--text-muted);
  font-size: 0.75rem; padding: 16px 20px 28px; max-width: 600px;
  margin: 0 auto; line-height: 1.5;
}

@media (max-width: 560px) {
  .topbar h1 { font-size: 0.95rem; }
  .dropzone { padding: 38px 18px; }
  .result-actions .btn { flex: 1; }
}
