/* =====================================================
   CSS Custom Properties (CSS Variables)
   Theming system for dark/light mode support
   ===================================================== */

/* Dark mode (default) */
:root {
  --bg: #0f1113;                          /* Background color */
  --card: #141618;                        /* Card/panel background */
  --card-hover: #1a1c1f;                  /* Card hover state */
  --muted: #9aa0a6;                       /* Muted text (labels, hints) */
  --text: #e7e9ea;                        /* Primary text color */
  --accent: #3b82f6;                      /* Accent color (buttons, links) */
  --accent-hover: #2563eb;                /* Accent hover state */
  --border: rgba(255, 255, 255, 0.04);    /* Subtle border */
  --border-strong: rgba(255, 255, 255, 0.08); /* Strong border */
}

/* Light mode (toggled via JS) */
:root.light-mode {
  --bg: #f5f5f5;                          /* Light background */
  --card: #ffffff;                        /* White cards */
  --card-hover: #f9fafb;                  /* Light hover state */
  --muted: #6b7280;                       /* Darker muted text */
  --text: #1f2937;                        /* Dark text */
  --accent: #3b82f6;                      /* Same accent (blue) */
  --accent-hover: #2563eb;                /* Same accent hover */
  --border: rgba(0, 0, 0, 0.08);          /* Dark borders */
  --border-strong: rgba(0, 0, 0, 0.12);   /* Stronger dark borders */
}

/* =====================================================
   Global Styles & Reset
   ===================================================== */

* {
  box-sizing: border-box;  /* Include padding and border in element's total width/height */
}

body {
  margin: 0;
  font-family: Inter, "Hiragino Kaku Gothic ProN", "メイリオ", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;  /* Better font rendering on macOS */
  font-size: 15px;
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* =====================================================
   Header & Navigation
   ===================================================== */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 28px 24px 24px 24px;
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: background 0.3s, box-shadow 0.3s;
}

:root.light-mode .site-header {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  text-align: center;
  position: relative;
}

h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text);
  margin: 10px 0 0 0;
  font-size: 16px;
  font-weight: 400;
  opacity: 0.85;
  letter-spacing: 0.3px;
  transition: color 0.3s;
}

/* Theme Toggle */
.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--card-hover);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 20px;
}

.theme-toggle:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: rotate(20deg) scale(1.1);
}

.theme-toggle:active {
  transform: rotate(20deg) scale(0.95);
}

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

/* Main Layout */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Tab Navigation */
.tab-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  justify-content: center;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 14px 32px;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  position: relative;
  top: 2px;
  border-radius: 6px 6px 0 0;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
  background: rgba(59, 130, 246, 0.05);
}

/* Tab Content */
.tab-content {
  position: relative;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  align-items: start;
}

.tab-pane#tab-education.active {
  display: block;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.main-content {
  min-width: 0;
}

/* Panel */
.panel {
  background: var(--card);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
}

