/* Tokens follow the official AI Pioneers site (aip.sa). */
:root {
  --primary: #80519f;
  --secondary: #ccadd9;
  --dark-bg: #0a0a0a;
  --card-bg: #1a1a1a;
  --field-bg: #111111;
  --text: #ffffff;
  --muted: #cccccc;
  --border: #333333;
  --danger: #ff8a94;
  --gradient-primary: linear-gradient(135deg, #846697, #351962);
  --gradient-text: linear-gradient(135deg, #ccadd9, #846697);
  --shadow: 0 8px 30px rgba(128, 81, 159, 0.2);
  --radius: 16px;
  --radius-small: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--dark-bg);
  color: var(--text);
  font-family: 'Cairo', system-ui, sans-serif;
  line-height: 1.7;
}

[hidden] { display: none !important; }

.container {
  width: min(1200px, 100%);
  margin-inline: auto;
  padding-inline: 16px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-block: 14px;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  display: block;
  height: 44px;
  width: auto;
  max-width: 62vw;
  object-fit: contain;
}

/* Hero */
.hero {
  position: relative;
  padding-block: 48px 28px;
}

.hero-text { max-width: 780px; }

.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(1.75rem, 4.4vw, 3rem);
  font-weight: 700;
  line-height: 1.3;
}

.hero h1 span { display: block; }

.gradient-text {
  background: var(--gradient-text);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}


.floats {
  position: absolute;
  inset-block: 24px 8px;
  inset-inline-end: 16px;
  width: 300px;
  pointer-events: none;
}

.floats span {
  position: absolute;
  font-size: 2.3rem;
  animation: float 6s ease-in-out infinite;
}

.floats span:nth-child(1) { top: 8%; inset-inline-end: 72%; }
.floats span:nth-child(2) { top: 4%; inset-inline-end: 26%; animation-delay: -1.2s; }
.floats span:nth-child(3) { top: 42%; inset-inline-end: 8%; animation-delay: -2.4s; }
.floats span:nth-child(4) { top: 62%; inset-inline-end: 56%; animation-delay: -3.6s; }
.floats span:nth-child(5) { top: 74%; inset-inline-end: 26%; animation-delay: -4.8s; }

@keyframes float {
  50% { transform: translateY(-12px); }
}

/* Tool layout */
.tool {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 24px;
  align-items: start;
  padding-bottom: 40px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 0;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--field-bg);
  border-radius: var(--radius-small);
  padding: 6px;
  margin-bottom: 20px;
}

.tab {
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font: 600 1rem 'Cairo', sans-serif;
  padding: 10px 8px;
}

.tab[aria-selected='true'] {
  background: var(--gradient-primary);
  color: var(--text);
  box-shadow: var(--shadow);
}

.pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Upload */
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-small);
  background: var(--field-bg);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover,
.dropzone.dragging,
.dropzone:focus-within {
  border-color: var(--primary);
  background: rgba(128, 81, 159, 0.08);
}

.drop-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--secondary);
}

.drop-prompt strong { color: var(--text); font-weight: 600; }
.drop-prompt small { color: var(--muted); }

.preview {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
}

.link-button {
  align-self: flex-start;
  margin-top: -8px;
  background: none;
  border: 0;
  color: var(--secondary);
  cursor: pointer;
  font: 600 0.9rem 'Cairo', sans-serif;
  text-decoration: underline;
  padding: 0;
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  font-weight: 600;
}

.field legend { padding: 0; margin-bottom: 6px; }

textarea {
  width: 100%;
  resize: vertical;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  color: var(--text);
  font: 400 1rem/1.7 'Cairo', sans-serif;
  padding: 12px 14px;
}

textarea:focus {
  border-color: var(--primary);
  outline: none;
}

textarea::placeholder { color: #8d8d8d; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-small);
  border: 2px solid transparent;
  color: var(--text);
  cursor: pointer;
  font: 600 1rem 'Cairo', sans-serif;
  padding: 12px 28px;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}

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

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.btn-primary {
  background: var(--gradient-primary);
  box-shadow: var(--shadow);
}

