:root {
  /* Google Material 3 Inspired Palette */
  --bg-page: #f0f4f8;
  /* Light blue-grey background */
  --bg-surface: #ffffff;

  --text-main: #1f1f1f;
  --text-muted: #444746;

  --primary: #0b57d0;
  /* Google Blue */
  --primary-bg: #d3e3fd;

  /* Pastel Icon Backgrounds & Accents */
  --color-blue-bg: #e8f0fe;
  --color-blue-fg: #1967d2;

  --color-green-bg: #e6f4ea;
  --color-green-fg: #188038;

  --color-orange-bg: #feefe3;
  --color-orange-fg: #e37400;

  --color-pink-bg: #fce8e6;
  --color-pink-fg: #d93025;

  --color-purple-bg: #f3e8fd;
  --color-purple-fg: #9334e6;

  --color-cyan-bg: #e4f7fb;
  --color-cyan-fg: #007b83;

  /* Elevations/Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --panel-radius: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Google Sans', 'Roboto', 'Segoe UI', system-ui, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 3rem;
}

h1 {
  font-size: 2.5rem;
  font-weight: 400;
  /* Cleaner look */
  margin: 0 0 0.5rem 0;
  color: var(--text-main);
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* Sections (Cards) */
section {
  background: var(--bg-surface);
  border-radius: var(--panel-radius);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
  border: none;
  /* Removed borders for cleaner look */
}

h2 {
  margin-top: 0;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Upload Zone */
.upload-area {
  border: 2px dashed #c4c7c5;
  border-radius: 16px;
  padding: 3rem 1rem;
  text-align: center;
  cursor: pointer;
  background: #f8f9fa;
  transition: all 0.2s ease;
}

.upload-area:hover {
  border-color: var(--primary);
  background: var(--color-blue-bg);
}

.upload-instruction {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
}

#avatar-preview {
  max-width: 150px;
  max-height: 150px;
  border-radius: 12px;
  display: block;
  margin: 1rem auto;
  object-fit: cover;
  box-shadow: var(--shadow-md);
}

/* Grid */
.expression-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.5rem;
}

/* Material List Item / Card Style */
.checkbox-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 0.75rem;
  background: var(--bg-surface);
  /* Transparent on surface? No, stick to surface */
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.8rem;
  font-weight: 500;
  user-select: none;
  border: 1px solid transparent;
  /* Reserve space */
}

.checkbox-label:hover {
  background-color: #f2f2f2;
}

/* Circular Icons with Colors */
.exp-icon {
  font-size: 1.5rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-bottom: 0.5rem;
  background-color: #f1f3f4;
  /* Default gray */
  transition: transform 0.2s;
}

/* Cycle colors for icons using nth-child */
.checkbox-label:nth-child(6n+1) .exp-icon {
  background-color: var(--color-blue-bg);
  color: var(--color-blue-fg);
}

.checkbox-label:nth-child(6n+2) .exp-icon {
  background-color: var(--color-green-bg);
  color: var(--color-green-fg);
}

.checkbox-label:nth-child(6n+3) .exp-icon {
  background-color: var(--color-orange-bg);
  color: var(--color-orange-fg);
}

.checkbox-label:nth-child(6n+4) .exp-icon {
  background-color: var(--color-purple-bg);
  color: var(--color-purple-fg);
}

.checkbox-label:nth-child(6n+5) .exp-icon {
  background-color: var(--color-pink-bg);
  color: var(--color-pink-fg);
}

.checkbox-label:nth-child(6n+6) .exp-icon {
  background-color: var(--color-cyan-bg);
  color: var(--color-cyan-fg);
}

/* Selection State */
.checkbox-label.checked {
  background-color: var(--primary-bg);
  color: var(--primary-text);
}

.checkbox-label.checked .exp-icon {
  background-color: var(--bg-surface);
  /* White circle inside blue pill */
  transform: scale(1.1);
  box-shadow: var(--shadow-sm);
}

.checkbox-label.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(1);
}

input[type="checkbox"] {
  display: none;
}

/* Buttons - Material 3 Filled & Tonal */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 1rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 100px;
  /* Pill shape */
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s;
  letter-spacing: 0.5px;
}

.btn:hover:not(:disabled) {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  filter: brightness(1.1);
}

