/* ==========================================================================
   Стили веб-генератора мемов с Флоппой
   ========================================================================== */

:root {
  --bg-main: #0c0e12;
  --bg-sidebar: #14171f;
  --bg-card: #1c212c;
  --bg-card-hover: #252b39;
  --bg-input: #11141a;
  --border-color: #272f3e;
  --border-focus: #4f8bf9;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-blue: #3b82f6;
  --accent-hover: #2563eb;
  --accent-green: #10b981;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-meme: 'Montserrat', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.app-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
}

/* --------------------------------------------------------------------------
   Левая панель (Sidebar)
   -------------------------------------------------------------------------- */
.sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  z-index: 10;
}

@media (max-width: 900px) {
  .sidebar {
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Custom Scrollbar for sidebar */
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}
.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* --------------------------------------------------------------------------
   Control Sections & Inputs
   -------------------------------------------------------------------------- */
.control-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 0.88rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.hint-text {
  font-size: 0.78rem;
  color: #cbd5e1;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.btn-upload:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-blue);
  color: #fff;
}

/* Presets Grid */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.presets-grid::-webkit-scrollbar {
  width: 4px;
}
.presets-grid::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.preset-card {
  position: relative;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: var(--transition);
  text-align: center;
}

.preset-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(79, 139, 249, 0.5);
}

.preset-card.active {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 0 0 1px var(--accent-blue);
}

.preset-thumb-wrapper {
  width: 100%;
  height: 52px;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preset-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.preset-card:hover .preset-thumb {
  transform: scale(1.04);
}

.preset-name {
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: #e2e8f0;
}

.active-check {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent-blue);
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

.preset-card.active .active-check {
  display: flex;
}

/* Text Inputs Group */
.input-group {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.input-header label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
}

.font-size-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-row input[type="text"] {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.88rem;
  color: #fff;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
}

.input-row input[type="text"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(79, 139, 249, 0.2);
}

.btn-icon {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}

.btn-icon:hover {
  color: #fff;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

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

.slider-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 44px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent-blue);
  cursor: pointer;
  height: 5px;
  border-radius: 4px;
  background: var(--border-color);
}

/* Advanced Style Settings */
.advanced-settings {
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.advanced-summary {
  padding: 12px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  list-style: none;
  transition: var(--transition);
}

.advanced-summary::-webkit-details-marker {
  display: none;
}

.advanced-summary:hover {
  color: #fff;
  background: var(--bg-card-hover);
}

.advanced-summary .chevron {
  transition: transform 0.2s ease;
}

.advanced-settings[open] .chevron {
  transform: rotate(180deg);
}

.advanced-content {
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-input);
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-reset {
  margin-top: 4px;
  background: transparent;
  border: 1px dashed var(--border-color);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-reset:hover {
  color: #fff;
  border-color: #cbd5e1;
}

/* --------------------------------------------------------------------------
   Sidebar Footer & Buttons
   -------------------------------------------------------------------------- */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-primary {
  width: 100%;
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

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

.btn-secondary {
  width: 100%;
  background: var(--bg-card);
  color: #e2e8f0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: #fff;
  border-color: #cbd5e1;
}

/* --------------------------------------------------------------------------
   Центральная рабочая зона (Workspace)
   -------------------------------------------------------------------------- */
.workspace {
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.3) 0%, transparent 80%),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 100% 100%, 32px 32px, 32px 32px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

@media (max-width: 900px) {
  .workspace {
    height: 70vh;
  }
}

.workspace-header {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.preview-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.1);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.drag-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

/* Обертка для позиционирования canvas и текстовых оверлеев */
.canvas-wrapper {
  position: relative;
  display: inline-block;
  border-radius: 12px;
  overflow: visible; /* Чтобы тени текста могли мягко выходить за пределы */
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08);
  background: #000;
  transition: transform 0.15s ease;
  user-select: none;
}

.canvas-wrapper.dragover {
  box-shadow: 0 0 0 3px var(--accent-blue), 0 16px 36px rgba(59, 130, 246, 0.4);
  transform: scale(1.01);
}

#memeCanvas {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  border-radius: 12px;
}

/* --------------------------------------------------------------------------
   Интерактивные текстовые оверлеи на картинке
   -------------------------------------------------------------------------- */
.text-overlay {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  text-align: center;
  font-family: var(--font-meme);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
  cursor: pointer;
  outline: none;
  border-radius: 8px;
  padding: 8px 12px;
  word-break: break-word;
  transition: opacity 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
  
  /* В обычном режиме оверлей невидим, отображается только идеальный Canvas */
  opacity: 0;
  color: #ffffff;
  background: transparent;
  border: 2px dashed transparent;
  user-select: none;
}

.text-overlay-top {
  top: 3%;
}

.text-overlay-bottom {
  bottom: 3%;
}

/* При наведении показываем рамку и подсказку о клике */
.text-overlay:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.7);
  background-color: rgba(0, 0, 0, 0.25);
  cursor: text;
}

/* При активном фокусе/редактировании оверлей полностью виден, а текст на canvas скрывается */
.text-overlay.editing,
.text-overlay:focus {
  opacity: 1;
  user-select: text;
  color: #ffffff;
  -webkit-text-stroke: 4px #000000;
  paint-order: stroke fill;
  filter: 
    drop-shadow(0px 6px 10px rgba(0, 0, 0, 0.95))
    drop-shadow(0px 2px 4px rgba(0, 0, 0, 0.9));
  background-color: rgba(0, 0, 0, 0.4);
  border: 2px solid var(--accent-blue);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

/* --------------------------------------------------------------------------
   Уведомления (Toast)
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(100px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: var(--accent-green);
  background: #064e3b;
}
