@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

:root {
  /* DARKER RED THEME VARIABLES (Softer on the eyes) */
  --primary: #c62828;       /* Deep Crimson Red */
  --primary-hover: #b71c1c; /* Even darker red for hover state */
  --primary-light: rgba(198, 40, 40, 0.1);
  --danger: #78909c;        
  --danger-hover: #546e7a;
  --bg-color: #f4f7f6;
  --surface: #ffffff;
  --text-main: #333333;
  --text-muted: #666666;
  --border-color: #e0e0e0;
  --canvas-border: #ef9a9a; /* Softer pastel red border */
  --elevation-1: 0 2px 4px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --elevation-2: 0 4px 8px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
  --link-color: #c62828;
  --link-hover: #b71c1c;
}

[data-theme="dark"] {
  --bg-color: #121212;
  --surface: #1e1e1e;
  --text-main: #e0e0e0;
  --text-muted: #a0a0a0;
  --danger: #546e7a;
  --danger-hover: #78909c;
  --border-color: #333333;
  --primary-light: rgba(229, 57, 53, 0.15); /* Slightly softer red background for dark mode */
  --canvas-border: #444444;
  --elevation-1: 0 2px 4px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --elevation-2: 0 4px 8px rgba(0,0,0,0.6), 0 2px 4px rgba(0,0,0,0.4);
  /* Softer pastel red for dark mode links (less glaring) */
  --link-color: #ef5350; 
  --link-hover: #e53935;
}

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

body {
  font-family: 'Roboto', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Custom Link Styling */
a {
  color: var(--link-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* Header & Theme Toggle */
.header-container {
  position: relative;
  background-color: var(--primary);
  box-shadow: var(--elevation-2);
  margin-bottom: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 20px;
}

.header-container h1 {
  background-color: transparent;
  color: white;
  box-shadow: none;
  margin: 0;
  padding: 0;
  flex-grow: 1;
  text-align: center;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.theme-toggle {
  background: rgba(0, 0, 0, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: none;
  padding: 6px 14px;
  margin: 0;
}

.theme-toggle:hover {
  background: rgba(0, 0, 0, 0.3);
  box-shadow: none;
}

h2 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--primary);
  margin-bottom: 16px;
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 8px;
}

.sub-section-title {
  margin: 0 0 15px;
  color: var(--text-main);
  border-bottom: none;
}

.wrapper {
  display: flex;
  flex-direction: column;
  margin: auto;
  width: 100%;
  max-width: 1000px;
  padding: 0 20px 40px;
  gap: 24px;
}

/* Material Cards */
.section {
  background: var(--surface);
  border-radius: 8px;
  padding: 24px 32px;
  box-shadow: var(--elevation-1);
  width: 100%;
  transition: box-shadow 0.3s ease, background-color 0.3s ease;
}

.section:hover {
  box-shadow: var(--elevation-2);
}

.bottom-divider {
  border-bottom: none;
  padding-bottom: 24px;
}

/* Flexbox for Section 1 layout */
.section > .sub-section:first-of-type {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.column { float: none; flex: 1; min-width: 250px; }
.column-center { display: flex; align-items: center; justify-content: center; min-width: 50px; color: var(--text-muted); font-style: italic; }
.column-right { float: none; flex: 1; min-width: 250px; }

p { margin: 10px 0 20px; color: var(--text-muted); }

/* Grid Layout for settings */
.table {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 10px 24px;
  margin: 10px 0;
  align-items: center;
}

.table-row {
  display: contents; 
}

.table-cell {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0;
}

.table-cell:first-child {
  justify-content: flex-end;
  text-align: right;
  font-weight: 500;
  color: var(--text-main);
}

.nested-table {
  display: grid;
  grid-template-columns: 180px 1fr;
  background: var(--bg-color);
  padding: 16px;
  border-radius: 8px;
  margin-top: 10px;
  border: 1px solid var(--border-color);
}

.nested-table .table-cell { color: var(--text-muted); font-size: 0.9em; width: auto; }

/* Inputs and dropdowns */
input[type="text"],
input[type="number"],
select,
textarea {
  font-family: 'Roboto', sans-serif;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  color: var(--text-main);
  transition: all 0.2s ease;
  outline: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Adds the gap between the pixel inputs and the read buttons */
.text-input-size {
  margin-bottom: 16px;
}

/* Material Buttons - Rounded Pill Shape */
button,
input[type="file"]::file-selector-button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 24px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  /* Updated shadow using the RGB values of the darker #c62828 red */
  box-shadow: 0 2px 4px rgba(198, 40, 40, 0.3);
  transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
}

button:hover,
input[type="file"]::file-selector-button:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 8px rgba(198, 40, 40, 0.4);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  background: #cccccc;
  box-shadow: none;
  cursor: not-allowed;
}

input[type="file"] {
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
  padding: 0;
  font-size: 14px;
}

/* Specific Buttons */
.remove-button {
  background: var(--danger);
  box-shadow: 0 2px 4px rgba(245, 124, 0, 0.3);
  padding: 6px 12px;
  font-size: 12px;
}

.remove-button:hover {
  background: var(--danger-hover);
  box-shadow: 0 4px 8px rgba(245, 124, 0, 0.4);
}

#reset-button, #clear-button {
  background: var(--bg-color);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  box-shadow: var(--elevation-1);
}

#reset-button:hover, #clear-button:hover {
  background: var(--border-color);
  box-shadow: var(--elevation-2);
}

/* Flexbox container for horizontal button alignment */
.button-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap; 
}

.button-group button {
  margin: 0; 
  white-space: nowrap; 
}

/* Utilities */
.note, .file-info {
  color: var(--text-muted);
  font-size: 0.85em;
  line-height: 1.4;
}

.upload-note { margin-bottom: 15px; }

.byte-input {
  width: 100%;
  min-height: 120px;
  resize: vertical;
}

.code-output {
  width: 100%;
  height: 250px;
  font-family: 'Courier New', Courier, monospace;
  background: #2b2b2b;
  color: #a9b7c6;
  border-radius: 6px;
  padding: 16px;
  margin-top: 20px;
  border: none;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
  resize: vertical;
}

.size-input { width: 70px; text-align: center; }
.glyph-input { width: 60px; text-align: center; }

#image-size-settings {
  list-style-type: none;
  width: 100%;
}

#image-size-settings li {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.file-input-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-color);
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 8px;
  border-left: 4px solid var(--primary);
}

/* Canvas Display */
#images-canvas-container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 15px 0;
}

#images-canvas-container canvas {
  border: 2px dashed var(--canvas-border);
  border-radius: 6px;
  background: var(--bg-color);
  box-shadow: var(--elevation-1);
}

/* Messages */
.msg {
  font-size: 1em;
  padding: 10px 15px;
  border-radius: 4px;
  background: #fff3cd;
  color: #856404;
  border-left: 4px solid #ffeeba;
  margin: 10px 0;
}

.error-msg {
  background: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
  display: none;
}

/* Checkbox & Radio Alignment */
input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

label {
  cursor: pointer;
  user-select: none;
}

#format-caption-container div {
  color: var(--text-muted);
  display: none;
  font-size: 0.85em;
  line-height: 1.4;
  background: var(--primary-light);
  padding: 8px 14px;
  border-radius: 6px;
  margin-top: 6px;
  border-left: 3px solid var(--primary);
}

/* Hidden elements */
#arduino-identifier,
#adafruit-gfx-settings,
#all-same-size {
  display: none;
}