:root {
  --bg-0: #fff7ea;
  --bg-1: #dcf4ff;
  --ink: #101829;
  --muted: #42526f;
  --line: rgba(16, 24, 41, 0.12);
  --card: rgba(255, 255, 255, 0.86);
  --accent: #007965;
  --accent-strong: #025847;
  --glow: rgba(0, 121, 101, 0.26);
  --warn: #9e2a2b;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Manrope", "Segoe UI", sans-serif;
  background:
    radial-gradient(1800px 800px at 10% -10%, #ffffff, transparent 60%),
    linear-gradient(135deg, var(--bg-0), var(--bg-1));
  min-height: 100vh;
  overflow-x: hidden;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(26, 33, 43, 0.34);
}

.login-overlay-card {
  width: min(460px, 92vw);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 20px 40px rgba(8, 14, 24, 0.28);
  padding: 1.1rem;
  display: grid;
  gap: 0.7rem;
}

.login-overlay-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.login-overlay-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

body.auth-locked .shell,
body.auth-locked .bg-orb {
  filter: grayscale(0.5) blur(3px);
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}

.bg-orb {
  position: fixed;
  width: 34vw;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}

.orb-a {
  top: -12vw;
  right: -8vw;
  background: #ffe58f;
  animation: driftA 12s ease-in-out infinite alternate;
}

.orb-b {
  bottom: -16vw;
  left: -8vw;
  background: #9fd5ff;
  animation: driftB 14s ease-in-out infinite alternate;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1320px, 96vw);
  margin: 1rem auto 1.8rem;
}

.upload-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 18px rgba(19, 33, 59, 0.08);
  padding: 0.8rem;
  display: grid;
  gap: 0.6rem;
}

.hidden-file-input {
  display: none;
}

button {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 700;
  padding: 0.74rem 0.9rem;
  cursor: pointer;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
}

button:hover {
  filter: saturate(1.1);
}

button:disabled {
  opacity: 0.66;
  cursor: progress;
}

#status {
  margin: 0;
  color: #2a446f;
  font-size: 0.93rem;
  line-height: 1.25;
}

.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1rem;
  position: relative;
}

body.menu-open .workspace > :not(#side-menu) {
  filter: blur(2px) grayscale(0.15);
  opacity: 0.62;
  pointer-events: none;
  user-select: none;
}

.card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  backdrop-filter: blur(7px);
  box-shadow: 0 16px 34px rgba(19, 33, 59, 0.1);
}

.left-rail {
  padding: 0.85rem;
  display: grid;
  gap: 0.7rem;
  align-content: start;
}

.side-menu {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 312px;
  padding: 0.65rem;
  display: grid;
  grid-template-rows: auto 1fr;
  align-content: start;
  gap: 0.55rem;
  z-index: 24;
  pointer-events: auto;
}

.side-menu.collapsed {
  display: none;
}

.side-menu-content {
  display: grid;
  gap: 0.7rem;
  align-content: start;
  overflow: auto;
}

.side-menu-header {
  display: flex;
  justify-content: flex-end;
}

.side-menu-close-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
}

.rail-section {
  display: grid;
  gap: 0.42rem;
}

.rail-section.intro h1 {
  margin: 0;
  font-size: 1.1rem;
}

.rail-section.intro p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.rail-section h2 {
  margin: 0;
  font-size: 0.92rem;
  font-family: "Space Grotesk", sans-serif;
}

.transcript {
  margin: 0;
  min-height: 125px;
  max-height: 220px;
  overflow: auto;
  background: #111827;
  border-radius: 12px;
  color: #dbf7ff;
  padding: 0.7rem;
  line-height: 1.38;
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.transcript.typing::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 3px;
  background: #5ff5c3;
  animation: blink 0.9s steps(1) infinite;
}

.timeline {
  display: grid;
  gap: 0.4rem;
}

.pipeline-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f3f7ff, #e8eefc);
  overflow: hidden;
}

.pipeline-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3ecf8e, #0c8f73);
  box-shadow: 0 0 12px rgba(12, 143, 115, 0.45);
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pipeline-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.line-list {
  max-height: 240px;
  overflow: auto;
  display: grid;
  gap: 0.34rem;
}

.line-list.collapsed {
  display: none;
}

.section-toggle {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: #243754;
  border-radius: 9px;
  padding: 0.38rem 0.52rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
}

.line-chip {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 10px;
  padding: 0.34rem 0.45rem;
  font-size: 0.77rem;
  color: #27344f;
  cursor: pointer;
}

