:root {
  --bg: #FAF7F2;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #e8e4de;
  --accent: #1a1a1a;
  --accent-text: #ffffff;
  --strip-color: transparent;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
::selection { background: var(--accent); color: var(--accent-text); }
::-moz-selection { background: var(--accent); color: var(--accent-text); }
body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background-color 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* BORDER FRAME — all four sides */
.border-frame {
  position: fixed;
  z-index: 100;
  transition: background-color 1s ease;
  background-color: var(--strip-color);
}
.border-frame.top    { top: 0; left: 0; right: 0; height: 4px; }
.border-frame.bottom { bottom: 0; left: 0; right: 0; height: 4px; }
.border-frame.left   { top: 0; bottom: 0; left: 0; width: 4px; }
.border-frame.right  { top: 0; bottom: 0; right: 0; width: 4px; }

/* NAV */
nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
}
.nav-left { display: flex; flex-direction: column; gap: 4px; }
nav h1 {
  font-family: 'Space Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.global-stat {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
}
nav .nav-links { display: flex; gap: 24px; }
nav .nav-links a {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s;
}
nav .nav-links a:hover, nav .nav-links a.active { color: var(--text); }

.page { display: none; }
.page.active { display: block; }

/* MIX PAGE */
.mix-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 24px;
  min-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: 20vh;
}

/* COLOR EQUATION ROW */
.mix-equation {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  margin-bottom: 40px;
  position: relative;
}

.slot-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  max-width: 220px;
  position: relative;
}
.slot-group:first-child {
  transform: rotate(-12deg);
  z-index: 1;
  margin-right: -12px;
}
.slot-group:last-child {
  transform: rotate(12deg);
  z-index: 2;
  margin-left: -12px;
}

.color-box {
  width: 100%;
  aspect-ratio: 5 / 6;
  border-radius: 20px;
  border: 2px dashed var(--border);
  transition: border 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  -moz-background-clip: padding;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
}
.color-box.filled {
  border: none;
  box-shadow: 0 6px 28px rgba(0,0,0,0.12);
}

/* White bar at bottom of color box */
.color-box-bar {
  background: rgba(255, 255, 255, 0.80);
  padding: 20px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex-shrink: 0;
}
.color-text-input {
  width: 100%;
  font-family: 'Space Mono', monospace;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  cursor: text;
}
.color-text-input::placeholder { color: #b5b0a8; font-weight: 400; }

.mix-operator {
  display: none;
}

/* MIX AREA — button + personal count */
.mix-area {
  text-align: center;
}
.mix-btn {
  display: inline-block;
  padding: 14px 56px;
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mix-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0,0,0,0.15); }
.mix-btn:active { transform: scale(0.92); box-shadow: none; transition: transform 0.1s ease; }
.mix-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; box-shadow: none; }

.randomize-btn {
  display: block;
  margin: 10px auto 0;
  padding: 8px 24px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.randomize-btn:hover { border-color: var(--text); color: var(--text); }
.randomize-btn:active { transform: scale(0.92); transition: transform 0.1s ease; }

.personal-stat {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 16px;
}
.personal-stat strong {
  font-weight: 700;
  color: var(--text);
}

/* ── PICKER OVERLAY ── */
.picker-overlay-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 900;
  display: none;
}
.picker-overlay-bg.open { display: block; }

.picker-popover {
  position: absolute;
  z-index: 901;
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.04);
  width: 256px;
  display: none;
  animation: popIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.picker-popover.open { display: block; }

