:root {
  --ink-deep: #192123;
  --forest-shadow: #2a3f36;
  --wine-core: #7e1418;
  --crimson-accent: #ce1d2f;
  --sage-lift: #7e9f84;
  --paper: #eef3ef;
  --text-main: #15211c;
  --text-soft: #385248;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 15% 15%, rgba(126, 159, 132, 0.35), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(206, 29, 47, 0.2), transparent 45%),
    linear-gradient(150deg, #f5faf7 0%, #e7eeea 100%);
  position: relative;
  overflow-x: hidden;
}

body[dir="rtl"] {
  font-family: "Noto Kufi Arabic", "Manrope", sans-serif;
}

.scene-glow {
  position: fixed;
  width: min(42vw, 460px);
  aspect-ratio: 1;
  border-radius: 999px;
  filter: blur(54px);
  opacity: 0.28;
  z-index: -1;
  animation: drift 16s ease-in-out infinite;
}

.scene-glow-a {
  background: var(--wine-core);
  top: -80px;
  left: -80px;
}

.scene-glow-b {
  background: var(--sage-lift);
  bottom: -120px;
  right: -80px;
  animation-delay: -8s;
}

.app-shell {
  width: min(1060px, 92vw);
  margin: 40px auto 56px;
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 24px;
}

.hero {
  grid-column: 1 / -1;
  padding: 24px 28px;
  border-radius: 24px;
  color: #f7fffb;
  background:
    linear-gradient(135deg, rgba(25, 33, 35, 0.96), rgba(42, 63, 54, 0.9)),
    repeating-linear-gradient(90deg, transparent, transparent 8px, rgba(255, 255, 255, 0.02) 8px, rgba(255, 255, 255, 0.02) 16px);
  border: 1px solid rgba(126, 159, 132, 0.35);
  box-shadow: 0 20px 40px rgba(25, 33, 35, 0.28);
}

.hero-kicker {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  font-size: 0.75rem;
  color: #c6ddcb;
}

.hero-banner-wrap {
  margin-bottom: 14px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(126, 159, 132, 0.35);
  background: rgba(255, 255, 255, 0.08);
}

.hero-banner {
  width: 100%;
  display: block;
  height: auto;
  max-height: none;
  object-fit: contain;
}

.hero h1 {
  margin: 10px 0;
  line-height: 1.1;
  font-size: clamp(1.9rem, 4vw, 3rem);
  font-weight: 800;
}

.hero-subtitle {
  margin: 0;
  max-width: 70ch;
  color: #d7e7db;
}

.panel {
  border-radius: 20px;
  padding: 22px;
  border: 1px solid rgba(42, 63, 54, 0.16);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(8px);
  box-shadow: 0 14px 35px rgba(42, 63, 54, 0.12);
  opacity: 0;
  transform: translateY(16px);
  animation: reveal 500ms ease forwards;
}

.controls-panel {
  animation-delay: 90ms;
}

.history-panel {
  animation-delay: 180ms;
}

.insight-panel {
  animation-delay: 270ms;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--ink-deep);
}

.lang-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 5px;
  border-radius: 999px;
  background: rgba(42, 63, 54, 0.1);
}

.lang-tab {
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 0.82rem;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  transition: all 180ms ease;
}

.lang-tab.is-active {
  color: #f5fffa;
  background: linear-gradient(135deg, var(--wine-core), var(--crimson-accent));
  box-shadow: 0 8px 18px rgba(126, 20, 24, 0.25);
}

.current-color-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(126, 159, 132, 0.2), rgba(42, 63, 54, 0.08));
  margin-bottom: 14px;
}

.current-swatch {
  width: 62px;
  height: 62px;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 18px rgba(25, 33, 35, 0.2);
}

