/* =========================================
EDITOR ROOT (Mobile First)
========================================= */
.hw-story-editor {
  position: fixed;
  top: 50px;
  bottom: 40px;
  left: 0;
  right: 0;
  background: #f8f9fa; /* Light gray */
  z-index: 9999999999 !important;
  display: none;
  flex-direction: column;
}

/* Explicit mobile styles to prevent override (optional but ensures priority) */
@media (max-width: 767px) {
  .hw-story-editor {
    width: 100%;
    left: 0;
    transform: none;
    background: #f8f9fa; /* Solid for mobile */
    bottom: 40px; /* Reset if needed */
  }
}

.hw-story-editor.active {
  display: flex;
}

/* =========================================
TOP BAR
========================================= */
.hw-editor-top {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: flex-start; /* Adjusted for more buttons */
  padding: 0 16px;
  background: #fff; /* white */
  backdrop-filter: blur(6px);
  z-index: 10;
  gap: 10px;
}

.hw-editor-top button {
  width: 33px;
  height: 33px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333; /* Darker for light theme */
}

.hw-editor-top svg {
  width: 18px;
  height: 18px;
  stroke: #883ca6;
  stroke-width: 2;
  fill: none;
}

#hw-editor-save {
  background: #883ca6; /* Brand purple "Done" */
  border-radius: 20px;
  width: auto;
  padding: 0 12px;
  color: #fff;
  margin-left: auto; /* Push to right */
}

#hw-editor-save svg {
  stroke: #000;
}

/* =========================================
CANVAS
========================================= */
#hw-editor-canvas {
  position: absolute;
  top: 63px;
  bottom: 70px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
  background: #fff;
}

/* Target the inner image/canvas element from tui (adjust selector if needed) */
#hw-editor-canvas .tui-image-editor-canvas-container,
#hw-editor-canvas canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain; /* Fits without deformation */
}

/* =========================================
BOTTOM TOOLBAR
========================================= */
.hw-editor-toolbar {
  position: absolute;
  bottom: 0px;
  left: 0;
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: flex-start; /* Scrollable if many tools */
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  overflow-x: auto;
  background: rgba(255,255,255,0.7); /* Light blur */
  backdrop-filter: blur(6px);
  border-top: 1px solid #ddd; /* Light border */
  z-index: 10;
}

.hw-editor-toolbar button {
  width: 60px; /* Wider for labels */
  height: 60px;
  border-radius: 12px; /* Rounded rect like Pintura */
  border: none;
  background: #fff; /* white */
  display: flex;
  flex-direction: column; /* For icon + text */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s;
  font-size: 10px;
  color: #333;
  flex-shrink: 0;
}

.hw-editor-toolbar button:hover {
  background: #d1d5da;
}

.hw-editor-toolbar svg {
  width: 18px;
  height: 18px;
  stroke: #bc94c7;
  stroke-width: 2;
  fill: none;
  margin-bottom: 4px; /* Space for label */
}

/* =========================================
SUBTOOLS
========================================= */
.hw-editor-subtools {
  position: absolute;
  bottom: 70px; /* Above toolbar */
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.hw-sub-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 10px;
}

.hw-sub-panel button {
  height: 40px;
  background: #e9ecef;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #333;
}

.hw-slider {
  display: flex;
  flex-direction: column;
}

.hw-slider label {
  font-size: 12px;
  color: #333;
}

.hw-slider input {
  width: 100%;
  appearance: none;
  height: 6px;
  background: #ddd;
  border-radius: 4px;
  outline: none;
}

.hw-slider input::-webkit-slider-thumb {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #6c757d;
  cursor: pointer;
}

.hw-slider input::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #6c757d;
  cursor: pointer;
}

/* =========================================
COLOR PICKER
========================================= */
.hw-editor-colors {
  position: absolute;
  bottom: 70px;
  left: 0;
  width: 100%;
  display: flex;
  flex-direction: column; /* Stack label, slider, preview vertically */
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: #fff;
  z-index: 10; /* Ensure above other elements */
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1); /* Optional: Subtle shadow for visibility */
}

.hw-editor-colors label {
  font-size: 10px;
  color: #333;
}

.hw-spectrum-container {
  width: 80%; /* Or 100% for full width */
  position: relative;
}

