/* ========================================
   STAMP DESIGNER — Design System & Styles
   ======================================== */

/* ---------- CSS Variables ---------- */
:root {
  /* Colors — Dark theme with warm accent */
  --bg-primary: #0d0f14;
  --bg-secondary: #181b25;
  --bg-tertiary: #212531;
  --bg-elevated: rgba(33, 37, 49, 0.9);

  --text-primary: #eef0f6;
  --text-secondary: #9ea3b8;
  --text-muted: #5c6180;

  --accent: #f0a848;
  --accent-hover: #f7c46e;
  --accent-glow: rgba(240, 168, 72, 0.3);
  --accent-dim: rgba(240, 168, 72, 0.08);
  --accent-secondary: #6b9dff;

  --border: rgba(255, 255, 255, 0.07);
  --border-active: rgba(240, 168, 72, 0.5);

  --glass-bg: rgba(22, 25, 35, 0.78);
  --glass-border: rgba(255, 255, 255, 0.05);
  --glass-blur: 24px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.45);
  --shadow-stamp: 0 16px 56px rgba(0, 0, 0, 0.55), 0 4px 16px rgba(0, 0, 0, 0.3);

  /* Sizes */
  --header-h: 56px;
  --tool-panel-w: 280px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration: 0.2s;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  color: inherit;
}

input,
select {
  font-family: inherit;
  color: inherit;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

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

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 24px;
  background: linear-gradient(180deg, rgba(22, 25, 35, 0.92), rgba(18, 20, 28, 0.88));
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 1px 20px rgba(0, 0, 0, 0.3);
  z-index: 100;
}

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

.logo-icon {
  font-size: 26px;
  filter: drop-shadow(0 0 12px var(--accent-glow));
  animation: iconFloat 3s ease-in-out infinite;
}

@keyframes iconFloat {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-2px);
  }
}

.logo h1 {
  font-family: 'Noto Serif SC', serif;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover), var(--accent));
  background-size: 200% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 2.5px;
  animation: logoShimmer 4s ease-in-out infinite;
}

@keyframes logoShimmer {

  0%,
  100% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
  position: relative;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #d4943e);
  color: #1a1a1a;
  box-shadow: 0 2px 12px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  font-weight: 600;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), var(--accent));
  box-shadow: 0 4px 24px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-active);
}

.btn-ghost {
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.btn-ghost:active {
  transform: scale(0.97);
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 10px;
}

/* ---------- Workspace ---------- */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---------- Tool Panel ---------- */
.tool-panel {
  width: var(--tool-panel-w);
  background: linear-gradient(180deg, rgba(22, 25, 35, 0.85), rgba(18, 20, 28, 0.8));
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: 2px 0 24px rgba(0, 0, 0, 0.15);
}

.tool-tabs {
  display: flex;
  padding: 8px 8px 0;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.tool-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 10px;
  font-size: 10px;
  color: var(--text-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all var(--duration) var(--ease);
  position: relative;
}

.tool-tab svg {
  opacity: 0.6;
  transition: opacity var(--duration) var(--ease);
}

.tool-tab:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.03);
}

.tool-tab:hover svg {
  opacity: 0.8;
}

.tool-tab.active {
  color: var(--accent);
  background: rgba(232, 164, 74, 0.08);
}

.tool-tab.active svg {
  opacity: 1;
  stroke: var(--accent);
}

.tool-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

/* Tool Content */
.tool-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tool-pane {
  display: none;
}

.tool-pane.active {
  display: block;
  animation: fadeIn 0.2s var(--ease);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.pane-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.section {
  margin-bottom: 16px;
}

.section-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

/* Color Grid */
.color-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.color-grid.compact {
  grid-template-columns: repeat(8, 1fr);
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease-spring);
  position: relative;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 3px rgba(0, 0, 0, 0.2);
}

.color-swatch:hover {
  transform: scale(1.18);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.color-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow), 0 2px 12px rgba(0, 0, 0, 0.3);
}

/* Gradient Grid */
.gradient-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.gradient-swatch {
  width: 100%;
  aspect-ratio: 1.2;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.gradient-swatch:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.gradient-swatch.active {
  border-color: var(--accent);
}

/* Pattern Grid */
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.pattern-swatch {
  width: 100%;
  aspect-ratio: 1.2;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  background-size: 20px 20px;
}

.pattern-swatch:hover {
  transform: scale(1.05);
  border-color: rgba(255, 255, 255, 0.15);
}

.pattern-swatch.active {
  border-color: var(--accent);
}

/* Sticker Grid */
.sticker-categories {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.sticker-cat-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 20px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: all var(--duration) var(--ease);
  border: 1px solid transparent;
}

.sticker-cat-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sticker-cat-btn.active {
  background: rgba(232, 164, 74, 0.15);
  color: var(--accent);
  border-color: var(--accent);
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sticker-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration) var(--ease-spring);
  border: 1px solid transparent;
  font-size: 28px;
  padding: 8px;
}

.sticker-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-active);
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.sticker-item:active {
  transform: scale(0.95);
}

.sticker-item svg {
  width: 100%;
  height: 100%;
}

/* Text Tool */
.text-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: all var(--duration) var(--ease);
  margin-bottom: 8px;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), 0 2px 8px rgba(0, 0, 0, 0.2);
}

.text-input.small {
  width: 100px;
  margin-bottom: 0;
}

.select-input {
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  flex: 1;
  transition: all var(--duration) var(--ease);
}

.select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.font-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.font-btn {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  text-align: left;
  font-size: 14px;
  transition: all var(--duration) var(--ease);
}

