:root {
  --bg: #252526;
  --panel: #2f2f30;
  --panel-2: #3a3a3c;
  --btn: #464646;
  --btn-hover: #555555;
  --btn-active: #3c3c3c;
  --text: #e6e6e6;
  --accent: #297ce2;
  --accent-hover: #4b93ec;
}

* {
  box-sizing: border-box;
}

/* lean scrollbars that match the dark UI */
* {
  scrollbar-width: thin;
  scrollbar-color: #4a4a4c transparent;
}
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #4a4a4c;
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: #5c5c5e;
  background-clip: padding-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

body {
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  width: 100vw;
}

#main-col {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

/* ---- top toolbar ---- */
#topbar {
  flex: 0 0 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 8px;
  background: var(--panel);
  border-bottom: 1px solid #1c1c1c;
  user-select: none;
}
.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tb-btn {
  height: 28px;
  min-width: 30px;
  padding: 0 10px;
  background: var(--btn);
  border: none;
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.tb-btn:hover {
  background: var(--btn-hover);
}
.tb-btn:active {
  background: var(--btn-active);
}
.tb-btn.sym {
  width: 28px;
  padding: 0;
  font-weight: 600;
}
.tb-btn.sym.on {
  background: var(--accent);
  color: #fff;
}
.tb-btn.help {
  margin-left: auto;
  width: 28px;
  padding: 0;
  font-weight: 700;
}
.tb-label {
  font-size: 12px;
  font-weight: 700;
  color: #aaa;
  white-space: nowrap;
  padding-right: 4px;
}
.tb-sep {
  width: 1px;
  height: 22px;
  background: #1c1c1c;
}
.tb-spacer {
  flex: 1 1 auto;
}
.tb-colors {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}
.tb-color {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid #1c1c1c;
  border-radius: 3px;
  cursor: pointer;
  flex: 0 0 auto;
}
.tb-color.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.tb-color.invisible {
  background-image: linear-gradient(45deg, #555 25%, transparent 25%),
    linear-gradient(-45deg, #555 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #555 75%),
    linear-gradient(-45deg, transparent 75%, #555 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  background-color: #3a3a3c;
}

#canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#hotkey-legend {
  position: absolute;
  left: 10px;
  bottom: 8px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid #1c1c1c;
  border-radius: 6px;
  font-size: 12px;
  color: #e6e6e6;
  user-select: none;
  max-width: 260px;
}
#hotkey-legend .legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
  letter-spacing: 0.4px;
}
#hotkey-legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 3px;
}
#hotkey-legend li {
  color: #cfcfcf;
}
#hotkey-legend b {
  display: inline-block;
  min-width: 92px;
  color: #fff;
}

.hidden {
  display: none !important;
}

#sidebar {
  flex: 0 0 200px;
  width: 200px;
  height: 100%;
  padding: 8px;
  background: var(--panel);
  border-left: 1px solid #1c1c1c;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---- collapsible sections ---- */
.panel-section {
  flex: 0 0 auto;
  border: 1px solid #1c1c1c;
  border-radius: 5px;
  background: var(--panel-2);
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 8px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  text-align: left;
}
.section-header:hover {
  background: rgba(255, 255, 255, 0.05);
}
.chevron {
  width: 0;
  height: 0;
  border-left: 5px solid #b9b9b9;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(90deg);
  transition: transform 0.12s ease;
  flex: 0 0 auto;
}
.panel-section.collapsed .chevron {
  transform: rotate(0deg);
}
.section-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid #1c1c1c;
}
.panel-section.collapsed .section-body {
  display: none;
}

button,
input[type="number"],
input[type="text"],
input[type="range"] {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}

button {
  background: var(--btn);
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
}
button:hover {
  background: var(--btn-hover);
}
button:active {
  background: var(--btn-active);
}
button.wide {
  width: 100%;
}

.section-title {
  text-align: center;
  color: #b9b9b9;
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 0.4px;
}

