/* Picky — refined color-palette picker.
   Theme colors are CSS custom properties so the optional "Live theme" toggle
   can repaint the whole UI from a selected palette by overriding them on :root. */

:root {
  --paper: #f5f2ec;
  --paper-2: #fbf9f5;
  --ink: #1c1b20;
  --ink-soft: #55535c;
  --line: #e2ddd2;
  --card: #ffffff;
  --accent: #2b2a33;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(28, 27, 32, .05), 0 8px 24px rgba(28, 27, 32, .06);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must always win — author display rules (e.g. the flex
   editor) would otherwise override the UA [hidden]{display:none}. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  transition: background .5s ease, color .5s ease;
}
body { min-height: 100vh; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  max-width: 640px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { border-radius: 7px; display: block; }
.app-header h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 21px;
  letter-spacing: .3px;
  margin: 0;
}
.home-link { color: var(--ink-soft); text-decoration: none; font-size: 14px; }
.home-link:hover { color: var(--ink); }

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 18px 56px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-family: var(--font);
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform .08s ease, background .2s ease, border-color .2s ease, filter .2s ease;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-sm { padding: 9px 16px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- Splash ---- */
.splash {
  text-align: center;
  padding: 28px 0 8px;
}
.add-btn {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 54px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, filter .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 6px;
}
.add-btn:hover { filter: brightness(1.08); }
.add-btn:active { transform: scale(.95); }
.splash-hint {
  color: var(--ink-soft);
  font-size: 15px;
  margin: 16px 0 0;
}

/* ---- Saved gallery ---- */
.saved { margin-top: 40px; text-align: left; }
.saved-title { font-family: var(--serif); font-size: 18px; margin: 0 0 14px; }
.saved-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.saved-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  cursor: pointer;
  box-shadow: var(--shadow);
  position: relative;
  transition: transform .1s ease;
}
.saved-item:active { transform: scale(.98); }
.saved-item img { display: block; width: 100%; height: 104px; object-fit: cover; background: #0b0b0d; }
.saved-strip { display: flex; height: 16px; }
.saved-strip span { flex: 1; }
.saved-del {
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 20, 24, .62);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.saved-note { color: var(--ink-soft); font-size: 12.5px; line-height: 1.5; margin: 16px 0 0; }

/* ---- Editor ---- */
.editor { display: flex; flex-direction: column; gap: 14px; }
.editor-top {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #0b0b0d;
}
#photo {
  display: block;
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
}
.round-btn {
  position: absolute;
  top: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 20, 24, .55);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
}
.round-btn.back { left: 12px; }
.round-btn.replace { right: 12px; }

/* ---- Palette carousel ---- */
.palette-area { position: relative; }
.carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  scrollbar-width: none;
  box-shadow: var(--shadow);
}
.carousel::-webkit-scrollbar { display: none; }
/* One palette per slide: 5 colors as equal columns filling the full width, so
   the whole palette is visible at once. Swipe left/right for the other options. */
.slide {
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: center;
  display: flex;
  flex-direction: row;
  height: 42vh;
  min-height: 300px;
}
.band {
  flex: 1 1 20%;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 3px 16px;
  text-align: center;
}
.band-info {
  opacity: 0;
  transition: opacity .22s ease;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.carousel.show-info .band-info { opacity: 1; }
.band-info .bi-hex { display: block; font-size: 13px; font-weight: 700; letter-spacing: .2px; }
.band-info .bi-rgb { margin-top: 3px; font-size: 10px; line-height: 1.3; opacity: .92; }
.band-info .bi-rgb span { display: block; }

.info-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .82);
  color: #1c1b20;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  transition: transform .2s ease, background .2s ease;
  display: grid;
  place-items: center;
  z-index: 2;
}
.info-toggle.open { transform: rotate(90deg); }

/* skeleton while generating */
.slide.skeleton .band {
  background: linear-gradient(100deg, #e9e5dc 30%, #f3efe7 50%, #e9e5dc 70%);
  background-size: 250% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  border: none;
  background: var(--line);
  cursor: pointer;
  padding: 0;
  transition: background .2s ease, transform .2s ease;
}
.dot.active { background: var(--accent); transform: scale(1.25); }

.pal-status { text-align: center; color: var(--ink-soft); font-size: 14px; margin: 8px 0 0; min-height: 1.2em; }
.pal-status.error { color: #b23b3b; }

.editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.editor-actions .toggle { margin-left: auto; }

/* ---- Toggle ---- */
.toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 42px; height: 25px; border-radius: 999px;
  background: var(--line); position: relative; transition: background .2s ease; flex: 0 0 auto;
}
.toggle-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 19px; height: 19px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s ease;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(17px); }
.toggle input:focus-visible + .toggle-track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.toggle-label { font-size: 14px; color: var(--ink-soft); }

/* ---- Settings ---- */
.settings { margin-top: 30px; border-top: 1px solid var(--line); padding-top: 10px; }
.settings-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; padding: 10px 2px; cursor: pointer;
  font-size: 14px; color: var(--ink-soft); font-family: var(--font);
}
.settings-toggle .chev { transition: transform .2s ease; }
.settings-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.settings-body { padding: 8px 2px 4px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--ink-soft); }
.field input {
  font-size: 16px; /* ≥16px so iOS Safari doesn't auto-zoom on focus */
  font-family: var(--font);
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink); width: 100%;
}
.field input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; }
.field-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.key-status { font-size: 13px; color: var(--ink-soft); }
.key-status.ok { color: #2e7d54; }
.field-note { font-size: 12.5px; color: var(--ink-soft); line-height: 1.5; margin: 12px 0 0; max-width: 52ch; }

/* ---- Spinner ---- */
.spin {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid color-mix(in srgb, var(--ink-soft) 40%, transparent);
  border-top-color: var(--ink-soft); border-radius: 50%;
  animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 560px) {
  .slide { height: 46vh; min-height: 340px; }
  .band-info .bi-hex { font-size: 16px; }
  .band-info .bi-rgb { font-size: 12px; }
  .band-info .bi-rgb span { display: inline; }
  .band-info .bi-rgb span + span::before { content: ", "; }
}
