* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f1115;
  color: #e6e6e6;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: #1a1d24;
  border-bottom: 1px solid #2a2f3a;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.picker {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  color: #8a8f99;
}
.picker select {
  background: #2a2f3a;
  color: #e6e6e6;
  border: 1px solid #3a4150;
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  max-width: 240px;
}

.upload-btn {
  background: #3b82f6;
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
}
.upload-btn:hover { background: #2563eb; }

.icon-btn {
  background: transparent;
  border: 1px solid #3a4150;
  color: #e6e6e6;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover { background: #2a2f3a; }

.layout {
  flex: 1;
  display: block;
  min-height: 0;
}

.viewer-pane { height: 100%; min-height: 0; min-width: 0; position: relative; }
.viewer-host {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #2a2d34;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: #8a8f99;
  padding: 20px;
}
.empty-state h2 { color: #e6e6e6; margin: 0 0 12px; font-size: 18px; }
.empty-state p { font-size: 13px; max-width: 380px; line-height: 1.5; margin: 0 auto; }

.viewer-host .toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #1a1d24;
  border-bottom: 1px solid #2a2f3a;
  font-size: 12px;
}
.viewer-host .lib-label { font-weight: 600; color: #60a5fa; }
.viewer-host .toolbar button {
  background: #2a2f3a;
  border: 1px solid #3a4150;
  color: #e6e6e6;
  border-radius: 4px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 14px;
}
.viewer-host .toolbar button:hover { background: #3a4150; }
.viewer-host .pagecount { color: #8a8f99; margin-left: auto; }

.viewer-host .pages {
  flex: 1;
  overflow: auto;
  padding: 12px;
  text-align: center;
}
.viewer-host .page {
  display: block;
  margin: 0 auto 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
  background: white;
  max-width: 100%;
}

/* Clamp rendered page to viewer-host width so large PDFs cannot overflow.
   Viewer maintains aspect ratio via intrinsic canvas size. */
.viewer-host canvas,
.viewer-host embed,
.viewer-host iframe {
  max-width: 100%;
  height: auto;
  /* High-DPI: image-rendering hints are mostly no-ops for canvas, but the real fix is
     to render at devicePixelRatio in the renderer (see renderPageToCanvas). */
  image-rendering: -webkit-optimize-contrast;
}

/* Outline toggle button state — highlights when pane is open. */
#outline-toggle[aria-pressed="true"] {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

.outline-pane {
  position: absolute;
  top: 60px;
  right: 12px;
  bottom: 12px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: #1a1d24;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  display: none;             /* default hidden — toggle button ile açılır */
  flex-direction: column;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.outline-pane[data-open="true"] { display: flex; }
.outline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #2a2f3a;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8a8f99;
}
.outline-head button {
  background: none;
  border: 0;
  color: #8a8f99;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.outline-head button:hover { color: #ef4444; }
.outline-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  flex: 1;
}
.outline-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  gap: 8px;
}
.outline-item:hover { background: #2a2f3a; }
.outline-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.outline-page {
  font-size: 11px;
  color: #8a8f99;
  background: #2a2f3a;
  padding: 1px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.need-config {
  margin: 30px auto;
  max-width: 480px;
  background: #1a1d24;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 20px;
}
.need-config h3 { margin: 0 0 8px; color: #fbbf24; font-size: 16px; }
.need-config p { color: #8a8f99; font-size: 13px; line-height: 1.5; }
.need-config code {
  background: #2a2f3a;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}
.need-config a { color: #60a5fa; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1d24;
  border: 1px solid #3a4150;
  color: #e6e6e6;
  padding: 8px 16px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* Performance panel — top bar of the viewer area, not floating overlay. */
.perf-panel {
  display: none;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: center;
  background: #1a1d24;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  padding: 6px 12px;
  margin: 8px 12px 0;
  font: 11px/1.5 ui-monospace, "SFMono-Regular", Menlo, monospace;
  color: #c9d1d9;
  min-height: 24px;
}
.perf-panel[data-open="true"] { display: flex; }
.perf-panel .perf-head { font-size: 11px; padding-right: 6px; border-right: 1px solid #2a2f3a; margin-right: 4px; }
.perf-panel .perf-head b { color: #60a5fa; }
.perf-panel span b { color: #f59e0b; font-weight: 600; }
.perf-panel #perf-row-fps b { color: #34d399; }

@media (max-width: 640px) {
  .topbar { padding: 8px 12px; }
  .topbar h1 { font-size: 14px; }
  .picker select { max-width: 140px; padding: 5px 8px; font-size: 12px; }
  .upload-btn { padding: 5px 10px; font-size: 12px; }
}