/* =======================
   Design tokens (tweak here)
======================= */
:root{
  --stage-gap: 8px;       /* space between left/center/right */
  --stage-side-pad: 10px; /* outer padding around stage */
  --left-col: 260px;      /* width of left sidebar */
  --right-col: 66px;      /* width of right palette */
}

/* =======================
   Fonts
======================= */
@font-face{
  font-family: 'SketchSocial';
  src: url('assets/fonts/Sketch.Social.ttf') format('truetype');
  font-display: swap;
}

@font-face{
  font-family: 'ComicSans';
  src: url('assets/fonts/comicsans.ttf') format('truetype');
  font-display: swap;
}

/* =======================
   Base
======================= */
* { margin: 0; padding: 0; box-sizing: border-box; }
html {
  max-width: 2560px;
  max-height: 1440px;
  min-height: 1024px;
  min-width: 768px;
}
body { background-color: #e2e2e2; color: #111; }
.hidden { display: none !important; }

/* =======================
   Navbar — mirrors thread.html exactly
======================= */
nav {
  background: #fff;
  border-bottom: 1px solid #d4d4d4;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;            /* containing block for #midicons pill */
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
  width: 100%;
  box-sizing: border-box;
}

/* Logo — exact copy of thread.html .nav-logo */
.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.nav-logo-text {
  font-family: 'Syne', ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  font-weight: 800;
  color: #111;
  white-space: nowrap;
}
.nav-logo-text em { color: #6b6bff; font-style: normal; }

/* Spacer — pushes midbar to center, avatar to right */
.nav-spacer { flex: 1; }

/* Midbar — absolutely centered in the nav */
#midbar {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 160px;
}

/* Nav Avatar — exact copy of thread.html .nav-avatar */
.nav-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7b6cf6, #a89cf7);
  background-size: cover;
  background-position: center;
  border: 2px solid #d4d4d4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  font-family: 'Syne', ui-sans-serif, system-ui, sans-serif;
  position: relative;
  overflow: visible;             /* lets dropdown escape the circle */
  flex-shrink: 0;
}
.nav-avatar:hover { border-color: #6b6bff; }

/* Initials — exact copy of thread.html */
.nav-avatar-initials {
  position: relative;
  z-index: 1;
  pointer-events: none;
  line-height: 1;
}

/* Dropdown — exact copy of thread.html */
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border: 1px solid #d4d4d4;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 160px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: all 0.15s;
}
.dropdown-menu.open {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}
.dropdown-item {
  padding: 10px 14px;
  font-size: 13px;
  color: #555;
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  cursor: pointer;
  transition: background .12s;
  border: none;
  font-family: 'Ubuntu', ui-sans-serif, system-ui, sans-serif;
}
.dropdown-item:hover { background: #f8f8f8; color: #111; }
.dropdown-item.danger { color: #e05a5a; }
.dropdown-item.danger:hover { background: #ffebeb; }

/* Slider value labels */
.slider {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 44px;
  width: 18vw;
  border-radius: 10px;
  background-color: #b7b7b7;
  position: relative;
  overflow: visible;
}
.slider-label {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  font-family: 'Ubuntu', ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
}
.slider-label::after {
  content: '';
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 5px 5px;
  border-style: solid;
  border-color: transparent transparent #111;
}
.slider-label.visible {
  opacity: 1;
}
#sliderSize { margin-left: 0; }
#opacity, #size {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 17vw;
  height: 35px;
  min-height: 35px;
  cursor: pointer;
  outline: none;
  border-radius: 15px;
}
#opacity { background-color: #e9c1ea; }
#size    { background-color: #a2c3ea; }

/* Chrome/Edge/Safari thumb */
#opacity::-webkit-slider-thumb, #size::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  background-size: cover; border: none; border-radius: 0;
}
#opacity::-webkit-slider-thumb { height: 40px; width: 40px; background-image: url("assets/images/OpacityButtonNOBOX-3.svg"); }
#size::-webkit-slider-thumb    { height: 40px; width: 40px; background-image: url("assets/images/SizeButtonNOBOX.svg"); }
#opacity::-webkit-slider-runnable-track,
#size::-webkit-slider-runnable-track { border-radius: 15px; height: 35px; }

/* Firefox thumb + track */
#opacity::-moz-range-thumb, #size::-moz-range-thumb {
  border: none; border-radius: 0; background-size: cover; width: 40px; height: 40px; cursor: pointer;
}
#opacity::-moz-range-thumb { background-image: url("assets/images/OpacityButtonNOBOX-3.svg"); }
#size::-moz-range-thumb    { background-image: url("assets/images/SizeButtonNOBOX.svg"); }
#opacity::-moz-range-track, #size::-moz-range-track { border-radius: 15px; height: 35px; }
#opacity::-moz-range-track { background-color: #e9c1ea; }
#size::-moz-range-track    { background-color: #a2c3ea; }

