/* ============================================================
   Sunset Time Ambient Art Wall Lamp — V3 pull-chain interaction
   - 3 clear zones: topbar / lamp-stage / control panel
   - bead position: translateY(--pull), cord length: SVG line y2
   - bottom padding so Reset/Auto Demo are above any iOS browser bar
   - mobile-first, viewport-fit=cover, safe-area-inset respected
   ============================================================ */

:root {
  /* core sizing */
  --panel-w: min(70vw, 300px);
  --panel-h: min(70vw, 300px);
  --panel-radius: 8px;
  --bead-size: 38px;
  --hit-w: 96px;
  --hit-h: 140px;

  /* cord geometry */
  --cord-rest-len: 110px;   /* resting cord length (line y2 = 110) */
  --cord-max-pull: 80px;    /* max visual drop when fully pulled */
  --cord-line-color: #1a1310;

  /* pulled state — both default to 0 (resting) */
  --red-pull: 0px;
  --black-pull: 0px;

  /* lamp state */
  --sun-top: 0.45;          /* 0.36 (high) — 0.56 (low) */
  --sun-size: 88px;
  --sun-opacity: 0.95;
  --ambient-warm: rgba(255, 150, 80, 0.22);

  /* motion */
  --ease-spring: cubic-bezier(.22, 1.25, .36, 1);
  --ease-soft:   cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: #efe7da;
  color: #2b2018;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body { overflow-x: hidden; }

button { font: inherit; }

/* ============================================================
   page = 3-row column, no overlap
   ============================================================ */

.page {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: stretch;
  isolation: isolate;
}

/* ============================================================
   room — light warm wall, subtle texture, corner plant, lamp glow
   ============================================================ */

.room {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 55% at 50% 30%, #faf3e6 0%, #efe2cf 50%, #e3d3bb 100%);
}

.wall {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg,
      rgba(120, 90, 60, 0.025) 0px,
      rgba(120, 90, 60, 0.025) 1px,
      transparent 1px,
      transparent 3px),
    repeating-linear-gradient(90deg,
      rgba(120, 90, 60, 0.018) 0px,
      rgba(120, 90, 60, 0.018) 1px,
      transparent 1px,
      transparent 3px);
  opacity: 0.55;
}

.wall__vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 55% 45% at 50% 38%,
      rgba(255, 240, 215, 0.55) 0%,
      rgba(255, 240, 215, 0) 60%),
    radial-gradient(ellipse 110% 90% at 50% 50%,
      transparent 55%,
      rgba(80, 50, 30, 0.10) 90%,
      rgba(60, 35, 20, 0.18) 100%);
  pointer-events: none;
}

