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

:root {
  --bg:        #111113;
  --surface:   #1c1c1f;
  --surface2:  #26262b;
  --surface3:  #2e2e35;
  --border:    #38383f;
  --accent:    #7c6cfc;
  --accent-h:  #6c5ef0;
  --text:      #e8e8ec;
  --text-dim:  #888896;
  --panel-w:   72px;
  --right-w:   240px;
  --toolbar-h: 48px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  z-index: 10;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--accent);
  margin-right: 8px;
}

.toolbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 6px;
}

#zoom-display {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 40px;
  text-align: center;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
  user-select: none;
}

.btn:hover:not(:disabled) { background: var(--surface3); border-color: #555; }
.btn:active:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn.icon-btn { padding: 5px 8px; font-size: 14px; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover:not(:disabled) { background: var(--accent-h); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app-layout {
  display: flex;
  height: calc(100vh - var(--toolbar-h));
  overflow: hidden;
}

/* ── Left panel ───────────────────────────────────────────────────────────── */
#panel-left {
  width: var(--panel-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 4px;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.tool-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
}

.tool-sep {
  width: 40px;
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.tool-btn {
  width: 48px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  font-size: 10px;
  font-weight: 500;
}

.tool-btn svg { width: 20px; height: 20px; }
.tool-btn:hover { background: var(--surface2); color: var(--text); }
.tool-btn.active { background: var(--surface3); color: var(--accent); border-color: var(--accent); }

.size-preview-wrap {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#size-preview-dot {
  border-radius: 50%;
  background: var(--text);
  pointer-events: none;
  transition: width 0.1s, height 0.1s;
}

.left-slider-wrap {
  width: 100%;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.left-slider-label {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="range"].vertical {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 80px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--accent);
}

input[type="range"].horizontal {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Canvas area ──────────────────────────────────────────────────────────── */
#canvas-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, #1a1a1e 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a1e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a1e 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a1e 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #141416;
}

#canvas-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

#canvas-wrapper {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
}

#color-canvas,
#temp-canvas,
#lines-canvas {
  position: absolute;
  top: 0; left: 0;
  display: block;
}

#lines-canvas   { pointer-events: none; }
#temp-canvas    { pointer-events: none; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
}

#empty-state.hidden { display: none; }

#empty-state .empty-icon { font-size: 56px; opacity: 0.25; }

#empty-state p {
  font-size: 15px;
  color: var(--text-dim);
  text-align: center;
}

#empty-state .btn { pointer-events: all; }

/* ── Right panel ──────────────────────────────────────────────────────────── */
#panel-right {
  width: var(--right-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 14px;
  flex-shrink: 0;
  overflow-y: auto;
}

.panel-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

#color-wheel {
  display: block;
  width: 100%;
  max-width: 200px;
  height: auto;
  aspect-ratio: 1;
  margin: 0 auto;
  cursor: crosshair;
}

.color-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

#current-color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

#hex-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: monospace;
  padding: 5px 8px;
  outline: none;
}

#hex-input:focus { border-color: var(--accent); }
#hex-input {
  -webkit-user-select: text;
  user-select: text;
  touch-action: auto;
}

/* ── Recent colors ────────────────────────────────────────────────────────── */
#recent-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.recent-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}

.recent-swatch:hover { transform: scale(1.2); border-color: rgba(255,255,255,0.3); }

/* ── Panel slider rows ────────────────────────────────────────────────────── */
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider-row label {
  font-size: 11px;
  color: var(--text-dim);
  flex: 0 0 58px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-row .val {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  flex: 0 0 28px;
}

.right-divider {
  height: 1px;
  background: var(--border);
}

/* ── Image settings panel ─────────────────────────────────────────────────── */
#image-settings { display: flex; flex-direction: column; gap: 8px; }

/* ── Session dialog ───────────────────────────────────────────────────────── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.dialog-overlay.hidden { display: none; }

.dialog-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 340px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.dialog-box h3 { font-size: 16px; font-weight: 600; }
.dialog-box p  { font-size: 13px; color: var(--text-dim); line-height: 1.5; }

.dialog-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.dialog-actions .btn { flex: 1; justify-content: center; }

/* ── Gallery modal ────────────────────────────────────────────────────────── */
.gallery-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(860px, 94vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  overflow: hidden;
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.gallery-header h3 { font-size: 15px; font-weight: 600; }

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}

.gallery-thumb {
  background: #fff;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.gallery-thumb:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.gallery-thumb img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  display: block;
  background: #fff;
  padding: 8px;
}

.gallery-thumb-name {
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 10px;
  padding: 5px 8px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--border);
}

#gallery-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

#gallery-empty.hidden { display: none; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive: tablet ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --right-w: 200px; }
}

@media (max-width: 680px) {
  :root { --right-w: 0px; --panel-w: 56px; }
  #panel-right { display: none; }
  #toolbar .app-name { display: none; }
}
