:root {
  --bg: #0b0b0d;
  --panel: #141418;
  --muted: #1b1b21;
  --border: #26262e;
  --text: #e9e9ef;
  --text-dim: #b7b7c7;
  --accent: #35c2ff;
  --accent-2: #7af;
  --danger: #ff4d4d;
  --good: #3ddc97;
  --shadow: 0 6px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { 
  height: 100%; 
  overscroll-behavior-y: contain; 
  user-select: none; 
  touch-action: pan-x pan-y; 
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* New: Prevent body scroll when a modal is open */
body.modal-open {
  overflow: hidden;
}

input, textarea, select {
  user-select: text;
}

.topbar, .bottombar {
  position: sticky;
  z-index: 10;
  backdrop-filter: saturate(1.1) blur(6px);
  background: color-mix(in oklab, var(--bg) 80%, black);
  border-bottom: 1px solid var(--border);
}

.topbar {
  top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; letter-spacing: 0.2px; font-family: 'Press Start 2P', "Noto Sans", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
.logo-image { /* New style for the image logo */
  height: 28px; /* Increased height to align with larger header buttons */
  width: auto;
  image-rendering: pixelated; /* Ensure it stays pixelated */
}
.title { /* Adjust title font size if needed to align with image */
  font-size: 16px; /* Example adjustment, keep original if preferred */
  font-family: 'Press Start 2P', "Noto Sans", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}
.meta { color: var(--text-dim); font-weight: 600; }

.actions { display: flex; gap: 6px; align-items: center; }

.btn, .icon-btn, .tool, .swatch, .swap {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px; /* increased padding for larger hit area */
  cursor: pointer;
  transition: transform .06s ease, background .2s ease, border-color .2s ease;
  font-size: 15px; /* slightly larger text for header buttons */
}
.btn:hover, .icon-btn:hover, .tool:hover, .swatch:hover, .swap:hover { background: var(--muted); }
.btn:active, .icon-btn:active, .tool:active, .swatch:active, .swap:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #001018; border-color: transparent; }
.btn.ghost { background: transparent; border-color: var(--border); }

.icon-btn { display: grid; place-content: center; width: 36px; height: 36px; padding: 0; }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

.tool i, .icon-btn i {
  font-size: 20px; /* increase icon size for header/action icons */
  line-height: 1;
  display: inline-block;
}
.tool {
  display: inline-grid; 
  place-items: center; 
  padding: 10px; 
}

.tool.active {
  background: var(--accent);
  color: var(--bg); 
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--accent-2); 
}
.tool.active:hover, .tool.active:active {
  background: color-mix(in oklab, var(--accent), black 10%); 
  transform: none; 
}

#btnUndo:active, #btnRedo:active, #btnClearTrace:active {
  background: var(--accent);
  color: var(--bg);
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--accent-2);
}

.workspace { 
  display: grid; 
  grid-template-columns: 1fr auto; 
  gap: 10px; 
  height: calc(100vh - 80px - 30px); 
}
.canvas-wrap {
  position: relative;
  display: grid; place-items: center;
  overflow: hidden; min-height: 60vh;
  touch-action: none; 
  background: #0f0f12; /* replaced fixed-size checker with solid; checker now drawn in canvas */
}
#screen {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  outline: none;
  background: transparent;
}

.hud {
  position: absolute; left: 8px; bottom: 8px;
  display: flex; gap: 8px; align-items: center;
  background: rgba(0,0,0,0.5);
  padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 12px;
}
.hud .toggle { display: inline-flex; align-items: center; gap: 6px; }
.hud input[type=checkbox] { accent-color: var(--accent); }

.sidebar {
  width: 300px; max-width: 40vw; padding: 10px; overflow: auto;
  border-left: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 85%, black);
}
.panel { background: var(--panel); padding: 10px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; }

.colors .swatches { display: flex; gap: 8px; align-items: center; }
.swatch { width: 36px; height: 36px; border-radius: 8px; }
.swap { width: 36px; height: 36px; display: grid; place-content: center; }
.swap svg { width: 20px; height: 20px; fill: currentColor; }
#colorPicker { width: 100%; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--muted); }

.palette, .recent { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; }
.palette button, .recent button {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
}

.tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.tool-brush-size {
  grid-column: 1 / -1;
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 6px;
}

.tool-brush-size label {
  flex-grow: 1;
}

.tool-brush-size label input[type=range] {
  width: 100%;
}

.tool-brush-size .brush-label { color: var(--text-dim); font-size: 0.9em; margin-right: 8px; white-space: nowrap; }

.brush-hud {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-left: 8px;
}
.brush-hud span { white-space: nowrap; }

