:root {
  --accent: #ffa800;
  --accent-alt: #ffb94d;
  --bg: #1e1f24;
  --bg-alt: #272a33;
  --bg-soft: #303542;
  --border: #3c4250;
  --text: #e5e8ef;
  --text-dim: #b2b8c6;
  --radius: 8px;
  --sidebar-width: 360px;
  --page-aspect-w: 612;
  --page-aspect-h: 792;
}
* { box-sizing: border-box; }
html, body {
  margin:0; height:100%;
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,sans-serif;
  background:var(--bg); color:var(--text);
}
body { display:flex; flex-direction:column; overflow:hidden; }
header {
  background:linear-gradient(90deg,var(--bg-alt),var(--bg-soft));
  padding:10px 16px;
  display:flex; flex-direction:column; gap:10px;
  box-shadow:0 4px 10px -2px rgba(0,0,0,.4);
}
header h1 { margin:0; font-size:18px; letter-spacing:.5px; }
.controls { display:flex; flex-wrap:wrap; gap:12px; align-items:center; }
.controls .block { display:flex; align-items:center; gap:8px; }
.controls .grow { flex:1; min-width:220px; }

input[type=text] {
  width:100%; padding:8px 10px;
  border:1px solid var(--border); border-radius:6px;
  background:var(--bg-soft); color:var(--text);
  font-size:14px; outline:none;
}
input[type=text]:focus { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }

.btn,.btn-secondary,button {
  cursor:pointer; border:none; border-radius:6px;
  padding:8px 14px; font-size:14px;
  display:inline-flex; align-items:center;
  font-weight:600;
}
.btn,button.primary { background:var(--accent); color:#222; }
.btn:hover,button.primary:hover { background:var(--accent-alt); }
.btn-secondary {
  background:#444; color:#eee; font-weight:500;
  box-shadow:0 2px 6px -1px rgba(0,0,0,.5);
  text-decoration:none;
}
.btn-secondary:hover { background:#555; }
button {
  background:var(--bg-soft); color:var(--text); font-weight:500;
  border:1px solid var(--border);
}
button:hover { background:#3b414f; }
button:disabled { opacity:.5; cursor:not-allowed; }

#layout { flex:1; display:grid; grid-template-columns: var(--sidebar-width) 6px 1fr; min-height:0; }
#sidebar {
  overflow:auto; padding:14px;
  display:flex; flex-direction:column; gap:20px;
  background:var(--bg-alt);
}
#divider {
  background:linear-gradient(180deg,var(--bg-alt),var(--bg-soft));
  cursor:col-resize; position:relative;
}
#divider:after {
  content:""; position:absolute; left:50%; top:50%;
  width:4px; height:42px; transform:translate(-50%,-50%);
  background:var(--border); border-radius:2px;
}

section h2 {
  margin:0 0 6px; font-size:13px;
  text-transform:uppercase; letter-spacing:1px;
  font-weight:600; color:var(--text-dim);
}

.legend {
  background:var(--bg-soft); padding:8px 10px;
  border:1px solid var(--border); border-radius:6px;
  min-height:42px; font-size:13px;
  display:flex; flex-wrap:wrap; gap:6px; align-items:center;
}
.swatch {
  width:24px; height:14px; background:var(--accent);
  border:1px solid #0006; border-radius:3px;
  box-shadow:0 0 0 1px #0004;
}

.results {
  list-style:none; margin:0; padding:0;
  border:1px solid var(--border); border-radius:6px;
  background:var(--bg-soft); max-height:250px; overflow:auto;
}
.results li {
  padding:6px 10px; font-size:13px;
  display:flex; justify-content:space-between; gap:10px;
  border-bottom:1px solid #ffffff08;
  cursor:pointer; transition:background .15s;
}
.results li:last-child { border-bottom:none; }
.results li:hover { background:#ffffff08; }
.results li.active { background:var(--accent); color:#222; font-weight:600; }

.note { font-size:11.5px; color:var(--text-dim); margin:6px 0 0; line-height:1.4; }

textarea#pageText {
  width:100%; min-height:200px; resize:vertical;
  background:var(--bg-soft); color:var(--text);
  border:1px solid var(--border); border-radius:6px;
  padding:10px 12px; font-size:12.5px;
  line-height:1.4;
  font-family:ui-monospace,SFMono-Regular,Consolas,"Roboto Mono",monospace;
}

#pagesWrap { overflow:auto; background:#16171b; }
#pages {
  padding:24px clamp(16px,4vw,60px);
  display:flex; flex-direction:column;
  gap:36px; align-items:center;
}

.page {
  position:relative;
  width:100%;
  max-width:1200px;
  background:#000;
  border-radius:4px;
  box-shadow:0 4px 24px -4px #000a,0 0 0 1px #000;
  overflow:hidden;
  aspect-ratio: var(--page-aspect-w) / var(--page-aspect-h);
}

.page.placeholder {
  display:flex;
  align-items:center;
  justify-content:center;
  background:linear-gradient(135deg,#222 0%,#2d3038 60%);
  color:#666;
  font-size:12px;
}

.page.placeholder .page-inner {
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
}

.placeholder-label {
  font-weight:600;
  letter-spacing:.5px;
  opacity:.85;
}

.placeholder-spinner {
  width:42px; height:42px;
  border:5px solid #ffffff14;
  border-top:5px solid var(--accent);
  border-right:5px solid var(--accent);
  border-radius:50%;
  animation:spin 0.9s linear infinite;
  box-shadow:0 0 6px -1px #000;
}

.page img { display:block; width:100%; height:100%; object-fit:cover; }

.page-label {
  position:absolute; top:0; left:0;
  padding:4px 8px; margin:6px;
  background:rgba(0,0,0,.55);
  color:#fff; font-size:12px;
  letter-spacing:.5px; border-radius:4px;
  font-weight:600; pointer-events:none;
}

.hl-box {
  position:absolute;
  border:2px solid var(--accent);
  background:rgba(255,168,0,0.28);
  border-radius:2px;
  box-shadow:0 0 0 1px #0005;
  pointer-events:none;
}

#statusBar {
  position:fixed; bottom:10px; left:12px;
  background:rgba(15,16,20,.85);
  backdrop-filter:blur(4px);
  color:var(--text); font-size:12.5px;
  padding:6px 12px;
  border-radius:32px;
  border:1px solid var(--border);
  box-shadow:0 4px 12px -2px rgba(0,0,0,.55);
  z-index:100;
}

#processingOverlay {
  position:fixed; inset:0;
  background:rgba(12,14,18,0.94);
  backdrop-filter:blur(6px);
  display:flex; align-items:center; justify-content:center;
  flex-direction:column;
  z-index:400;
  padding:40px 30px;
  text-align:center;
}
#processingOverlay.hidden { display:none; }
#processingOverlay .overlay-content {
  max-width:520px;
  display:flex; flex-direction:column;
  align-items:center; gap:18px;
}
.spinner {
  width:60px; height:60px;
  border:6px solid #ffffff18;
  border-top:6px solid var(--accent);
  border-right:6px solid var(--accent);
  border-radius:50%;
  animation:spin 0.9s linear infinite;
}
@keyframes spin { to { transform:rotate(360deg);} }

.detail { font-size:14px; color:var(--text-dim); margin:0; line-height:1.5; }
.hint { font-size:12px; color:var(--text-dim); margin:0; }

.dim { opacity:.6; }

@media (max-width:1100px) {
  #layout { grid-template-columns: minmax(0,1fr); grid-auto-rows:auto; }
  #divider { display:none; }
  #sidebar { order:1; max-height:42vh; }
  #pagesWrap { order:2; }
}