/* =========================================================
   Image Palette Extractor — Material Design 3 Theme
   Font: Be Vietnam Pro (supports Vietnamese)
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* ---------- Material Symbols ---------- */
.material-symbols-rounded {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  user-select: none;
}

/* ---------- CSS Custom Properties — Light Theme ---------- */
:root, [data-theme="light"] {
  color-scheme: light;
  --md-sys-color-primary: #1565C0;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #D6E4FF;
  --md-sys-color-on-primary-container: #001C3D;
  --md-sys-color-secondary: #545F70;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #D8E3F7;
  --md-sys-color-on-secondary-container: #111C2B;
  --md-sys-color-surface: #F8F9FF;
  --md-sys-color-surface-variant: #DFE2EB;
  --md-sys-color-surface-container: #ECEEF6;
  --md-sys-color-surface-container-high: #E6E8F0;
  --md-sys-color-surface-container-highest: #E0E2EA;
  --md-sys-color-surface-container-low: #F2F4FC;
  --md-sys-color-on-surface: #191C22;
  --md-sys-color-on-surface-variant: #42474F;
  --md-sys-color-outline: #72777F;
  --md-sys-color-outline-variant: #C2C7CF;
  --md-sys-color-inverse-surface: #2E3038;
  --md-sys-color-inverse-on-surface: #EFF0F8;
  --md-sys-color-error: #BA1A1A;
  --md-sys-color-error-container: #FFDAD6;
  --md-sys-color-on-error-container: #410002;
  --md-sys-color-shadow: rgba(0,0,0,0.12);
  --md-sys-color-scrim: rgba(0,0,0,0.32);

  --elevation-1: 0 1px 2px rgba(0,0,0,0.08), 0 1px 3px 1px rgba(0,0,0,0.06);
  --elevation-2: 0 1px 2px rgba(0,0,0,0.12), 0 2px 6px 2px rgba(0,0,0,0.08);
  --elevation-3: 0 4px 8px 3px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.12);
  --top-bar-bg: rgba(248,249,255,0.92);
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
  color-scheme: dark;
  --md-sys-color-primary: #A9C7FF;
  --md-sys-color-on-primary: #003063;
  --md-sys-color-primary-container: #00468B;
  --md-sys-color-on-primary-container: #D6E4FF;
  --md-sys-color-secondary: #BBC7DB;
  --md-sys-color-on-secondary: #253140;
  --md-sys-color-secondary-container: #3B4858;
  --md-sys-color-on-secondary-container: #D8E3F7;
  --md-sys-color-surface: #111318;
  --md-sys-color-surface-variant: #42474F;
  --md-sys-color-surface-container: #1E2026;
  --md-sys-color-surface-container-high: #282A31;
  --md-sys-color-surface-container-highest: #33353C;
  --md-sys-color-surface-container-low: #191C22;
  --md-sys-color-on-surface: #E2E2EA;
  --md-sys-color-on-surface-variant: #C2C7CF;
  --md-sys-color-outline: #8C9199;
  --md-sys-color-outline-variant: #42474F;
  --md-sys-color-inverse-surface: #E2E2EA;
  --md-sys-color-inverse-on-surface: #2E3038;
  --md-sys-color-error: #FFB4AB;
  --md-sys-color-error-container: #93000A;
  --md-sys-color-on-error-container: #FFDAD6;
  --md-sys-color-shadow: rgba(0,0,0,0.36);
  --md-sys-color-scrim: rgba(0,0,0,0.60);

  --elevation-1: 0 1px 3px rgba(0,0,0,0.36), 0 1px 2px rgba(0,0,0,0.28);
  --elevation-2: 0 2px 6px rgba(0,0,0,0.36), 0 1px 2px rgba(0,0,0,0.28);
  --elevation-3: 0 4px 12px rgba(0,0,0,0.40), 0 2px 4px rgba(0,0,0,0.32);
  --top-bar-bg: rgba(17,19,24,0.92);
}