.font-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.font-btn.active {
  border-color: var(--accent);
  background: rgba(232, 164, 74, 0.1);
}

/* Range Slider */
.range-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Denomination */
.denomination-row {
  display: flex;
  gap: 8px;
}

/* Position Grid */
.position-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.pos-btn {
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 16px;
  border: 1px solid transparent;
  transition: all var(--duration) var(--ease);
}

.pos-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.pos-btn.active {
  border-color: var(--accent);
  background: rgba(232, 164, 74, 0.1);
}

/* Stamp Size Selector */
.stamp-size-select {
  width: 100%;
  margin-bottom: 6px;
}

.size-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  padding: 2px 0;
}

.perf-options {
  display: flex;
  gap: 6px;
}

.perf-btn {
  flex: 1;
  padding: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all var(--duration) var(--ease);
}

.perf-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.perf-btn.active {
  border-color: var(--accent);
  background: rgba(232, 164, 74, 0.1);
  color: var(--accent);
}

/* ---------- Canvas Area ---------- */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
  /* Subtle dot pattern background */
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

.canvas-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(ellipse at 50% 40%, rgba(240, 168, 72, 0.03) 0%, transparent 70%);
  pointer-events: none;
}

.canvas-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 800px;
}

/* ---------- Stamp ---------- */
.stamp-outer {
  padding: 0;
  background: transparent;
  position: relative;
  box-shadow: none;
  transition: all 0.4s var(--ease);
  animation: stampEnter 0.7s var(--ease);
  /* SVG filter for drop shadow since box-shadow won't follow SVG clip path */
  filter: drop-shadow(0 16px 32px rgba(0, 0, 0, 0.5)) drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35)) drop-shadow(0 0 2px rgba(0, 0, 0, 0.15));
}

@keyframes stampEnter {
  from {
    opacity: 0;
    transform: scale(0.92) rotateX(6deg) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) rotateX(0) translateY(0);
  }
}

.stamp-outer:hover {
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.5)) drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35)) drop-shadow(0 0 40px rgba(240, 168, 72, 0.06));
}

/* Stamp inner canvas */
.stamp-canvas {
  width: 300px;
  height: 400px;
  position: relative;
  overflow: hidden;
  background: #f5f0e6;
  transition: width 0.4s var(--ease), height 0.4s var(--ease);
}

/* Stamp canvas dimensions are now controlled by JS inline styles
   based on STAMP_SIZES presets. No fixed CSS classes needed. */

/* Stamp Layers */
.stamp-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.layer-stickers,
.layer-text {
  pointer-events: none;
}

.layer-stickers>*,
.layer-text>* {
  pointer-events: auto;
}

/* Stamp Background Layer */
.layer-background {
  background: #f5f0e6;
  transition: background 0.4s var(--ease);
}

/* Denomination Layer */
.layer-denomination {
  pointer-events: none;
  z-index: 10;
}

.denomination-display {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font-family: 'Noto Serif SC', serif;
  font-size: 20px;
  font-weight: 700;
  color: #1a1a1a;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
  transition: all var(--duration) var(--ease);
}

.stamp-country-display {
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  color: #1a1a1a;
  text-transform: uppercase;
  opacity: 0.8;
}

.stamp-year-display {
  position: absolute;
  bottom: 12px;
  right: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: #1a1a1a;
  opacity: 0.6;
}

/* Draggable elements on stamp */
.stamp-element {
  position: absolute;
  cursor: grab;
  user-select: none;
  transition: box-shadow var(--duration) var(--ease);
}

.stamp-element:active {
  cursor: grabbing;
}

.stamp-element.selected {
  outline: 2px dashed var(--accent);
  outline-offset: 3px;
}

.stamp-element .delete-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  background: #e74c3c;
  color: white;
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
  pointer-events: auto;
  z-index: 20;
  line-height: 1;
}

.stamp-element:hover .delete-btn,
.stamp-element.selected .delete-btn {
  opacity: 1;
}

/* Sticker elements */
.stamp-sticker {
  font-size: 48px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stamp-sticker svg {
  width: 64px;
  height: 64px;
}

/* Text elements */
.stamp-text {
  font-size: 18px;
  padding: 2px 6px;
  white-space: nowrap;
  min-width: 20px;
  color: #1a1a1a;
}

/* Canvas Hint */
.canvas-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-muted);
  animation: hintPulse 3s infinite;
}

@keyframes hintPulse {

  0%,
  100% {
    opacity: 0.7;
  }

  50% {
    opacity: 1;
  }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 28px;
  background: linear-gradient(135deg, var(--accent), #d4943e);
  color: #1a1a1a;
  font-weight: 600;
  font-size: 14px;
  border-radius: 30px;
  box-shadow: 0 8px 32px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  z-index: 10000;
  opacity: 0;
  transition: all 0.4s var(--ease-spring);
  pointer-events: none;
}

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

/* ---------- Resize handle ---------- */
.resize-handle {
  position: absolute;
  bottom: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.resize-handle::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
}

.stamp-element:hover .resize-handle,
.stamp-element.selected .resize-handle {
  opacity: 1;
}

/* ---------- Rotate handle ---------- */
.rotate-handle {
  position: absolute;
  top: -10px;
  left: -10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
  pointer-events: auto;
  z-index: 20;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  line-height: 1;
  user-select: none;
}

.rotate-handle:active {
  cursor: grabbing;
}

.stamp-element:hover .rotate-handle,
.stamp-element.selected .rotate-handle {
  opacity: 1;
}