@keyframes popIn {
  0% { opacity: 0; transform: scale(0.9) translateY(4px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.sv-canvas-wrap {
  position: relative;
  width: 224px;
  height: 148px;
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
  margin-bottom: 10px;
}
.sv-canvas { width: 224px; height: 148px; display: block; }
.sv-thumb {
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.2), 0 2px 6px rgba(0,0,0,0.25);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.hue-slider-wrap {
  position: relative;
  width: 224px;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  margin-bottom: 10px;
}
.hue-slider-bg {
  width: 100%; height: 100%;
  background: linear-gradient(to right,
    hsl(0,100%,50%), hsl(30,100%,50%), hsl(60,100%,50%),
    hsl(90,100%,50%), hsl(120,100%,50%), hsl(150,100%,50%),
    hsl(180,100%,50%), hsl(210,100%,50%), hsl(240,100%,50%),
    hsl(270,100%,50%), hsl(300,100%,50%), hsl(330,100%,50%),
    hsl(360,100%,50%));
}
.hue-thumb {
  position: absolute;
  top: 50%;
  width: 6px; height: 16px;
  border-radius: 3px;
  border: 2px solid white;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.2);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.picker-popover-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}
.picker-popover-hex {
  flex: 1;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  padding: 7px 8px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.picker-popover-hex:focus { border-color: var(--accent); }

.eyedropper-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.eyedropper-btn:hover { border-color: var(--accent); background: white; }
.eyedropper-btn svg { width: 16px; height: 16px; fill: var(--text-muted); }
.eyedropper-btn.unsupported { opacity: 0.3; cursor: not-allowed; }

.picker-done-btn {
  display: none;
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}

/* RESULT OVERLAY */
.mix-result-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(250,247,242,0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
.mix-result-overlay.active { display: flex; }
.mix-result-card {
  text-align: center;
  animation: resultReveal 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
  cursor: default;
}
.result-swatch {
  width: 160px; height: 160px;
  border-radius: 28px;
  margin: 0 auto 24px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.2);
}
.result-name-input {
  display: block;
  width: 200px;
  margin: 0 auto 16px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border: none;
  border-bottom: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 4px 0;
  transition: border-color 0.2s;
}
.result-name-input::placeholder { color: #8a8580; font-weight: 400; }
.result-name-input:focus { border-color: var(--accent); }
.result-hex {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.result-recipe {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.recipe-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0,0,0,0.1);
}
.result-badge {
  display: inline-block;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 100px;
  letter-spacing: 1px;
}
.result-badge.new-badge { background: #e8f5e9; color: #2e7d32; }
.result-badge.dupe-badge { background: #fff3e0; color: #e65100; }
.result-dismiss {
  display: block;
  margin: 20px auto 0;
  padding: 10px 32px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s;
}
.result-dismiss:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.15); }

@keyframes resultReveal {
  0% { opacity: 0; transform: scale(0.5) translateY(40px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* BLOB */
.blob-container {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 999;
  pointer-events: none;
  overflow: hidden;
}
.mix-canvas {
  width: 100%;
  height: 100%;
}

/* GALLERY */
.gallery-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 48px 24px 100px;
}
.gallery-header {
  text-align: center;
  margin-bottom: 40px;
}
.gallery-header h2 {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
}
.gallery-header .gallery-count {
  font-family: 'Space Mono', monospace;
  font-size: 36px;
  font-weight: 700;
}
.gallery-tabs {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
}
.gallery-tab {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  padding: 6px 16px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.gallery-tab:hover { border-color: var(--text); color: var(--text); }
.gallery-tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.gallery-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  font-family: 'Space Mono', monospace;
  font-size: 13px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
}
.gallery-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.gallery-cell:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
  z-index: 2;
}
.gallery-cell .cell-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.gallery-cell:hover .cell-tooltip { opacity: 1; }
.cell-copied {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.gallery-cell.copied .cell-copied { opacity: 1; }

/* COLOR DETAIL DIALOG */
.detail-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(250,247,242,0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
.detail-overlay.active { display: flex; }
.detail-card {
  text-align: center;
  animation: resultReveal 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
  cursor: default;
}
.detail-swatch {
  width: 240px;
  aspect-ratio: 4 / 5;
  border-radius: 24px;
  margin: 0 auto 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  -moz-background-clip: padding;
  -webkit-background-clip: padding-box;
  background-clip: padding-box;
}
.detail-swatch-bar {
  background: rgba(255, 255, 255, 0.85);
  padding: 16px 18px;
  text-align: left;
}
.detail-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.detail-name:empty { display: none; }
.detail-hex {
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.detail-recipe {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.detail-recipe:empty { display: none; }
.detail-date {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
}
.detail-date:empty { display: none; }
.detail-share-btn {
  display: inline-block;
  padding: 10px 32px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.detail-share-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,0.15); }
.detail-share-btn:active { transform: scale(0.92); transition: transform 0.1s ease; }
.detail-share-toast {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}
.detail-share-toast.show { opacity: 1; }

/* CREDIT */
.credit {
  position: fixed;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.5;
  z-index: 10;
}
.credit a {
  color: var(--text-muted);
  text-decoration: none;
  transition: opacity 0.2s;
}
.credit a:hover { opacity: 1; text-decoration: underline; }

/* ── MOBILE BREAKPOINTS ── */

/* Tablets and small desktops */
@media (max-width: 640px) {
  nav { padding: 16px 20px; }
  nav h1 { font-size: 18px; }
  .global-stat { font-size: 12px; }
  nav .nav-links { gap: 16px; }
  nav .nav-links a { font-size: 14px; }

  /* Stack nav vertically on mobile */
  nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .nav-left { width: 100%; }
  nav .nav-links { width: 100%; }

  /* Mix page: fill viewport, no scroll */
  .mix-page {
    padding: 0 16px;
    padding-bottom: 28vh;
    min-height: calc(100dvh - 60px);
    overflow: hidden;
  }
  body.page-mix { overflow: hidden; height: 100dvh; }

  .mix-equation { gap: 0; margin-bottom: 24px; }
  .slot-group { max-width: 44vw; }
  .slot-group:first-child { margin-right: -10px; }
  .slot-group:last-child { margin-left: -10px; }
  .color-box { border-radius: 16px; }
  .color-text-input { font-size: 14px; }

  .mix-btn { padding: 14px 48px; font-size: 14px; }
  .personal-stat { margin-top: 12px; font-size: 13px; }

  /* Picker: bottom sheet */
  .picker-popover {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    top: auto !important;
    right: 0 !important;
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 20px 20px 28px;
    animation: slideUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }
  .sv-canvas-wrap { width: 100%; height: 180px; }
  .sv-canvas { width: 100%; height: 180px; }
  .hue-slider-wrap { width: 100%; }
  .picker-done-btn { display: block; }

  /* Gallery: scrollable */
  .gallery-page { padding: 32px 16px 80px; }
  .gallery-header .gallery-count { font-size: 28px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
  .gallery-cell { border-radius: 10px; }

  .result-swatch { width: 130px; height: 130px; border-radius: 24px; margin-bottom: 20px; }

  .detail-swatch { width: 200px; border-radius: 20px; margin-bottom: 16px; }
  .detail-swatch-bar { padding: 14px 14px; }
}

/* Small phones */
@media (max-width: 420px) {
  nav { padding: 14px 16px; }
  nav h1 { font-size: 17px; }

  .mix-page { padding: 0 12px; padding-bottom: 24vh; }
  .mix-equation { gap: 0; margin-bottom: 20px; }
  .slot-group { max-width: 42vw; }
  .slot-group:first-child { margin-right: -8px; }
  .slot-group:last-child { margin-left: -8px; }
  .color-box { border-radius: 14px; }
  .color-text-input { font-size: 13px; }

  .mix-btn { padding: 12px 40px; font-size: 13px; }

  .gallery-page { padding: 24px 12px 72px; }
  .gallery-header { margin-bottom: 28px; }
  .gallery-header .gallery-count { font-size: 24px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 5px; }
  .gallery-cell { border-radius: 8px; }

  .result-swatch { width: 110px; height: 110px; border-radius: 20px; margin-bottom: 16px; }
  .result-name-input { width: 180px; font-size: 15px; }
  .result-dismiss { padding: 10px 28px; font-size: 12px; }

  .detail-swatch { width: 180px; border-radius: 18px; margin-bottom: 14px; }
  .detail-swatch-bar { padding: 12px 12px; }
  .detail-name { font-size: 14px; }
  .detail-hex { font-size: 13px; }
}

@keyframes slideUp {
  0% { opacity: 0; transform: translateY(100%); }
  100% { opacity: 1; transform: translateY(0); }
}