/* System preference auto-switch */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    color-scheme: dark;
    --md-sys-color-primary: #A9C7FF;
    --md-sys-color-on-primary: #003063;
    --md-sys-color-primary-container: #00468B;
    --md-sys-color-on-primary-container: #D6E4FF;
    --md-sys-color-secondary: #BBC7DB;
    --md-sys-color-on-secondary: #253140;
    --md-sys-color-secondary-container: #3B4858;
    --md-sys-color-on-secondary-container: #D8E3F7;
    --md-sys-color-surface: #111318;
    --md-sys-color-surface-variant: #42474F;
    --md-sys-color-surface-container: #1E2026;
    --md-sys-color-surface-container-high: #282A31;
    --md-sys-color-surface-container-highest: #33353C;
    --md-sys-color-surface-container-low: #191C22;
    --md-sys-color-on-surface: #E2E2EA;
    --md-sys-color-on-surface-variant: #C2C7CF;
    --md-sys-color-outline: #8C9199;
    --md-sys-color-outline-variant: #42474F;
    --md-sys-color-inverse-surface: #E2E2EA;
    --md-sys-color-inverse-on-surface: #2E3038;
    --md-sys-color-error: #FFB4AB;
    --md-sys-color-error-container: #93000A;
    --md-sys-color-on-error-container: #FFDAD6;
    --md-sys-color-shadow: rgba(0,0,0,0.36);
    --md-sys-color-scrim: rgba(0,0,0,0.60);
    --elevation-1: 0 1px 3px rgba(0,0,0,0.36), 0 1px 2px rgba(0,0,0,0.28);
    --elevation-2: 0 2px 6px rgba(0,0,0,0.36), 0 1px 2px rgba(0,0,0,0.28);
    --elevation-3: 0 4px 12px rgba(0,0,0,0.40), 0 2px 4px rgba(0,0,0,0.32);
    --top-bar-bg: rgba(17,19,24,0.92);
  }
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Be Vietnam Pro', sans-serif;
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline-variant); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--md-sys-color-outline); }

/* ---------- Top App Bar ---------- */
.top-app-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--top-bar-bg);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.top-app-bar.elevated {
  box-shadow: var(--elevation-2);
}

.top-app-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  height: 64px;
}

.top-app-bar-leading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  letter-spacing: -0.01em;
}

.top-app-bar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---------- Icon Buttons ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
  flex-shrink: 0;
}

.icon-btn:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); color: var(--md-sys-color-on-surface); }
.icon-btn:active { background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent); }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm .material-symbols-rounded { font-size: 18px; }

/* ---------- Main Content ---------- */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---------- Upload Section ---------- */
.upload-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--elevation-1);
  transition: background 0.3s ease;
}

.upload-zone {
  border: 2px dashed var(--md-sys-color-outline-variant);
  border-radius: 20px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  position: relative;
  overflow: hidden;
  outline: none;
}

.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--md-sys-color-primary);
  background: color-mix(in srgb, var(--md-sys-color-primary) 5%, transparent);
}

.upload-zone.dragover {
  border-color: var(--md-sys-color-primary);
  background: color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent);
  border-style: solid;
}

.upload-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  text-align: center;
  pointer-events: none;
}

.upload-icon-wrap {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--md-sys-color-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  transition: transform 0.2s ease;
}

.upload-zone:hover .upload-icon-wrap {
  transform: scale(1.05);
}

.upload-icon {
  font-size: 36px !important;
  color: var(--md-sys-color-primary);
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 36;
}

.upload-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.upload-subtitle {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--md-sys-color-outline);
}

.upload-zone-content .btn {
  pointer-events: all;
  margin-top: 8px;
}

/* Image Preview */
.image-preview-wrap {
  width: 100%;
  height: 100%;
  min-height: 220px;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 18px;
}

.image-preview-overlay {
  position: absolute;
  bottom: 12px;
  right: 12px;
}

/* Divider */
.divider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
}
.divider-line {
  flex: 1;
  height: 1px;
  background: var(--md-sys-color-outline-variant);
}
.divider-text {
  font-size: 0.75rem;
  color: var(--md-sys-color-outline);
  white-space: nowrap;
}

/* URL Input Row */
.url-input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

/* ---------- Text Field (Material Outlined) ---------- */
.text-field {
  position: relative;
  flex: 1;
}

.text-field input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 12px;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.9375rem;
  padding: 0 16px 0 44px;
  outline: none;
  transition: border-color 0.2s ease;
}

.text-field input:focus {
  border: 2px solid var(--md-sys-color-primary);
}

