/* ========================================
   CSS CUSTOM PROPERTIES (DARK THEME)
   ========================================
   Dark theme color palette for CAPTCHA Art Generator
   These variables are overridden in [data-theme="light"] for light mode
*/
:root{
  --bg:#0f1220;          /* Main background - deep blue */
  --panel:#151935;        /* Panel background - lighter blue */
  --text:#e9ecff;         /* Primary text - light blue-white */
  --muted:#b7bde6;        /* Muted text - medium blue */
  --accent:#7ea8ff;       /* Primary accent - bright blue */
  --accent2:#6ee7b7;      /* Secondary accent - green */
  --danger:#ff8a8a;       /* Danger/warning - red */
  --border:#242a55;       /* Border color - dark blue */
  --input-bg:#0e1330;     /* Input background - darker blue */
  --button-text:#0f1220;
  --input-hover:#22285a;  /* Input hover state - medium blue */
}

/* ========================================
   LIGHT THEME OVERRIDES
   ========================================
   Light theme color palette - overrides dark theme variables
*/
[data-theme="light"]{
  --bg:#f7f8fa;          /* Light gray background */
  --panel:#ffffff;        /* White panels */
  --text:#1a1f36;         /* Dark blue text */
  --muted:#475569;        /* Gray muted text */
  --accent:#2563eb;       /* Blue accent */
  --accent2:#10b981;      /* Green accent */
  --danger:#ef4444;       /* Red danger */
  --border:#e2e8f0;       /* Light gray border */
  --input-bg:#f1f5f9;     /* Light input background */
  --button-text:#ffffff;
  --input-hover:#e2e8f0;  /* Light input hover */
}
/* ========================================
   GLOBAL STYLES
   ========================================
*/
*{box-sizing:border-box} /* Consistent box model */
/* ========================================
   THEME TOGGLE BUTTON
   ========================================
   Floating theme switcher positioned relative to content area
*/
.theme-toggle{
  position:static;
  background:var(--panel);
  border:1px solid var(--border);
  color:var(--text);
  width:44px;
  height:44px;
  border-radius:12px;
  cursor:pointer;
  font-size:20px;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:all 0.3s ease;
  z-index:100;
}

.theme-toggle:hover{
  background:var(--input-hover);
  transform:scale(1.05);
}

.theme-icon{
  display:inline-block;
  transition:transform 0.3s ease;
}

.theme-toggle:active .theme-icon{
  transform:rotate(20deg); /* Fun click animation */
}
/* ========================================
   BASE LAYOUT
   ========================================
*/
html,body{
  margin:0;
  padding:0;
  background:var(--bg);
  color:var(--text);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,"Noto Sans JP","Apple Color Emoji","Segoe UI Emoji",sans-serif;
}
/* ========================================
   HEADER SECTION
   ========================================
*/
.header{
  padding:28px 16px 8px;
  text-align:center;
}

.header h1{
  margin:0;
  font-size:28px;
  letter-spacing:.5px;
}

.subtitle{
  margin:.25rem 0 0;
  color:var(--muted);
  font-size:14px;
}
/* ========================================
   MAIN CONTAINER LAYOUT
   ========================================
   Two-column grid: controls panel + preview panel
*/
.container{
  display:grid;
  grid-template-columns:minmax(0, 1fr);
  gap:16px;
  max-width:1200px;
  padding:16px;
  margin:0 auto;
}
/* ========================================
   PANEL COMPONENTS
   ========================================
   Reusable panel styling for controls and preview
*/
.panel{
  min-width:0;
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:16px;
  padding:20px;
  box-shadow:0 2px 8px rgba(0,0,0,0.1); /* Subtle elevation */
}

.panel h2{
  margin:0 0 8px;
  font-size:18px;
}
/* ========================================
   FORM CONTROLS
   ========================================
   Input fields, labels, and form layout
*/
.controls .field{
  display:flex;
  flex-direction:column;
  margin-bottom:10px;
}

.controls .field span{
  font-size:14px;
  color:var(--muted);
  margin-bottom:6px;
  display:block;
}

/* ========================================
   HELP TOOLTIPS
   ========================================
   Interactive help icons with hover tooltips
*/
.help-text, .controls .field .help-text {
  display:none;
  margin:6px 0;
  font-size:14px;
  line-height:1.5;
}
.show-help .help-text, .show-help .controls .field .help-text {
  display:block;
}
/* Text inputs and selects */
.controls input[type="text"],
.controls input[type="number"],
.controls select{
  background:var(--input-bg);
  border:1px solid var(--border);
  color:var(--text);
  padding:8px;
  font-size:16px;
  min-height:44px;
  min-width:0;
  width:100%;
  border-radius:10px;
}
/* Two-column grid for form elements */
.grid-2{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:12px;
}
/* ========================================
   COLLAPSIBLE SECTIONS
   ========================================
   Expandable details for parameters and info
*/
.details{
  margin-top:12px;
  border:1px solid var(--border);
  border-radius:10px;
  padding:12px;
  background:var(--input-bg);
}

