:root {
  --bg: #f6f2e8;
  --ink: #1d1b17;
  --accent: #0b3d2e;
  --muted: #6d655a;
  --panel: #ffffff;
  --line: #ded7c9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #ffffff, var(--bg));
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: 0.4px;
}

.sub {
  margin: 0 0 18px;
  color: var(--muted);
}

.search {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.search input {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search button {
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

.meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.results {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 120px;
}

.result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 8px 6px;
  border-bottom: 1px dashed var(--line);
}

.result:last-child { border-bottom: none; }

.result .title { font-weight: 600; }

.result .details { color: var(--muted); font-size: 13px; }

.result button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}

.result button:disabled {
  opacity: 0.6;
  cursor: default;
}

.preview {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

#preview-canvas {
  min-height: 120px;
  background: #faf8f3;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#preview-canvas .progress {
  width: 100%;
  max-width: 520px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

#preview-canvas .progress-bar {
  height: 10px;
  background: #e9e2d3;
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 6px;
}

#preview-canvas .progress-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

#preview-canvas canvas {
  max-width: 100%;
  height: auto;
  border: 1px solid #ccc;
}

#calib-container {
  position: relative;
  overflow: auto;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #faf8f3;
  padding: 8px;
}

#page-wrap {
  position: relative;
  display: inline-block;
}

#page-img {
  display: block;
  max-width: 100%;
  height: auto;
}

#cell-outline {
  position: absolute;
  border: 2px dashed rgba(0, 120, 80, 0.9);
  pointer-events: none;
}

#crop-box {
  position: absolute;
  border: 2px solid rgba(255, 80, 0, 0.9);
  background: rgba(255, 80, 0, 0.15);
  cursor: move;
}

#crop-box .handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #ff5a1f;
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
}

#crop-box .handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
#crop-box .handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
#crop-box .handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
#crop-box .handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }

#grid-outline {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  border: 2px dashed rgba(0, 120, 80, 0.5);
  pointer-events: auto;
}

#grid-outline .handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #0b3d2e;
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
}

#grid-outline .handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
#grid-outline .handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
#grid-outline .handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
#grid-outline .handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }

#header-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

#print {
  background: #2b2b2b;
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
}

@media (max-width: 720px) {
  header h1 { font-size: 22px; }
}
