/* css/styles.css */

/* ===========================================
   NEO-BRUTALISM DESIGN SYSTEM - Design Tokens
   =========================================== */

:root {
  /* Colors - Playful Geometric + Neo-brutalism fusion */
  --neo-bg: #FFFDF5;         /* Warm Cream/Off-White (Paper feel) */
  --neo-fg: #1E293B;         /* Slate 800 (Softer than black) */
  --neo-accent: #8B5CF6;     /* Vivid Violet (Primary Brand) */
  --neo-secondary: #F472B6;  /* Hot Pink (Playful pop) */
  --neo-tertiary: #FBBF24;   /* Amber/Yellow (Optimism) */
  --neo-quaternary: #34D399; /* Emerald/Mint (Freshness) */
  --neo-muted: #F1F5F9;      /* Slate 100 */
  --neo-white: #FFFFFF;      /* White for contrast */
  --neo-border: #E2E8F0;     /* Slate 200 */

  /* Typography */
  --font-heading: 'Outfit', 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Plus Jakarta Sans', 'Space Grotesk', system-ui, sans-serif;
  --font-neo: 'Space Grotesk', sans-serif;

  /* Shadows - Hard offset, no blur */
  --shadow-sm: 4px 4px 0px 0px var(--neo-fg);
  --shadow-md: 6px 6px 0px 0px var(--neo-fg);
  --shadow-lg: 8px 8px 0px 0px var(--neo-fg);
  --shadow-xl: 12px 12px 0px 0px var(--neo-fg);
  --shadow-color: 4px 4px 0px 0px var(--neo-accent);

  /* Borders */
  --border-thick: 3px solid var(--neo-fg);
  --border-thin: 2px solid var(--neo-fg);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
}

/* ===========================================
   Body & Background
   =========================================== */

.body-neo {
  background-color: var(--neo-bg);
  /* Dot grid pattern - Playful Geometric style */
  background-image: radial-gradient(circle, rgba(30, 41, 59, 0.08) 1px, transparent 1px);
  background-size: 20px 20px;
  font-family: var(--font-body);
  color: var(--neo-fg);
}

/* ===========================================
   Typography
   =========================================== */

.text-neo-heading {
  font-family: var(--font-neo);
  font-weight: 700;
  color: var(--neo-fg);
  text-transform: uppercase;
  letter-spacing: -0.02em;
}

.text-neo-body {
  font-family: var(--font-neo);
  font-weight: 500;
  color: var(--neo-fg);
}

.text-neo-label {
  font-family: var(--font-neo);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--neo-fg);
}

/* ===========================================
   Buttons - Neo-brutalism style
   =========================================== */

.btn-neo {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: var(--border-thick);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
  background-color: var(--neo-white);
  color: var(--neo-fg);
}

.btn-neo:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0px 0px var(--neo-fg);
}

.btn-neo:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px 0px var(--neo-fg);
}

.btn-neo:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-sm);
}

/* Button variants - Playful Geometric colors */
.btn-primary {
  background-color: var(--neo-accent);
  color: white;
}

.btn-primary:hover {
  background-color: #7c3aed;
}

.btn-secondary {
  background-color: var(--neo-secondary);
  color: white;
}

.btn-action {
  background-color: var(--neo-tertiary);
  color: var(--neo-fg);
}

.btn-success {
  background-color: var(--neo-quaternary);
  color: var(--neo-fg);
}

.btn-ghost {
  background-color: var(--neo-white);
  color: var(--neo-fg);
  box-shadow: none;
  border: var(--border-thin);
}

.btn-ghost:hover {
  background-color: var(--neo-muted);
  box-shadow: var(--shadow-sm);
  border: var(--border-thick);
}

