:root {
  color-scheme: light;
  --ivory: #F0EEE6;
  --ivory-2: #F6F4EC;
  --ivory-3: #E9E6DC;
  --warm-white: #FAF9F5;
  --navy: #1B3A5C;
  --navy-deep: #16314D;
  --clay: #CC785C;
  --clay-deep: #B5613F;
  --ink: #23252A;
  --ink-soft: #5E6B78;
  --cool: #C9CFD8;
  --line: rgba(27, 58, 92, 0.18);
  --focus: 0 0 0 3px rgba(204, 120, 92, 0.32);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--ivory);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
label.file-tool,
select {
  -webkit-tap-highlight-color: transparent;
}

svg {
  display: block;
  fill: currentColor;
  width: 1.08rem;
  height: 1.08rem;
  flex: 0 0 auto;
}

.appbar {
  min-height: 72px;
  padding: 12px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(240, 238, 230, 0.94);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 196px;
  color: var(--navy);
  text-decoration: none;
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.brand span {
  display: grid;
  gap: 1px;
}

.brand strong {
  font-family: Newsreader, Iowan Old Style, Georgia, serif;
  font-size: 1.22rem;
  font-weight: 500;
  line-height: 1.05;
}

.brand small {
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.1;
}

.primary-actions,
.button-grid,
.edit-rail,
.trust-strip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.primary-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tool-button,
.mini-button,
.segment {
  border: 1px solid var(--line);
  background: var(--warm-white);
  color: var(--navy);
  cursor: pointer;
  min-height: 42px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  font-weight: 650;
  white-space: nowrap;
}

.tool-button:hover,
.mini-button:hover,
.segment:hover {
  border-color: rgba(27, 58, 92, 0.34);
}

.tool-button:focus-visible,
.mini-button:focus-visible,
.segment:focus-visible,
.handle:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.tool-button:disabled,
.mini-button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.tool-button.clay,
.mini-button.clay {
  background: var(--clay);
  border-color: var(--clay);
  color: var(--warm-white);
}

.mini-button.danger {
  color: #8C3E2E;
}

.file-tool {
  position: relative;
}

.file-tool input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  width: min(100%, 1560px);
  margin: 0 auto;
  padding: clamp(12px, 2vw, 24px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(294px, 360px);
  gap: clamp(12px, 2vw, 22px);
  min-height: calc(100vh - 73px);
}

.stage-panel,
.side-panel {
  min-width: 0;
}

.stage-head {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.status-line {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cool);
  box-shadow: 0 0 0 4px rgba(201, 207, 216, 0.28);
}

.status-dot.live {
  background: var(--clay);
  box-shadow: 0 0 0 4px rgba(204, 120, 92, 0.22);
}

.trust-strip {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.trust-strip span {
  border: 1px solid var(--line);
  background: var(--ivory-2);
  color: var(--navy);
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 650;
}

.scan-surface {
  position: relative;
  min-height: 580px;
  height: calc(100vh - 238px);
  max-height: 860px;
  border: 1px solid var(--line);
  background: var(--warm-white);
  overflow: hidden;
  display: grid;
  place-items: center;
}

#cameraView,
#editorCanvas {
  max-width: 100%;
  max-height: 100%;
  display: none;
  background: #111820;
}

#cameraView {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#editorCanvas {
  width: auto;
  height: auto;
}

.scan-surface.camera #cameraView,
.scan-surface.editor #editorCanvas {
  display: block;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--ink-soft);
  text-align: center;
  padding: 28px;
}

.empty-state img {
  width: min(220px, 48vw);
  max-height: 150px;
  object-fit: contain;
  opacity: 0.92;
}

.empty-state strong {
  font-family: Newsreader, Iowan Old Style, Georgia, serif;
  color: var(--navy);
  font-size: clamp(2rem, 4vw, 4.1rem);
  font-weight: 500;
  line-height: 1;
}