.rows { display: grid; gap: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.compact { gap: 6px; }
.row input[type=range] { width: 50%; accent-color: var(--accent); }
.row.info { color: var(--text-dim); font-size: 12px; }

.bottombar {
  bottom: 0;
  border-top: 1px solid var(--border);
  padding: 6px 8px;
}
.tooltray { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tooltray .tool { padding: 10px; }

dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); }
.dialog-content { min-width: 280px; padding: 16px; }
.dialog-content h3 { margin: 0 0 10px 0; }
.dialog-content .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.dialog-content .opt { padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--muted); }
.dialog-content .custom { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.dialog-content menu { display: flex; justify-content: flex-end; margin: 16px 0 0; gap: 10px; }

/* New styles to separate sections in the New canvas dialog */
#newDialog .dialog-content h3 {
  margin-bottom: 20px; /* Increased bottom margin for the title */
}

#newDialog .dialog-content .grid {
  margin-top: 15px; /* Add top margin to separate from title */
}

#newDialog .dialog-content .custom {
  margin-top: 20px; /* Increased top margin to separate from presets */
}

#newDialog .dialog-content menu {
  margin-top: 20px; /* Increased top margin to separate from custom inputs */
}

/* New styles for dialog content and close button */
.dialog-content {
  position: relative; /* Needed for absolute positioning of close button */
  min-width: 280px; 
  padding: 16px; 
}

.dialog-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 20px;
  padding: 5px;
  line-height: 1;
  transition: color 0.2s ease;
  border-radius: 50%; /* Make it circular */
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-close-btn:hover {
  color: var(--text);
  background: var(--muted);
}

.dialog-close-btn:active {
  transform: translateY(1px);
}

.vis { display: none; } 

.color-info {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

/* NEW: Style for the color picker label */
.colors .color-picker-label {
  font-size: 0.85em; /* A bit smaller */
  color: var(--text-dim); /* Muted text color */
  margin-top: 10px; /* Space above the label */
  margin-bottom: 6px; /* Space between label and color picker */
  text-align: center; /* Center the text */
  width: 100%; /* Ensure it takes full width of its container for centering */
}

.color-info span { white-space: nowrap; }
.color-info .toggle { display: inline-flex; align-items: center; gap: 6px; }
.color-info input[type=checkbox] { accent-color: var(--accent); }

.export-options {
  grid-template-columns: 1fr; 
}
.export-options .opt {
  text-align: center; 
}

.help-sections h4 {
  margin-top: 1em;
  margin-bottom: 0.5em;
  color: var(--accent); /* A bit of color for section headers */
}

.help-sections ul {
  list-style: none; /* Remove default bullets */
  padding: 0;
  margin: 0;
}

.help-sections ul li {
  margin-bottom: 0.5em;
  font-size: 0.9em;
  line-height: 1.4;
  display: flex; /* Align icon and text */
  align-items: flex-start;
  gap: 8px; /* Space between icon and text */
}

.help-sections ul li i {
  font-size: 1.1em; /* Make icons slightly larger */
  color: var(--text-dim); /* Mute icon color */
  flex-shrink: 0; /* Prevent icon from shrinking */
  margin-top: 2px; /* Small adjustment for vertical alignment */
}

/* New styles for background option radios */
.bg-options {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 20px; /* increased spacing above the trans/negro/blanco buttons */
  margin-bottom: 12px;
}
.bg-options label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  background: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.95em;
}
.bg-options input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); }

footer {
  text-align: center;
  padding: 8px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 80%, black);
}
footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover {
  text-decoration: underline;
}

/* Mobile: improve Help dialog readability and layout on tall/narrow screens */
@media (max-width: 480px) {
  dialog { width: calc(100% - 24px); margin: 12px; }
  .dialog-content { min-width: unset; padding: 22px; max-height: 78vh; overflow: auto; -webkit-overflow-scrolling: touch; }
  .help-sections { display: block; gap: 16px; }
  .help-sections h4 { font-size: 1.05rem; margin-top: 0.9em; }
  .help-sections ul li { font-size: 1.05rem; line-height: 1.6; gap: 12px; padding-left: 6px; }
  .help-sections ul li i { font-size: 1.3em; margin-top: 3px; color: var(--accent); flex-shrink: 0; }
  .dialog-close-btn { top: 8px; right: 8px; width:36px;height:36px; }
  /* Make lists easier to scan on mobile: add spacing between list items and subtle separators */
  .help-sections ul li { padding: 10px 6px; border-bottom: 1px solid rgba(255,255,255,0.03); border-radius: 6px; }
  /* Increase dialog button hit area on mobile */
  .dialog-content menu button { padding: 12px 14px; font-size: 0.98rem; }
}

@media (max-width: 980px) {
  .workspace { 
    grid-template-columns: 1fr; 
    height: auto; 
    min-height: calc(100vh - 100px - 30px); 
  }
  .sidebar { width: auto; max-width: none; border-left: none; border-top: 1px solid var(--border); }
}

/* Center the action button only for the Help dialog */
#helpDialog .dialog-content menu {
  justify-content: center;
  gap: 12px; /* slightly larger touch target spacing for the centered layout */
}