:root {
  color-scheme: light;
  --bg: #f7fcf9;
  --surface: #ffffff;
  --surface-muted: #f2f8f5;
  --border: #e2ece6;
  --border-strong: #cfded5;
  --text: #17211b;
  --muted: #5f7568;
  --accent: #049664;
  --accent-hover: #037d53;
  --accent-active: #026b47;
  --accent-soft: #e6f7ef;
  --accent-gradient: linear-gradient(135deg, #049664 0%, #037d53 100%);
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --error: #b42318;
  --error-soft: #fdecec;
  --mono: "Maple Mono", "JetBrains Mono", "SFMono-Regular", "Consolas", Menlo, monospace;
  --shadow-sm: 0 1px 2px rgba(18, 73, 48, .06);
  --shadow-md: 0 8px 24px rgba(18, 73, 48, .08);
}

* { box-sizing: border-box; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(25, 84, 59, .18);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(25, 84, 59, .3); background-clip: padding-box; }
::selection { background: rgba(4, 150, 100, .18); color: inherit; }

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

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "MiSans", "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent-gradient);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.brand-text h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0; }
.brand-text p { margin: 0; font-size: 12px; color: var(--muted); }

.topbar-status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.topbar-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #10b981; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease;
}
.home-link:hover { background: var(--accent-soft); border-color: var(--accent); }

.layout { max-width: 1320px; margin: 24px auto; padding: 0 28px; }

.mode-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}
.mode-label { font-size: 13px; color: var(--muted); }
.mode-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.segmented .seg { border: 0; background: transparent; padding: 6px 14px; font-size: 13px; font-weight: 500; color: var(--muted); cursor: pointer; transition: color .15s ease, background .15s ease; }
.segmented .seg:hover { color: var(--accent); }
.segmented .seg.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented .seg + .seg { border-left: 1px solid var(--border); }

.help-wrap { position: relative; display: inline-flex; }
.help-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color .15s ease, background .15s ease;
}
.help-btn:hover, .help-btn:focus-visible { color: var(--accent); background: var(--accent-soft); }
.help-btn svg { width: 16px; height: 16px; }
.help-tip {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  z-index: 40;
  width: 320px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: 12px;
  line-height: 1.7;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 4px);
  transition: opacity .18s ease, transform .18s ease, visibility .18s ease;
  pointer-events: none;
}
.help-wrap:hover .help-tip, .help-wrap:focus-within .help-tip {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.help-tip-item { display: block; }
.help-tip-item + .help-tip-item { margin-top: 7px; }
.help-tip-item strong { color: var(--accent); font-weight: 600; }
.help-tip code { padding: 1px 5px; border-radius: 4px; background: var(--surface-muted); color: var(--accent-active); font-family: var(--mono); font-size: .92em; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #cbd0d6;
  border-radius: 999px;
  transition: background .15s ease;
}
.switch-track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(16px); }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fcf9 100%);
  padding: 68px 24px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, background .18s ease, transform .18s ease, box-shadow .18s ease;
}

.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.dropzone svg { width: 42px; height: 42px; color: var(--accent); }
.dropzone-title { margin: 16px 0 4px; font-size: 16px; font-weight: 600; }
.dropzone-hint { margin: 0; font-size: 13px; color: var(--muted); }

.status-panel { padding: 72px 24px; text-align: center; color: var(--muted); }
.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  position: sticky;
  top: 64px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 16px;
  padding: 10px 12px;
  background: rgba(247, 252, 249, .92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.toolbar .file { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

.panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }

.pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  background: #fbfdfc;
}
.pane-head::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.pane-head-btn {
  margin-left: auto;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.pane-head-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.pane-body { padding: 18px 20px; overflow: auto; }

.source-wrap { position: relative; }
.source-marker {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(4, 150, 100, .14);
  border-left: 2px solid var(--accent);
  pointer-events: none;
  opacity: 0;
}
.source-marker.sync-flash { animation: marker-fade .8s ease-out; }
.preview .sync-flash { animation: block-flash .8s ease-out; border-radius: 4px; }

@keyframes marker-fade { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes block-flash { 0% { background: rgba(4, 150, 100, .14); } 100% { background: transparent; } }

textarea.code {
  width: 100%;
  display: block;
  border: 0;
  resize: none;
  outline: none;
  padding: 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  background: #fbfcfc;
}

.preview h1 { margin: 0 0 12px; font-size: 24px; }
.preview h2 { margin: 20px 0 10px; font-size: 20px; }
.preview h3 { margin: 16px 0 8px; font-size: 17px; }
.preview h4, .preview h5, .preview h6 { margin: 14px 0 8px; }
.preview p { margin: 0 0 12px; }
.preview hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.preview code { padding: 1px 5px; border-radius: 4px; background: #f0f2f5; font-family: var(--mono); font-size: .9em; }
.preview img { max-width: 100%; height: auto; border-radius: 6px; cursor: zoom-in; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(15, 17, 19, .82);
  backdrop-filter: blur(6px);
  cursor: zoom-out;
  animation: lightbox-backdrop .18s ease-out;
}

.lightbox-img {
  max-width: min(90vw, 1400px);
  max-height: 78vh;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
  animation: lightbox-img .22s cubic-bezier(.2, .7, .2, 1);
}

.lightbox-caption { margin: 0; color: #b9c0c8; font-size: 13px; max-width: 80vw; text-align: center; }

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  color: #e7eaee;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .14); }
.lightbox-close svg { width: 18px; height: 18px; }

@keyframes lightbox-backdrop { from { opacity: 0; } to { opacity: 1; } }
@keyframes lightbox-img { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

body.lightbox-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox-img { animation: none; }
}

.preview table { border-collapse: collapse; width: 100%; margin: 4px 0 16px; }
.preview th, .preview td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; font-size: 14px; }
.preview th { background: #f7f8fa; font-weight: 600; }
.preview mark { background-color: #fff3b0; }

.result { animation: result-in .32s ease-out both; }
@keyframes result-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.report { margin-top: 18px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-sm); }
.report-summary { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.stat { font-size: 13px; color: var(--muted); }
.stat b { color: var(--text); font-weight: 600; }
.stat-warn b { color: var(--warn); }

.warnings { margin: 12px 0 0; padding: 12px 0 0; border-top: 1px solid var(--border); list-style: none; }
.warnings li { margin-bottom: 6px; padding: 6px 10px; border-radius: 6px; background: var(--warn-soft); color: #7a3e08; font-size: 13px; }

.error-banner { margin-bottom: 16px; padding: 12px 16px; border: 1px solid #f1c0bd; border-radius: 8px; background: var(--error-soft); color: var(--error); }

.hidden { display: none !important; }

@media (max-width: 760px) {
  .panes { grid-template-columns: 1fr; }
  .layout { margin: 20px auto; }
  .dropzone { padding: 56px 16px; }
  .help-tip { left: auto; right: 0; width: min(320px, calc(100vw - 48px)); transform: translateY(4px); }
  .help-wrap:hover .help-tip, .help-wrap:focus-within .help-tip { transform: translateY(0); }
}
