/* style.css */

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

/* ── Variables ── */
:root {
  --panel-width:   260px;
  --panel-min:     250px;
  --panel-max:     520px;
  --panel-padding: 12px;
  --bg:            #1a1a1a;
  --panel-bg:      #111;
  --panel-border:  #2a2a2a;
  --text:          #ccc;
  --text-dim:      #555;
  --accent:        #e8e0c8;
  --swatch-size:   18px;
}

/* ── Base ── */
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: monospace;
}

#app {
  display: flex;
  width: 100%; height: 100%;
}

/* ── Buttons ── */
button {
  background: #222;
  border: 1px solid #444;
  color: var(--text);
  font-family: monospace;
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover    { background: #2a2a2a; }
button:disabled { color: var(--text-dim); cursor: default; }
button.active   { background: #383838; border-color: #666; color: #fff; }

/* ── Button groups ── */
.btn-group {
  display: flex;
}
.btn-group button {
  border-radius: 0;
  border-right-width: 0;
}
.btn-group button:first-child { border-radius: 2px 0 0 2px; }
.btn-group button:last-child  { border-radius: 0 2px 2px 0; border-right-width: 1px; }

/* ── Inputs & selects ── */
input, select {
  background: var(--bg);
  border: 1px solid #333;
  color: var(--text);
  font-family: monospace;
  font-size: 10px;
  padding: 2px 6px;
}
input:focus, select:focus { outline: 1px solid #555; }

input[type="text"]   { width: 100%; text-align: left; }
input[type="number"] { width: 56px; text-align: right; }

/* Hide number spinner arrows — arrow key inc/dec still works */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* ── Side panel ── */
#panel {
  position: relative;
  width: var(--panel-width);
  min-width: var(--panel-min);
  max-width: var(--panel-max);
  height: 100%;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  padding: 12px var(--panel-padding) 12px;
  gap: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  flex-shrink: 0;
}

/* Drag handle */
#panel-resize {
  position: absolute;
  top: 0; right: -3px;
  width: 6px; height: 100%;
  cursor: col-resize;
  z-index: 20;
}
#panel-resize:hover,
#panel-resize.dragging {
  background: rgba(255,255,255,0.06);
}

/* ── Expandable sections (<details>) ── */
details {
  border-bottom: 1px solid var(--panel-border);
}

details > summary {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 8px 0 8px 14px;
  cursor: pointer;
  list-style: none;
  position: relative;
  user-select: none;
}
details > summary::-webkit-details-marker { display: none; }

/* Arrow indicator */
details > summary::before {
  content: '▸';
  position: absolute;
  left: 0;
  font-size: 8px;
  transition: transform 0.15s;
  color: var(--text-dim);
}
details[open] > summary::before {
  transform: rotate(90deg);
}

details > summary:hover { color: var(--text); }

.section-body {
  padding: 6px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* Nested details (comparison buffer) */
details details {
  border-bottom: none;
  border-top: 1px solid var(--panel-border);
  margin-top: 8px;
}
details details > summary {
  padding-left: 14px;
  font-size: 8px;
}
details details .section-body {
  padding-top: 6px;
}

/* ── Subsection labels (within a section body) ── */
.subsection-label {
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 8px;
  margin-bottom: 2px;
}
.subsection-label:first-child { margin-top: 0; }

/* ── Panel rows ── */
.panel-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.panel-row label {
  color: var(--text-dim);
  font-size: 10px;
  white-space: nowrap;
}

/* Two-column label+input pairs */
.input-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 8px;
}

.input-grid label {
  color: var(--text-dim);
  font-size: 10px;
  white-space: nowrap;
}

/* ── Glyph palette ── */
#palette-wrap {
  width: 100%;
  flex-shrink: 0;
}

#palette-grid {
  display: grid;
  grid-template-columns: repeat(16, var(--palette-cell, 1fr));
  grid-template-rows:    repeat(16, var(--palette-cell, 1fr));
  width: 100%;
  gap: 0;
  background: #222;
  outline: 1px solid #222;
}

#palette-grid img {
  width:  var(--palette-cell);
  height: var(--palette-cell);
  display: block;
  cursor: pointer;
  image-rendering: pixelated;
}

#palette-grid img.pal-active {
  outline: 1px solid #fff;
  outline-offset: -1px;
  z-index: 1;
  position: relative;
}

/* ── Colour swatches ── */
#colour-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.swatch-row {
  display: flex;
  gap: 2px;
}

.swatch {
  width:  var(--swatch-size);
  height: var(--swatch-size);
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}

.swatch.active-fg::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px #000;
}

.swatch.active-bg::before {
  content: '';
  position: absolute;
  bottom: 2px; right: 2px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px #000;
}

/* ── Export ── */
#export-size-label {
  font-size: 10px;
  color: var(--text-dim);
}

/* ── Comparison buffer ── */
#cmp-status {
  color: var(--text-dim);
  font-size: 9px;
}

.dim {
  color: var(--text-dim);
  font-size: 9px;
}

input[type="range"] {
  accent-color: var(--text);
  height: 4px;
  cursor: pointer;
}

/* ── Canvas area ── */
#canvas-wrap {
  flex: 1;
  height: 100%;
  position: relative;
  overflow: hidden;
  cursor: crosshair;
  min-width: 0;
}

#canvas {
  position: absolute;
  top: 0; left: 0;
  image-rendering: pixelated;
}

/* ── Status bar ── */
#status {
  position: fixed;
  bottom: 0;
  left: var(--panel-width);
  right: 0;
  height: 22px;
  background: #0d0d0d;
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 20px;
  font-size: 10px;
  color: var(--text-dim);
  z-index: 5;
}

#status span { white-space: nowrap; }

#st-fg-swatch,
#st-bg-swatch {
  display: inline-block;
  width: 8px; height: 8px;
  border: 1px solid #444;
  vertical-align: middle;
  margin-right: 3px;
}

/* ── Help overlay ── */
#help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
}
#help-overlay.open {
  display: flex;
}

#help-dialog {
  background: #161616;
  border: 1px solid #333;
  width: min(820px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px 28px 28px;
  position: relative;
  color: var(--text);
  font-family: monospace;
}

#help-close {
  position: absolute;
  top: 12px; right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
#help-close:hover { color: var(--text); background: none; }

#help-dialog h2 {
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 18px;
  font-weight: normal;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px 32px;
}

.help-group h3 {
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: normal;
  border-bottom: 1px solid #222;
  padding-bottom: 4px;
}

.help-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 10px;
}

.help-key {
  color: #fff;
  white-space: nowrap;
  flex-shrink: 0;
}

.help-key kbd {
  display: inline-block;
  background: #2a2a2a;
  border: 1px solid #444;
  border-bottom-width: 2px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 9px;
  border-radius: 3px;
  color: var(--text);
}

.help-desc {
  color: var(--text-dim);
  font-size: 10px;
  text-align: right;
}

#btn-help {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 10px;
  padding: 2px 4px;
  cursor: pointer;
  letter-spacing: 0.05em;
}
#btn-help:hover { color: var(--text); background: none; }