.line-chip:hover,
.line-chip.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--glow);
}

.auth-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.42rem;
  background: rgba(255, 255, 255, 0.82);
}

.account-panel {
  display: grid;
  gap: 0.42rem;
}

.account-panel.collapsed {
  display: none;
}

.auth-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.45rem;
  background: #fff;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
}

.user-text {
  min-width: 0;
  display: grid;
  gap: 0.05rem;
}

.user-text strong {
  font-size: 0.8rem;
  line-height: 1.1;
}

.user-text span {
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
}

.credits-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.82rem;
}

.buy-actions {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}

.buy-actions .ghost {
  padding: 0.28rem 0.45rem;
  font-size: 0.76rem;
}

.referral-block {
  display: grid;
  gap: 0.34rem;
}

.referral-copy {
  margin: 0;
  font-size: 0.74rem;
  color: var(--muted);
}

.referral-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.32rem;
}

#referral-link {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.34rem 0.42rem;
  font: inherit;
  font-size: 0.72rem;
  color: #22324f;
  background: #fff;
}

.history-list {
  max-height: 180px;
  overflow: auto;
  display: grid;
  gap: 0.32rem;
}

.history-item {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  color: #1f3553;
  border-radius: 9px;
  padding: 0.38rem 0.45rem;
  cursor: pointer;
  font-size: 0.76rem;
  line-height: 1.25;
}

.history-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--glow);
}

