:root {
  --ink: #171a3a;
  --muted: #77738f;
  --paper: #fff9fd;
  --surface: #ffffff;
  --line: #e6def1;
  --purple: #7562e8;
  --purple-dark: #5947cb;
  --purple-soft: #f0ecff;
  --pink-soft: #ffeaf2;
  --green: #319b68;
  --shadow: 0 18px 52px rgba(91, 71, 145, 0.12);
}

* { box-sizing: border-box; }

.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
}

html { background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 234, 242, 0.72), transparent 38%),
    var(--paper);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
.hidden { display: none !important; }

.tool-header {
  min-height: 70px;
  padding: 14px clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--purple-dark);
  font-weight: 800;
  text-decoration: none;
}

.brand-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--purple);
}

.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.privacy-note > span:first-child { color: var(--green); font-size: 10px; }
.tool-header-actions { display: flex; align-items: center; gap: 18px; }
.cleaner-language-control { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.cleaner-language-control select { min-height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; }

.tool-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 44px clamp(18px, 4vw, 64px) 64px;
}

.tool-intro { max-width: 760px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 8px; color: var(--purple); font-size: 12px; font-weight: 800; }
.tool-intro h1 {
  margin: 0;
  max-width: 100%;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(40px, 6vw, 68px);
  line-height: 1.02;
  font-weight: 500;
  overflow-wrap: break-word;
}
.tool-intro > p:last-child { max-width: 650px; margin: 18px 0 0; color: var(--muted); font-size: 17px; line-height: 1.6; }

.workspace {
  min-height: 660px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.controls {
  min-width: 0;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.upload-block { padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.upload-button, .primary-button, .download-button, .secondary-button, .icon-button, .mode-switch button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 750;
}

.upload-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--purple);
  color: var(--purple-dark);
  background: var(--purple-soft);
  cursor: pointer;
}

.upload-block p { margin: 9px 0 0; overflow: hidden; color: var(--muted); font-size: 11px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.control-group { padding: 20px 0; border-bottom: 1px solid var(--line); }
.control-heading, .range-label, .toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.control-heading, .control-label, .range-label { color: var(--ink); font-size: 13px; font-weight: 750; }
.control-heading output, .range-label output { color: var(--purple); font-size: 11px; }
.colour-filter { display: grid; gap: 6px; margin-top: 14px; color: var(--ink); font-size: 12px; font-weight: 750; }
.colour-filter select { width: 100%; min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; }
.colour-filter select:focus { outline: 0; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(117, 98, 232, 0.12); }
input[type="range"] { width: 100%; margin: 14px 0; accent-color: var(--purple); }

.primary-button, .download-button {
  width: 100%;
  border: 0;
  color: white;
  background: var(--purple);
}

.mode-switch { margin-top: 12px; padding: 3px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border-radius: 8px; background: var(--purple-soft); }
.mode-switch button { min-height: 36px; border: 0; color: var(--muted); background: transparent; }
.mode-switch button.active { color: var(--purple-dark); background: white; box-shadow: 0 2px 10px rgba(91, 71, 145, 0.1); }
.range-label { margin-top: 16px; }
.compact-actions { display: grid; grid-template-columns: 44px 1fr; gap: 8px; }
.icon-button, .secondary-button { border: 1px solid var(--line); color: var(--purple-dark); background: white; }
.icon-button { font-size: 20px; }
.preview-controls { display: grid; gap: 14px; }
.toggle-row { font-size: 13px; font-weight: 650; }
.toggle-row input { width: 38px; height: 20px; accent-color: var(--purple); }
.download-button { margin-top: 20px; }

.editor-panel { min-width: 0; display: flex; flex-direction: column; background: #f6f2fa; }
.editor-bar {
  min-height: 68px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: white;
}
.editor-bar > div { min-width: 0; display: grid; gap: 3px; }
.editor-bar strong { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.editor-bar span { color: var(--muted); font-size: 11px; }
.selection-count { flex: 0 0 auto; padding: 6px 10px; border-radius: 999px; color: var(--purple-dark) !important; background: var(--purple-soft); font-weight: 700; }
.pdf-page-controls { display: flex !important; align-items: center; justify-content: center; gap: 8px; }
.pdf-page-controls button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--purple-dark);
  background: white;
  font-size: 20px;
  line-height: 1;
}
.pdf-page-controls output { min-width: 76px; color: var(--ink); font-size: 11px; font-weight: 700; text-align: center; }

.canvas-stage {
  min-height: 590px;
  flex: 1;
  padding: 28px;
  display: grid;
  place-items: center;
  overflow: auto;
  touch-action: none;
}
.canvas-stage.empty { touch-action: auto; }
#editor-canvas { display: none; max-width: 100%; height: auto; border: 1px solid #d8d0df; background: white; box-shadow: 0 12px 34px rgba(40, 31, 72, 0.15); cursor: crosshair; }
.canvas-stage.has-image #editor-canvas { display: block; }
.canvas-stage.has-image .empty-state { display: none; }
.empty-state { max-width: 300px; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 18px 0 6px; color: var(--ink); font-size: 18px; }
.empty-state p { margin: 0; font-size: 13px; }
.empty-illustration { width: 110px; height: 132px; margin: 0 auto; padding: 22px 18px; border: 1px solid var(--line); border-radius: 8px; background: white; transform: rotate(-3deg); }
.empty-illustration span { height: 8px; display: block; margin-bottom: 16px; border-radius: 4px; background: var(--purple-soft); }
.empty-illustration span:nth-child(2) { width: 70%; background: var(--pink-soft); }
.empty-illustration span:nth-child(3) { width: 85%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 8px;
  color: white;
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .privacy-note { display: none; }
  .tool-shell { padding-top: 30px; }
  .workspace { grid-template-columns: 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-panel { min-height: 520px; }
  .canvas-stage { min-height: 450px; padding: 16px; }
}

@media (max-width: 480px) {
  .tool-header { min-height: 60px; }
  .cleaner-language-control > span { display: none; }
  .tool-intro h1 { font-size: 40px; }
  .tool-intro > p:last-child { font-size: 15px; }
  .workspace { width: 100%; }
  .controls { padding: 18px; }
  .editor-bar { align-items: flex-start; }
  .editor-bar { flex-wrap: wrap; }
  .pdf-page-controls { order: 3; width: 100%; }
}
