@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:wght@400;600;700&family=Libre+Baskerville:wght@400;700&family=EB+Garamond:wght@400;500;700&family=Courier+Prime:wght@400;700&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Crimson Text', 'Georgia', serif;
  background: #1c1a16;
  color: #d4c5a0;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  overflow-x: hidden;
}

/* ── Ambient background glow ── */
.ambient-glow {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.12;
  transition: background 0.8s ease;
  background: radial-gradient(ellipse at 50% 30%, var(--glow-color, #ff0000) 0%, transparent 70%);
}

.app {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 690px;
  position: relative;
  z-index: 1;
}

h1 {
  font-family: 'Libre Baskerville', 'Georgia', serif;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
  border-bottom: 1px solid #4a4232;
  padding-bottom: 0.6rem;
  transition: text-shadow 0.6s ease;
}

.repo-embed {
  width: fit-content;
  max-width: 100%;
  margin: 1rem auto 0.2rem;
  padding: 0.32rem 0.55rem;
  border: 1px solid #4a4232;
  border-radius: 999px;
  background: rgba(212, 197, 160, 0.06);
  display: flex;
  align-items: center;
  gap: 0.38rem;
  text-decoration: none;
  color: #d4c5a0;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.repo-embed:hover {
  border-color: rgba(212, 197, 160, 0.45);
  background: rgba(212, 197, 160, 0.1);
}

.repo-embed-icon {
  color: #a99a78;
  flex-shrink: 0;
}

.repo-embed-text {
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 0.84rem;
  color: #d4c5a0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .repo-embed {
    max-width: 100%;
  }
}

.writeup {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(212, 197, 160, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.writeup-title {
  font-family: 'Libre Baskerville', 'Georgia', serif;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #a99a78;
  text-align: center;
}

.writeup-text {
  font-size: 0.95rem;
  line-height: 1.45;
  color: #b8aa8b;
  text-align: justify;
}

/* ── Input row with random button ── */
.input-row {
  display: flex;
  gap: 8px;
}

#phraseInput {
  flex: 1;
  padding: 0.7rem 1rem;
  font-size: 1.1rem;
  font-family: 'Crimson Text', 'Georgia', serif;
  font-style: italic;
  border: 1px solid #4a4232;
  border-radius: 0;
  background: rgba(212,197,160,0.08);
  color: #d4c5a0;
  text-align: center;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.3s;
}
#phraseInput::placeholder { color: #7a7058; font-style: italic; }
#phraseInput:focus { border-color: #d4c5a0; box-shadow: 0 0 12px rgba(212,197,160,0.1); }
#phraseInput.valid { border-color: #8aaa5e; box-shadow: 0 0 12px rgba(138,170,94,0.15); }
#phraseInput.invalid { border-color: #4a4232; }

#randomBtn {
  background: rgba(212,197,160,0.08);
  border: 1px solid #4a4232;
  color: #7a7058;
  padding: 0 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}
#randomBtn:hover {
  color: #d4c5a0;
  border-color: #d4c5a0;
  background: rgba(212,197,160,0.12);
}
#randomBtn:active {
  transform: scale(0.92);
}
#randomBtn.spinning svg {
  animation: dice-spin 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes dice-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

.panel {
  background: rgba(212,197,160,0.05);
  border: 1px solid #4a4232;
  padding: 16px;
  position: relative;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.panel::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(212,197,160,0.08);
  pointer-events: none;
}
.panel:hover {
  border-color: rgba(212,197,160,0.25);
}

.main-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.picker-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.hue-slider {
  position: relative;
  width: 30px;
  height: 256px;
  cursor: crosshair;
  border: 1px solid #4a4232;
  transition: border-color 0.2s;
}
.hue-slider:hover { border-color: rgba(212,197,160,0.35); }
.hue-slider canvas { display: block; }
.hue-marker {
  position: absolute;
  left: -4px;
  right: -4px;
  height: 3px;
  background: #d4c5a0;
  box-shadow: 0 -1px 0 rgba(0,0,0,0.8), 0 1px 0 rgba(0,0,0,0.8);
  pointer-events: none;
  transform: translateY(-50%);
  top: 0;
  transition: top 0.08s ease-out;
}