.empty-state span {
  font-size: 0.95rem;
}

.scan-surface.camera .empty-state,
.scan-surface.editor .empty-state {
  display: none;
}

.crop-box {
  position: absolute;
  display: none;
  border: 2px solid var(--clay);
  box-shadow: 0 0 0 9999px rgba(22, 49, 77, 0.24);
  cursor: move;
  touch-action: none;
}

.scan-surface.editor .crop-box {
  display: block;
}

.handle {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 2px solid var(--warm-white);
  border-radius: 50%;
  background: var(--clay);
  padding: 0;
  cursor: grab;
}

.handle.nw {
  left: -15px;
  top: -15px;
}

.handle.ne {
  right: -15px;
  top: -15px;
}

.handle.sw {
  left: -15px;
  bottom: -15px;
}

.handle.se {
  right: -15px;
  bottom: -15px;
}

.edit-rail {
  min-height: 62px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  flex-wrap: wrap;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  background: var(--ivory-3);
  border-radius: 8px;
  padding: 3px;
}

.segment {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0 12px;
  color: var(--ink-soft);
}

.segment.active {
  background: var(--warm-white);
  color: var(--navy);
}

.range-control,
.select-control {
  display: grid;
  gap: 7px;
  min-width: 132px;
}

.range-control span,
.select-control span {
  color: var(--ink-soft);
  font-size: 0.76rem;
  font-weight: 700;
}

.range-control input {
  width: 132px;
  accent-color: var(--clay);
}

.side-panel {
  display: grid;
  grid-template-rows: minmax(220px, 1fr) auto auto;
  gap: 12px;
}

.panel-section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.pages-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-head {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head h2 {
  margin: 0;
  color: var(--navy);
  font-family: Newsreader, Iowan Old Style, Georgia, serif;
  font-size: 1.2rem;
  font-weight: 500;
}

#pageCount {
  min-width: 30px;
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--ivory-2);
  color: var(--navy);
  border-radius: 999px;
  font-weight: 700;
}

.page-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.page-card {
  border: 1px solid var(--line);
  background: var(--warm-white);
  border-radius: 8px;
  min-height: 92px;
  padding: 8px;
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
}

.page-card.active {
  border-color: var(--clay);
}

.page-card canvas {
  width: 68px;
  height: 76px;
  object-fit: contain;
  background: var(--ivory-3);
  border: 1px solid rgba(27, 58, 92, 0.12);
}

.page-card strong,
.page-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-card strong {
  color: var(--navy);
  font-size: 0.95rem;
}

.page-card span {
  color: var(--ink-soft);
  font-size: 0.8rem;
  margin-top: 4px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}

.mini-button {
  min-height: 44px;
  padding: 0 10px;
}

.select-control select {
  min-height: 42px;
  border: 1px solid var(--line);
  background: var(--warm-white);
  color: var(--navy);
  border-radius: 8px;
  padding: 0 10px;
  margin-bottom: 10px;
}

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

  .side-panel {
    grid-template-rows: auto;
  }

  .page-list {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    max-height: 340px;
  }
}

@media (max-width: 720px) {
  .appbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .brand {
    min-width: 0;
  }

  .primary-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tool-button {
    padding: 0 8px;
  }

  .tool-button span,
  .mini-button span {
    font-size: 0.82rem;
  }

  .workspace {
    min-height: auto;
    padding: 10px;
  }

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

  .scan-surface {
    min-height: 410px;
    height: 58vh;
  }

  .edit-rail {
    align-items: stretch;
  }

  .segmented {
    width: 100%;
    grid-auto-flow: column;
  }

  .segment {
    padding: 0 6px;
  }

  .range-control {
    flex: 1 1 30%;
    min-width: 96px;
  }

  .range-control input {
    width: 100%;
  }

  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 440px) {
  .primary-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tool-button {
    justify-content: center;
  }

  .trust-strip span {
    font-size: 0.72rem;
  }
}
