:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #eef3f8;
  --text: #17202a;
  --muted: #667085;
  --line: #d7dde6;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --danger-bg: #fff4f2;
  --shadow: 0 18px 45px rgba(21, 32, 43, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.title-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  overflow: hidden;
  font-size: clamp(18px, 3vw, 24px);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  background: var(--surface);
}

.language-control select {
  min-width: 112px;
  max-width: 176px;
  border: 0;
  color: var(--text);
  font: inherit;
  background: transparent;
  outline: none;
}

.open-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  background: var(--surface);
}

.open-link[aria-disabled="true"] {
  pointer-events: none;
  color: var(--muted);
  opacity: 0.65;
}

.reader-shell {
  min-height: calc(100vh - 144px);
  padding: 20px clamp(12px, 4vw, 32px) 92px;
}

.state-panel {
  width: min(720px, 100%);
  margin: 36px auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.state-panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.state-panel p {
  margin: 0 0 12px;
  color: var(--muted);
}

.state-panel pre {
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  color: #243447;
  background: var(--surface-strong);
  white-space: pre-wrap;
  word-break: break-all;
}

.state-panel.error {
  border-color: #f3b8b2;
  background: var(--danger-bg);
}

.state-panel.error h2 {
  color: var(--danger);
}

.state-panel.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.spinner {
  width: 36px;
  height: 36px;
  margin-bottom: 14px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.viewer {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.canvas-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #cfd8e3;
  box-shadow: var(--shadow);
}

#pdfCanvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  background: #ffffff;
}

.toolbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px max(12px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.tool-button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  background: var(--accent);
  cursor: pointer;
}

.tool-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.tool-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  background: #a8b3bd;
}

.page-status,
.zoom-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.page-status {
  min-width: 76px;
  padding: 0 12px;
  font-weight: 700;
}

.divider {
  margin: 0 5px;
  color: var(--muted);
}

.zoom-group {
  gap: 6px;
  padding: 4px;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  font-size: 20px;
  line-height: 1;
}

.zoom-value {
  min-width: 52px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.noscript {
  position: fixed;
  inset: auto 12px 12px;
  z-index: 30;
  padding: 12px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--danger);
}

.qr-shell {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 24px clamp(12px, 4vw, 32px) 48px;
}

.qr-list {
  display: grid;
  gap: 14px;
}

.qr-item {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.qr-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.qr-item-title {
  min-width: 0;
}

.qr-item-title h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.qr-item-title code,
.qr-url-row code {
  color: #243447;
  word-break: break-all;
}

.qr-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.compact-button,
.compact-link {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.qr-url-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-strong);
}

.qr-url-row span,
.qr-languages > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.qr-languages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.qr-languages a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  background: var(--surface);
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .language-control,
  .open-link {
    flex: 1 1 150px;
    width: 100%;
  }

  .language-control select {
    flex: 1 1 auto;
    min-width: 0;
  }

  .reader-shell {
    min-height: calc(100vh - 190px);
    padding-top: 12px;
  }

  .state-panel {
    margin-top: 18px;
    padding: 18px;
  }

  .toolbar {
    grid-template-columns: 1fr auto 1fr;
  }

  .zoom-group {
    grid-column: 1 / -1;
  }

  .qr-item-header,
  .qr-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .qr-url-row {
    grid-template-columns: 1fr;
  }
}
