/* Farb-Picker - eigenes Design: Dunkelgrau #18181b + Regenbogen-Akzente */

:root {
  --rb-1: #ef4444; /* rot */
  --rb-2: #f97316; /* orange */
  --rb-3: #eab308; /* gelb */
  --rb-4: #22c55e; /* grün */
  --rb-5: #3b82f6; /* blau */
  --rb-6: #a855f7; /* violett */
  --rainbow: linear-gradient(90deg, var(--rb-1), var(--rb-2), var(--rb-3), var(--rb-4), var(--rb-5), var(--rb-6));

  --radius: 14px;
  --radius-sm: 9px;
  --gap: 16px;
  --maxw: 980px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --t: 180ms ease;
}

/* Dunkelmodus (Default) */
[data-theme="dark"] {
  --bg: #18181b;
  --bg-2: #1f1f23;
  --surface: #232328;
  --surface-2: #2a2a30;
  --border: #34343b;
  --text: #f4f4f5;
  --text-dim: #a1a1aa;
  --accent: #a855f7;
  --accent-soft: rgba(168,85,247,0.16);
  --focus: #c084fc;
}

/* Hellmodus */
[data-theme="light"] {
  --bg: #f4f4f5;
  --bg-2: #ececef;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --border: #d9d9e0;
  --text: #18181b;
  --text-dim: #52525b;
  --accent: #7c3aed;
  --accent-soft: rgba(124,58,237,0.12);
  --focus: #7c3aed;
  --shadow: 0 10px 26px rgba(24,24,27,0.12);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px clamp(14px, 4vw, 28px);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.app-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 3px;
  background: var(--rainbow);
  opacity: 0.9;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: 38px; height: 38px;
  padding: 4px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  flex: none;
}
.brand-mark .dot { border-radius: 4px; }
.dot.d1 { background: var(--rb-1); }
.dot.d2 { background: var(--rb-2); }
.dot.d3 { background: var(--rb-3); }
.dot.d4 { background: var(--rb-4); }
.dot.d5 { background: var(--rb-5); }
.dot.d6 { background: var(--rb-6); }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1.18rem; margin: 0; line-height: 1.1; }
.tagline { margin: 1px 0 0; font-size: 0.74rem; color: var(--text-dim); }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t), border-color var(--t), transform var(--t), opacity var(--t);
  line-height: 1.1;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-icon {
  padding: 9px 12px;
  font-size: 1.1rem;
}
.theme-icon { display: inline-block; }
.file-btn { display: inline-flex; align-items: center; }

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

/* Main layout */
.app-main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(14px, 3vw, 26px);
  display: grid;
  gap: var(--gap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 22px);
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ttl-accent {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #fff;
  background: var(--rainbow);
  flex: none;
}
.card-hint { margin: 0 0 14px; color: var(--text-dim); font-size: 0.84rem; }

/* Upload */
.upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 14px;
  transition: border-color var(--t), background var(--t);
  position: relative;
}
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.9rem;
}
.drop-ico {
  font-size: 1.6rem;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--rainbow);
  color: #fff;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}
#imgCanvas {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  display: block;
  touch-action: none;
}

/* Lupe */
.loupe {
  position: absolute;
  width: 124px; height: 124px;
  pointer-events: none;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  transform: translate(-50%, -130%);
  z-index: 5;
  background: var(--surface);
}
.loupe canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.loupe-cross {
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  transform: translate(-50%,-50%);
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.6);
}

/* Picked value box */
.picked {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.picked-swatch {
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #888;
  flex: none;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.06);
}
.picked-values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.val-chip {
  font: inherit;
  font-size: 0.78rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: border-color var(--t), color var(--t), background var(--t);
  white-space: nowrap;
}
.val-chip strong {
  color: var(--text);
  font-family: var(--mono);
  margin-left: 6px;
  font-weight: 600;
}
.val-chip:hover { border-color: var(--accent); color: var(--text); }
.val-chip::after {
  content: " ⧉";
  opacity: 0.5;
}

/* Palette controls */
.pal-controls, .manual-actions, .hist-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}
.count-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.select {
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.swatch {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
}
.swatch-color {
  height: 78px;
  width: 100%;
  cursor: pointer;
  border: none;
  display: block;
  position: relative;
}
.swatch-color::after {
  content: "Kopieren";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity var(--t);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.swatch-color:hover::after, .swatch-color:focus-visible::after { opacity: 1; }
.swatch-meta {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.swatch-hex {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
}
.swatch-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-family: var(--mono);
}
.swatch-actions {
  display: flex;
  gap: 4px;
  padding: 0 8px 8px;
}
.mini-btn {
  flex: 1;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 5px 4px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color var(--t), color var(--t);
}
.mini-btn:hover { border-color: var(--accent); color: var(--text); }

.empty-note {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
  margin: 4px 0 0;
}

/* Manual */
.manual-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.color-input-wrap {
  position: relative;
  width: 72px; height: 72px;
  flex: none;
}
#manualColor {
  width: 72px; height: 72px;
  border: none;
  padding: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
}
#manualColor::-webkit-color-swatch-wrapper { padding: 4px; }
#manualColor::-webkit-color-swatch { border: none; border-radius: 10px; }
#manualColor::-moz-color-swatch { border: none; border-radius: 10px; }
.color-input-ring {
  position: absolute;
  inset: -3px;
  border-radius: 13px;
  padding: 3px;
  background: var(--rainbow);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* Footer */
.app-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px clamp(14px, 3vw, 26px) 30px;
  color: var(--text-dim);
  font-size: 0.78rem;
  text-align: center;
}
.app-footer .ts { opacity: 0.8; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 80;
  opacity: 0;
  transition: opacity var(--t), transform var(--t);
  max-width: calc(100vw - 28px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: grid;
  place-items: center;
  z-index: 90;
  padding: 18px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--accent);
}
.modal-title { margin: 0 0 8px; font-size: 1.05rem; }
.modal-msg { margin: 0 0 18px; color: var(--text-dim); font-size: 0.9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* Responsive */
@media (max-width: 480px) {
  .brand-text h1 { font-size: 1.05rem; }
  .upload-row .btn, .pal-controls .btn { flex: 1 1 auto; }
  .palette-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .picked-swatch { width: 48px; height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