.btn-secondary {
  background: transparent;
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

/* Output */
.output {
  min-height: 420px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 24px 8px;
}

.state p { margin: 0; }

.state-title { font-size: 1.1rem; font-weight: 600; }

.muted { color: var(--muted); }

.empty-emblem { opacity: 0.35; }

#state-empty p { color: var(--muted); max-width: 340px; }

.spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

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

.error-title {
  color: var(--danger);
  font-size: 1.1rem;
  font-weight: 700;
}

.compare {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.compare figure {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
}

#original-figure { flex: 0 0 26%; }

.compare figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
}

.compare figcaption {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* Footer */
.footer {
  padding-block: 8px 32px;
  color: #9a9a9a;
  font-size: 0.85rem;
  text-align: center;
}

.footer p { margin: 0; }

.footer .copyright {
  margin-top: 12px;
  color: var(--muted);
  font-weight: 600;
}

@media (max-width: 900px) {
  .tool { grid-template-columns: minmax(0, 1fr); }
  .floats { display: none; }
  .hero { padding-block: 28px 20px; }
  .output { min-height: 280px; }
}

@media (max-width: 560px) {
  .wordmark { height: 34px; }
  .card { padding: 16px; }
  .btn { width: 100%; padding-inline: 16px; }
  .compare { flex-direction: column; }
  #original-figure { flex-basis: auto; width: 40%; }
  .compare figure { width: 100%; }
  #original-figure { width: 40%; }
}

@media (prefers-reduced-motion: reduce) {
  .floats span,
  .spinner { animation: none; }
  .btn { transition: none; }
}

/* Light interaction */
.card {
  position: relative;
  background-image: radial-gradient(320px circle at var(--glow-x, -400px) var(--glow-y, -400px), rgba(128, 81, 159, 0.14), transparent 70%);
}

.floats { transition: transform 0.4s ease-out; }

.counter {
  align-self: flex-end;
  min-height: 1.2em;
  color: #8d8d8d;
  font-size: 0.8rem;
  font-weight: 400;
}

#state-result { animation: appear 0.4s ease-out; }

@keyframes appear {
  from { opacity: 0; transform: translateY(6px); }
}

@media (prefers-reduced-motion: reduce) {
  #state-result { animation: none; }
  .floats { transition: none; }
}

/* Icon result */
.icon-stage {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
}

.icon-stage[data-surface='dark'] { background: linear-gradient(135deg, #13184a, #412e69); }
.icon-stage[data-surface='light'] { background: #f6f9fc; }

.icon-stage img {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: contain;
}

.colors {
  flex-flow: row wrap;
  gap: 14px;
  margin-top: 16px;
}

.colors legend {
  width: 100%;
  margin-bottom: 8px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.swatch input {
  position: absolute;
  opacity: 0;
}

.swatch span {
  display: block;
  width: 36px;
  height: 36px;
  border: 1px solid #666666;
  border-radius: 50%;
}

.swatch span[data-color='FFFFFF'] { background: #ffffff; }
.swatch span[data-color='C084FC'] { background: #c084fc; }
.swatch span[data-color='D4DAFA'] { background: #d4dafa; }
.swatch span[data-color='4A3B68'] { background: #4a3b68; }
.swatch span[data-color='0F1543'] { background: #0f1543; }

.swatch input:checked + span {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

.swatch input:focus-visible + span {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.swatch small {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

@media (max-width: 560px) {
  .icon-stage {
    flex: none;
    width: 100%;
  }
}

.badge-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  cursor: pointer;
  font-weight: 600;
}

.badge-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* Room for Arabic descenders, which background-clip would otherwise cut off. */
.hero h1 .gradient-text {
  padding-bottom: 0.35em;
  margin-bottom: -0.2em;
}

/* Icon library */
.segmented {
  flex-flow: row wrap;
  gap: 8px;
}

.segmented legend {
  width: 100%;
  margin-bottom: 6px;
}

.chip { cursor: pointer; }

.chip input {
  position: absolute;
  opacity: 0;
}

.chip span {
  display: block;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.chip input:checked + span {
  border-color: var(--primary);
  background: rgba(128, 81, 159, 0.2);
  color: var(--text);
}

.chip input:focus-visible + span {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

.gallery-hint {
  margin: 0 0 12px;
  font-weight: 600;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.gallery-item {
  aspect-ratio: 1;
  padding: 14%;
  background: linear-gradient(135deg, #13184a, #412e69);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.gallery-item:hover {
  transform: translateY(-2px);
  border-color: var(--secondary);
}

.gallery-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}

@media (max-width: 560px) {
  .tab { font-size: 0.85rem; padding-inline: 4px; }
  .gallery { grid-template-columns: repeat(2, 1fr); }
}