.text-field label {
  position: absolute;
  left: 44px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9375rem;
  color: var(--md-sys-color-outline);
  pointer-events: none;
  transition: all 0.15s ease;
  background: var(--md-sys-color-surface-container-low);
  padding: 0 4px;
}

.text-field input:focus + label,
.text-field input:not(:placeholder-shown) + label {
  top: 0;
  font-size: 0.75rem;
  color: var(--md-sys-color-primary);
}

.text-field input:not(:focus):not(:placeholder-shown) + label {
  color: var(--md-sys-color-on-surface-variant);
}

.text-field-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px !important;
  color: var(--md-sys-color-outline);
  pointer-events: none;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 24px;
  border-radius: 20px;
  border: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.btn .material-symbols-rounded { font-size: 18px !important; }

.btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.btn-filled:hover { box-shadow: 0 2px 8px color-mix(in srgb, var(--md-sys-color-primary) 40%, transparent); }
.btn-filled:active { opacity: 0.88; }
.btn-filled:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }

.btn-filled-tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.btn-filled-tonal:hover { background: color-mix(in srgb, var(--md-sys-color-secondary-container) 90%, var(--md-sys-color-on-secondary-container)); }

.btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 0 12px;
}
.btn-text:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }

.btn-sm { height: 36px; padding: 0 16px; font-size: 0.8125rem; }

/* ---------- Settings Bar ---------- */
.settings-bar {
  background: var(--md-sys-color-surface-container);
  border-radius: 28px;
  padding: 20px 24px;
  box-shadow: var(--elevation-1);
  transition: background 0.3s ease;
}

.settings-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Number Stepper */
.number-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--md-sys-color-surface-container-high);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.stepper-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background 0.15s ease;
}
.stepper-btn:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); color: var(--md-sys-color-on-surface); }
.stepper-btn .material-symbols-rounded { font-size: 18px !important; }

.stepper-value {
  min-width: 36px;
  text-align: center;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

/* Segmented Button */
.segmented-button {
  display: flex;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline);
}

.seg-btn {
  flex: 1;
  height: 36px;
  padding: 0 16px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  position: relative;
}

.seg-btn + .seg-btn::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  height: 50%;
  width: 1px;
  background: var(--md-sys-color-outline);
}

.seg-btn.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 600;
}

.seg-btn:hover:not(.active) {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 6%, transparent);
}

/* ---------- Results Section ---------- */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: fadeInUp 0.4s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.palette-card,
.image-analysis-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: 28px;
  padding: 24px;
  box-shadow: var(--elevation-1);
  transition: background 0.3s ease;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

/* Gradient Bar */
.gradient-bar {
  height: 48px;
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
  transition: all 0.4s ease;
}

/* Color Grid */
.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.color-chip {
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--elevation-1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: chipIn 0.35s ease both;
}

.color-chip:hover {
  transform: translateY(-3px);
  box-shadow: var(--elevation-3);
}

.color-chip:active { transform: translateY(0); }

@keyframes chipIn {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1); }
}

.chip-swatch {
  height: 88px;
  position: relative;
}

.chip-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.35);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  backdrop-filter: blur(4px);
}
.chip-copy-btn .material-symbols-rounded { font-size: 14px !important; }
.color-chip:hover .chip-copy-btn { opacity: 1; }

.chip-info {
  padding: 10px 12px;
  background: var(--md-sys-color-surface-container-high);
}

.chip-hex {
  font-size: 0.8125rem;
  font-weight: 700;
  font-family: 'Be Vietnam Pro', monospace;
  color: var(--md-sys-color-on-surface);
  letter-spacing: 0.04em;
}

.chip-rgb {
  font-size: 0.6875rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

.chip-percent {
  font-size: 0.6875rem;
  color: var(--md-sys-color-outline);
  margin-top: 1px;
}

/* ---------- Dropdown Menu ---------- */
.dropdown-menu {
  position: absolute;
  right: 0;
  top: 44px;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: 16px;
  box-shadow: var(--elevation-3);
  padding: 8px 0;
  min-width: 200px;
  z-index: 200;
  animation: menuIn 0.15s ease both;
}

@keyframes menuIn {
  from { opacity: 0; transform: scale(0.92) translateY(-8px); transform-origin: top right; }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease;
}
.dropdown-item:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.dropdown-item .material-symbols-rounded { font-size: 20px !important; color: var(--md-sys-color-on-surface-variant); }

/* ---------- Analysis Card ---------- */
.analysis-layout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: start;
}

