:root {
  color-scheme: light;
  --ink: #1d2733;
  --muted: #607080;
  --line: #d9e1e8;
  --surface: #ffffff;
  --wash: #f4f7fa;
  --accent: #176b5f;
  --accent-strong: #0f5148;
  --warn: #9a5b00;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.panel {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 24px;
}

.brand {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.05;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 150px;
  margin-bottom: 16px;
  border: 2px dashed #b7c6d4;
  border-radius: 8px;
  background: #f9fbfc;
  cursor: pointer;
  text-align: center;
}

.dropzone.dragging {
  border-color: var(--accent);
  background: #eef8f6;
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone span {
  display: block;
  font-weight: 700;
}

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

.toolbar,
.settings {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.tool,
.settings label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.tool input,
.settings select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
}

.saved-asset {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--muted);
  background: #f9fbfc;
}

.saved-asset.ready {
  color: var(--accent-strong);
}

.saved-asset img {
  max-width: 48px;
  max-height: 26px;
  object-fit: contain;
}

.primary {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.secondary {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.secondary:disabled {
  color: #94a1ad;
  cursor: not-allowed;
}

.scan-toggle,
.compression-toggle {
  margin-bottom: 10px;
}

.scan-toggle.active,
.compression-toggle.medium {
  border-color: var(--accent);
  background: #eef8f6;
  color: var(--accent-strong);
}

.compression-toggle.strong {
  border-color: #a16000;
  background: #fff7e8;
  color: #7a4400;
}

.primary:disabled {
  background: #9ab6b1;
  cursor: not-allowed;
}

.status {
  margin-top: 12px;
  color: var(--warn);
  font-size: 14px;
}

.archive-open {
  width: 100%;
  margin-top: 10px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 700;
  text-decoration: underline;
}

.archive-modal {
  width: min(720px, calc(100vw - 28px));
  max-height: min(720px, calc(100vh - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.archive-modal::backdrop {
  background: rgba(29, 39, 51, 0.42);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
}

.archive-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.archive-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.archive-link {
  display: grid;
  gap: 2px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.archive-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-link small {
  color: var(--muted);
}

.archive-delete {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #9f2f24;
  cursor: pointer;
  opacity: 0;
}

.archive-item:hover .archive-delete,
.archive-delete:focus-visible {
  opacity: 1;
}

.workspace {
  overflow: auto;
  padding: 28px;
}

.pages {
  display: grid;
  gap: 24px;
  justify-content: center;
}

.page {
  position: relative;
  width: min(100%, var(--page-width));
  aspect-ratio: var(--page-ratio);
  background: white;
  box-shadow: 0 14px 42px rgba(19, 34, 49, 0.16);
}

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

.scan-preview .page canvas {
  filter: contrast(1.1) brightness(1.02) saturate(0.86);
}

.scan-preview .page::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(105deg, rgba(255, 255, 255, 0.10), rgba(227, 218, 198, 0.08)),
    radial-gradient(ellipse at 34% 22%, rgba(29, 39, 51, 0.018), transparent 38%),
    radial-gradient(ellipse at 74% 70%, rgba(29, 39, 51, 0.014), transparent 42%);
  mix-blend-mode: multiply;
}

.placement {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  touch-action: none;
  cursor: move;
  transform: rotate(var(--r));
  transform-origin: center;
}

.placement img {
  display: block;
  width: 100%;
  pointer-events: none;
  user-select: none;
}

.placement.selected {
  outline: 2px solid var(--accent);
}

.placement-controls {
  position: absolute;
  left: 50%;
  top: -42px;
  display: none;
  grid-template-columns: repeat(5, 30px);
  gap: 4px;
  transform: translateX(-50%);
}

.placement.selected .placement-controls {
  display: grid;
}

.placement-control {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}

.placement-control.danger {
  color: #9f2f24;
}

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

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 16px;
  }
}
