/* ---------- BASE ---------- */
* { box-sizing: border-box; margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: #0b0d12;
  color: #e9ecf3;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

/* --lamp is the chosen colour as "hue saturation lightness".
   --c is the colour actually shown: the lamp colour, unless a mood overrides it. */
.scene {
  --lamp: 42 100% 62%;
  --c: var(--lamp);
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 8vw, 120px);
  padding: 32px 16px;
}
.scene[data-mood="error"] { --c: 0 90% 64%; }
.scene[data-mood="ok"]    { --c: 145 70% 55%; }
/* ---------- END BASE ---------- */

/* ---------- ROOM GLOW ---------- */
.glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 35% 45%, hsl(var(--c) / .28), transparent 55%),
    radial-gradient(circle at 70% 60%, hsl(var(--c) / .12), transparent 60%);
  opacity: 0;
  transition: opacity .8s ease, background .5s ease;
}
.scene[data-on="true"] .glow { opacity: 1; }
/* ---------- END ROOM GLOW ---------- */

/* ---------- LAMP ---------- */
.lamp {
  position: relative;
  flex: none;
  width: 220px;
  height: 430px;
}

.shade {
  position: absolute;
  top: 0;
  left: 10px;
  width: 200px;
  height: 120px;
  clip-path: polygon(22% 0, 78% 0, 100% 100%, 0 100%);
  background: linear-gradient(#3b404e, #262a35);
  transition: background .4s ease;
  z-index: 2;
}
.scene[data-on="true"] .shade {
  background: linear-gradient(hsl(var(--c)), hsl(var(--c) / .78));
}

.bulb {
  position: absolute;
  top: 112px;
  left: 80px;
  width: 60px;
  height: 30px;
  border-radius: 0 0 30px 30px;
  background: #4a4f5c;
  transition: background .3s, box-shadow .5s;
  z-index: 1;
}
.scene[data-on="true"] .bulb {
  background: #fffbea;
  box-shadow: 0 0 30px 10px hsl(var(--c) / .8), 0 0 90px 30px hsl(var(--c) / .35);
}

/* The cone of light under the shade */
.light {
  position: absolute;
  top: 118px;
  left: -100px;
  width: 420px;
  height: 330px;
  clip-path: polygon(38% 0, 62% 0, 100% 100%, 0 100%);
  background: linear-gradient(hsl(var(--c) / .5), hsl(var(--c) / .08) 70%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s ease, background .5s ease;
}
.scene[data-on="true"] .light {
  opacity: 1;
  animation: flicker .9s linear;
}

.stand {
  position: absolute;
  top: 120px;
  left: 105px;
  width: 10px;
  height: 290px;
  border-radius: 4px;
  background: linear-gradient(90deg, #2b2f3a, #4a4f5c, #2b2f3a);
}
.base {
  position: absolute;
  bottom: 0;
  left: 40px;
  width: 140px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 30%, #4a4f5c, #22252e);
}
/* ---------- END LAMP ---------- */

/* ---------- FACE ---------- */
.eye {
  position: absolute;
  top: 58px;
  width: 16px;
  height: 3px;              /* closed: a sleepy line */
  border-radius: 3px;
  background: #11131a;
  transition: height .25s ease, top .25s ease;
}
.eye.left  { left: 68px; }
.eye.right { left: 116px; }
.scene[data-on="true"] .eye {
  top: 50px;
  height: 16px;             /* open */
  border-radius: 50%;
  animation: blink 4s infinite 1.2s;
}
/* a little shine in each open eye */
.scene[data-on="true"] .eye::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

.cheek {
  position: absolute;
  top: 74px;
  width: 18px;
  height: 9px;
  border-radius: 50%;
  background: #ff6b8b;
  opacity: 0;
  transition: opacity .3s;
}
.cheek.left  { left: 50px; }
.cheek.right { left: 132px; }
.scene[data-on="true"] .cheek { opacity: .55; }

.mouth {
  position: absolute;
  top: 78px;
  left: 92px;
  width: 16px;
  height: 3px;
  border-radius: 3px;
  background: #11131a;
  transition: all .3s ease;
}
/* awake: a gentle smile */
.scene[data-on="true"] .mouth {
  top: 74px;
  height: 9px;
  background: transparent;
  border: 3px solid #11131a;
  border-top: 0;
  border-radius: 0 0 12px 12px;
}
/* error: a frown */
.scene[data-mood="error"] .mouth {
  top: 80px;
  border: 3px solid #11131a;
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
}
/* success: a big open grin */
.scene[data-mood="ok"] .mouth {
  left: 88px;
  width: 24px;
  height: 13px;
  background: #11131a;
  border-radius: 0 0 14px 14px;
}
/* ---------- END FACE ---------- */

/* ---------- CORD ---------- */
.cord {
  --pull: 0px;              /* set by script.js while you drag */
  position: absolute;
  top: 108px;
  left: 160px;
  width: 36px;
  height: calc(150px + var(--pull));
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  touch-action: none;       /* lets us drag on phones without scrolling */
  z-index: 3;
}
.cord:active { cursor: grabbing; }
.cord-line {
  position: absolute;
  top: 0;
  left: 17px;
  width: 2px;
  height: calc(110px + var(--pull));
  background: #9aa1b1;
}
.cord-knob {
  position: absolute;
  top: calc(106px + var(--pull));
  left: 9px;
  width: 18px;
  height: 26px;
  border-radius: 9px 9px 12px 12px;
  background: linear-gradient(#d7dbe4, #8d93a3);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
  transition: background .3s;
}
.scene[data-on="true"] .cord-knob { background: linear-gradient(hsl(var(--c)), hsl(var(--c) / .7)); }
.cord:focus-visible { outline: none; }
.cord:focus-visible .cord-knob { outline: 3px solid #fff; outline-offset: 3px; }

.hint {
  position: absolute;
  top: 280px;
  left: 150px;
  width: 140px;
  font-size: 14px;
  color: #9aa1b1;
  animation: nudge 1.6s ease-in-out infinite;
  transition: opacity .3s;
}
.hint::before { content: "\2190  "; }
.scene[data-on="true"] .hint { opacity: 0; }
/* ---------- END CORD ---------- */

/* ---------- FORM CARD ---------- */
.card {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 28px 26px 22px;
  border-radius: 20px;
  background: rgba(18, 20, 28, .78);
  border: 1px solid hsl(var(--c) / .35);
  box-shadow: 0 0 50px hsl(var(--c) / .22), 0 20px 50px rgba(0, 0, 0, .5);
  backdrop-filter: blur(10px);
  /* hidden while the lamp is off */
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(.96);
  filter: blur(6px);
  transition: opacity .5s ease, transform .6s cubic-bezier(.2, .9, .3, 1.2), filter .5s ease,
              visibility 0s linear .6s, border-color .5s, box-shadow .5s;
}
.scene[data-on="true"] .card {
  opacity: 1;
  visibility: visible;
  transform: none;
  filter: none;
  transition-delay: .25s, .25s, .25s, 0s, 0s, 0s;
}
.card.shake { animation: shake .45s ease; }

.card h1 { font-size: 26px; margin-bottom: 4px; }
.sub { color: #9aa1b1; font-size: 14px; margin-bottom: 20px; }

.swatches { display: flex; gap: 8px; margin-bottom: 18px; }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: hsl(var(--sw));
  cursor: pointer;
  transition: transform .2s;
}
.swatch:hover { transform: scale(1.15); }
.swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 12px hsl(var(--sw)); }
.swatch:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-size: 13px; color: #b9bfcc; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #2c3040;
  background: #0f1118;
  color: inherit;
  font: inherit;
  transition: border-color .25s, box-shadow .25s;
}
.field input:focus {
  outline: none;
  border-color: hsl(var(--c));
  box-shadow: 0 0 0 4px hsl(var(--c) / .18);
}
.field input[aria-invalid="true"] { border-color: hsl(0 90% 64%); box-shadow: 0 0 0 4px hsl(0 90% 64% / .18); }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 64px; }
.eye-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: #9aa1b1;
  font: 600 12px/1 system-ui, sans-serif;
  cursor: pointer;
}
.eye-btn:hover, .eye-btn:focus-visible { color: hsl(var(--c)); }

.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 18px; font-size: 13px; }
.remember { display: flex; align-items: center; gap: 6px; color: #b9bfcc; cursor: pointer; }
.remember input { accent-color: hsl(var(--c)); }
.link { color: hsl(var(--c)); text-decoration: none; }
.link:hover { text-decoration: underline; }

.submit {
  position: relative;
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: hsl(var(--c));
  color: #11131a;
  font: 700 15px/1.2 system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 8px 24px hsl(var(--c) / .35);
  transition: transform .15s, background .4s, box-shadow .4s;
}
.submit:hover { transform: translateY(-1px); }
.submit:active { transform: translateY(1px); }
.submit:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.submit.loading .label { visibility: hidden; }
.submit.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 3px solid #11131a;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.msg { min-height: 20px; margin-top: 12px; font-size: 13px; text-align: center; color: hsl(var(--c)); }
/* ---------- END FORM CARD ---------- */

/* ---------- SPARKLES ---------- */
.spark {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: hsl(var(--c));
  box-shadow: 0 0 10px hsl(var(--c));
  pointer-events: none;
  animation: fly 1s ease-out forwards;
}
/* ---------- END SPARKLES ---------- */

/* ---------- KEYFRAMES ---------- */
@keyframes flicker {
  0%, 18%, 22%, 50%, 54% { opacity: 1; }
  20%, 52% { opacity: .2; }
}
@keyframes blink {
  0%, 95%, 100% { transform: scaleY(1); }
  97% { transform: scaleY(.1); }
}
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(8px); }
}
@keyframes shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fly {
  to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
/* ---------- END KEYFRAMES ---------- */

/* ---------- SMALL SCREENS ---------- */
@media (max-width: 760px) {
  .scene { flex-direction: column; gap: 0; justify-content: flex-start; padding-top: 8px; }
  /* shrink the lamp without changing any of its numbers */
  .lamp { transform: scale(.6); transform-origin: top center; margin-bottom: -160px; }
  .hint { font-size: 22px; }
}
/* ---------- END SMALL SCREENS ---------- */

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
}
/* ---------- END REDUCED MOTION ---------- */
