:root {
  color-scheme: light dark;
  --bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-fallback: #f0f4ff;
  --panel-bg: rgba(255, 255, 255, 0.95);
  --panel-bg-glass: rgba(255, 255, 255, 0.7);
  --border: rgba(255, 255, 255, 0.3);
  --border-solid: rgba(0, 0, 0, 0.1);
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --accent-muted: rgba(99, 102, 241, 0.15);
  --text: #1e293b;
  --text-light: #64748b;
  --muted: #94a3b8;
  --danger: #ef4444;
  --success: #10b981;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.2);
  --blur: blur(20px);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-fallback);
  background: var(--bg);
  color: var(--text);
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: -1;
  opacity: 0.9;
}

.page-header {
  margin: 32px auto 24px;
  padding: 24px 32px;
  max-width: 1200px;
  text-align: center;
  background: none;
  border: none;
  box-shadow: none;
}

.page-header h1 {
  margin: 0;
  font-size: 2.5rem;
  font-weight: 800;
  color: white;
  text-shadow: 
    -2px -2px 0 rgba(0, 0, 0, 0.8),
    2px -2px 0 rgba(0, 0, 0, 0.8),
    -2px 2px 0 rgba(0, 0, 0, 0.8),
    2px 2px 0 rgba(0, 0, 0, 0.8),
    -1px -1px 0 rgba(0, 0, 0, 0.8),
    1px -1px 0 rgba(0, 0, 0, 0.8),
    -1px 1px 0 rgba(0, 0, 0, 0.8),
    1px 1px 0 rgba(0, 0, 0, 0.8),
    0 0 4px rgba(0, 0, 0, 0.9);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.page-header .subtitle {
  margin: 8px 0 0;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.6;
  text-shadow: 
    -1px -1px 0 rgba(0, 0, 0, 0.8),
    1px -1px 0 rgba(0, 0, 0, 0.8),
    -1px 1px 0 rgba(0, 0, 0, 0.8),
    1px 1px 0 rgba(0, 0, 0, 0.8),
    0 0 3px rgba(0, 0, 0, 0.9);
}

.page-footer,
.actions-panel,
.panel {
  background: var(--panel-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel {
  border: 1px solid var(--border-solid);
}

.page-footer {
  margin: 32px auto;
  padding: 24px 32px;
  max-width: 1200px;
  text-align: center;
  font-size: 0.9rem;
  color: white;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.page-footer p {
  margin: 12px 0;
  line-height: 1.8;
  text-shadow: 
    -1px -1px 0 rgba(0, 0, 0, 0.8),
    1px -1px 0 rgba(0, 0, 0, 0.8),
    -1px 1px 0 rgba(0, 0, 0, 0.8),
    1px 1px 0 rgba(0, 0, 0, 0.8),
    0 0 3px rgba(0, 0, 0, 0.9);
  font-weight: 500;
}

.page-footer a {
  color: white;
  text-decoration: none;
  font-weight: 700;
  transition: all 0.2s ease;
  position: relative;
  text-shadow: 
    -1px -1px 0 rgba(0, 0, 0, 0.8),
    1px -1px 0 rgba(0, 0, 0, 0.8),
    -1px 1px 0 rgba(0, 0, 0, 0.8),
    1px 1px 0 rgba(0, 0, 0, 0.8),
    0 0 3px rgba(0, 0, 0, 0.9);
}

.page-footer a:hover {
  color: #ffd700;
  text-shadow: 
    -1px -1px 0 rgba(0, 0, 0, 0.8),
    1px -1px 0 rgba(0, 0, 0, 0.8),
    -1px 1px 0 rgba(0, 0, 0, 0.8),
    1px 1px 0 rgba(0, 0, 0, 0.8),
    0 0 3px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(255, 215, 0, 0.6);
}

.page-footer a::after {
  display: none;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 32px;
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

@media (min-width: 769px) {
  .canvas-panel,
  .boxes-panel {
    grid-column: span 1;
  }
  
  .layout {
    grid-template-columns: 1fr 1fr;
  }
}

.panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.upload-panel {
  grid-column: 1 / -1;
  background: var(--panel-bg-glass);
}

.upload-inline {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.upload-inline .status {
  margin-left: auto;
  font-weight: 500;
}

.input-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  min-width: 80px;
}

input[type="file"] {
  flex: 1;
  padding: 16px 20px;
  border: 2px dashed var(--border-solid);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
  cursor: pointer;
}

input[type="file"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-muted);
}

button,
select,
a.download-link {
  font-size: 0.95rem;
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

button::before {
  display: none;
}

button:active {
  transform: scale(0.98);
}

button:disabled,
select:disabled,
a.download-link.disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

a.download-link {
  background: var(--accent-gradient);
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 1;
}

a.download-link:active:not(.disabled) {
  transform: translateY(0);
}

button {
  background: var(--accent-gradient);
  color: white;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 1;
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
  box-shadow: none;
}

.hint-line {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-left: 0;
  line-height: 1.6;
}

.status {
  min-height: 20px;
  font-size: 0.9rem;
  color: var(--text-light);
  font-weight: 500;
}

.status.error {
  color: var(--danger);
  font-weight: 600;
}

.canvas-wrapper {
  position: relative;
  border: 2px solid var(--border-solid);
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

#imageCanvas {
  max-width: 100%;
  height: auto;
  border-radius: 16px;
}

.canvas-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
  pointer-events: none;
  transition: opacity 0.3s ease;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.canvas-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.canvas-footer {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.options-section.unified-controls {
  padding: 20px;
  border: 1px solid var(--border-solid);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.control-row:not(:last-child) {
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.options-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.options-section {
  padding: 16px 20px;
  border: 1px solid var(--border-solid);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

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

.toggle-group span {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-right: 8px;
  font-weight: 600;
}

.toggle-btn {
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 10px;
  border: 2px solid var(--border-solid);
  background: white;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.toggle-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: white;
  box-shadow: var(--shadow-sm);
}

.toggle-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.strength-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
  flex: 1;
}

.strength-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.strength-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  min-width: 50px;
}

.strength-slider {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 200px;
}

.options-row:last-child .strength-control {
  flex: 1 1 220px;
}

.options-row:last-child .hint-line {
  margin-left: auto;
}

.list-hint {
  margin-top: 8px;
  margin-left: 0;
}

.strength-slider input[type="range"] {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #e2e8f0, var(--accent));
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.strength-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-gradient);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.strength-slider input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-gradient);
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-sm);
}

.strength-value {
  font-size: 0.95rem;
  color: var(--text);
  min-width: 45px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.box-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border-solid);
  margin: 20px 0 16px;
  opacity: 0.3;
}

.box-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-radius: 16px;
  border: 2px solid var(--border-solid);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  gap: 16px;
  cursor: pointer;
}

.box-item.manual {
  border-color: var(--accent);
  background: var(--accent-muted);
  box-shadow: var(--shadow-sm);
}

.box-item.hovered {
  box-shadow: 0 0 0 4px var(--accent-muted), var(--shadow-md);
  border-color: var(--accent);
  background: var(--accent-muted);
  transform: translateX(4px) scale(1.02);
}

.box-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

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

.box-actions button {
  font-size: 0.85rem;
  padding: 8px 14px;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 10px;
}

.box-actions button.delete {
  color: var(--danger);
  border-color: var(--danger);
}

.box-actions button.toggle.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: white;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-light);
}