.plant {
  position: absolute;
  right: -14%;
  bottom: -6%;
  width: 26%;
  max-width: 130px;
  height: 18%;
  pointer-events: none;
  filter: blur(0.4px);
  opacity: 0.40;
  background:
    radial-gradient(ellipse 16% 14% at 50% 100%, #3b2a1d 0%, #2a1d12 60%, transparent 75%),
    radial-gradient(ellipse 9% 55% at 30% 60%, #2c4a32 55%, transparent 75%),
    radial-gradient(ellipse 13% 65% at 55% 50%, #1f3a26 55%, transparent 75%),
    radial-gradient(ellipse 8% 50% at 75% 65%, #345a3a 55%, transparent 75%),
    radial-gradient(ellipse 14% 30% at 50% 35%, #284a30 60%, transparent 80%);
}

.lampGlow {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: 90vw;
  max-width: 540px;
  height: 60vh;
  max-height: 520px;
  pointer-events: none;
  background: radial-gradient(ellipse 50% 50% at 50% 50%,
    var(--ambient-warm) 0%,
    transparent 65%);
  filter: blur(8px);
  transition: background 600ms var(--ease-soft);
  z-index: 0;
}

/* ============================================================
   1) TOP compact header — single line each, capped height
   ============================================================ */

.topbar {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 8px 6vw 6px;
}

.topbar__title {
  margin: 0;
  font-size: clamp(15px, 4.4vw, 19px);
  font-weight: 600;
  letter-spacing: 0.005em;
  line-height: 1.22;
  color: #2b2018;
}

.topbar__subtitle {
  margin: 3px 0 0;
  font-size: clamp(10.5px, 2.9vw, 12px);
  letter-spacing: 0.05em;
  color: #8a7a64;
  font-weight: 400;
}

/* ============================================================
   2) MIDDLE lamp stage — panel + cords + beads only
   ============================================================ */

.stage {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;        /* lamp sits at the top, not vertically centered — gives room for control panel */
  justify-content: center;
  width: 100%;
  padding: 6px 0 0;
  min-height: 0;
}

.lamp {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bracket {
  width: 4px;
  height: 14px;
  background: linear-gradient(180deg, #5a4a3a 0%, #2a2018 100%);
  border-radius: 2px 2px 0 0;
  margin-bottom: -2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.18);
}

/* ============================================================
   panel — small radius, real-frame feel
   ============================================================ */

.panel {
  position: relative;
  width: var(--panel-w);
  height: var(--panel-h);
  border-radius: var(--panel-radius);
  overflow: hidden;
  background: #1a0608;
  box-shadow:
    0 0 70px -10px var(--ambient-warm),
    inset 0 0 0 1px rgba(255, 220, 180, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 22px 40px -22px rgba(60, 30, 10, 0.45),
    0 6px 14px -8px rgba(60, 30, 10, 0.30);
  transition: box-shadow 600ms var(--ease-soft);
}

.panel__sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    #ffdf7a 0%,
    #ffb44a 14%,
    #ff8a2a 28%,
    #f25a22 44%,
    #c41d1d 62%,
    #6e0e0e 80%,
    #1a0505 100%);
}

/* sun — 3 layers */
.panel__sun {
  position: absolute;
  left: 50%;
  top: calc(var(--sun-top) * 100%);
  width: var(--sun-size);
  height: var(--sun-size);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition:
    top 360ms var(--ease-spring),
    width 360ms var(--ease-spring),
    height 360ms var(--ease-spring),
    opacity 360ms var(--ease-soft);
  opacity: var(--sun-opacity);
  will-change: top, transform, opacity;
}

.panel__sunOuter {
  position: absolute;
  inset: -10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(220, 50, 40, 0.45) 0%, rgba(220, 50, 40, 0.10) 45%, transparent 70%);
  filter: blur(4px);
  animation: outerBreath 4.2s ease-in-out infinite;
}

.panel__sunHalo {
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 180, 90, 0.65) 0%, rgba(255, 140, 60, 0.20) 50%, transparent 75%);
  filter: blur(3px);
  animation: haloBreath 4.2s ease-in-out infinite;
}

.panel__sunCore {
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%,
    #ffffff 0%,
    #fff4d0 35%,
    #ffd07a 70%,
    #ff9a3a 100%);
  box-shadow:
    0 0 16px rgba(255, 230, 180, 0.7),
    0 0 36px rgba(255, 170, 80, 0.45);
  animation: coreBreath 4.2s ease-in-out infinite;
}

@keyframes outerBreath { 0%,100% { opacity:.7; } 50% { opacity:1; } }
@keyframes haloBreath  { 0%,100% { transform:scale(1);   opacity:.85; } 50% { transform:scale(1.06); opacity:1; } }
@keyframes coreBreath  { 0%,100% { transform:scale(1);   filter:brightness(1); } 50% { transform:scale(1.04); filter:brightness(1.08); } }

.panel__horizon {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 24%;
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.45) 60%, rgba(0,0,0,0.85) 100%);
  pointer-events: none;
}

.panel__sheen {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg,
      rgba(255, 255, 255, 0.16) 0%,
      transparent 28%,
      transparent 72%,
      rgba(255, 255, 255, 0.06) 100%);
  pointer-events: none;
  mix-blend-mode: screen;
}

.panel__frame {
  position: absolute;
  inset: 0;
  border-radius: var(--panel-radius);
  border: 1px solid rgba(255, 220, 180, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -1px 0 rgba(0, 0, 0, 0.30);
  pointer-events: none;
}

.screw {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c8b9a0 0%, #6e5c44 55%, #2a2018 100%);
  box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.4), 0 0.5px 1px rgba(0,0,0,0.25);
  z-index: 4;
}
.screw--tl { top: 8px;  left: 8px; }
.screw--tr { top: 8px;  right: 8px; }
.screw--bl { bottom: 8px; left: 8px; }
.screw--br { bottom: 8px; right: 8px; }

/* ============================================================
   cords — fixed geometry, no overlap with title or buttons
   - cord container: fixed 30px wide, height = rest + max pull + small slack
   - cord string:    absolute from top:0, width 20px, height = rest + pull
   - cord line:      SVG line, y1=0, y2 controlled by JS
   - bead hit area:  positioned at bottom of cord string, bead centered inside
   ============================================================ */

.cords {
  position: relative;
  display: flex;
  gap: 16vw;
  margin-top: 2px;
  width: 100%;
  justify-content: center;
  z-index: 1;
  touch-action: none;
  /* container height defines the visual zone the cord occupies */
  height: calc(var(--cord-rest-len) + var(--cord-max-pull) + 18px);
}

.cord {
  position: relative;
  width: 30px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cord__string {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.18));
  z-index: 1;          /* above the bead which sits below the cord tail */
}