.btn-ghost:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* Style toggle buttons - Playful Geometric */
.btn-style {
  background-color: var(--neo-white);
  color: var(--neo-fg);
  border: var(--border-thin);
  border-radius: var(--radius-md);
  box-shadow: none;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-style:hover {
  background-color: var(--neo-muted);
  border: var(--border-thick);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

.btn-style-active {
  background-color: var(--neo-accent);
  border: var(--border-thick);
  box-shadow: var(--shadow-sm);
}

.btn-style-active svg {
  stroke: white;
}

/* ===========================================
   Form Elements
   =========================================== */

.select-neo {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.8rem;
  background-color: var(--neo-white);
  border: var(--border-thick);
  border-radius: var(--radius-sm);
  color: var(--neo-fg);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-sm);
}

.select-neo:hover,
.select-neo:focus {
  background-color: var(--neo-muted);
  outline: none;
  border-color: var(--neo-accent);
}

/* ===========================================
   Toolbar - Neo-brutalism
   =========================================== */

.toolbar-neo {
  background-color: var(--neo-white);
  border: var(--border-thick);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

/* ===========================================
   Dropzone - Neo-brutalism
   =========================================== */

.dropzone-neo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border: 4px dashed var(--neo-fg);
  background-color: var(--neo-white);
  transition: all 0.15s ease-out;
  cursor: pointer;
}

.dropzone-neo:hover,
.dropzone-neo.drag-over {
  background-color: var(--neo-secondary);
  border-style: solid;
  box-shadow: var(--shadow-lg);
}

.dropzone-neo .dropzone-title {
  font-family: var(--font-neo);
  font-weight: 700;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  color: var(--neo-fg);
  margin-bottom: 0.5rem;
}

.dropzone-neo .dropzone-subtitle {
  font-family: var(--font-neo);
  font-weight: 500;
  font-size: 1rem;
  color: var(--neo-fg);
  opacity: 0.7;
}

/* ===========================================
   Kbd (keyboard shortcut styling)
   =========================================== */

.kbd-neo {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-family: var(--font-neo);
  font-weight: 700;
  font-size: 0.75rem;
  background-color: var(--neo-bg);
  border: var(--border-thin);
  box-shadow: 2px 2px 0px 0px var(--neo-fg);
}

/* ===========================================
   Gallery Thumbnails - Neo-brutalism
   =========================================== */

.thumbnail-neo {
  border: var(--border-thick);
  box-shadow: var(--shadow-sm);
  transition: all 0.1s ease-out;
  cursor: pointer;
  background-color: var(--neo-white);
}

.thumbnail-neo:hover {
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
}

.btn-delete-neo {
  background-color: var(--neo-accent);
  color: var(--neo-fg);
  border: var(--border-thick);
  font-family: var(--font-neo);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s ease-out;
  box-shadow: 2px 2px 0px 0px var(--neo-fg);
}

.btn-delete-neo:hover {
  transform: translate(1px, 1px);
  box-shadow: none;
}

/* ===========================================
   LAYOUT & CORE STYLES
   =========================================== */

/* Editor container fills viewport */
.editor-container {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* Dropzone styling - legacy fallback */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.dropzone-hidden {
  display: none;
}

/* Image container / Canvas area */
.image-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  cursor: default;
}

.image-container.canvas-area {
  transition: background-color 0.15s ease-out;
}

.image-container.drag-over {
  background-color: var(--neo-secondary);
}

.image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  /* Neo-brutalism: add border and shadow to the image */
  border: var(--border-thick);
  box-shadow: var(--shadow-lg);
}

/* Empty state in canvas */
.canvas-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.empty-state-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px;
  border: 4px dashed var(--neo-fg);
  border-radius: 12px;
  background-color: var(--neo-white);
  opacity: 0.8;
  transition: all 0.15s ease-out;
}

.empty-state-content:hover {
  opacity: 1;
  background-color: var(--neo-secondary);
  border-style: solid;
  box-shadow: var(--shadow-md);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.empty-state-text {
  font-family: var(--font-neo);
  font-weight: 600;
  font-size: 14px;
  color: var(--neo-fg);
  opacity: 0.7;
}

/* Bubbles container - overlay on image */
.bubbles-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Individual bubble */
.bubble {
  position: absolute;
  pointer-events: auto;
  user-select: none;
}

.bubble.selected {
  outline: 4px solid var(--neo-fg);
  outline-offset: 4px;
}

/* Resize handles - Neo-brutalism style */
.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background-color: var(--neo-secondary);
  border: 3px solid var(--neo-fg);
  box-sizing: border-box;
  display: none;
  z-index: 10;
}

