:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --ink: #18202a;
  --muted: #687385;
  --line: #dbe1e8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.viewer-panel,
.result-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto auto auto;
  border-radius: 8px;
  overflow: hidden;
}

.result-panel {
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

.primary-button input {
  display: none;
}

.ghost-button {
  background: #edf2f7;
  color: #243244;
}

.ghost-button:hover:not(:disabled) {
  background: #e2e8f0;
}

.drop-zone {
  margin: 16px 18px 0;
  min-height: 148px;
  display: grid;
  place-items: center;
  border: 1px dashed #9aa7b5;
  border-radius: 8px;
  background: var(--panel-soft);
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: #ecfdf5;
}

.drop-message {
  display: grid;
  gap: 8px;
  text-align: center;
}

.drop-message strong {
  font-size: 20px;
}

.drop-message span {
  color: var(--muted);
}

.page-strip {
  min-height: 0;
  overflow: visible;
  padding: 18px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.page-card {
  position: relative;
  width: min(100%, 1080px);
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.page-card canvas {
  display: block;
  width: 100%;
  height: auto;
}

.page-label {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(24, 32, 42, 0.72);
  color: #fff;
  font-size: 12px;
}

.summary-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px 22px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fcfdff;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

#fileName {
  display: block;
  font-size: 16px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 8px;
  margin-top: 0;
  color: var(--muted);
}

.summary-grid b {
  color: var(--ink);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 42px;
  background: #fff;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.tab.active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
  font-weight: 700;
}

.tab-panel {
  display: none;
  min-height: 0;
  overflow: visible;
  padding: 16px;
}

.tab-panel.active {
  display: block;
}

.empty-state {
  color: var(--muted);
  padding: 26px 10px;
  text-align: center;
}

.group-title {
  margin: 14px 0 8px;
  color: #3b4758;
  font-size: 13px;
}

.element-row {
  display: grid;
  grid-template-columns: minmax(100px, 140px) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  margin-bottom: 8px;
  cursor: pointer;
}

.element-row:hover {
  border-color: #9bc7c2;
  background: #f8fffd;
}

.element-label {
  color: var(--muted);
  font-size: 13px;
}

.element-value {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.copy-button {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: #e7f6f3;
  color: var(--accent-strong);
  font-size: 16px;
}

.copy-button:hover {
  background: #c9ece6;
}

.raw-row {
  grid-template-columns: 72px minmax(0, 1fr) auto;
}

.rebuild-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.rebuild-stage {
  display: grid;
  gap: 18px;
  justify-items: center;
  overflow-x: auto;
  padding: 4px 0 12px;
}

.rebuild-page {
  position: relative;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #cfd8e3;
  box-shadow: 0 12px 28px rgba(31, 41, 55, 0.12);
  overflow: hidden;
  user-select: text;
}

.rebuild-page-label {
  position: absolute;
  z-index: 2;
  top: 6px;
  left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(24, 32, 42, 0.68);
  color: #fff;
  font-size: 11px;
  pointer-events: none;
}

.rebuild-text {
  position: absolute;
  display: inline-block;
  color: #111827;
  line-height: 1;
  white-space: pre;
  overflow: visible;
  font-family: "SimSun", "Songti SC", "Microsoft YaHei", Arial, sans-serif;
  cursor: pointer;
}

.rebuild-text:hover {
  outline: 1px solid rgba(15, 118, 110, 0.38);
  background: rgba(15, 118, 110, 0.08);
}

pre {
  margin: 0;
  padding: 14px;
  border-radius: 6px;
  background: #101827;
  color: #e5eef8;
  overflow: auto;
  font-size: 13px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(24, 32, 42, 0.92);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1080px) {
  .result-panel {
    min-height: 0;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 120px;
  }

  .summary-card {
    grid-template-columns: 1fr;
  }

  .element-row,
  .raw-row {
    grid-template-columns: 1fr auto;
  }

  .element-label {
    grid-column: 1 / -1;
  }
}