.cord__line {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.cord__line line {
  /* never tilted, always vertical */
  transform: none !important;
}

/* bead hit area — invisible 96×140 box anchored at the bottom of the cord
   string. The visible bead is positioned so that:
     - at rest, the bead's TOP edge lines up with the cord tail (y = 110)
     - when pulled, --pull translates both the bead and the cord tail down */
.beadHit {
  position: absolute;
  top: 0;             /* aligns with top of .cord */
  left: 50%;
  width: var(--hit-w);
  height: 100%;
  transform: translateX(-50%);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 3;
}

.beadHit:active { cursor: grabbing; }

.cord[data-cord="red"] .bead {
  --pull: var(--red-pull);
}

.cord[data-cord="black"] .bead {
  --pull: var(--black-pull);
}

/* the visible bead — anchored absolutely inside the cord column.
   At rest, top = CORD_REST (110px) so the bead's TOP touches the cord tail.
   When dragged, --pull translates the bead straight down. */
.bead {
  position: absolute;
  left: 50%;
  top: var(--cord-rest-len);  /* bead top at cord tail */
  width: var(--bead-size);
  height: var(--bead-size);
  border-radius: 50%;
  display: block;
  transform: translate(-50%, var(--pull, 0px));
  transition: transform 520ms var(--ease-spring);
  background-clip: padding-box;
  will-change: transform;
}

.bead--red {
  background:
    radial-gradient(circle at 32% 28%, #ffb0a0 0%, #f0573d 35%, #b81f15 70%, #4a0807 100%);
  box-shadow:
    inset -3px -4px 6px rgba(0, 0, 0, 0.45),
    inset 3px 4px 6px rgba(255, 200, 180, 0.30),
    inset 0 -1px 2px rgba(255, 255, 255, 0.10),
    0 5px 12px rgba(140, 30, 15, 0.40),
    0 2px 4px rgba(0, 0, 0, 0.25);
}

.bead--black {
  background:
    radial-gradient(circle at 32% 28%, #6a625a 0%, #2a2622 40%, #14110f 75%, #050403 100%);
  box-shadow:
    inset -3px -4px 6px rgba(0, 0, 0, 0.65),
    inset 3px 4px 6px rgba(200, 190, 180, 0.22),
    inset 0 -1px 2px rgba(255, 255, 255, 0.06),
    0 5px 12px rgba(0, 0, 0, 0.40),
    0 2px 4px rgba(0, 0, 0, 0.25);
}

.bead.is-dragging {
  transition: none;            /* no spring while user is actively dragging */
}

/* while dragging, suppress the spring so the bead tracks the finger 1:1 */
.cord.is-dragging .bead {
  transition: none;
}

/* ============================================================
   3) BOTTOM control panel — separated from lamp stage
   ============================================================ */

.control {
  position: relative;
  z-index: 2;
  width: 100%;
  padding:
    10px 7vw
    calc(max(96px, env(safe-area-inset-bottom) + 88px));
  text-align: center;
  /* clear gap between this block and the lamp stage above */
  margin-top: 14px;
}

.hint {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.4;
  color: #6a5a48;
  letter-spacing: 0.01em;
}

.chips {
  display: inline-flex;
  gap: 8px;
  margin: 0 0 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(160, 120, 80, 0.18);
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #5a4a38;
  backdrop-filter: blur(2px);
  box-shadow: 0 1px 0 rgba(255,255,255,0.5) inset, 0 2px 6px -3px rgba(80,50,30,0.15);
}

.chip__key {
  font-size: 10px;
  color: #9a8a72;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  font-weight: 500;
}

.chip__val {
  color: #2b2018;
  font-weight: 600;
}

.controls {
  display: inline-flex;
  gap: 10px;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(120, 90, 60, 0.25);
  background: rgba(255, 255, 255, 0.7);
  color: #3a2a1c;
  font: 600 13px/1 inherit;
  letter-spacing: 0.06em;
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 160ms var(--ease-soft),
    background 200ms var(--ease-soft),
    box-shadow 200ms var(--ease-soft);
  min-width: 100px;
  touch-action: manipulation;
  backdrop-filter: blur(2px);
  box-shadow: 0 2px 8px -3px rgba(80,50,30,0.20);
}

.btn:active { transform: scale(0.97); }

.btn--primary {
  background: linear-gradient(180deg, #f8a85a 0%, #e07020 100%);
  border-color: rgba(180, 100, 40, 0.35);
  color: #2a1208;
  box-shadow:
    0 2px 8px -3px rgba(180, 90, 30, 0.45),
    inset 0 1px 0 rgba(255, 240, 200, 0.4);
}

.btn--primary:hover { background: linear-gradient(180deg, #fbb86a 0%, #ea7828 100%); }

.btn--ghost:hover { background: rgba(255, 255, 255, 0.85); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   responsive tweaks
   ============================================================ */

@media (max-height: 720px) {
  :root {
    --panel-w: min(60vw, 260px);
    --panel-h: min(60vw, 260px);
    --cord-rest-len: 90px;
    --cord-max-pull: 70px;
  }
  .topbar { padding-top: 4px; }
  .topbar__title { font-size: 14px; }
  .topbar__subtitle { font-size: 10px; }
  .stage { padding-top: 2px; }
  .control { margin-top: 8px; padding-bottom: calc(max(80px, env(safe-area-inset-bottom) + 76px)); }
  .hint { margin: 0 0 8px; font-size: 11px; }
}

@media (min-width: 720px) {
  :root {
    --panel-w: 360px;
    --panel-h: 360px;
  }
  .cords { gap: 180px; }
  .topbar__title { font-size: 22px; }
  .topbar__subtitle { font-size: 13px; }
  .hint { font-size: 13px; }
  .plant { right: 4%; bottom: 0; opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  .panel__sunCore,
  .panel__sunHalo,
  .panel__sunOuter { animation: none; }
  * { transition-duration: 0ms !important; }
}
