/* Reusable UI components */

.cx-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.65rem 1.25rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    background var(--transition-fast);
}

.cx-btn:active {
  transform: scale(0.98);
}

.cx-btn--primary {
  background: linear-gradient(135deg, var(--brand-primary), #5b21b6);
  color: #fff;
  box-shadow: var(--shadow-md), 0 0 0 0 rgba(124, 58, 237, 0.4);
}

.cx-btn--primary:hover {
  box-shadow: var(--shadow-lg), 0 0 20px rgba(124, 58, 237, 0.35);
}

.cx-btn--ghost {
  background: rgba(124, 58, 237, 0.12);
  color: var(--text-primary);
  border: 1px solid var(--bg-border);
}

[data-theme='light'] .cx-btn--ghost {
  background: rgba(124, 58, 237, 0.08);
}

.cx-btn--ghost:hover {
  border-color: var(--brand-primary);
  background: rgba(124, 58, 237, 0.18);
}

.cx-btn--accent {
  background: linear-gradient(135deg, var(--brand-accent), #0891b2);
  color: #0a0a0f;
}

.cx-card {
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition:
    transform var(--transition-base),
    border-color var(--transition-base),
    box-shadow var(--transition-base);
}

.cx-card--glass {
  background: rgba(17, 17, 24, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

[data-theme='light'] .cx-card--glass {
  background: rgba(255, 255, 255, 0.85);
}

.cx-card--hover:hover {
  transform: translateY(-2px);
  border-color: rgba(124, 58, 237, 0.45);
  box-shadow: var(--shadow-glow);
}

.cx-tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-lg);
  align-items: stretch;
}

.cx-tool-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  text-decoration: none;
  color: inherit;
  height: 100%;
  min-height: 0;
}

.cx-tool-card__icon {
  font-size: 1.75rem;
  line-height: 1;
}

.cx-tool-card h3 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--text-primary);
}

.cx-tool-card p {
  font-size: 0.9rem;
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  line-height: 1.55;
  word-break: break-word;
}

.cx-tool-card__link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand-accent);
  margin-top: auto;
  padding-top: var(--space-md);
  flex-shrink: 0;
  align-self: flex-start;
}

.cx-tool-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  flex-shrink: 0;
  padding-top: var(--space-sm);
}

.cx-tool-card__tag {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-border);
  color: var(--text-muted);
}

.cx-tool-card__tag--accent {
  border-color: rgba(6, 182, 212, 0.35);
  color: var(--brand-accent);
}

.cx-color-card {
  --card-color: #7c3aed;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.cx-color-card:hover {
  border-color: rgba(124, 58, 237, 0.35);
  box-shadow: var(--shadow-sm);
}

.cx-color-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs) var(--space-sm);
  margin-bottom: var(--space-xs);
}

.cx-color-card__name {
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 0;
}

.cx-color-role-chip {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-border);
  color: var(--text-muted);
  line-height: 1.2;
  flex-shrink: 0;
}

.cx-color-role-chip--primary {
  border-color: rgba(124, 58, 237, 0.45);
  color: var(--brand-primary);
  background: rgba(124, 58, 237, 0.1);
}

.cx-color-role-chip--secondary {
  border-color: rgba(6, 182, 212, 0.4);
  color: var(--brand-accent);
  background: rgba(6, 182, 212, 0.08);
}

.cx-color-role-chip--accent {
  border-color: rgba(234, 88, 12, 0.35);
  color: #ea580c;
  background: rgba(234, 88, 12, 0.08);
}

[data-theme='dark'] .cx-color-role-chip--accent {
  color: #fb923c;
}

.cx-color-role-chip--neutral {
  background: var(--bg-surface);
}

.cx-color-card__swatch {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--card-color);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.cx-color-card--car,
.cx-color-card--game,
.cx-color-card--dev,
.cx-color-card--culture {
  grid-template-columns: 64px 1fr;
}

.cx-color-card--car .cx-color-card__swatch,
.cx-color-card--game .cx-color-card__swatch,
.cx-color-card--dev .cx-color-card__swatch,
.cx-color-card--culture .cx-color-card__swatch {
  width: 64px;
  height: 64px;
}

.cx-color-card--flag-country {
  grid-template-columns: 96px 1fr;
  align-items: start;
}

.cx-flag-preview {
  position: relative;
  width: 96px;
  height: 64px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--bg-border);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 1px 3px rgba(0, 0, 0, 0.1);
}