/* Undo/Clear/Redo pill — centered, straddles nav bottom edge */
#midicons {
  position: fixed;
  left: 50%;
  top: 38px;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  background: #fff;
  padding: 5px;
  border-radius: 13px;
  box-shadow: 0 6px 6px -2px rgba(0,0,0,0.2);
  z-index: 10;
}
#undo, #clear, #redo {
  display: flex; align-items: center; justify-content: center;
  margin: 0 2.5px; cursor: pointer;
}
#EraseAllIcon, #RedoIcon { width: 50px; height: 60px; }
#undoicon { width: 50px; height: 60px; }



/* =======================
   Stage Header (Palette selector above palettes)
======================= */
.stageHeader{
  display: grid;
  grid-template-columns: var(--left-col) max-content var(--right-col);
  column-gap: var(--stage-gap);
  row-gap: 0;
  padding: 12px var(--stage-side-pad) 4px;
  justify-content: center;  /* center the entire 3-col row */
  align-items: end;
  margin-left: 650px;
}

/* Palette selector */
.paletteSelector{
  justify-self: center;
  align-self: end;

  display: inline-flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border-radius: 14px;
  padding: 6px 12px;
  box-shadow: 0 8px 10px rgba(0,0,0,.12);
}

.palNum{
  font-family: 'SketchSocial', ui-sans-serif;
  font-size: 30px;
  line-height: 1;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: #333;
  transform-origin: center;
  transition: transform .15s ease, color .15s ease, text-decoration .15s ease, font-size .15s ease;
}
.palNum.active{
  font-size: 45px;
  color: #000;
  text-decoration: underline;
}

/* =======================
   Stage Layout (3 columns tight)
======================= */
.stage{
  display: grid;
  grid-template-columns: var(--left-col) max-content var(--right-col);
  column-gap: var(--stage-gap);
  row-gap: 0;
  padding: 6px var(--stage-side-pad) 0;
  justify-content: center;   /* keep columns together */
  align-items: start;
  margin-left: -175px;
}
.stage > * { min-width: 0; }
.leftColumn{ display: flex; flex-direction: column; gap: 12px; }

/* =======================
   Toolbox
======================= */
.toolbox{
  display: flex; gap: 8px;
  background: #fff; border: 1px solid #d8d8d8;
  border-radius: 14px; padding: 10px 14px;
  box-shadow: 0 6px 12px rgba(0,0,0,.08);
}
.tool{
  display: flex; align-items:center; justify-content:center;
  width: 40px; height: 40px; border: none; border-radius: 8px;
  background: transparent; cursor: pointer;
  transition: background .2s, transform .1s;
}
.tool img{ width:45px; height:45px; object-fit:contain; display:block; }
.tool:hover{ background:#f3f3f3; }
.tool.active{ background:#e5e5e5; }

/* =======================
   Layers Panel (left)
======================= */
.layersPanel{
  background: #eee;
  border: 1px solid #d8d8d8;
  border-radius: 16px;
  box-shadow: 0 6px 12px rgba(0,0,0,.08);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.layerItem{
  background: #d1d1d1;
  border-radius: 12px;
  padding: 8px;
  border: 1px solid #c7c7c7;
}
.layerHeader{
  font: 600 12px/1 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  color: #5b5b5b;
  margin-bottom: 6px;
}
.layerBody{
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 8px; align-items: center;
}
.layerThumbWrap{
  background: #fff; border: 1px solid #e0e0e0; border-radius: 8px;
  width: 100%; height: 84px; display:flex; align-items:center; justify-content:center;
  overflow: hidden;
}
.layerThumb{ width: 100%; height: 100%; display: block; }
.layerBtns{ display: flex; flex-direction: column; gap: 6px; }
.layerBtn{
  width: 28px; height: 28px; border: none; border-radius: 6px;
  display:flex; align-items:center; justify-content:center; cursor:pointer;
  background: #fff; box-shadow: inset 0 -1px 0 rgba(0,0,0,.08);
  font-weight: 700; font-size: 18px;
}
.layerBtn.add{ color: #2fa64a; }
.layerBtn.del{ color: #a14b41; }
.layerItem.active{ outline: 3px solid #6b6bff; }

/* =======================
   Paper / Canvas Stack (center)
======================= */
.paper{
  position: relative;
  width: 900px; height: 560px;
  background: #ffffff;
  border: 1px solid #dcdcdc;
  border-radius: 14px;
  box-shadow: 0 8px 16px rgba(0,0,0,.12);
  overflow: hidden;
}
#layerStack{ position: absolute; inset: 0; }
.stackCanvas, #draw, #draw-overlay{
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
}
#draw { opacity: 0; pointer-events: none; } /* sizing reference only */

/* =======================
   Save Row (below the stage)
======================= */
.saveRow{
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 0 20px;
}

.captionGroup{
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 900px;
  padding: 0 10px;
}

#captionInput{
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d8d8d8;
  border-radius: 10px;
  font-size: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: #fff;
  outline: none;
  transition: border-color .2s ease;
}

#captionInput:focus{
  border-color: #6b6bff;
}

.lockLabel{
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #555;
  user-select: none;
}

.lockLabel input[type="checkbox"]{
  cursor: pointer;
}

.lockIcon{
  font-size: 14px;
}

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

#saveCanvasBtn{
  background: #555; 
  color: #fff; 
  border: none;
  padding: 10px 16px; 
  border-radius: 8px;
  font-weight: 600; 
  cursor: pointer;
  transition: background .2s ease;
}

#saveCanvasBtn:hover{
  background: #444;
}

.postBtn{
  background: #6b6bff;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: background .2s ease, transform .05s ease;
}

.postBtn:hover{
  background: #5a5aee;
}

.postBtn:active{
  transform: scale(0.98);
}

/* =======================
   Right Column: Palettes
======================= */
.rightColumn{
  position: relative;
  height: 560px;
  align-self: start;
}
.paletteColumn{
  position: relative;
  width: var(--right-col); height: 100%;
  background: #f6f6f6;
  border-radius: 18px;
  box-shadow: inset 0 0 0 1px #e4e4e4;
  padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

/* swatches */
.swatch{
  width: 42px; height: 42px;
  border-radius: 999px; border: none;
  display:flex; align-items:center; justify-content:center;
  cursor: pointer; background: #fff;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.08);
  transition: background .15s ease, transform .05s ease, width .1s ease, border-radius .1s ease;
}
.swatch img{ width: 26px; height: 26px; pointer-events: none; }
.swatch:active{ transform: scale(.98); }
.swatch.color::after{
  content: "";
  width: 32px; height: 32px;
  border-radius: 999px;
  background: var(--swatch);
  display: block;
}
/* selected swatch turns into a rectangle indicator */
.swatch.selected{
  background: #e5e5e5;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.05);
  width: 56px;
  border-radius: 10px;
}
.swatches{
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; align-items: center;
}

/* hide native color input (for picker button only) */
#hiddenColorInput{
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
}

/* =======================
   Text Tool UI
======================= */
#textToolbar{
  position: absolute;
  top: 8px; left: 8px;
  z-index: 40;
  display: flex; gap: 8px; align-items: center;
  background: #fff; border: 1px solid #ddd; border-radius: 10px;
  padding: 6px 8px; box-shadow: 0 4px 10px rgba(0,0,0,.08);
}
#textToolbar label{
  font-size: 12px; color: #666;
}
#fontSelect{
  border: 1px solid #ccc; border-radius: 8px;
  padding: 4px 6px; outline: none; background: #fff;
}