.details summary{
  cursor:pointer;
  color:var(--muted);
}
/* ========================================
   RANGE SLIDERS
   ========================================
   Custom styled range inputs for parameter control
*/
.sliders .field{
  margin:12px 0;
}

/* Parameter groups */
.param-group{
  margin:16px 0;
  padding:12px;
  background:rgba(0,0,0,0.1);
  border-radius:8px;
  border-left:3px solid var(--accent);
}

.param-group:first-child{
  margin-top:8px;
}

.group-title{
  margin:0 0 12px 0;
  font-size:13px;
  font-weight:600;
  color:var(--text);
  display:flex;
  align-items:center;
  gap:6px;
}

.param-group .sliders{
  margin-top:8px;
}

.param-group .sliders .field{
  margin:8px 0;
}

/* Range input track */
input[type="range"]{
  width:100%;
  min-height:44px;
  border-radius:3px;
  background:var(--border);
  accent-color:var(--accent);
  -webkit-appearance:none;
}

/* Webkit slider thumb (Chrome, Safari, Edge) */
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:24px;
  height:24px;
  border-radius:50%;
  background:var(--accent);
  cursor:pointer;
  transition:all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover{
  transform:scale(1.2);
  box-shadow:0 0 8px rgba(126,168,255,0.4);
}

/* Firefox slider thumb */
input[type="range"]::-moz-range-thumb{
  width:24px;
  height:24px;
  border-radius:50%;
  background:var(--accent);
  cursor:pointer;
  border:none;
  transition:all 0.2s;
}

input[type="range"]::-moz-range-thumb:hover{
  transform:scale(1.2);
  box-shadow:0 0 8px rgba(126,168,255,0.4);
}
/* ========================================
   BUTTON GROUPS AND ACTIONS
   ========================================
   Organized button sections with visual hierarchy
*/
.action-section{
  margin:16px 0;
  padding:12px 0;
  border-top:1px solid var(--border);
}

.action-section:first-of-type{
  border-top:none;
  margin-top:8px;
}

.section-label{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:0.5px;
  color:var(--muted);
  margin-bottom:8px;
  font-weight:600;
}

.btn-group{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

/* Base button styling */
.btn{
  background:var(--input-hover);
  border:1px solid var(--border);
  color:var(--text);
  padding:8px 14px;
  border-radius:8px;
  cursor:pointer;
  font-size:13px;
  transition:all 0.2s ease;
  display:inline-flex;
  align-items:center;
  gap:6px; /* Space between icon and text */
}

.btn:hover{
  transform:translateY(-1px); /* Lift effect */
  box-shadow:0 2px 8px rgba(0,0,0,0.15);
}

.btn:active{
  transform:translateY(0); /* Press down effect */
}

/* Primary button (main action) */
.btn.primary{
  background:var(--accent);
  color:var(--button-text);
  font-weight:600;
  border:none;
  box-shadow:0 2px 12px rgba(126,168,255,0.3);
}

.btn.primary:hover{
  box-shadow:0 4px 20px rgba(126,168,255,0.5);
}

/* Large button variant */
.btn.large{
  padding:12px 24px;
  font-size:14px;
  flex:1;
}

/* Secondary button (outline style) */
.btn.secondary{
  background:var(--panel);
  border:2px solid var(--accent);
  color:var(--accent);
  font-weight:500;
}

.btn.secondary:hover{
  background:var(--accent);
  color:var(--button-text);
}
/* ========================================
   PREVIEW SECTION
   ========================================
   Canvas display and readability meters
*/
.preview .canvas-wrap{
  display:flex;
  justify-content:center;
  align-items:center;
  background:var(--input-bg);
  border:2px solid var(--border);
  border-radius:12px;
  min-height:100px;
  padding:8px;
  margin-bottom:16px;
  box-shadow:inset 0 2px 4px rgba(0,0,0,0.1); /* Inset shadow */
}
/* Readability meters grid */
.meters{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}

/* Individual meter styling */
.meter{
  background:var(--input-bg);
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px;
}

/* Meter header with label and value */
.meter-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  font-size:14px;
  color:var(--muted);
}

.meter-label{
  display:inline-flex;
  align-items:center;
  gap:6px;
}

.meter-head strong{
  color:var(--text);
}