.analysis-image-wrap {
  border-radius: 16px;
  overflow: hidden;
  max-height: 320px;
}

.analysis-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 160px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-icon {
  font-size: 22px !important;
  color: var(--md-sys-color-primary);
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  flex-shrink: 0;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Processing Overlay ---------- */
.processing-overlay {
  position: fixed;
  inset: 0;
  background: var(--md-sys-color-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}

.processing-card {
  background: var(--md-sys-color-surface-container-highest);
  border-radius: 28px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: var(--elevation-3);
  font-size: 1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

/* Circular Progress */
.circular-progress {
  width: 48px;
  height: 48px;
}

.circular-progress svg {
  animation: rotate 1.4s linear infinite;
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

.circular-progress .track {
  fill: none;
  stroke: var(--md-sys-color-surface-variant);
  stroke-width: 4;
}

.circular-progress .indicator {
  fill: none;
  stroke: var(--md-sys-color-primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 80, 125;
  animation: dash 1.4s ease-in-out infinite;
}

@keyframes dash {
  0% { stroke-dasharray: 1, 125; stroke-dashoffset: 0; }
  50% { stroke-dasharray: 90, 125; stroke-dashoffset: -35; }
  100% { stroke-dasharray: 90, 125; stroke-dashoffset: -124; }
}

/* ---------- Snackbar ---------- */
.snackbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 600;
  box-shadow: var(--elevation-3);
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

.snackbar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.snackbar-icon { font-size: 18px !important; }

/* ---------- Dialog ---------- */
.dialog-scrim {
  position: fixed;
  inset: 0;
  background: var(--md-sys-color-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 24px;
  backdrop-filter: blur(4px);
  animation: scrimIn 0.2s ease both;
}

@keyframes scrimIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog {
  background: var(--md-sys-color-surface-container-highest);
  border-radius: 28px;
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  box-shadow: var(--elevation-3);
  animation: dialogIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.dialog-color-swatch {
  height: 120px;
  width: 100%;
}

.dialog-content {
  padding: 24px 24px 0;
}

.dialog-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 16px;
}

.color-formats {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.format-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  transition: background 0.15s;
}
.format-row:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent); }

.format-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--md-sys-color-outline);
  width: 44px;
  flex-shrink: 0;
}

.format-value {
  flex: 1;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: 'Be Vietnam Pro', monospace;
  color: var(--md-sys-color-on-surface);
  word-break: break-all;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  padding: 16px 16px 16px;
}

/* ---------- Utilities ---------- */
.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .top-app-bar-inner { height: 56px; }
  .app-title { font-size: 1.125rem; }
  .main-content { padding: 16px 12px 80px; gap: 16px; }

  .upload-card { border-radius: 20px; padding: 16px; }
  .upload-zone { min-height: 180px; }
  .upload-icon-wrap { width: 60px; height: 60px; }
  .upload-icon { font-size: 28px !important; }
  .upload-title { font-size: 1rem; }

  .settings-inner { gap: 14px; }
  .segmented-button .seg-btn { padding: 0 10px; font-size: 0.75rem; }

  .color-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }

  .analysis-layout {
    grid-template-columns: 1fr;
  }
  .stats-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-width: unset;
  }

  .palette-card, .image-analysis-card { border-radius: 20px; padding: 16px; }
}

@media (max-width: 480px) {
  .settings-inner { flex-direction: column; align-items: stretch; }
  .setting-group { flex-direction: row; align-items: center; justify-content: space-between; }
  .settings-bar { border-radius: 20px; padding: 16px; }
  #extractBtn { width: 100%; }
  .color-grid { grid-template-columns: repeat(3, 1fr); }
  .gradient-bar { height: 36px; }
  .url-input-row { flex-direction: column; align-items: stretch; }
  .url-input-row .btn { width: 100%; }
  .snackbar { bottom: 16px; font-size: 0.8125rem; }
}

@media (min-width: 960px) {
  .results-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
  .palette-card { grid-column: 1 / -1; }
  .color-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
