/* =========================================================
   Picture Colour Picker
   A darkroom / colour-lab aesthetic: warm paper & ink in
   light mode, glowing safelight amber in dark mode.
   ========================================================= */

:root {
  --bg: #f3efe4;
  --bg-soft: #ece5d4;
  --bg-elevated: #fffdf8;
  --ink: #201c16;
  --ink-soft: #6b6153;
  --ink-faint: #94897a;
  --line: rgba(32, 28, 22, 0.14);
  --line-strong: rgba(32, 28, 22, 0.28);

  --accent: #d9581f;
  --accent-strong: #b8441a;
  --accent-ink: #fff8f0;
  --accent-soft: #f2ded0;

  --secondary: #2f6a5c;
  --secondary-soft: #dce9e3;

  --shadow-color: 32, 20, 10;
  --shadow-sm: 0 1px 2px rgba(var(--shadow-color), 0.08);
  --shadow-md: 0 8px 24px -8px rgba(var(--shadow-color), 0.22);
  --shadow-lg: 0 24px 60px -20px rgba(var(--shadow-color), 0.35);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --font-display: "Fraunces", "Iowan Old Style", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
  --font-body: "Work Sans", -apple-system, sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120d;
    --bg-soft: #1c1710;
    --bg-elevated: #211b13;
    --ink: #f2ead9;
    --ink-soft: #b9ac97;
    --ink-faint: #7d7364;
    --line: rgba(242, 234, 217, 0.1);
    --line-strong: rgba(242, 234, 217, 0.22);

    --accent: #ff7d40;
    --accent-strong: #ff9b64;
    --accent-ink: #201202;
    --accent-soft: rgba(255, 125, 64, 0.16);

    --secondary: #5cc2a6;
    --secondary-soft: rgba(92, 194, 166, 0.14);

    --shadow-color: 0, 0, 0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 28px -8px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, 0.65);

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

::selection { background: var(--accent); color: var(--accent-ink); }

/* film-grain atmosphere */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  .grain { opacity: 0.09; }
}

/* ---------------- header ---------------- */
.site-header {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.6rem clamp(1.25rem, 4vw, 2.5rem) 1.6rem;
  display: flex;
  align-items: flex-start;
}

.brand { display: flex; align-items: flex-start; gap: 0.9rem; }
.brand-mark { color: var(--accent); flex-shrink: 0; margin-top: 0.35rem; }

.brand-text h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.7rem, 3.4vw, 2.35rem);
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}

.tagline {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-style: italic;
  font-family: var(--font-display);
  font-weight: 500;
}

.reg-mark {
  position: absolute;
  top: 2.3rem;
  right: clamp(1.25rem, 4vw, 2.5rem);
  color: var(--line-strong);
  font-family: var(--font-mono);
  font-size: 1.2rem;
  user-select: none;
}

/* ---------------- layout ---------------- */
.app-grid {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 clamp(1.25rem, 4vw, 2.5rem) 2rem;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
  gap: clamp(1.25rem, 3vw, 2rem);
  align-items: start;
}

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

.stage-wrap { position: sticky; top: 1.25rem; }
@media (max-width: 880px) { .stage-wrap { position: static; } }

.stage-hint {
  margin: 0.75rem 0.25rem 0;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

/* ---------------- dropzone / stage ---------------- */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  min-height: 420px;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.dropzone[data-drag="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-lg);
}

.empty-state {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.55rem;
  padding: 3rem 1.5rem;
  color: var(--ink-soft);
  cursor: pointer;
  width: 100%;
}
.empty-state svg { color: var(--ink-faint); margin-bottom: 0.4rem; }

.empty-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}
.empty-sub { margin: 0 0 0.6rem; font-size: 0.88rem; }

/* ---------------- canvas area ---------------- */
.canvas-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.75rem, 2vw, 1.5rem);
}

#canvas {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  cursor: crosshair;
  box-shadow: var(--shadow-sm);
  touch-action: none;
}

#canvas:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 3px;
}

