:root {
  --dark: #1e293b;
  --dark-hover: #334155;
  --border: #e2e8f0;
  --bg-light: #f8fafc;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { background: #f1f5f9; color: #1e293b; }

.hidden { display: none !important; }

/* ---------- Landing ---------- */
.landing-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.dropzone {
  max-width: 420px;
  width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  padding: 32px;
  text-align: center;
  border: 2px dashed #cbd5e1;
}
.dropzone h1 { font-size: 20px; font-weight: 600; margin: 0 0 8px; }
.dropzone p { font-size: 14px; color: var(--text-muted); margin: 0 0 24px; }
.dropzone .hint { font-size: 12px; color: var(--text-faint); margin: 16px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--dark); color: #fff; border-color: var(--dark); }
.btn-primary:hover { background: var(--dark-hover); }
.tool-active { background: var(--dark) !important; color: #fff !important; border-color: var(--dark) !important; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar, .toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.nav-group { display: flex; align-items: center; gap: 4px; margin: 0 4px; }
.page-label { font-size: 14px; color: var(--text-muted); white-space: nowrap; padding: 0 4px; }
.spacer { flex: 1; }
.status-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex: none; }
.color-input {
  width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border);
  margin-left: 4px; padding: 0; flex: 0 0 auto;
}
.range-input { width: 80px; margin: 0 4px; flex: 0 0 auto; }

/* ---------- Main content ---------- */
.main-area { flex: 1; display: flex; flex-direction: column-reverse; overflow: hidden; }
@media (min-width: 768px) {
  .main-area { flex-direction: row; }
}

.thumbs {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--bg-light);
  border-top: 1px solid var(--border);
  overflow-x: auto;
}
@media (min-width: 768px) {
  .thumbs {
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    overflow-x: visible;
    overflow-y: auto;
    width: 128px;
    flex: 0 0 auto;
  }
}

.canvas-wrap { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 16px; }
.canvas-stack { position: relative; display: inline-block; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); touch-action: none; }
.canvas-stack canvas { display: block; }
.canvas-stack canvas:last-child { position: absolute; top: 0; left: 0; }

/* ---------- Thumbnails ---------- */
.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 100px;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.thumb canvas { display: block; width: 100%; height: auto; }
.thumb-active { border-color: var(--dark); }
.thumb-num {
  position: absolute; bottom: 2px; left: 4px; font-size: 10px;
  background: rgba(0, 0, 0, 0.55); color: #fff; padding: 0 4px; border-radius: 3px;
}
.thumb-del {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  line-height: 16px; text-align: center; border-radius: 9999px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 13px; border: none; cursor: pointer;
}

/* ---------- Startup error ---------- */
.startup-error {
  max-width: 480px;
  margin: 80px auto;
  padding: 24px;
  text-align: center;
  border: 1px solid #fca5a5;
  background: #fef2f2;
  border-radius: 12px;
  color: #991b1b;
  font-size: 14px;
  line-height: 1.6;
}
.startup-error code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