.bubble.selected .resize-handle {
  display: block;
}

.resize-handle-nw {
  top: -7px;
  left: -7px;
  cursor: nw-resize;
}

.resize-handle-ne {
  top: -7px;
  right: -7px;
  cursor: ne-resize;
}

.resize-handle-sw {
  bottom: -7px;
  left: -7px;
  cursor: sw-resize;
}

.resize-handle-se {
  bottom: -7px;
  right: -7px;
  cursor: se-resize;
}

/* Bubble text wrapper */
.bubble-text-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: table;
  padding: 10%;
  box-sizing: border-box;
  pointer-events: none;
}

/* Bubble text */
.bubble-text {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  font-family: 'Comic Sans MS', cursive;
  font-size: 18px;
  line-height: 1.3;
  color: black;
  word-wrap: break-word;
}

/* Bubble SVG layer */
.bubble-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* Tail handle - Neo-brutalism style */
.tail-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background-color: var(--neo-accent);
  border: 3px solid var(--neo-fg);
  box-sizing: border-box;
  display: none;
  z-index: 10;
  cursor: move;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.bubble.selected .tail-handle {
  display: block;
}

/* Bubble text editing wrapper */
.bubble-edit-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15%;
  box-sizing: border-box;
  z-index: 20;
}

/* Bubble text editing input */
.bubble-edit-input {
  display: inline-block;
  text-align: center;
  color: black;
  word-wrap: break-word;
  outline: none;
  background: transparent;
  cursor: text;
  max-width: 100%;
  caret-color: black;
}

/* Font classes for bubbles */
.font-comic { font-family: 'Comic Sans MS', 'Comic Sans', cursive; }
.font-marker { font-family: 'Marker Felt', 'Marker', fantasy; }
.font-helvetica { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; }
.font-impact { font-family: Impact, Haettenschweiler, sans-serif; }
.font-noteworthy { font-family: Noteworthy, 'Comic Sans MS', cursive; }

/* Toolbar positioning - left side like Photoshop */
.toolbar {
  position: fixed;
  z-index: 100;
}

.toolbar-left {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 8px;
  width: 180px;
}

.toolbar-left button span,
.toolbar-left button {
  white-space: nowrap;
}

.toolbar-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Label styling */
.label-neo {
  font-family: var(--font-neo);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--neo-fg);
}

/* Separator */
.separator-neo {
  width: 3px;
  background-color: var(--neo-fg);
  height: 32px;
}

/* Toolbar separator (horizontal) */
.toolbar-separator {
  width: 100%;
  height: 2px;
  background-color: var(--neo-fg);
  opacity: 0.3;
  margin: 4px 0;
}

/* ===========================================
   Responsive Styles
   =========================================== */

@media (max-width: 639px) {
  .toolbar-left {
    left: 8px;
    top: auto;
    bottom: 12px;
    transform: none;
    flex-direction: row;
    flex-wrap: wrap;
    max-width: calc(100% - 16px);
  }
  .toolbar-button {
    min-height: 44px;
    min-width: 44px;
  }
  .resize-handle { width: 44px; height: 44px; }
  .resize-handle-nw { top: -22px; left: -22px; }
  .resize-handle-ne { top: -22px; right: -22px; }
  .resize-handle-sw { bottom: -22px; left: -22px; }
  .resize-handle-se { bottom: -22px; right: -22px; }
  .tail-handle { width: 44px; height: 44px; }
  .image-container {
    padding-bottom: 120px;
  }
}

@media (min-width: 640px) {
  .toolbar-left {
    left: 12px;
  }
  .resize-handle { width: 14px; height: 14px; }
  .image-container {
    padding-left: 210px;
    padding-right: 110px;
    padding-top: 80px;
    padding-bottom: 40px;
  }
}

/* ===========================================
   Utility Classes
   =========================================== */

.text-muted {
  opacity: 0.6;
}