.btn:disabled {
  background: #e3e3e3;
  color: #1f1f1f;
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

/* Primary is Blue (Google Blue) */
/* Pro Button - Gold/Orange but cleaner */
.btn-pro {
  background: linear-gradient(135deg, #FFC107, #FF9800);
  /* Keep some gradient for Pro distinction */
  color: #000;
}

.btn-success {
  background: #1e8e3e;
  /* Google Green */
}

/* Result Area */
#generated-image {
  width: 100%;
  display: block;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}

/* Table */
.expression-table td {
  background: #f8f9fa;
  padding: 0.5rem;
  border-radius: 8px;
  color: var(--text-muted);
}

/* --- Phase 2: Workstation Layout (Responsive) --- */

.container-wide {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
  /* height: 100vh;  Removed for natural scroll */
  display: flex;
  flex-direction: column;
}

.app-header {
  margin-bottom: 0.5rem;
  padding: 0.5rem;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 3-Column Layout */
.app-layout {
  display: flex;
  gap: 1.5rem;
  flex: 1;
  min-height: 0;
  align-items: flex-start;
  /* Align tops */
}

/* Base Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex-shrink: 0;
  padding-bottom: 2rem;
}

.sidebar-left {
  width: 250px;
}

.sidebar-right {
  width: 300px;
}

.main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #ffffff;
  /* White stage */
  border-radius: var(--panel-radius);
  /* border: 1px solid #e0e3e7; */
  position: relative;
  /* overflow-y: auto; Removed for natural scroll */
  padding: 1.5rem;
}

/* Compact Panels (Sidebar) */
.compact-panel {
  padding: 1.5rem;
  margin: 0;
  border-radius: 20px;
  background: #fff;
  /* border: 1px solid #eff1f4; */
}

/* Ensure Headers (1, 2, 3) Align Horizontally Across Columns */
.compact-panel h2,
.section-header h2 {
  min-height: 2.25rem;
  /* Force consistent height even if toolbar is missing */
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
}

.section-header {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #f1f3f4;
  /* min-height: 3.5rem; Removed for alignment */
  /* Match sidebar headers which don't have this border but space matters */
}

.upload-area-compact {
  border: 2px dashed #c4c7c5;
  border-radius: 16px;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  background: #f8f9fa;
  transition: all 0.2s;
}

.upload-area-compact:hover {
  border-color: var(--primary);
  background: var(--color-blue-bg);
}

.upload-placeholder .icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  color: var(--primary);
  background: var(--color-blue-bg);
  width: 64px;
  height: 64px;
  line-height: 64px;
  border-radius: 50%;
  display: inline-block;
}

/* Helper Classes */
.hidden {
  display: none !important;
}

/* Selection Counter */
.selection-toolbar {
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 100px;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
}

.btn-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-sm:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Steps Guide */
.steps-guide {
  display: flex;
  gap: 0.5rem;
  background: #f1f3f4;
  padding: 0.5rem 1rem;
  border-radius: 100px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.step-num {
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--text-main);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Responsive */
@media (max-width: 900px) {
  .container-wide {
    display: block;
    height: auto;
  }

  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .sidebar-left,
  .sidebar-right {
    width: 100%;
    order: initial;
  }

  .main-stage {
    min-height: auto;
  }
}

/* Pro Card Special */
.pro-card {
  background: linear-gradient(145deg, #fff, #fff8e1);
  border: 1px solid #ffecb3;
}

/* Pro Lock State */
.pro-card {
  position: relative;
}

.pro-card.locked {
  opacity: 0.7;
  pointer-events: none;
  filter: grayscale(0.8);
}

.pro-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.6);
  z-index: 10;
  justify-content: center;
  align-items: center;
  border-radius: var(--radius-md);
}

.pro-card.locked .pro-overlay {
  display: flex !important;
}

.pro-overlay p {
  font-weight: bold;
  color: var(--text-primary);
  background: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 0;
}

/* Toolbar Text Buttons */
.btn-text {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-text:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--primary-color);
}

/* Icon Keys (3D Droplets) */
.btn-icon {
  position: relative;
  /* For Tooltip positioning */
  /* Gradient Background */
  background: linear-gradient(135deg, #99f6e4, #d9f99d);

  /* Circular Shape */
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  border: none;

  color: #111827;
  font-size: 1.2rem;
  cursor: pointer;

  /* Flex Center */
  display: flex;
  align-items: center;
  justify-content: center;

  /* 3D "Droplet" Lighting Effect */
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.1),
    /* Drop shadow */
    inset 2px 2px 4px rgba(255, 255, 255, 0.7),
    /* Highlight */
    inset -2px -2px 4px rgba(0, 0, 0, 0.1);
  /* Lowlight */

  transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-icon:hover {
  transform: scale(1.1);
  /* Slight pop */
  box-shadow:
    0 8px 10px rgba(0, 0, 0, 0.15),
    inset 2px 2px 6px rgba(255, 255, 255, 0.8),
    inset -2px -2px 4px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.btn-icon:active {
  transform: scale(0.95);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.1),
    inset 0 0 10px rgba(0, 0, 0, 0.1);
  /* Pressed look */
}

.btn-icon:focus {
  outline: none;
}

/* Instant Custom Tooltip */
.btn-icon[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 110%;
  /* Below button */
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;

  /* Animation */
  opacity: 0;
  animation: fadeIn 0.1s forwards;
}

/* Optional Arrow */
.btn-icon[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent rgba(0, 0, 0, 0.8) transparent;
  /* Pointing up */

  /* Animation */
  opacity: 0;
  animation: fadeIn 0.1s forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(5px);
  }
}