:root.light-mode .panel {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.panel h2 {
  margin: 0 0 16px 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

/* Form Elements */
.field {
  display: block;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.field:first-child {
  margin-top: 0;
}

.input {
  width: 100%;
  padding: 9px 12px;
  margin-top: 6px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}

.input:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

select.input {
  cursor: pointer;
}

select.input option {
  background: var(--card);
  color: var(--text);
}

/* Range Inputs */
.range {
  width: 100%;
  margin-top: 8px;
  margin-bottom: 4px;
}

.range-value {
  display: inline-block;
  min-width: 50px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: var(--accent);
  text-align: center;
  margin-top: 4px;
}

/* Range field with inline label and value (new compact layout) */
/* Layout: [Label] [Slider] [Value] all on one line */
.field.range-field {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

.field.range-field .field-label {
  flex-shrink: 0;           /* Don't shrink label */
  min-width: 100px;         /* Fixed label width for alignment */
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.field.range-field .input.range {
  flex: 1;                  /* Slider takes remaining space */
  margin-top: 0;
  min-width: 0;             /* Allow shrinking if needed */
}

.field.range-field .range-value {
  flex-shrink: 0;           /* Keep value display fixed width */
  margin-top: 0;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Buttons */
.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
  align-items: center;
}

.btn {
  background: var(--card-hover);
  border: 1px solid var(--border-strong);
  padding: 10px 18px;
  border-radius: 7px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

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

.btn-random {
  background: #8b5cf6;
  border-color: #8b5cf6;
  color: #fff;
  font-weight: 600;
}

.btn-random:hover {
  background: #7c3aed;
  border-color: #7c3aed;
}

.btn-export {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
  font-weight: 600;
  padding: 12px 24px;
  font-size: 15px;
  max-width: 280px;
  align-self: flex-start;
}

.btn-export:hover {
  background: #059669;
  border-color: #059669;
}

/* File Upload */
.upload-field {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.input-file {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

.input-file::file-selector-button {
  background: var(--card-hover);
  border: 1px solid var(--border-strong);
  padding: 8px 14px;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  margin-right: 10px;
}

.input-file::file-selector-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Checkbox */
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.checkbox-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  margin: 0;
}

.checkbox-field span {
  font-size: 14px;
  color: var(--text);
}

/* Overlay Controls */
.overlay-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#alphaControl {
  margin-left: 0;
}

/* Palette Preview */
.palette-input-group {
  margin: 12px 0;
}

.palette-preview {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  min-height: 40px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.palette-swatch {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  position: relative;
}

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

.palette-swatch::after {
  content: attr(data-color);
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.palette-swatch:hover::after {
  opacity: 1;
}

/* Note */
.note {
  margin-top: 20px;
  background: rgba(234, 179, 8, 0.08);
  padding: 12px 14px;
  border-radius: 7px;
  border-left: 3px solid #eab308;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.note strong {
  color: #fbbf24;
}

/* Canvas */
.canvas-wrap {
  background: #000;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  position: relative;
}

canvas {
  width: 100%;
  height: auto;
  border-radius: 7px;
  background: #000;
  display: block;
}

/* Comparison Slider */
.comparison-wrap {
  position: relative;
  overflow: hidden;
  background: #000;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
}

.comparison-wrap canvas {
  position: absolute;
  top: 12px;
  left: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  object-fit: contain;
}

.comparison-wrap #envOnlyCanvas {
  z-index: 1;
}

.comparison-wrap #compositeCanvas {
  z-index: 2;
  clip-path: inset(0 0 0 50%);
}

.comparison-slider {
  position: absolute;
  top: 0;
  left: 50%;
  width: 4px;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: none;
}

.comparison-wrap.active .comparison-slider {
  display: block;
}

.slider-line {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.slider-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
  pointer-events: all;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s, background 0.2s;
}

.slider-handle:hover {
  transform: translate(-50%, -50%) scale(1.1);
  background: var(--accent-hover);
}

.slider-handle:active {
  transform: translate(-50%, -50%) scale(0.95);
}

.slider-handle-icon {
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  user-select: none;
}

.comparison-controls {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Preview Footer */
.preview-footer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* Info Section (Collapsible) */
.info details {
  cursor: pointer;
}

.info summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.info summary::-webkit-details-marker {
  display: none;
}

.info summary h2 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  cursor: pointer;
}

.info summary h2::before {
  content: '▶';
  font-size: 12px;
  color: var(--muted);
  transition: transform 0.2s;
}

.info details[open] summary h2::before {
  transform: rotate(90deg);
}

.info summary:hover h2 {
  color: var(--accent);
}

.info-content {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.info-content p {
  margin: 0 0 12px 0;
  font-size: 14px;
  line-height: 1.6;
}

.info-content details.nested {
  margin-top: 14px;
}

.info-content summary {
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 8px;
}

.info-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.info-content li {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.5;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 24px;
  color: var(--muted);
  font-size: 14px;
  margin-top: 40px;
  background: var(--card);
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  text-align: center;
  line-height: 1.6;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Education Tab Styles */
.education-content {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.education-panel {
  padding: 32px;
}

.education-section {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.education-section:last-child {
  border-bottom: none;
}

.education-section h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  color: var(--text);
}

.education-section p {
  margin: 0 0 12px 0;
  line-height: 1.8;
  color: var(--text);
}

.education-section ul,
.education-section ol {
  margin: 12px 0;
  padding-left: 24px;
  line-height: 1.8;
}

.education-section li {
  margin: 8px 0;
}

.education-section.warning {
  background: rgba(234, 179, 8, 0.05);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid rgba(234, 179, 8, 0.2);
}

.education-section.warning h3 {
  color: #fbbf24;
}

/* Info Box */
.info-box {
  background: rgba(59, 130, 246, 0.05);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
}

.info-box h3 {
  margin: 0 0 12px 0;
  font-size: 15px;
  color: var(--accent);
}

.info-box p,
.info-box ol {
  margin: 8px 0;
  font-size: 14px;
  line-height: 1.6;
}

.info-box ol {
  padding-left: 20px;
}

.info-box li {
  margin: 6px 0;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .tab-pane.active {
    grid-template-columns: 360px 1fr;
    gap: 16px;
  }

  .sidebar {
    top: 16px;
    max-height: calc(100vh - 32px);
  }
}

@media (max-width: 900px) {
  .tab-pane.active {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    order: 2;
  }

  .main-content {
    order: 1;
  }

  .site-header {
    padding: 20px 16px 16px 16px;
  }

  h1 {
    font-size: 26px;
  }

  .subtitle {
    font-size: 14px;
  }

  .panel {
    padding: 16px;
  }

  .tab-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    padding: 0 8px;
  }

  .tab-btn {
    white-space: nowrap;
    padding: 12px 20px;
    font-size: 14px;
  }

  .education-panel {
    padding: 20px;
  }

  .footer-inner {
    font-size: 13px;
  }
}

@media (max-width: 600px) {
  body {
    font-size: 14px;
  }

  .site-header {
    padding: 18px 12px 14px 12px;
  }

  h1 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 13px;
  }

  .panel {
    padding: 14px;
  }

  .panel h2 {
    font-size: 16px;
  }

  .btn-export {
    width: 100%;
  }

  .preview-footer {
    text-align: center;
  }
}

/* Preset Palette Select Styling */
select#palettePreset optgroup {
  color: var(--muted);
  font-style: normal;
  font-weight: 600;
}