#hw-spectrum-slider {
  width: 100%;
  appearance: none;
  height: 20px; /* Taller for better touch/visibility */
  background: linear-gradient(to right, hsl(0,100%,50%), hsl(60,100%,50%), hsl(120,100%,50%), hsl(180,100%,50%), hsl(240,100%,50%), hsl(300,100%,50%), hsl(360,100%,50%)); /* Rainbow gradient for spectrum effect */
  border-radius: 10px;
  outline: none;
}

#hw-spectrum-slider::-webkit-slider-thumb {
  appearance: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #333;
  cursor: pointer;
}

#hw-spectrum-slider::-moz-range-thumb {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #333;
  cursor: pointer;
}

.hw-color-preview {
  width: 60px;
  height: 20px;
  border-radius: 8px; /* Square-ish for preview */
  border: 2px solid #ddd;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* =========================================
FONT SIZE SLIDER
========================================= */
.hw-editor-fontsize {
  position: absolute;
  bottom:153px;
  left: 0;
  width: 100%;
  padding: 10px 16px;
  background: #fff;
  z-index: 10;
}

#hw-editor-fontsize-slider {
  width: 100%;
  appearance: none;
  height: 6px; /* Thicker for easier mobile interaction */
  background: #444;
  border-radius: 4px;
  outline: none;
}

#hw-editor-fontsize-slider::-webkit-slider-thumb {
  appearance: none;
  width: 24px; /* Larger thumb for touch */
  height: 24px;
  border-radius: 50%;
  background: #883ca6;
  cursor: pointer;
}

#hw-editor-fontsize-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #883ca6;
  cursor: pointer;
}

/* ACTIVE TOOL */
.hw-editor-toolbar button.active {
  background: #883ca6; 
  color: #fff;
}

.hw-editor-toolbar button.active svg {
  stroke: #fff;
  fill: #fff;
}

/* =========================================
STICKERS
========================================= */
.hw-stickers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
  gap: 10px;
  width: 100%;
}

.hw-stickers-grid button {
  height: 50px;
  font-size: 30px; /* For emojis */
  background: #e9ecef;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hw-stickers-grid button:hover {
  background: #d1d5da;
}

/* =========================================
DESKTOP MODE (Media Query for Larger Screens)
========================================= */
@media (min-width: 768px) {
  .hw-story-editor {
    width: 800px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(248,249,250,0.85); /* Light overlay */
    align-items: center;
    justify-content: center;
    bottom: -77px;
  }

  .hw-story-editor::before {
    content: '';
   /* position: fixed; */
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7); /* Darker semi-transparent black */
    z-index: -1; /* Behind the editor content */
  }

  .hw-editor-top {
    width: 800px;
    border-radius: 14px 14px 0 0;
    left: 0;
    transform: none; /* Reset since parent is centered */
  }

  #hw-editor-canvas {
    width: 800px;
    margin: 0 auto;
  }

  .hw-editor-toolbar,
  .hw-editor-subtools,
  .hw-editor-colors,
  .hw-editor-fontsize {
    width: 800px;
    left: 0;
    transform: none; /* Reset */
  }

  /* Sidebar for tools on desktop */
  .hw-editor-toolbar {
    flex-direction: column;
    width: auto;
    height: auto;
    bottom: auto;
    left: -100px; /* Position as sidebar; adjust as needed */
    top: 80px;
    gap: 10px;
    background: none;
    border: none;
    padding: 0;
  }

  .hw-editor-toolbar button {
    width: 80px;
    height: auto;
    padding: 10px;
    flex-direction: row; /* Icon + text side by side */
  }

  .hw-editor-subtools {
    bottom: auto;
    top: 80px;
    left: 20px; /* Next to toolbar */
    width: auto;
    flex-direction: column;
  }

  /* Reset hover effects if needed, but keep as is since cursor:pointer is fine */
  .hw-editor-toolbar button {
   /* width: 46px; */
    height: 46px;
  }

  .hw-editor-colors button {
    width: 26px; /* Revert to original */
    height: 26px;
  }

  #hw-editor-fontsize-slider {
    height: 4px; /* Revert to original */
  }

  #hw-editor-fontsize-slider::-webkit-slider-thumb,
  #hw-editor-fontsize-slider::-moz-range-thumb {
    width: 18px; /* Revert to original */
    height: 18px;
  }

  .hw-editor-top svg,
  .hw-editor-toolbar svg {
    width: 22px; /* Revert to original */
    height: 22px;
  }
}