.download-link {
  margin-top: 0;
  text-decoration: none;
  color: #0d4f3f;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.prominent-download {
  background: linear-gradient(145deg, #0e8f75, #0b6f5b);
  color: #ffffff;
  border: 1px solid rgba(5, 74, 62, 0.65);
  box-shadow: 0 10px 18px rgba(11, 111, 91, 0.24), 0 0 0 1px rgba(255, 255, 255, 0.24) inset;
  padding: 0.5rem 0.9rem;
  border-radius: 11px;
}

.prominent-download:hover {
  filter: saturate(1.08) brightness(1.03);
  box-shadow: 0 12px 20px rgba(11, 111, 91, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.3) inset;
}

.new-upload-btn {
  padding: 0.46rem 0.75rem;
  border-radius: 11px;
}

.viewer {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.viewer-topbar {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.viewer-tools {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

#menu-open-btn {
  position: relative;
  z-index: 30;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 22;
  background: rgba(20, 28, 41, 0.34);
  backdrop-filter: blur(1px);
}

.viewer-download-row {
  border-top: 1px solid var(--line);
  padding: 0.75rem 0.8rem 0.9rem;
}

.full-width-download {
  width: 100%;
  min-height: 2.65rem;
  font-size: 0.98rem;
  text-align: center;
}

.icon-toggle-btn {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.material-symbols-outlined {
  font-size: 1.2rem;
  line-height: 1;
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ghost {
  background: #fff;
  color: #26334f;
  border: 1px solid var(--line);
  font-weight: 600;
  padding: 0.35rem 0.55rem;
}

.action-row .ghost {
  border-radius: 12px;
  padding-inline: 0.85rem;
}

.refine-btn {
  width: 100%;
}

.mode-switch-row {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.mode-label {
  font-weight: 700;
  color: #2b3d5a;
}

.mode-switch {
  position: relative;
  width: 42px;
  height: 24px;
  display: inline-block;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.mode-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  transition: background 0.18s ease;
}

.mode-slider::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  transition: transform 0.18s ease;
}

.mode-switch input:checked + .mode-slider::before {
  transform: translateX(18px);
}

.mode-info {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.72rem;
  font-weight: 800;
  color: #2b3d5a;
  background: #fff;
  cursor: help;
}

.mode-tooltip {
  position: absolute;
  left: 50%;
  top: 26px;
  transform: translateX(-50%);
  min-width: 230px;
  max-width: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.38rem 0.48rem;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 20px rgba(18, 32, 56, 0.16);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 35;
}

.mode-info:hover .mode-tooltip,
.mode-info:focus-visible .mode-tooltip {
  opacity: 1;
  visibility: visible;
}

.refine-prompt-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: #fff;
}

.legend {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #3a4a69;
  font-size: 0.82rem;
}

.legend-box {
  width: 14px;
  height: 10px;
  border: 1px solid rgba(193, 56, 56, 0.92);
  background: rgba(255, 187, 69, 0.25);
  border-radius: 3px;
}

.canvas-wrap {
  position: relative;
  min-height: 540px;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: linear-gradient(150deg, #f8fbff, #eef2ff);
  cursor: pointer;
}

.canvas-wrap.dragover {
  box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 8px rgba(0, 121, 101, 0.09);
}

.upload-hint {
  position: absolute;
  z-index: 2;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.92);
  color: #2f476d;
  font-size: 0.84rem;
  pointer-events: none;
}

.upload-hint.hidden {
  display: none;
}

#pdf-canvas {
  max-width: 100%;
  max-height: 72vh;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 20px 30px rgba(13, 24, 42, 0.22);
  transform-origin: center center;
  animation: fadeIn 0.38s ease;
}

.box-layer {
  position: absolute;
  pointer-events: auto;
}

.selection-marquee {
  position: absolute;
  border: 1px solid rgba(13, 122, 101, 0.9);
  background: rgba(13, 122, 101, 0.14);
  border-radius: 4px;
  pointer-events: none;
  z-index: 8;
}

.overlay-box {
  position: absolute;
  border: 1px solid transparent;
  background: rgba(255, 188, 77, 0.2);
  border-radius: 4px;
  opacity: 1;
  transform: none;
  cursor: grab;
  overflow: visible;
}

.overlay-box.focused {
  border-color: #0d7a65;
  box-shadow: 0 0 0 3px var(--glow);
  background: rgba(84, 247, 186, 0.19);
}

.overlay-box.dragging {
  cursor: grabbing;
}

.overlay-box-text {
  position: absolute;
  left: 2px;
  top: 2px;
  right: 2px;
  line-height: 1.06;
  color: #6f1f1f;
  background: rgba(255, 255, 255, 0.78);
  border-radius: 3px;
  padding: 0.08rem 0.14rem;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  text-overflow: clip;
  pointer-events: none;
  z-index: 1;
}

.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 3px;
  border: 1px solid #0b6f5b;
  background: #d8fff3;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.65);
  pointer-events: auto;
  z-index: 2;
}

.handle-nw { left: -4px; top: -4px; }
.handle-ne { right: -4px; top: -4px; }
.handle-sw { left: -4px; bottom: -4px; }
.handle-se { right: -4px; bottom: -4px; }
.handle-n { left: calc(50% - 4px); top: -4px; }
.handle-s { left: calc(50% - 4px); bottom: -4px; }
.handle-w { left: -4px; top: calc(50% - 4px); }
.handle-e { right: -4px; top: calc(50% - 4px); }
.handle-n,
.handle-s { cursor: ns-resize; }
.handle-e,
.handle-w { cursor: ew-resize; }
.handle-ne,
.handle-sw { cursor: nesw-resize; }
.handle-nw,
.handle-se { cursor: nwse-resize; }

.rotate-handle {
  position: absolute;
  left: 50%;
  top: -19px;
  width: 14px;
  height: 14px;
  margin-left: -5px;
  border-radius: 50%;
  border: 1px solid #0b6f5b;
  background: #b8ffe6;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.72);
  cursor: grab;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font: inherit;
  color: #0b6f5b;
}

.rotate-handle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 14px;
  width: 1px;
  height: 8px;
  margin-left: -0.5px;
  background: rgba(11, 111, 91, 0.85);
}

.rotate-handle::after {
  content: "⟳";
  font-size: 10px;
  line-height: 1;
}

.box-editor {
  display: grid;
  gap: 0.35rem;
}

.box-tooltip {
  position: fixed;
  z-index: 99;
  max-width: min(320px, 70vw);
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(16, 24, 41, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #122038;
  font-size: 0.78rem;
  line-height: 1.25;
  box-shadow: 0 12px 24px rgba(18, 32, 56, 0.18);
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.box-tooltip.hidden {
  display: none;
}

#selected-box-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

#selected-box-text {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem;
  font: inherit;
  font-size: 0.8rem;
}

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

  .side-menu {
    position: fixed;
    top: 0.7rem;
    right: 0.7rem;
    bottom: 0.7rem;
    width: min(86vw, 340px);
    max-height: calc(100vh - 1.4rem);
  }

  .side-menu.collapsed {
    display: none;
  }

  .canvas-wrap {
    min-height: 420px;
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes riseIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes driftA {
  from {
    transform: translateY(0px);
  }
  to {
    transform: translateY(20px);
  }
}

@keyframes driftB {
  from {
    transform: translateY(0px);
  }
  to {
    transform: translateY(-18px);
  }
}