/* =======================
   Swatch editor popup
======================= */
.swatchEditor{
  position: absolute;
  z-index: 1000;
  background: #fff;
  border: 1px solid #d8d8d8;
  border-radius: 10px;
  box-shadow: 0 10px 20px rgba(0,0,0,.15);
  padding: 10px;
  width: 210px;
}
.swatchEditor .row{ display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.swatchEditor .row.actions{ justify-content: flex-end; margin-bottom: 0; gap: 6px; }
.swatchEditor label{ font-size: 12px; width: 42px; color: #555; }
.swatchEditor input[type="text"],
.swatchEditor input[type="number"]{
  border: 1px solid #ccc; border-radius: 6px; padding: 4px 6px; width: 70px;
}
.swatchEditor input[type="number"]{ width: 52px; }
.swatchEditor button{
  border: none; border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
#swatchSave{ background: #111; color: #fff; }
#swatchCancel{ background: #eee; color: #222; }

/* Ensure stacking order during Text preview */
#layerStack { z-index: 10; }           /* layer canvases */
#draw        { z-index: 5; }            /* hidden sizing canvas */
#draw-overlay{ z-index: 15; pointer-events: none; } /* preview strokes */

.textBox     { z-index: 100; }          /* floating text container (injected) */
.textBox .rh { z-index: 101; }          /* resize handles above the box */

/* Badge cluster */
.badges{
  position: fixed;
  left: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  z-index: 10000;
}

/* Version badge (non-interactive) */
.buildBadge{
  padding: 6px 10px;
  background: rgba(17,17,17,.85);
  color: #fff;
  border-radius: 8px;
  font: 600 11px/1 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  letter-spacing: .2px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  pointer-events: none;   /* doesn't block clicks on the Discord badge */
  user-select: none;
}

/* Discord badge (clickable) */
.discordBadge{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #5865F2;           /* Discord blurple */
  color: #fff;
  border-radius: 8px;
  font: 600 11px/1 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  transition: transform .08s ease, filter .12s ease, box-shadow .12s ease;
}
.discordBadge:hover{
  filter: brightness(1.05);
  box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
.discordBadge:active{
  transform: translateY(1px);
}


