:root {
  color-scheme: light;
  --bg-primary: #f5f7fb;
  --bg-card: #ffffff;
  --border-muted: #e2e8f0;
  --shadow-soft: 0 16px 40px rgba(15, 30, 70, 0.08);
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Noto Sans KR', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

.layout {
  max-width: 1220px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

.page-header {
  margin-bottom: 32px;
}

.page-header__eyebrow {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.page-title {
  margin: 0;
  font-size: clamp(2rem, 3vw, 2.8rem);
  font-weight: 700;
}

.page-subtitle {
  margin: 16px 0 0;
  max-width: 640px;
  color: var(--text-secondary);
  font-size: 1rem;
}

.page-main {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.tabs {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tab-button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-button:hover {
  color: var(--text-primary);
  background: rgba(15, 30, 70, 0.05);
}

.tab-button.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: var(--focus-ring);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.card-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.card {
  background: var(--bg-card);
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.card-header {
  padding: 24px 24px 0;
}

.card-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.card-header p {
  margin: 12px 0 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.card-body {
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.file-input {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.file-input input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-input__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  border: none;
  transition: transform 0.2s ease;
}

.file-input__action:hover {
  transform: translateY(-1px);
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.controls {
  gap: 20px;
}

.slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
}

.slider-label {
  font-weight: 600;
  color: var(--text-secondary);
}

#threshold-slider {
  accent-color: var(--accent);
  width: 100%;
}

.slider-value {
  font-weight: 700;
  font-size: 1.1rem;
  min-width: 48px;
  text-align: right;
}

.results-card .card-body {
  gap: 20px;
}

.result-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-radius: 12px;
  background: var(--accent-soft);
}

.result-label {
  font-weight: 600;
  color: var(--accent);
}

.result-value {
  font-weight: 700;
  font-size: 2rem;
}

.result-detail {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.primary-button,
.ghost-button {
  appearance: none;
  border-radius: 12px;
  padding: 11px 20px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.primary-button {
  border: none;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.25);
}

.primary-button:disabled {
  background: rgba(148, 163, 184, 0.6);
  box-shadow: none;
  cursor: not-allowed;
}

.primary-button:not(:disabled):hover {
  transform: translateY(-1px);
}

.ghost-button {
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: transparent;
  color: var(--text-secondary);
}

.ghost-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.preview-section {
  background: var(--bg-card);
  border-radius: 24px;
  padding: 28px 32px 36px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.preview-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.preview-header p {
  margin: 12px 0 0;
  color: var(--text-secondary);
}

.preview-grid {
  margin-top: 28px;
  display: grid;
  gap: 32px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.preview-card h3 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  color: var(--text-secondary);
}

.canvas-wrapper {
  background: #0f172a;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.canvas-wrapper canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

.canvas-wrapper.stacked {
  position: relative;
}

.canvas-wrapper.stacked canvas:nth-of-type(2) {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.panel-header p {
  margin: 0;
  color: var(--text-secondary);
}

.panel-header .ghost-button {
  align-self: flex-start;
  margin-top: 8px;
}

.history-list {
  display: grid;
  gap: 18px;
}

.history-item {
  display: flex;
  gap: 20px;
  background: var(--bg-card);
  border-radius: 20px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: var(--shadow-soft);
  padding: 18px 24px;
  flex-wrap: wrap;
}

.history-thumb {
  flex: 0 0 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
}

.history-thumb img {
  width: 100%;
  height: auto;
  display: block;
}

.history-content {
  flex: 1;
  min-width: 220px;
  display: grid;
  gap: 8px;
}

.history-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.history-actions {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.history-actions button {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.empty-state {
  margin: 0;
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
  background: rgba(148, 163, 184, 0.12);
  border-radius: 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 20px 40px rgba(37, 99, 235, 0.25);
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 768px) {
  .slider-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

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

  .history-item {
    padding: 16px;
  }
}