.cx-flag-preview__stripes {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.cx-flag-preview__stripes--vertical {
  flex-direction: row;
}

.cx-flag-preview__stripe {
  flex: 1 1 0;
  min-height: 2px;
  min-width: 2px;
}

/* Horizontal / vertical tricolors */
.cx-flag-preview--horizontal,
.cx-flag-preview--horizontal-alt,
.cx-flag-preview--bicolor-h {
  display: flex;
  flex-direction: column;
}

.cx-flag-preview--vertical,
.cx-flag-preview--bicolor-v {
  display: flex;
  flex-direction: row;
}

/* Canton (US, AU, CL, MY, …) */
.cx-flag-preview--canton,
.cx-flag-preview--usa {
  display: block;
}

.cx-flag-preview--canton .cx-flag-preview__canton,
.cx-flag-preview--usa .cx-flag-preview__canton {
  position: absolute;
  left: 0;
  top: 0;
  width: 42%;
  height: 52%;
  z-index: 2;
}

.cx-flag-preview--canton .cx-flag-preview__stripes,
.cx-flag-preview--usa .cx-flag-preview__stripes {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Nordic / UK crosses */
.cx-flag-preview--cross,
.cx-flag-preview--cross-nordic,
.cx-flag-preview--cross-centered,
.cx-flag-preview--cross-union,
.cx-flag-preview--saltire {
  display: block;
}

.cx-flag-preview__field {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.cx-flag-preview__cross {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  background: var(--cross-color, #fff);
}

.cx-flag-preview__cross--white,
.cx-flag-preview__cross--color {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  clip-path: polygon(
    0 38%,
    32% 38%,
    32% 0,
    68% 0,
    68% 38%,
    100% 38%,
    100% 62%,
    68% 62%,
    68% 100%,
    32% 100%,
    32% 62%,
    0 62%
  );
}

.cx-flag-preview__cross--nordic.cx-flag-preview__cross--white,
.cx-flag-preview__cross--nordic.cx-flag-preview__cross--color {
  clip-path: polygon(
    0 42%,
    28% 42%,
    28% 0,
    38% 0,
    38% 42%,
    100% 42%,
    100% 58%,
    38% 58%,
    38% 100%,
    28% 100%,
    28% 58%,
    0 58%
  );
}

.cx-flag-preview__cross--centered.cx-flag-preview__cross--white,
.cx-flag-preview__cross--centered.cx-flag-preview__cross--color {
  clip-path: polygon(
    0 40%,
    36% 40%,
    36% 0,
    64% 0,
    64% 40%,
    100% 40%,
    100% 60%,
    64% 60%,
    64% 100%,
    36% 100%,
    36% 60%,
    0 60%
  );
}

.cx-flag-preview__cross--color {
  z-index: 2;
  clip-path: polygon(
    0 41%,
    33% 41%,
    33% 0,
    67% 0,
    67% 41%,
    100% 41%,
    100% 59%,
    67% 59%,
    67% 100%,
    33% 100%,
    33% 59%,
    0 59%
  );
}

.cx-flag-preview__cross--nordic.cx-flag-preview__cross--color {
  clip-path: polygon(
    0 44%,
    29% 44%,
    29% 0,
    37% 0,
    37% 44%,
    100% 44%,
    100% 56%,
    37% 56%,
    37% 100%,
    29% 100%,
    29% 56%,
    0 56%
  );
}

.cx-flag-preview__cross--centered.cx-flag-preview__cross--color {
  clip-path: polygon(
    0 42%,
    37% 42%,
    37% 0,
    63% 0,
    63% 42%,
    100% 42%,
    100% 58%,
    63% 58%,
    63% 100%,
    37% 100%,
    37% 58%,
    0 58%
  );
}

/* Disc (JP, BD, …) */
.cx-flag-preview--disc,
.cx-flag-preview--field {
  display: block;
}

.cx-flag-preview__disc {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  height: 44%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  z-index: 1;
}

/* Triangle at hoist (CZ, PH, …) */
.cx-flag-preview--triangle-hoist,
.cx-flag-preview--triangle-double {
  display: block;
}

.cx-flag-preview__triangle {
  position: absolute;
  left: 0;
  top: 0;
  width: 40%;
  height: 100%;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  z-index: 2;
}

.cx-flag-preview--triangle-hoist .cx-flag-preview__stripes {
  position: absolute;
  inset: 0;
}

/* Hoist band (BH, PK) */
.cx-flag-preview--hoist-band,
.cx-flag-preview--pk {
  display: flex;
  flex-direction: row;
}

.cx-flag-preview__hoist {
  width: 28%;
  flex-shrink: 0;
  height: 100%;
}

.cx-flag-preview__fly {
  flex: 1;
  height: 100%;
}

/* UAE */
.cx-flag-preview--ae {
  display: flex;
  flex-direction: row;
}

.cx-flag-preview__ae-red {
  width: 22%;
  flex-shrink: 0;
  height: 100%;
}

.cx-flag-preview__ae-fly {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Quartered (Panama) */
.cx-flag-preview--quartered {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.cx-flag-preview__q {
  min-height: 0;
  min-width: 0;
}

/* Diagonal / Y-flags */
.cx-flag-preview--diagonal,
.cx-flag-preview--diagonal-x,
.cx-flag-preview--south-africa {
  display: block;
}

.cx-flag-preview__diagonal,
.cx-flag-preview__sa {
  position: absolute;
  inset: 0;
}

.cx-flag-preview__iso {
  position: absolute;
  right: 3px;
  bottom: 2px;
  z-index: 5;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.2;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.cx-flag-preview--empty {
  background: var(--bg-surface);
}

.cx-flag-chip-label {
  opacity: 0.75;
  margin-left: 0.25rem;
  font-size: 0.7rem;
}

.cx-dev-snippet-chip {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.75rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cx-code-block {
  margin: 0;
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.8125rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}

.cx-paint-meta {
  display: grid;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
  color: var(--text-secondary);
}

.cx-paint-meta div {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-sm);
  align-items: baseline;
}

.cx-paint-meta dt {
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
}

.cx-paint-meta dd {
  margin: 0;
}

.cx-code-chip--muted {
  font-size: 0.7rem;
  opacity: 0.92;
}

.cx-code-chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
}

.cx-code-chip:hover {
  background: rgba(124, 58, 237, 0.15);
  color: var(--text-primary);
}

.cx-code-chip--secondary {
  font-size: 0.7rem;
  opacity: 0.95;
  border-style: dashed;
}

.cx-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
}

.cx-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.cx-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.cx-toast {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 10000;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.95rem;
  color: var(--text-primary);
  opacity: 0;
  transition:
    transform var(--transition-base),
    opacity var(--transition-base);
}

.cx-toast--visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.cx-toast--error {
  border-color: var(--error);
}

.cx-breadcrumb {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

.cx-breadcrumb a {
  color: var(--text-secondary);
}

.cx-page-header {
  padding-block: var(--space-xl) var(--space-lg);
}

.cx-faq {
  margin-top: var(--space-2xl);
}

.cx-faq details {
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-surface);
}

.cx-faq summary {
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
}

.cx-faq summary::-webkit-details-marker {
  display: none;
}

.cx-faq details[open] summary {
  margin-bottom: var(--space-sm);
}

/* Legal & policy pages */
.cx-legal {
  max-width: 46rem;
  margin-inline: auto;
}

.cx-legal .cx-legal-meta {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xl);
}

.cx-legal h2 {
  font-size: 1.15rem;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}

.cx-legal h2:first-of-type {
  margin-top: var(--space-md);
}

.cx-legal p,
.cx-legal li {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.65;
}

.cx-legal ul,
.cx-legal ol {
  padding-left: 1.25rem;
  margin-bottom: var(--space-md);
}

.cx-legal li + li {
  margin-top: 0.35rem;
}

.cx-legal a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cx-legal strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Learn — color theory & education */
.cx-learn-article {
  display: grid;
  gap: var(--space-lg);
}

.cx-learn-section h2 {
  margin-bottom: var(--space-sm);
}

.cx-learn-section p {
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.cx-learn-list {
  margin: 0 0 var(--space-sm);
  padding-left: 1.25rem;
  color: var(--text-secondary);
}

.cx-learn-list li + li {
  margin-top: 0.35rem;
}

.cx-learn-widget__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.cx-learn-widget__hex {
  max-width: 7rem;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85rem;
}

.cx-learn-widget__swatches {
  display: grid;
  gap: var(--space-sm);
}

.cx-learn-widget__chip {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--bg-border);
}

.cx-learn-widget__chip-swatch {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.cx-learn-widget__pair,
.cx-learn-widget__split {
  display: flex;
  height: 4rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--bg-border);
}

.cx-learn-widget__half {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.35rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.cx-learn-widget__half--warm {
  background: linear-gradient(135deg, #dc2626, #f59e0b, #fbbf24);
}

.cx-learn-widget__half--cool {
  background: linear-gradient(135deg, #059669, #2563eb, #6366f1);
}

.cx-learn-widget__contrast-demo {
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  border: 1px solid var(--bg-border);
  margin-bottom: var(--space-sm);
}

.cx-learn-widget__contrast-text {
  margin: 0;
  font-size: 1rem;
}

.cx-learn-widget__ratio {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.cx-learn-widget__cb-grid {
  display: grid;
  gap: var(--space-sm);
}

.cx-learn-widget__cb-row {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: var(--space-sm);
  align-items: center;
}

.cx-learn-widget__cb-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.cx-learn-widget__cb-stripes {
  display: flex;
  height: 1.5rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--bg-border);
}
