:root {
  --gap: 12px;
  --radius: 10px;
  --grid-cols: 7; /* red, yellow, green, blue, magenta, brown, neutral */
  --grid-rows: 5; /* rows in the reference image */

  /* Sidebar sizes */
  --sidebar-width: 350px;
  --sidebar-collapsed: 64px;
  --sidebar-bg: rgba(20, 20, 22, 0.96);
  --sidebar-z: 1200;

  background-color: #2c2c2c;
}

body {
  --sidebar-current: var(--sidebar-width);
}

/* When collapsed, switch the current width variable */
body.sidebar-collapsed {
  --sidebar-current: var(--sidebar-collapsed);
}

/* Prevent any accidental horizontal overflow */
html,
body {
  overflow-x: hidden;
}

/* Sidebar layout */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  box-sizing: border-box;
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: var(--sidebar-z);
  transition: width 0.28s ease, transform 0.28s ease, opacity 0.28s ease;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  scrollbar-width: hidden; /* Firefox */
  -ms-overflow-style: none; /* hide scrollbar in IE and Edge */
}

/* collapsed state: only toggle button remains width-wise */
body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed);
}

/* Toggle button (minimizer) */
.sidebar-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  margin-bottom: 0.4rem;
  overflow: hidden;
}
.sidebar-toggle:hover {
  background: rgb(184, 184, 184);
  color: #000;
}

/* hide the heading and list when collapsed (visually) */
body.sidebar-collapsed .sidebar .sidebar-inner {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-6px);
  transition: opacity 0.18s, transform 0.18s;
}

/* inner area scrollable */
.sidebar-inner {
  padding-right: 0.35rem;
  display: flex;
  height: 100%;
  flex-direction: column;
  overflow: auto; /* remove/override the later overflow:hidden */
  padding-right: 0.35rem;
  scrollbar-width: hidden; /* Firefox */
  -ms-overflow-style: none; /* hide scrollbar in IE and Edge */
}

/* sidebar title */
.sidebar-title {
  font-size: 0.95rem;
  margin: 0 0 0.5rem 0;
  font-weight: 700;
  font: 700 1rem/1.1 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
}

/* sets list */
.colour-sets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  overflow: hidden;
  scrollbar-width: hidden; /* Firefox */
  -ms-overflow-style: none; /* hide scrollbar in IE and Edge */
}

/* each set item */
.colour-set {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: background 0.16s, transform 0.12s;
  overflow: hidden;
  scrollbar-width: hidden; /* Firefox */
  -ms-overflow-style: none; /* hide scrollbar in IE and Edge */
}
.colour-set:hover {
  background: rgba(255, 255, 255, 0.158);
  transform: translateY(-1px);
}
.colour-set.active {
  background: rgba(255, 255, 255, 0.212);
  border-color: rgba(255, 255, 255, 0.08);
}

/* small swatches in the item (preview few colours) */
.colour-swatches {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 0 0 auto;
}
.colour-swatch {
  width: 18px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

/* label */
.colour-set-label {
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font: 700 1rem/1.1 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
  width: 100%;
  flex-shrink: 1;
}

.col {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  width: 20rem;
  min-height: 0;
  padding-right: 0.8rem;
  border-right: 1px solid #ffffff62;
}

.col__label, .set__label {
  font: 700 0.9rem/1.15 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
  color: #fff;
  text-align: center;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 0.25rem;
  padding: 0.5rem;
}

.col__label:hover, .set__label:hover {
  background: #ffffff3d;
  cursor: pointer;
}

.col__grid {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: var(--gap);
  min-height: 0;
}

/* make room for sidebar: shift board to the right by sidebar width */
.board {
  position: fixed;
  top: 0;
  left: var(--sidebar-current);
  right: 0;
  height: 100svh;
  padding: var(--gap);
  box-sizing: border-box;

  display: flex;
  flex-direction: column;
  gap: var(--gap);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;

  font: 700 0.9rem/1.15 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;

    color: #fff;
  transition: left 0.28s ease, right 0.28s ease, padding 0.28s ease;
}

.board__cols {
  display: flex;
  gap: var(--gap);
  height: 100%;
}

/* collapsed -> update left position */
body.sidebar-collapsed .board {
  left: var(--sidebar-collapsed);
}

/* Inner buttons */
.btn {
  display: flex;
  flex: 1 auto;
  width: 100%;
  place-items: center;
  border-radius: 8px;
  border: 1.6px solid var(--fg-weak);
  background: transparent;
  color: var(--fg);
  font: 700 1rem/1.1 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
  font-size: clamp(0.58rem, 2.6vw, 0.9rem);
  text-align: center;
  align-self: center;
  justify-content: center;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.55em 0.6em;
  cursor: pointer;
  outline: none;
  z-index: 10;
  transition: filter 120ms ease, transform 60ms ease, opacity 160ms ease;
}
.btn:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}
.btn:hover {
  background: #fff;
  color: #000;
  border: 1px solid #fff;
}
.btn:active {
  transform: scale(0.99);
}