.section-label {
  margin: 0;
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.current-hex {
  margin: 4px 0 0;
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--ink-deep);
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.action-btn {
  border: 0;
  border-radius: 12px;
  padding: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.action-btn img {
  width: 18px;
  height: 18px;
}

.action-btn:hover {
  transform: translateY(-2px);
}

.action-btn-primary {
  color: #f7fffb;
  background: linear-gradient(135deg, var(--ink-deep), var(--forest-shadow));
  box-shadow: 0 10px 20px rgba(25, 33, 35, 0.28);
}

.action-btn-secondary {
  color: #fff4f5;
  background: linear-gradient(135deg, var(--wine-core), var(--crimson-accent));
  box-shadow: 0 10px 20px rgba(126, 20, 24, 0.26);
}

.palette-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.palette-chip {
  border: 0;
  height: 52px;
  border-radius: 14px;
  background: var(--chip);
  cursor: pointer;
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.24);
  transition: transform 180ms ease, outline-color 180ms ease;
  outline: 2px solid transparent;
}

.palette-chip:hover,
.palette-chip:focus-visible {
  transform: translateY(-2px) scale(1.03);
  outline-color: rgba(255, 255, 255, 0.9);
}

.status-message {
  margin: 12px 2px 0;
  min-height: 1.4rem;
  color: var(--wine-core);
  font-weight: 700;
}

.upload-wrap {
  margin-top: 16px;
}

.image-input {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px dashed rgba(42, 63, 54, 0.35);
  background: rgba(126, 159, 132, 0.08);
  color: var(--text-main);
}

.eyedropper-wrap {
  margin-top: 12px;
}

.image-preview-canvas {
  width: 100%;
  margin-top: 8px;
  border-radius: 12px;
  border: 1px solid rgba(42, 63, 54, 0.26);
  background: linear-gradient(135deg, rgba(42, 63, 54, 0.1), rgba(126, 159, 132, 0.15));
  display: block;
}

.eyedropper-readout {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(42, 63, 54, 0.2);
  background: #ffffff;
  font-weight: 700;
  color: var(--ink-deep);
}

.detected-colors-wrap {
  margin-top: 12px;
}

.detected-sort-tabs {
  margin-top: 8px;
  display: inline-flex;
  gap: 6px;
  padding: 5px;
  border-radius: 999px;
  background: rgba(42, 63, 54, 0.1);
}

.detected-sort-btn {
  border: 0;
  border-radius: 999px;
  padding: 7px 11px;
  font-weight: 700;
  font-size: 0.78rem;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}

.detected-sort-btn.is-active {
  color: #f7fffb;
  background: linear-gradient(135deg, var(--wine-core), var(--crimson-accent));
}

.detected-colors-list {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detected-colors-list.is-sorting {
  animation: detectedSortSwap 220ms ease;
}

.detected-color-btn {
  border: 1px solid rgba(42, 63, 54, 0.2);
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink-deep);
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  text-align: left;
}

.detected-color-btn:hover,
.detected-color-btn:focus-visible {
  border-color: rgba(126, 20, 24, 0.45);
}

.detected-color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  flex-shrink: 0;
}

.history-head {
  margin-bottom: 12px;
}

.history-icon {
  width: 20px;
  height: 20px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(42, 63, 54, 0.16);
  background: #f8fcf9;
}

.history-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(25, 33, 35, 0.24);
  flex-shrink: 0;
}

.history-code {
  font-weight: 800;
  color: var(--ink-deep);
}

.history-empty {
  margin: 12px 0 0;
  color: var(--text-soft);
}

.insight-panel {
  grid-column: 1 / -1;
}

.insight-card {
  border: 1px solid rgba(42, 63, 54, 0.16);
  border-radius: 14px;
  background: #f7fbf8;
  padding: 12px;
}

.insight-card + .insight-card {
  margin-top: 10px;
}

.insight-text {
  margin: 8px 0 4px;
  font-weight: 800;
  color: var(--ink-deep);
}

.insight-meta {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.92rem;
}

.harmony-modes {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.harmony-mode-btn {
  border: 1px solid rgba(42, 63, 54, 0.2);
  background: #ffffff;
  color: var(--text-soft);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.harmony-mode-btn.is-active {
  color: #f7fffb;
  background: linear-gradient(135deg, var(--ink-deep), var(--forest-shadow));
  border-color: transparent;
}

.harmony-palette {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.harmony-chip {
  height: 52px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: end;
  padding: 8px;
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

.harmony-chip-btn {
  border: 0;
  cursor: pointer;
  text-align: left;
  transition: transform 140ms ease;
}

.harmony-chip-btn:hover,
.harmony-chip-btn:focus-visible {
  transform: translateY(-2px);
}

.quote-text {
  margin: 10px 0 8px;
  color: var(--forest-shadow);
  font-style: italic;
}

.quote-author {
  margin: 0;
  color: var(--text-soft);
  font-weight: 700;
}

body[dir="rtl"] .panel-header,
body[dir="rtl"] .current-color-wrap,
body[dir="rtl"] .history-item {
  flex-direction: row-reverse;
}

@keyframes drift {
  0%,
  100% {
    transform: translateY(0px) scale(1);
  }
  50% {
    transform: translateY(18px) scale(1.05);
  }
}

@keyframes reveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes detectedSortSwap {
  0% {
    opacity: 0.35;
    transform: translateY(6px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 940px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .palette-grid {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
  }

  .harmony-palette {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .hero,
  .panel {
    padding: 18px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .current-hex {
    font-size: 1.35rem;
  }

  .detected-colors-list {
    grid-template-columns: 1fr;
  }
}