.legend-item::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 8px;
  vertical-align: middle;
  box-shadow: var(--shadow-sm);
}

.legend-item.auto::before {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.legend-item.manual::before {
  background: var(--accent-gradient);
}

.actions-panel {
  max-width: 1200px;
  margin: 0 auto 40px;
  padding: 24px;
}

.button-row {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 16px;
}

@media (max-width: 768px) {
  .page-header {
    margin: 20px 16px 16px;
    padding: 20px;
  }

  .page-header h1 {
    font-size: 2rem;
  }

  .page-header .subtitle {
    font-size: 1rem;
  }

  .layout {
    padding: 0 16px 24px;
    gap: 16px;
    grid-template-columns: 1fr;
  }

  .canvas-panel,
  .boxes-panel {
    grid-column: 1 / -1;
  }

  .panel {
    padding: 20px;
  }

  .canvas-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .strength-slider {
    flex-direction: column;
    align-items: stretch;
  }

  .strength-slider input[type="range"] {
    width: 100%;
  }

  .strength-value {
    text-align: left;
  }

  .button-row {
    flex-direction: column;
    align-items: stretch;
  }

  .options-row {
    flex-direction: column;
    align-items: stretch;
  }

  .control-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .control-row:not(:last-child) {
    padding-bottom: 12px;
  }

  .strength-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .strength-label {
    min-width: auto;
  }

  .toggle-group {
    width: 100%;
    justify-content: space-between;
  }

  #toggleDrawButton {
    width: 100%;
  }
}

.options-section:last-child {
  background: rgba(255, 255, 255, 0.8);
}

.options-section + .options-section {
  margin-top: 12px;
}

#toggleDrawButton {
  min-width: 120px;
}
