:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --ink: #1e2528;
  --muted: #697477;
  --line: #d8d1c7;
  --accent: #1d6f68;
  --accent-strong: #14524d;
  --warn: #9a4e17;
  --shadow: 0 20px 50px rgba(32, 29, 23, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
}

button {
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

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

button:not(:disabled):hover,
select:hover {
  border-color: #9bb7b3;
}

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

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  min-width: 0;
}

.topbar,
.upload-panel,
.viewer-panel,
.thumb-strip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.05;
  letter-spacing: 0;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 92px;
  border: 1px solid #b6cfc9;
  border-radius: 999px;
  padding: 7px 12px;
  background: #eef8f5;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-pill.is-error {
  border-color: #e4b38c;
  background: #fff4ea;
  color: var(--warn);
}

.upload-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(240px, 0.65fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
}

#fileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.drop-target {
  display: grid;
  gap: 4px;
  min-height: 64px;
  border: 1px dashed #a9aaa3;
  border-radius: 8px;
  padding: 12px 14px;
  background: #fffaf2;
  cursor: pointer;
}

.drop-target:hover,
.upload-panel.is-dragging .drop-target {
  border-color: var(--accent);
  background: #f1fbf8;
}

.drop-title {
  font-size: 16px;
  font-weight: 800;
}

.drop-meta {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-row {
  display: grid;
  gap: 6px;
  min-width: 150px;
}

.settings-row label,
.progress-group {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.settings-row select {
  min-height: 38px;
  padding: 0 10px;
}

.progress-group {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ded4;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.viewer-toolbar {
  display: grid;
  grid-template-columns: auto auto minmax(220px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.page-jump {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.page-jump input {
  width: 100%;
  accent-color: var(--accent);
}

.book-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 540px;
  padding: 22px;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(29, 111, 104, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(29, 111, 104, 0.05) 1px, transparent 1px),
    #eee8de;
  background-size: 24px 24px;
}

.empty-state {
  display: grid;
  gap: 8px;
  max-width: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 253, 250, 0.9);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.book-mount {
  display: grid;
  place-items: center;
  width: min(100%, 1280px);
}

.book {
  margin: 0 auto;
  filter: drop-shadow(var(--shadow));
}

.stf__parent {
  margin-inline: auto;
}

.book-page {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: #ffffff;
  backface-visibility: hidden;
}

.book-page::after {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  content: "";
  box-shadow: inset 0 0 0 1px rgba(31, 37, 40, 0.08);
}

.page-image,
.page-fallback,
.svg-layer,
.textLayer {
  position: absolute;
  inset: 0;
}

.page-image,
.page-fallback,
.svg-layer {
  width: 100%;
  height: 100%;
}

.page-image,
.page-fallback {
  z-index: 1;
  object-fit: contain;
  user-select: none;
}

.page-fallback {
  display: none;
}

.svg-layer {
  z-index: 2;
  display: block;
  background: #ffffff;
}

.textLayer {
  z-index: 4;
  overflow: hidden;
  text-align: initial;
  line-height: 1;
  pointer-events: none;
  transform-origin: 0 0;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
}

.textLayer span,
.textLayer br {
  position: absolute;
  color: transparent;
  white-space: pre;
  transform-origin: 0 0;
}

.textLayer ::selection {
  background: rgba(29, 111, 104, 0.24);
}

.page-number-badge {
  position: absolute;
  right: 10px;
  bottom: 8px;
  z-index: 6;
  min-width: 24px;
  border-radius: 999px;
  padding: 4px 7px;
  background: rgba(255, 255, 255, 0.72);
  color: rgba(30, 37, 40, 0.64);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.thumb-strip {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.thumb-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.thumb-list {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  overflow: auto;
}

.thumb-button {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 76px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  text-align: left;
}

.thumb-button.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.thumb-button img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border: 1px solid #e6e1d8;
  border-radius: 4px;
  background: #ffffff;
}

.thumb-button span {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .thumb-strip {
    max-height: 190px;
  }

  .thumb-list {
    grid-auto-flow: column;
    grid-auto-columns: 140px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .thumb-button {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app {
    padding: 8px;
  }

  .topbar,
  .upload-panel,
  .viewer-toolbar {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  .status-pill {
    width: 100%;
  }

  .upload-panel {
    display: grid;
  }

  .viewer-toolbar {
    display: grid;
  }

  .page-jump {
    grid-template-columns: 1fr;
  }

  .book-stage {
    min-height: 420px;
    padding: 14px;
  }
}