hr {
  width: 100%;
  border: none;
  border-top: 1px solid #1c1c1c;
  margin: 6px 0;
}

.size-row {
  display: flex;
  gap: 6px;
}
.size-row input {
  width: 50%;
}

input[type="number"],
input[type="text"] {
  background: var(--panel-2);
  border: 1px solid #1c1c1c;
  border-radius: 4px;
  padding: 5px 6px;
  width: 100%;
}

select {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #1c1c1c;
  border-radius: 4px;
  padding: 5px 6px;
}
select.wide {
  width: 100%;
}

.dims-label {
  text-align: center;
  color: #cfcfcf;
  font-size: 13px;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

#color-selector {
  background: var(--panel-2);
  border: 1px solid #1c1c1c;
  border-radius: 4px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scale-ring-count {
  text-align: center;
  color: #b9b9b9;
  font-size: 12px;
  letter-spacing: 0.4px;
  padding: 3px 0 1px;
  font-variant-numeric: tabular-nums;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 5px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}
.color-row:hover {
  background: rgba(255, 255, 255, 0.06);
}
.color-row.selected {
  background: var(--accent);
  color: #fff;
}

.swatch {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid #1c1c1c;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  flex: 0 0 auto;
}
input.swatch {
  -webkit-appearance: none;
  appearance: none;
}
input.swatch::-webkit-color-swatch-wrapper {
  padding: 0;
}
input.swatch::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}
.swatch.invisible {
  background-image: linear-gradient(45deg, #555 25%, transparent 25%),
    linear-gradient(-45deg, #555 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #555 75%),
    linear-gradient(-45deg, transparent 75%, #555 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.color-label {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sym-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sym-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  padding: 0;
  background: #464646;
}
.sym-btn.on {
  background: var(--accent);
  color: #fff;
}
.sym-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
}

/* ---- save manager modal ---- */
#modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.modal {
  width: min(560px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid #1c1c1c;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #1c1c1c;
}
.modal-head h2 {
  margin: 0;
  font-size: 16px;
}
.modal-x {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: transparent;
}
.modal-x:hover {
  background: var(--btn-hover);
}
.modal-body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-title {
  color: #b9b9b9;
  font-size: 12px;
  letter-spacing: 0.4px;
  margin-top: 4px;
}
.save-current,
.import-row {
  display: flex;
  gap: 6px;
}
.save-current input,
.import-row input {
  flex: 1 1 auto;
  min-width: 0;
}
.save-current button,
.import-row button {
  flex: 0 0 auto;
  white-space: nowrap;
}
.slot-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
}
.slot-empty {
  color: #9a9a9a;
  font-size: 13px;
  text-align: center;
  padding: 8px 0;
}
.slot-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid #1c1c1c;
  border-radius: 5px;
}
.slot-row.active {
  border-color: var(--accent);
}
.slot-info {
  flex: 1 1 auto;
  min-width: 0;
}
.slot-name {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-meta {
  font-size: 11px;
  color: #9a9a9a;
  font-variant-numeric: tabular-nums;
}
.slot-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}
.slot-actions button {
  padding: 4px 8px;
  font-size: 12px;
}
.slot-actions .danger:hover {
  background: #7a2b2b;
}
#export-all-box {
  background: var(--panel-2);
  border: 1px solid #1c1c1c;
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text);
  font-family: "Consolas", monospace;
  font-size: 12px;
  resize: vertical;
}

/* ---- toast ---- */
#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  padding: 8px 16px;
  background: rgba(20, 20, 20, 0.92);
  border: 1px solid #1c1c1c;
  border-radius: 6px;
  font-size: 13px;
  color: #fff;
  pointer-events: none;
}

/* Responsive: stack the sidebar below the canvas on narrow screens */
@media (max-width: 720px) {
  #app {
    flex-direction: column;
  }
  #canvas-wrap {
    flex: 1 1 60%;
  }
  #sidebar {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid #1c1c1c;
  }
}
