:root {
  --bg: #dfe2d2;
  --panel: rgba(245, 247, 238, 0.94);
  --panel-warm: linear-gradient(180deg, rgba(244, 247, 236, 0.98), rgba(232, 236, 221, 0.96));
  --panel-cool: linear-gradient(180deg, rgba(250, 250, 245, 0.98), rgba(243, 243, 237, 0.96));
  --ink: #1d2733;
  --muted: #5e6d74;
  --line: #bdc3af;
  --accent: #b35a2b;
  --accent-soft: rgba(179, 90, 43, 0.14);
  --cool-soft: rgba(108, 116, 90, 0.1);
  --cool-accent: #6f7461;
  --workspace-panel: linear-gradient(160deg, rgba(255, 255, 252, 0.98), rgba(248, 248, 244, 0.96));
  --workspace-edge: #d9ddd0;
  --workspace-ink: #34392f;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(179, 90, 43, 0.16), transparent 30%),
    radial-gradient(circle at 88% 14%, rgba(108, 116, 90, 0.14), transparent 34%),
    linear-gradient(180deg, #edf0e1 0%, var(--bg) 100%);
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
}

.card {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  box-shadow:
    0 16px 38px rgba(64, 47, 26, 0.09),
    0 2px 0 rgba(255, 255, 255, 0.45) inset;
}

.left-rail,
.image-pane {
  overflow: hidden;
}

.left-rail {
  height: 100%;
  background:
    radial-gradient(circle at top left, rgba(179, 90, 43, 0.1), transparent 28%),
    var(--panel-warm);
}

.image-pane {
  height: 100%;
  background:
    radial-gradient(circle at top right, rgba(108, 116, 90, 0.12), transparent 28%),
    var(--panel-cool);
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.app-title {
  font-size: clamp(1.45rem, 2vw, 1.95rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.app-badge {
  border-color: var(--line) !important;
  color: var(--muted) !important;
  background: rgba(255, 255, 255, 0.78) !important;
  font-weight: 600;
}

.section-block + .section-block {
  margin-top: 1.5rem;
}

.section-block {
  border: 1px solid rgba(189, 195, 175, 0.82);
  border-radius: 18px;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.34);
}

.tool-controls {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), rgba(242, 246, 234, 0.3));
}

.section-title {
  font-size: 0.98rem;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.app-legal {
  font-size: 0.75rem;
  line-height: 1.35;
  color: rgba(52, 57, 47, 0.7);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  min-height: 88px;
  line-height: 1.55;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    0 1px 2px rgba(25, 34, 42, 0.04);
}

#manualResultsText {
  border-color: rgba(179, 90, 43, 0.34);
  background:
    linear-gradient(180deg, rgba(250, 252, 244, 0.96), rgba(239, 244, 231, 0.92));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 6px 16px rgba(179, 90, 43, 0.06);
}

.toolbar-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.65rem;
}

.toolbar-buttons-rotation {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.btn {
  border-radius: 12px;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 0.8rem;
  white-space: nowrap;
}

.has-tooltip {
  position: relative;
}

.has-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(4px);
  background: rgba(29, 39, 51, 0.92);
  color: #fffdf8;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  font-size: 0.77rem;
  line-height: 1.1;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  box-shadow: 0 10px 24px rgba(29, 39, 51, 0.18);
  z-index: 10;
}

.has-tooltip:hover::after,
.has-tooltip:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

label.has-tooltip::after {
  left: 0;
  transform: translateX(0) translateY(4px);
}

label.has-tooltip:hover::after,
label.has-tooltip:focus-visible::after {
  transform: translateX(0) translateY(0);
}

.btn-outline-secondary {
  --bs-btn-color: var(--ink);
  --bs-btn-border-color: rgba(176, 185, 164, 0.95);
  --bs-btn-hover-bg: rgba(111, 116, 97, 0.12);
  --bs-btn-hover-border-color: rgba(111, 116, 97, 0.38);
  --bs-btn-hover-color: var(--ink);
  --bs-btn-active-bg: rgba(179, 90, 43, 0.18);
  --bs-btn-active-border-color: rgba(179, 90, 43, 0.4);
  --bs-btn-active-color: var(--ink);
  background:
    linear-gradient(180deg, rgba(251, 252, 247, 0.98), rgba(239, 243, 232, 0.96));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.form-select {
  border-color: rgba(176, 185, 164, 0.95);
  border-radius: 12px;
  background-color: rgba(251, 252, 247, 0.98);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.form-select:focus {
  border-color: rgba(179, 90, 43, 0.4);
  box-shadow:
    0 0 0 0.2rem rgba(179, 90, 43, 0.14),
    0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.workspace-shell {
  margin-top: 0;
}

.left-rail .card-body {
  overflow: visible;
}

.workspace {
  position: relative;
  min-height: 760px;
  max-height: calc(100vh - 56px);
  overflow: auto;
  border: 1px solid var(--workspace-edge);
  border-radius: 18px;
  background:
    var(--workspace-panel),
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(244, 244, 238, 0.18));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    0 16px 28px rgba(61, 57, 43, 0.08);
}

.workspace.page-scroll-mode {
  max-height: none;
  overflow: visible;
}

.workspace.drag-active {
  border-color: rgba(179, 90, 43, 0.45);
  box-shadow:
    inset 0 0 0 2px rgba(179, 90, 43, 0.16),
    0 18px 34px rgba(91, 93, 78, 0.08);
  background:
    linear-gradient(160deg, rgba(255, 255, 252, 0.98), rgba(247, 247, 241, 0.96)),
    linear-gradient(135deg, rgba(179, 90, 43, 0.08), rgba(111, 116, 97, 0.05));
}

.workspace-empty {
  display: grid;
  place-items: center;
  min-height: 420px;
  color: var(--muted);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
}

.upload-title {
  font-size: 1.08rem;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--workspace-ink);
}

.upload-copy {
  font-size: 0.95rem;
  color: #6d6f63;
  white-space: nowrap;
}

.canvas-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
}

.rotated-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
}

.canvas-stage img {
  position: absolute;
  inset: 0;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  filter: saturate(1.02) contrast(1.01);
}

.canvas-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.loupe {
  position: absolute;
  left: 0;
  top: 0;
  width: 176px;
  height: 176px;
  border-radius: 20px;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
  border: 1px solid rgba(111, 116, 97, 0.35);
  background: rgba(255, 255, 252, 0.96);
  box-shadow:
    0 18px 34px rgba(29, 39, 51, 0.18),
    0 1px 0 rgba(255, 255, 255, 0.72) inset;
}

.loupe::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 14px;
  border: 1px solid rgba(29, 39, 51, 0.1);
  pointer-events: none;
}

.loupe canvas {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 1599px) {
  .workspace {
    min-height: 520px;
    max-height: 72vh;
  }

  .workspace.page-scroll-mode {
    max-height: none;
  }

  .toolbar-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1600px) {
  .left-rail {
    position: sticky;
    top: 1rem;
  }
}

@media (max-width: 991px) {
  .btn {
    white-space: normal;
    line-height: 1.2;
  }

  .section-title {
    white-space: normal;
  }

  .upload-copy {
    white-space: normal;
  }
}

@media (max-width: 767px) {
  .toolbar-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-buttons-rotation {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