.sv-picker {
  position: relative;
  width: 256px;
  height: 256px;
  cursor: crosshair;
  border: 1px solid #4a4232;
  transition: border-color 0.2s;
}
.sv-picker:hover { border-color: rgba(212,197,160,0.35); }
.sv-picker canvas { display: block; }
.sv-marker {
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid #d4c5a0;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.8);
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: left 0.08s ease-out, top 0.08s ease-out;
}

.right-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.info-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-btn {
  background: none;
  border: none;
  color: #7a7058;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, transform 0.15s;
  flex-shrink: 0;
}
.copy-btn:hover { color: #d4c5a0; transform: scale(1.15); }
.copy-btn:active { transform: scale(0.9); }
.copy-btn.copied { color: #8aaa5e; }

#phraseDisplay {
  font-family: 'Libre Baskerville', 'Georgia', serif;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.3s;
}

#hexDisplay, #rgbDisplay {
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.info-row:hover #hexDisplay,
.info-row:hover #rgbDisplay {
  opacity: 0.85;
}

.preview-panel {
  flex: 1;
  display: flex;
}

#colourPreview {
  flex: 1;
  min-height: 80px;
  border: 1px solid rgba(212,197,160,0.15);
  transition: background-color 0.15s, box-shadow 0.6s;
}

.rgb-sliders {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rgb-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.rgb-label {
  font-family: 'Crimson Text', 'Georgia', serif;
  font-size: 0.95rem;
  font-weight: 600;
  width: 1.2em;
  text-align: center;
  transition: text-shadow 0.3s;
}
.rgb-label.rgb-r { color: #c07050; }
.rgb-label.rgb-g { color: #8aaa5e; }
.rgb-label.rgb-b { color: #7090b0; }
.rgb-row:hover .rgb-label.rgb-r { text-shadow: 0 0 8px rgba(192,112,80,0.5); }
.rgb-row:hover .rgb-label.rgb-g { text-shadow: 0 0 8px rgba(138,170,94,0.5); }
.rgb-row:hover .rgb-label.rgb-b { text-shadow: 0 0 8px rgba(112,144,176,0.5); }
.rgb-val {
  font-family: 'Courier Prime', 'Courier New', monospace;
  font-size: 0.85rem;
  width: 2.5em;
  text-align: right;
  opacity: 0.6;
}
.rgb-input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 0;
  outline: none;
  background: rgba(212,197,160,0.12);
  transition: height 0.15s;
}
.rgb-row:hover .rgb-input {
  height: 6px;
}
.rgb-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 3px;
  height: 14px;
  border-radius: 0;
  background: #d4c5a0;
  box-shadow: -1px 0 0 rgba(0,0,0,0.6), 1px 0 0 rgba(0,0,0,0.6);
  cursor: pointer;
  transition: height 0.15s, width 0.15s;
}
.rgb-row:hover .rgb-input::-webkit-slider-thumb {
  height: 18px;
  width: 5px;
}
.rgb-input::-moz-range-thumb {
  width: 3px;
  height: 14px;
  border: none;
  border-radius: 0;
  background: #d4c5a0;
  box-shadow: -1px 0 0 rgba(0,0,0,0.6), 1px 0 0 rgba(0,0,0,0.6);
  cursor: pointer;
}
.rgb-input::-moz-range-track {
  height: 4px;
  border-radius: 0;
  background: transparent;
  border: none;
}

/* ── Color history ── */
.history-section {
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s, transform 0.4s;
}
.history-section.visible {
  opacity: 1;
  transform: translateY(0);
}
.history-label {
  font-family: 'Libre Baskerville', 'Georgia', serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #7a7058;
  flex-shrink: 0;
}
.history-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.history-swatch {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(212,197,160,0.2);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  animation: swatch-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.history-swatch:hover {
  transform: scale(1.25);
  border-color: #d4c5a0;
  box-shadow: 0 0 10px rgba(212,197,160,0.2);
  z-index: 2;
}
.history-swatch:active {
  transform: scale(0.95);
}
@keyframes swatch-pop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 28, 24, 0.95);
  border: 1px solid #4a4232;
  color: #d4c5a0;
  padding: 8px 20px;
  font-family: 'Courier Prime', monospace;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