.icon-muted {
  opacity: 0.5;
}

/* ===========================================
   Gallery Panel (Right Side)
   =========================================== */

.gallery-panel {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background-color: var(--neo-white);
  border: var(--border-thick);
  box-shadow: var(--shadow-md);
  border-radius: 8px;
  padding: 12px;
  z-index: 100;
  max-height: 80vh;
  overflow-y: auto;
  width: 80px;
}

.gallery-header {
  text-align: center;
  border-bottom: 2px solid var(--neo-fg);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.gallery-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gallery-item {
  position: relative;
  cursor: pointer;
}

.gallery-thumbnail {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 2px solid var(--neo-fg);
  border-radius: 4px;
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
}

.gallery-thumbnail:hover {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--neo-fg);
}

.gallery-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background-color: var(--neo-accent);
  border: 2px solid var(--neo-fg);
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.gallery-item:hover .gallery-delete {
  display: flex;
}

.gallery-delete:hover {
  background-color: #ff4444;
}

@media (max-width: 639px) {
  .gallery-panel {
    right: 8px;
    top: auto;
    bottom: 120px;
    transform: none;
    flex-direction: row;
    width: auto;
    max-width: calc(100% - 16px);
    max-height: none;
    padding: 8px;
  }

  .gallery-list {
    flex-direction: row;
    overflow-x: auto;
  }

  .gallery-thumbnail {
    width: 48px;
    height: 48px;
  }
}

/* ===========================================
   Shared Library Picker
   =========================================== */

.lib-btn-dropzone {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.5rem 1.2rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--neo-tertiary);
  color: var(--neo-fg);
  border: 2.5px solid var(--neo-fg);
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--neo-fg);
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.15s cubic-bezier(0.34,1.56,0.64,1);
  line-height: 1;
}
.lib-btn-dropzone svg {
  flex-shrink: 0;
  display: block;
  width: 14px;
  height: 14px;
  position: relative;
  top: 1px;
}
.lib-btn-dropzone:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--neo-fg);
}
.lib-btn-dropzone:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--neo-fg);
}

.lib-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(30,41,59,0.45);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.lib-overlay.open { display: flex; }

.lib-modal {
  background: var(--neo-white);
  border: 2.5px solid var(--neo-fg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 480px;
  max-height: 70vh;
  overflow-y: auto;
  position: relative;
  animation: dropzone-pop 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes dropzone-pop {
  from { opacity: 0; transform: scale(0.85) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.lib-modal-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 1rem;
}

.lib-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--neo-fg);
  background: var(--neo-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
}
.lib-close:hover { transform: scale(1.1); }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.75rem;
}

.lib-card {
  position: relative;
  cursor: pointer;
  border: 2px solid var(--neo-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), border-color 0.15s;
  aspect-ratio: 1;
}
.lib-card:hover {
  transform: scale(1.05);
  border-color: var(--neo-accent);
}
.lib-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.lib-badge {
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  font-size: 0.6rem;
  font-weight: 700;
  text-align: center;
  background: rgba(30,41,59,0.75);
  color: white;
  padding: 1px 4px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lib-empty {
  text-align: center;
  color: var(--neo-fg);
  opacity: 0.5;
  font-size: 0.9rem;
  padding: 2rem 0;
  font-weight: 500;
}

.back-btn { position: fixed; top: 1.25rem; left: 1.25rem; z-index: 100; display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.5rem 1rem; font-family: 'Plus Jakarta Sans', system-ui, sans-serif; font-weight: 700; font-size: 0.85rem; background: var(--neo-white); color: var(--neo-fg); border: 2.5px solid var(--neo-fg); border-radius: 9999px; cursor: pointer; box-shadow: 3px 3px 0 var(--neo-fg); transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.15s cubic-bezier(0.34,1.56,0.64,1); text-decoration: none; }
.back-btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--neo-fg); }
.back-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--neo-fg); }
@media (max-width: 600px) { .back-btn { top: 0.75rem; left: 0.75rem; padding: 0.4rem 0.75rem; font-size: 0.78rem; } }