.tile .btn {
  display: flex;
  flex: 1 auto;
  padding: 0;
  margin: 0;
  opacity: 0;
  max-height: 20%;
  transition: filter 120ms ease, transform 60ms ease, opacity 160ms ease;
}
.tile:hover .btn {
  opacity: 1;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 0.5rem;
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: flex-end;
}

/* ensure sidebar controls are visible */
.sidebar-bottom .btn {
  opacity: 1;
  padding: 1.5rem;
  margin-bottom: 1rem;
  width: 100%;
  border: 1px solid #fff;
}

.row3 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;

  /* Prevent overflow growth inside the tile grid area */
  min-width: 0;
  min-height: 0;
}

/* Copy toast (modal-like) */
.toast {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}
.toast.show {
  opacity: 1;
}
.toast__msg {
  background: rgba(20, 20, 22, 0.98);
  color: #fff;
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  font: 600 1rem system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    sans-serif;
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

/* Colour tile */
.tile {
  display: flex;
  flex-direction: column;
  flex: 1 auto;
  gap: 8px;
  max-width: 20rem;
  max-height: 20%;
  border-radius: var(--radius);
  transition: filter 120ms ease, transform 60ms ease;
  outline: none;
  padding: 0.6rem;

  /* Ensure content never forces the grid to overflow the viewport */
  min-width: 0;
  overflow: clip;

  /* Per-tile responsiveness for narrow cells */
  container-type: inline-size;
}
.tile:active {
  transform: scale(0.995);
}

.tile:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* Fallback for browsers without container queries: switch on narrow viewports */

/* when a tile is hovered, reveal all its buttons */
.tile:hover .btn {
  opacity: 1;
}

/* “Add colour” tile */
.tile--add {
  display: flex;
  flex-direction: column;
  flex: 1 auto;
  max-height: 7.5%;
  place-items: center;
  background: repeating-conic-gradient(
      from 45deg,
      rgba(255, 255, 255, 0.08) 0 25%,
      rgba(0, 0, 0, 0.08) 0 50%
    )
    50% / 16px 16px;
  border: 1px dashed rgba(255, 255, 255, 0.35);
}

.tile--add .add-btn {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: transparent;
  font: 800 clamp(1.6rem, 7vw, 3rem) / 1 system-ui, -apple-system, Segoe UI,
    Roboto, Helvetica, Arial, sans-serif;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}
.tile--add .add-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}
.tile--add .add-btn:hover {
  background: #ffffff3d;
  border: 1px solid rgba(255, 255, 255, 0.781);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1500;
}
.modal--open {
  display: grid;
  place-items: center;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal__panel {
  position: relative;
  width: min(92vw, 640px);
  padding: 18px;
  border-radius: 12px;
  background: #1f1f1f;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.modal__title {
  margin: 0.5rem 0 2rem 0;
  font: 700 1.1rem/1.2 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
  color: #fff;
}
.modal__body {
  display: grid;
  gap: 12px;
  width: 100%;
}
#color-input {
  width: 100%;
  height: 148px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #111;
  border-radius: 8px;
}
#color-input:hover {
  filter: brightness(2);
  cursor: pointer;
}

