:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #dfe2e7;
  --text: #1c2128;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
}

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

.layout {
  display: flex;
  height: calc(100vh - 57px);
  min-height: 500px;
}

.sidebar {
  width: 300px;
  flex: 0 0 300px;
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.4;
}

.filebtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}
.filebtn:hover { background: var(--accent-dark); }
.filebtn.secondary {
  background: #eef2ff;
  color: var(--accent-dark);
}
.filebtn.secondary:hover { background: #e0e7ff; }

.filename {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
}

.stamp-library {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stamp-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
  background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 12px 12px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stamp-item:hover { border-color: var(--accent); }
.stamp-item img {
  max-width: 100%;
  max-height: 100%;
}
.stamp-item .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 11px;
  line-height: 18px;
  cursor: pointer;
  padding: 0;
}

button.primary {
  width: 100%;
  padding: 11px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.primary:disabled {
  background: #c7d2fe;
  cursor: not-allowed;
}

.rangewrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.rangewrap input { flex: 1; }

.viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
}
.viewer-toolbar .spacer { flex: 1; }
.viewer-toolbar button {
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.viewer-toolbar button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.canvas-scroll {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.page-stage {
  position: relative;
  background: white;
  box-shadow: 0 1px 6px rgba(0,0,0,.15);
  line-height: 0;
}

.page-stage canvas {
  display: block;
}

.empty-state {
  padding: 80px 40px;
  color: var(--muted);
  font-size: 14px;
  box-shadow: none;
}

.placement {
  position: absolute;
  border: 1px dashed transparent;
  cursor: move;
  touch-action: none;
}
.placement:hover, .placement.selected {
  border-color: var(--accent);
}
.placement img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}
.placement .handle {
  position: absolute;
  width: 14px;
  height: 14px;
  right: -7px;
  bottom: -7px;
  background: var(--accent);
  border: 2px solid white;
  border-radius: 50%;
  cursor: nwse-resize;
  display: none;
}
.placement.selected .handle { display: block; }
.placement .del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 12px;
  cursor: pointer;
  display: none;
  padding: 0;
  line-height: 20px;
}
.placement.selected .del { display: block; }

@media (max-width: 800px) {
  .layout { flex-direction: column; height: auto; }
  .sidebar { width: 100%; flex: none; border-right: none; border-bottom: 1px solid var(--border); }
  .canvas-scroll { padding: 12px; }
}