.coords-readout {
  position: absolute;
  left: 1.1rem;
  bottom: 1.1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: rgba(var(--shadow-color), 0.7);
  color: #f2ece0;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  letter-spacing: 0.02em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.coords-readout[data-visible="true"] { opacity: 1; }

.change-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

/* loupe (magnifier) */
.loupe {
  position: absolute;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  pointer-events: none;
  overflow: hidden;
  box-shadow:
    0 0 0 4px var(--bg-elevated),
    0 0 0 6px var(--line-strong),
    var(--shadow-lg);
  z-index: 20;
  transform: translate(-50%, -50%);
  background: #000;
}
.loupe canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  display: block;
}
.loupe-cross {
  position: absolute;
  inset: 0;
}
.loupe-cross::before,
.loupe-cross::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}
.loupe-cross::before { left: 50%; top: 0; bottom: 0; width: 1px; transform: translateX(-50%); }
.loupe-cross::after { top: 50%; left: 0; right: 0; height: 1px; transform: translateY(-50%); }
.loupe-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 15%;
  height: 15%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.6);
}

/* ---------------- panel / cards ---------------- */
.panel { display: flex; flex-direction: column; gap: 1.1rem; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-md);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.card-head h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.card-sub {
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.empty-hint {
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin: 0;
}

/* picked colour card */
.swatch-big {
  height: 132px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  padding: 0.8rem;
  margin-bottom: 1rem;
  background:
    repeating-conic-gradient(var(--bg-soft) 0% 25%, var(--bg-elevated) 0% 50%) 0 0 / 20px 20px;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.25s ease;
}
.swatch-placeholder {
  font-size: 0.82rem;
  color: var(--ink-faint);
  background: rgba(var(--shadow-color), 0.06);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  backdrop-filter: blur(2px);
}

.swatch-big.pulse { animation: swatchPulse 0.5s ease; }
@keyframes swatchPulse {
  0% { box-shadow: 0 0 0 0 var(--accent-soft), var(--shadow-sm); }
  70% { box-shadow: 0 0 0 10px rgba(0,0,0,0), var(--shadow-sm); }
  100% { box-shadow: var(--shadow-sm); }
}

.picked-values { display: flex; flex-direction: column; gap: 0.5rem; }

.value-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-family: var(--font-mono);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.value-row:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.value-row:active:not(:disabled) { transform: scale(0.98); }
.value-row:disabled { opacity: 0.5; cursor: default; }
.value-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.value-row .label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  width: 2.6rem;
  flex-shrink: 0;
}
.value-row .val {
  flex: 1;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-icon { width: 15px; height: 15px; color: var(--ink-faint); flex-shrink: 0; }
.value-row:hover:not(:disabled) .copy-icon { color: var(--accent-strong); }

/* buttons */
.primary-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-strong); box-shadow: var(--shadow-md); }
.primary-btn:active:not(:disabled) { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.45; cursor: default; }
.primary-btn.full { width: 100%; margin-top: 1rem; }
.primary-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.ghost-btn {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  background: rgba(var(--shadow-color), 0.55);
  color: #f4f0e6;
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.ghost-btn:hover { background: var(--accent-strong); color: var(--accent-ink); }

.chip-btn {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.32rem 0.65rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip-btn:hover:not(:disabled) { border-color: var(--secondary); color: var(--secondary); background: var(--secondary-soft); }
.chip-btn:disabled { opacity: 0.4; cursor: default; }

/* palette */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}
@media (max-width: 420px) { .palette-grid { grid-template-columns: repeat(3, 1fr); } }

.palette-chip {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  aspect-ratio: 1 / 1.15;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: var(--font-mono);
}
.palette-chip:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.palette-chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.palette-chip .chip-color { position: absolute; inset: 0 0 30% 0; }
.palette-chip .chip-label {
  position: absolute;
  left: 0; right: 0; bottom: 0; height: 30%;
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: var(--ink-soft);
  line-height: 1.3;
}
.palette-chip .chip-index {
  position: absolute;
  top: 0.3rem;
  left: 0.4rem;
  font-size: 0.62rem;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  font-weight: 700;
}

/* saved swatches */
.saved-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  min-height: 2.5rem;
}
.saved-chip {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}
.saved-chip:hover { transform: scale(1.08); }
.saved-chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.saved-chip .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  border: none;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.saved-chip:hover .remove, .saved-chip:focus-within .remove { opacity: 1; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.toast[data-visible="true"] { opacity: 1; transform: translate(-50%, 0); }

/* footer */
.site-footer {
  max-width: 1180px;
  margin: 1.5rem auto 3rem;
  padding: 1.25rem clamp(1.25rem, 4vw, 2.5rem) 0;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 0.78rem;
}

@media (max-width: 480px) {
  .swatch-big { height: 104px; }
  .dropzone { min-height: 320px; }
  .site-header { flex-direction: column; gap: 0.5rem; }
  .reg-mark { display: none; }
}

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