/* Progress bar container */
.meter-bar{
  height:12px;
  background:var(--border);
  border-radius:8px;
  overflow:hidden;
  margin-top:6px;
}

/* Progress bar fill (good readability) */
.meter-bar>div{
  height:100%;
  width:0; /* Animated by JavaScript */
  background:linear-gradient(90deg,var(--accent2),#a7f3d0);
}

/* Danger variant for bot readability */
.meter-bar.danger>div{
  background:linear-gradient(90deg,#ffb3b3,var(--danger));
}
/* ========================================
   LAYER PREVIEWS
   ========================================
   Step-by-step rendering process visualization
*/
.layer-previews{
  display:flex;
  flex-direction:column;
  gap:12px;
  margin:12px 0;
}

.layer-step{
  display:flex;
  align-items:center;
  gap:12px;
  padding:8px;
  background:rgba(0,0,0,0.1);
  border-radius:8px;
  transition:background-color 0.2s;
}

.layer-step:hover{
  background:rgba(0,0,0,0.15);
}

.layer-info{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
  flex:1;
}

.layer-number{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:20px;
  height:20px;
  border-radius:50%;
  background:var(--accent);
  color:white;
  font-size:11px;
  font-weight:bold;
  flex-shrink:0;
}

.layer-title{
  font-size:12px;
  color:var(--text);
  font-weight:500;
}

.layer-canvas{
  border:1px solid var(--border);
  border-radius:4px;
  background:var(--input-bg);
  max-width:100%;
  height:auto;
  flex-shrink:0;
  image-rendering:pixelated; /* Keep crisp pixels when scaled */
}

/* ========================================
   INFORMATIONAL CONTENT
   ========================================
   Lists, notes, and descriptive text
*/
.layers{
  margin:.5rem 0 .25rem 1.1rem;
}

.layers li{
  margin:.2rem 0;
}

.note{
  color:var(--muted);
  font-size:12px;
  margin-top:4px;
}
/* ========================================
   FOOTER AND LINKS
   ========================================
*/
footer .footer{
  max-width:1100px;
  margin:18px auto 40px;
  padding:0 16px;
  color:var(--muted);
  text-align:center;
}

/* Link styling */
a{
  color:var(--accent);
  text-decoration:none;
}

a:hover{
  text-decoration:underline;
}

/* ========================================
   RESPONSIVE DESIGN
   ========================================
   Mobile and tablet adaptations
*/

/* Mobile-first sizing and keyboard access. */
[hidden] { display:none !important; }
.analysis-canvas { display:block; width:100%; height:auto; border:1px solid var(--border); }
#maskCanvas { image-rendering:pixelated; }
.comparison { border-top:1px solid var(--border); margin-top:1.5rem; padding-top:1rem; min-width:0; }
.comparison-images { display:grid; grid-template-columns:minmax(0, 1fr); gap:1rem; }
.comparison figure { margin:0; min-width:0; }
.comparison figcaption { margin-bottom:.5rem; font-weight:600; }
.comparison-table-wrap { max-width:100%; overflow-x:auto; }
.comparison table { width:100%; border-collapse:collapse; font-size:.875rem; }
.comparison th, .comparison td { padding:.5rem; text-align:left; border-bottom:1px solid var(--border); overflow-wrap:anywhere; }
.comparison th { font-weight:600; }
.comparison-table-wrap:focus-visible { outline:3px solid var(--accent); outline-offset:2px; }
@media (min-width:600px) {
  .comparison-images { grid-template-columns:repeat(2, minmax(0, 1fr)); }
}
html { line-height:1.5; overflow-wrap:anywhere; }
.header-actions { display:flex; justify-content:center; gap:8px; margin-top:12px; }
button, summary { min-height:44px; min-width:44px; font:inherit; cursor:pointer; }
summary { padding:8px 0; }
button:disabled { opacity:.6; cursor:not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline:3px solid var(--accent);
  outline-offset:3px;
}
.btn.primary:hover, .btn.secondary:hover { background:var(--accent); color:var(--button-text); }
#canvas { display:block; max-width:100%; height:auto; }
.statistics dt { font-size:14px; }
.statistics dd { margin:4px 0 0; font-size:20px; font-weight:600; }
.statistics p, .note { font-size:14px; }
#status:empty { display:none; }
#status { padding:10px; border:1px solid var(--accent); border-radius:8px; }
.layer-step { flex-wrap:wrap; }
.layer-info { flex-basis:100%; }
@media (min-width:600px) {
  .layer-info { flex-basis:0; }
}
@media (min-width:1000px) {
  .container { grid-template-columns:340px minmax(0, 1fr); }
}
@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { transition:none !important; scroll-behavior:auto !important; }
}