.modal__actions {
  margin-top: 3rem;
  margin-bottom: 1rem;
  display: flex;
  gap: 2rem;
  justify-content: flex-end;
}
.modal__btn {
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #2a2a2a;
  color: #fff;
  cursor: pointer;
}
.modal__btn:hover {
  background: #4da3ff;
  border-color: #4da3ff;
  color: #000;
}
.modal__btn--primary {
  border-color: #4da3ff;
  background: #2e68a1;
}

/* Optional minimal styles; align with existing modal styling */
#label-modal {
  display: none;
}
#label-modal.modal--open {
  display: grid;
  place-items: center;
}

#label-input {
  min-height: 1.5rem;
  width: 75%;
  text-align: center;
  align-self: center;
  justify-self: center;
}

/* Minimal inline picker styles; neutral so it inherits your modal design */
.inline-picker {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  gap: 0.75rem;
  color: #fff;
  font: 700 1rem/1.1 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
}
.inline-picker__row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
}
.inline-picker__preview {
  width: 150px;
  height: 40px;
  border-radius: 4px;
  border: 1px solid var(--border, #ccc);
}
.inline-picker__label {
  display: grid;
  gap: 0.375rem;
  font-size: 0.9rem;
  margin-top: 1rem;
  width: 80%;
}
.inline-picker__slider {
  margin-top: 0.45rem;
  width: 100%;
  height: 18px;
  border-radius: 999px;
  appearance: none;
  background: #ddd;
}
.inline-picker__slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: currentColor;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
.inline-picker__slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: currentColor;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
/* Hue track gradient (updated dynamically as well for S/L sliders) */
#inline-h {
  background: linear-gradient(
    90deg,
    #f00 0%,
    #ff0 17%,
    #0f0 33%,
    #0ff 50%,
    #00f 67%,
    #f0f 83%,
    #f00 100%
  );
}
.inline-picker__hex input#inline-hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  padding: 0.35rem 0.5rem;
  width: 8ch; /* fits '#RRGGBB' */
  border: 1px solid var(--border, #ccc);
  border-radius: 4px;
}
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 1px, 1px);
  white-space: nowrap;
  border: 0;
}

#color-delete{
  margin-right: auto;
  background: #ff4d4d;
  border-color: #ff4d4d;
}
#color-delete:hover{
  filter:brightness(2);
  color: #fff;
}
.set__label {
  font-weight: 600;
  margin-bottom: .5rem;
  cursor: pointer;
  user-select: none;
}
.set__label:focus {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.colour-set-delete-container{
  display: flex;
  justify-content: flex-end;
  flex-shrink: 1;
  height: auto;
  border-radius: 2rem;
  padding: 0.2rem;
}
.colour-set-delete-container:hover{
  background: #ffffff3d;
  cursor: pointer;
}

.colour-set-delete{
  width: 20px;
  height: auto;
}

/* confirm modal message (optional) */
.modal__message { color:#ddd; text-align:center;    font: 700 1rem/1.1 system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;}

/* danger action */
.modal__btn--danger {
  border-color: #ff4d4d;
  background: #b00020;
}
.modal__btn--danger:hover {
  filter: brightness(1.2);
  color: #fff;
}

/* Tabs */
.tabs {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
  margin-bottom: 0.5rem;
  width: 100%;
}
.tabs__btn {
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  background: #2a2a2a;
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  cursor: pointer;
}
.tabs__btn[aria-selected="true"] {
  background: #4da3ff;
  border-color: #4da3ff;
  color: #000;
}

/* Text tile */
.tile--text {
  background: #1f1f1f;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
}
.text-tile__preview {
  padding: 0.4rem 0.2rem;
  border-radius: 6px;
  width: 100%;
  min-height: 2.25rem;
  background: transparent;
}

/* Text editor inside modal */
.text-editor { display: grid; gap: 12px; color: #fff; }
.text-editor__preview {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
}
.text-editor__row { display: grid; gap: 8px; }
.text-editor__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 10px;
}
.text-editor__label { display: grid; gap: 6px; font-size: 0.9rem; }
.text-editor input, .text-editor select {
  width: 80%;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: #111;
  color: #fff;
}