:root {
  font-family: 'Trebuchet MS', 'Avenir Next', 'Segoe UI', sans-serif;
  color: #111318;
  background:
    radial-gradient(circle at top left, rgba(236, 73, 73, 0.16), transparent 30%),
    radial-gradient(circle at top right, rgba(11, 17, 29, 0.08), transparent 28%),
    linear-gradient(180deg, #f6eee6 0%, #efe0d2 100%);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  --bg-card: rgba(255, 252, 248, 0.78);
  --bg-card-strong: rgba(255, 255, 255, 0.92);
  --ink: #12141a;
  --muted: #5f6572;
  --line: rgba(17, 19, 24, 0.11);
  --accent: #e43f36;
  --accent-dark: #a32620;
  --accent-soft: rgba(228, 63, 54, 0.12);
  --success: #205d3b;
  --error: #8e2020;
  --shadow: 0 24px 70px rgba(31, 22, 15, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

a {
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
}

#app {
  min-height: 100vh;
}

.is-hidden {
  display: none !important;
}

.shell {
  width: min(1380px, calc(100vw - 32px));
  margin: 0 auto;
  padding:
    max(20px, env(safe-area-inset-top))
    0
    max(56px, env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 18px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  margin-bottom: 26px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  background: rgba(255, 249, 243, 0.78);
  backdrop-filter: blur(18px);
  box-shadow: 0 14px 32px rgba(53, 34, 22, 0.09);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff6f4;
  font-size: 0.85rem;
}

.brand__text {
  font-size: 1.05rem;
  text-transform: lowercase;
}

.topbar__nav {
  display: inline-flex;
  gap: 18px;
  color: var(--muted);
  font-size: 0.96rem;
}

.topbar__nav a {
  transition: color 160ms ease;
}

.topbar__nav a:hover {
  color: var(--ink);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  gap: 28px;
  align-items: stretch;
}

.hero__copy,
.dropzone__panel,
.statusbar,
.stat-card,
.panel {
  border: 1px solid rgba(255, 255, 255, 0.46);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.hero__copy {
  position: relative;
  overflow: hidden;
  padding: 44px;
  border-radius: var(--radius-lg);
}

.hero__copy::after {
  content: '';
  position: absolute;
  inset: auto -20% -45% auto;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(228, 63, 54, 0.18) 0%, transparent 68%);
  pointer-events: none;
}

.eyebrow,
.workspace__eyebrow,
.dropzone__label {
  margin: 0 0 14px;
  color: var(--accent-dark);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  max-width: 12ch;
  font-size: clamp(3rem, 8vw, 5.8rem);
  line-height: 0.94;
  letter-spacing: -0.045em;
}

.hero__lede {
  max-width: 60ch;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.7;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 28px;
}

.hero__notes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 34px 0 0;
  padding: 0;
  list-style: none;
}

.hero__notes li {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.dropzone {
  display: flex;
  min-height: 100%;
  border-radius: var(--radius-lg);
  transition:
    transform 180ms ease,
    border-color 180ms ease;
}

.dropzone.is-dragover {
  transform: translateY(-4px);
}

.dropzone__panel {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding: 34px;
  border-radius: inherit;
}

.dropzone__panel::before {
  content: '';
  position: absolute;
  inset: 14px;
  border: 1.5px dashed rgba(228, 63, 54, 0.4);
  border-radius: calc(var(--radius-lg) - 10px);
  pointer-events: none;
}

.dropzone__panel h2 {
  margin: 0;
  font-size: clamp(1.9rem, 4vw, 2.8rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.dropzone__panel p {
  margin: 16px 0 0;
  max-width: 34ch;
  color: var(--muted);
  line-height: 1.65;
}

.dropzone__hint {
  font-family: 'SFMono-Regular', 'Cascadia Code', 'Liberation Mono', monospace;
  font-size: 0.84rem;
  letter-spacing: 0.03em;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 999px;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

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

.button--primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff9f6;
}

.button--ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink);
}

.button--small {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.94rem;
}

.button--wide {
  width: 100%;
  margin-top: 24px;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 28px;
  padding: 18px 22px;
  border-radius: 22px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(17, 19, 24, 0.08);
  font-weight: 700;
  font-size: 0.9rem;
}

.status-pill[data-tone='working'] {
  background: rgba(228, 63, 54, 0.12);
  color: var(--accent-dark);
}

.status-pill[data-tone='success'] {
  background: rgba(32, 93, 59, 0.12);
  color: var(--success);
}

.status-pill[data-tone='error'] {
  background: rgba(142, 32, 32, 0.12);
  color: var(--error);
}

.status-text {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.stat-card {
  padding: 22px;
  border-radius: 22px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  line-height: 1.25;
  word-break: break-word;
}

.workspace {
  margin-top: 26px;
}

.workspace.is-hidden {
  display: none;
}

.workspace__toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.workspace__toolbar h2 {
  margin: 0;
  font-size: clamp(1.9rem, 3vw, 2.9rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.workspace__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.zoom-control {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  min-height: 52px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
}

.zoom-control span {
  color: var(--muted);
  font-size: 0.92rem;
}

.zoom-control input {
  width: 140px;
  min-width: 0;
}

.workspace__grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 360px;
  gap: 18px;
}

.panel {
  min-height: 0;
  padding: 18px;
  border-radius: 28px;
}

.panel__heading {
  margin-bottom: 16px;
}

.panel__heading h3,
.panel__heading p,
.panel__heading--spaced h3 {
  margin: 0;
}

.panel__heading h3 {
  font-size: 1.12rem;
}

.panel__heading p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.95rem;
}

.panel__heading--inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel__heading--spaced {
  margin-top: 24px;
}

.preview-nav {
  display: flex;
  gap: 8px;
}

.page-list,
.text-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.page-list {
  scroll-padding-inline: 18px;
}

.page-chip,
.text-row {
  width: 100%;
  min-height: 56px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.48);
  text-align: left;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.page-chip:hover,
.text-row:hover {
  transform: translateY(-1px);
  border-color: rgba(228, 63, 54, 0.36);
}

.page-chip.is-active,
.text-row.is-selected {
  border-color: rgba(228, 63, 54, 0.5);
  background: rgba(228, 63, 54, 0.12);
}

.page-chip__title,
.text-row__title {
  display: block;
  color: var(--ink);
  font-weight: 700;
}

.page-chip__meta,
.text-row__meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-row__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-shell {
  min-height: 720px;
  padding: 14px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0.72)),
    linear-gradient(90deg, rgba(17, 19, 24, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(17, 19, 24, 0.04) 1px, transparent 1px);
  background-size: auto, 18px 18px, 18px 18px;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.canvas-stack {
  position: relative;
  margin: 0 auto;
  min-width: fit-content;
}

#pdf-canvas {
  display: block;
  width: 100%;
  height: auto;
  box-shadow: 0 28px 50px rgba(18, 20, 26, 0.18);
  background: #ffffff;
}

.text-overlay {
  position: absolute;
  inset: 0;
}

.overlay-cover {
  position: absolute;
  z-index: 0;
  background: #ffffff;
  pointer-events: none;
}

.overlay-hit {
  position: absolute;
  z-index: 1;
  border: 1px solid rgba(228, 63, 54, 0.34);
  border-radius: 8px;
  background: rgba(228, 63, 54, 0.08);
}

.overlay-hit.is-edited {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0 2px 1px;
  overflow: visible;
  background: transparent;
  border-color: transparent;
  color: #141821;
  box-shadow: none;
}

.overlay-hit.is-movable {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.overlay-hit.is-movable:active {
  cursor: grabbing;
}

.overlay-hit.is-selected {
  background: rgba(228, 63, 54, 0.18);
  border-color: rgba(228, 63, 54, 0.8);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.56);
}

.overlay-hit.is-edited.is-selected {
  background: transparent;
  border-color: rgba(228, 63, 54, 0.8);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.56);
}

.overlay-hit__text {
  display: inline-block;
  width: max-content;
  max-width: none;
  overflow: visible;
  color: #141821;
  font-family: 'Helvetica', 'Arial', sans-serif;
  line-height: 1.08;
  text-align: left;
  white-space: nowrap;
  pointer-events: none;
}

.inspector {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.46);
}

.inspector.is-hidden {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field + .field {
  margin-top: 16px;
}

.field span {
  color: var(--muted);
  font-size: 0.9rem;
}

.field__readonly,
textarea {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.85);
}

.field__readonly {
  min-height: 72px;
  line-height: 1.6;
}

textarea {
  min-height: 126px;
  resize: vertical;
  color: var(--ink);
  font-size: 16px;
}

.inspector__meta {
  margin-top: 12px;
  color: var(--muted);
  font-family: 'SFMono-Regular', 'Cascadia Code', 'Liberation Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
}

.inspector__actions {
  margin-top: 16px;
}

.empty-state {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  line-height: 1.65;
}

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

  .workspace__grid {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .panel--editor {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .shell {
    width: min(100vw - 20px, 100%);
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .topbar {
    position: static;
    border-radius: 28px;
  }

  .topbar,
  .workspace__toolbar,
  .panel__heading--inline,
  .statusbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar__nav,
  .workspace__controls {
    justify-content: space-between;
  }

  .workspace__controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    width: 100%;
  }

  .workspace__controls > * {
    width: 100%;
  }

  .hero__copy,
  .dropzone__panel {
    padding: 28px;
  }

  .hero__notes,
  .stats,
  .workspace__grid {
    grid-template-columns: 1fr;
  }

  .panel--preview {
    order: 1;
  }

  .panel--pages {
    order: 2;
  }

  .panel--editor {
    order: 3;
    grid-column: auto;
  }

  .page-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 6px;
    margin: 0 -4px;
    padding-inline: 4px;
    scroll-snap-type: x proximity;
  }

  .page-chip {
    min-width: 160px;
    scroll-snap-align: start;
  }

  .preview-shell {
    min-height: min(70dvh, 560px);
  }

  .panel--preview .panel__heading--inline {
    gap: 16px;
  }

  .panel--preview .preview-nav {
    width: 100%;
  }

  .panel--preview .preview-nav .button {
    flex: 1 1 0;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 12px, 100%);
  }

  .topbar,
  .hero__copy,
  .dropzone__panel,
  .statusbar,
  .stat-card,
  .panel {
    border-radius: 20px;
  }

  .hero h1 {
    max-width: none;
    font-size: clamp(2.6rem, 15vw, 3.8rem);
  }

  .hero__copy,
  .dropzone__panel,
  .statusbar,
  .panel,
  .stat-card {
    padding-inline: 18px;
  }

  .workspace {
    margin-top: 18px;
  }

  .workspace__toolbar {
    gap: 12px;
    margin-bottom: 12px;
  }

  .workspace__toolbar h2 {
    font-size: clamp(1.5rem, 8vw, 2rem);
  }

  .hero__actions,
  .preview-nav {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button,
  .zoom-control {
    width: 100%;
  }

  .button,
  .page-chip,
  .text-row,
  textarea,
  .field__readonly {
    font-size: 16px;
  }

  .workspace__controls {
    grid-template-columns: 1fr;
  }

  .workspace__controls > * {
    min-width: 0;
  }

  .panel {
    padding: 16px;
  }

  .panel__heading {
    margin-bottom: 12px;
  }

  .preview-shell {
    min-height: min(58dvh, 440px);
    padding: 8px;
  }

  .page-chip {
    min-width: 78vw;
  }

  .page-list {
    gap: 8px;
    padding-bottom: 2px;
  }

  .text-list {
    gap: 8px;
  }

  .panel--pages .panel__heading p,
  .panel--editor .panel__heading p {
    font-size: 0.9rem;
  }

  .panel--preview {
    padding: 12px;
  }

  .panel--preview .panel__heading--inline {
    margin-bottom: 10px;
  }

  .panel--preview .preview-nav {
    gap: 10px;
  }

  .overlay-hit {
    min-height: 24px;
  }

  .topbar__nav {
    flex-wrap: wrap;
    gap: 10px;
  }
}
