@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Reset & Tokens ─── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-deep: #0c0c0f;
  --bg-surface: #141418;
  --bg-raised: #1c1c22;
  --bg-hover: #26262e;
  --border-subtle: #2a2a34;
  --border-focus: #3a3a48;
  --text-primary: #e8e8ec;
  --text-secondary: #8a8a9a;
  --text-muted: #5a5a6a;
  --accent: #e87040;
  --accent-soft: rgba(232, 112, 64, 0.12);
  --accent-hover: #f08050;
  --danger: #e05454;
  --danger-soft: rgba(224, 84, 84, 0.12);
  --canvas-shadow: rgba(232, 112, 64, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Header ─── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.logo-mark {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.logo-mark::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
}

.logo-mark svg {
  width: 16px;
  height: 16px;
  color: white;
  position: relative;
  z-index: 1;
}

.logo h1 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.logo span {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 2px;
}

/* ─── Toolbar ─── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-subtle);
  margin: 0 4px;
}

.tool-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tool-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tool-btn svg {
  width: 18px;
  height: 18px;
}

/* Color picker wrapper */
.color-wrapper {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.color-wrapper:hover {
  background: var(--bg-hover);
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-focus);
  transition: border-color var(--transition), transform var(--transition);
  pointer-events: none;
}

.color-wrapper:hover .color-swatch {
  border-color: var(--text-secondary);
  transform: scale(1.08);
}

.color-wrapper input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
}

/* Brush size */
.size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
}

.size-control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: var(--border-subtle);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.size-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-raised);
  box-shadow: 0 0 0 1px var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.size-control input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent);
  transform: scale(1.15);
}

.size-control input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-raised);
  box-shadow: 0 0 0 1px var(--border-subtle);
  cursor: pointer;
}

.size-value {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 28px;
  text-align: right;
}

/* Action buttons */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-focus);
  color: var(--text-primary);
}

.btn svg {
  width: 14px;
  height: 14px;
}

.btn-danger {
  color: var(--danger);
  border-color: transparent;
  background: var(--danger-soft);
}

.btn-danger:hover {
  background: rgba(224, 84, 84, 0.2);
  border-color: transparent;
  color: #f06868;
}

.btn-accent {
  color: var(--accent);
  border-color: transparent;
  background: var(--accent-soft);
}

.btn-accent:hover {
  background: rgba(232, 112, 64, 0.2);
  border-color: transparent;
  color: var(--accent-hover);
}

/* ─── Page Strip ─── */
.page-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  overflow: hidden;
}

.page-strip-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  user-select: none;
}

.page-strip-inner {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
  padding: 4px 2px;
  flex: 1;
  min-width: 0;
}

.page-strip-inner::-webkit-scrollbar {
  height: 4px;
}

.page-strip-inner::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 2px;
}

.page-thumb {
  position: relative;
  width: 96px;
  height: 56px;
  border-radius: 6px;
  border: 2px solid var(--border-subtle);
  background: #ffffff;
  cursor: pointer;
  flex-shrink: 0;
  overflow: visible;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.page-thumb:hover {
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

.page-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), 0 4px 12px var(--canvas-shadow);
}

.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
}

.page-thumb-label {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--bg-deep);
  background: var(--text-secondary);
  padding: 0 6px;
  line-height: 1.6;
  border-radius: 3px;
  min-width: 18px;
  text-align: center;
}

.page-thumb.active .page-thumb-label {
  background: var(--accent);
  color: white;
}

.page-thumb-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
  padding: 0;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity var(--transition), transform var(--transition);
}

.page-thumb:hover .page-thumb-delete {
  opacity: 1;
  transform: scale(1);
}

.page-thumb-delete:hover {
  background: #f06868;
  transform: scale(1.1) !important;
}

.page-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-focus);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  white-space: nowrap;
}

.page-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  border-style: solid;
}

.page-add-btn svg {
  width: 15px;
  height: 15px;
  stroke-width: 2.5;
}

/* ─── Canvas Area ─── */
.canvas-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  background: var(--bg-deep);
  position: relative;
  overflow: hidden;
}

/* Subtle grid pattern */
.canvas-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, var(--border-subtle) 0.5px, transparent 0);
  background-size: 24px 24px;
  opacity: 0.4;
  pointer-events: none;
}

canvas {
  background: #ffffff;
  border-radius: var(--radius);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04),
    0 4px 24px var(--canvas-shadow),
    0 20px 60px rgba(0,0,0,0.4);
  cursor: crosshair;
  max-width: 100%;
  touch-action: none;
  position: relative;
  z-index: 1;
  transition: box-shadow 0.4s ease;
}

canvas:hover {
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.06),
    0 4px 24px rgba(232, 112, 64, 0.1),
    0 20px 60px rgba(0,0,0,0.5);
}

/* ─── Status Bar ─── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 32px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.status-msg {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  transition: color var(--transition);
}

.status-msg.flash {
  color: var(--accent);
}

.status-footer {
  font-size: 0.68rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.status-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.status-footer a:hover {
  text-decoration: underline;
}

.status-coords {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ─── Eraser cursor ─── */
canvas.eraser-cursor {
  cursor: none;
}

/* ─── Toast notification ─── */
.toast {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 8px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-primary);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  header {
    height: auto;
    padding: 12px 16px;
    flex-direction: column;
    gap: 10px;
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .actions {
    width: 100%;
    justify-content: center;
  }

  .canvas-container {
    padding: 12px;
  }

  .size-control input[type="range"] {
    width: 60px;
  }

  .btn span.label {
    display: none;
  }
}

/* ─── Fade-in animation ─── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

header { animation: fadeUp 0.4s ease both; }
.page-strip { animation: fadeUp 0.4s ease 0.05s both; }
.canvas-container { animation: fadeUp 0.5s ease 0.1s both; }
.status-bar { animation: fadeUp 0.4s ease 0.2s both; }
