* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #eef1fb;
  --ink-dim: #9aa3c7;
  --panel: rgba(14, 19, 38, 0.82);
  --panel-border: rgba(154, 163, 199, 0.22);
  --accent: #a998ff;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #04060f;
  color: var(--ink);
  font-family: 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
}

body { opacity: 0; transition: opacity 1.6s ease; }
body.ready { opacity: 1; }

#tree {
  position: fixed;
  inset: 0;
  display: block;
  cursor: pointer;
}

.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 26px 30px;
  pointer-events: none;
}
.top .brand h1 {
  font-family: 'Italiana', serif;
  font-size: 34px;
  font-weight: 400;
  letter-spacing: 0.24em;
  text-shadow: 0 0 24px rgba(120, 130, 200, 0.35);
}
.top .brand p {
  font-size: 13px;
  color: var(--ink-dim);
  font-style: italic;
  letter-spacing: 0.06em;
  margin-top: 6px;
}
.top-actions { display: flex; gap: 8px; pointer-events: auto; }

.chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: color 0.2s, border-color 0.2s;
}
.chip:hover { color: var(--ink); border-color: var(--ink-dim); }

.bottom {
  position: fixed;
  bottom: 24px; left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  pointer-events: none;
}
.bottom .tie-btn { pointer-events: auto; }
.hint { font-size: 12.5px; color: var(--ink-dim); font-style: italic; }
.count { font-size: 11.5px; color: rgba(154, 163, 199, 0.75); letter-spacing: 0.08em; }

.tie-btn {
  background: rgba(38, 33, 92, 0.72);
  color: #d9d5ff;
  border: 1px solid rgba(169, 152, 255, 0.55);
  border-radius: 999px;
  padding: 13px 36px;
  font-size: 15px;
  letter-spacing: 0.08em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.15s, box-shadow 0.4s, border-color 0.3s;
  box-shadow: 0 0 28px rgba(127, 119, 221, 0.28);
}
.tie-btn:hover {
  transform: translateY(-1px);
  border-color: #a998ff;
  box-shadow: 0 0 42px rgba(148, 134, 255, 0.5);
}
.tie-btn:active { transform: scale(0.97); }
.tie-btn.wide { width: 100%; margin-top: 18px; }
.tie-btn:disabled { opacity: 0.5; cursor: default; }

.wish-card {
  position: fixed;
  width: 270px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px 18px;
  backdrop-filter: blur(10px);
  z-index: 10;
  animation: rise 0.25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }
.wish-card p:first-child { font-size: 15px; line-height: 1.6; font-style: italic; }
.wish-card .meta { font-size: 12px; color: var(--ink-dim); margin-top: 10px; }
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  gap: 10px;
}
.lights { font-size: 12.5px; color: #ffd98a; white-space: nowrap; }
.light-btn {
  background: none;
  border: 1px solid var(--panel-border);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.2s;
}
.light-btn:hover { color: #ffd98a; border-color: #ffd98a; }
.light-btn.lit { color: #ffd98a; border-color: #ffd98a; cursor: default; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 12, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}
.modal-box {
  position: relative;
  width: 100%;
  max-width: 430px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 28px 30px;
  backdrop-filter: blur(12px);
  animation: rise 0.25s ease;
}
.modal-box h2 {
  font-family: 'Italiana', serif;
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 0.1em;
  margin-bottom: 16px;
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 15px;
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

textarea, input {
  width: 100%;
  background: rgba(6, 9, 20, 0.7);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  padding: 12px 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}
textarea::placeholder, input::placeholder { color: #7d87ad; }
textarea:focus, input:focus { border-color: var(--accent); }
input { margin-top: 10px; }
.char-row { text-align: right; font-size: 11.5px; color: var(--ink-dim); margin-top: 5px; }

.color-label { font-size: 13px; color: var(--ink-dim); margin: 16px 0 8px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.color-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: 1px solid var(--panel-border);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.2s;
}
.color-pill .dot { width: 10px; height: 10px; border-radius: 50%; }
.color-pill.selected { color: var(--ink); border-color: currentColor; }

.modal-error { margin-top: 12px; font-size: 13px; color: #f09595; }

.crisis-box { max-width: 400px; text-align: center; }
.crisis-box p { font-size: 14.5px; line-height: 1.6; color: var(--ink-dim); }
.crisis-box h2 { color: #ffd98a; }
.crisis-links { margin-top: 14px; font-size: 14px; }
.crisis-links a { color: var(--accent); }

.toast {
  position: fixed;
  bottom: 104px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 11px 22px;
  font-size: 13.5px;
  backdrop-filter: blur(8px);
  z-index: 30;
  animation: rise 0.3s ease;
  white-space: nowrap;
}

.hidden { display: none !important; }

@media (max-width: 600px) {
  .top { padding: 18px 20px; }
  .top .brand h1 { font-size: 26px; }
  .wish-card { width: min(270px, calc(100vw - 24px)); }
}

/* ---------- intro: the box ---------- */

.intro {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: radial-gradient(ellipse at 50% 42%, #0c1124 0%, #04060f 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: opacity 1.1s ease;
}
.intro.gone { opacity: 0; pointer-events: none; }
.intro-title {
  font-family: 'Italiana', serif;
  font-size: 44px;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-shadow: 0 0 30px rgba(120, 130, 200, 0.4);
}
.intro-sub { font-size: 13.5px; color: var(--ink-dim); font-style: italic; letter-spacing: 0.06em; }
.intro-hint {
  font-size: 12.5px;
  color: var(--ink-dim);
  letter-spacing: 0.14em;
  animation: breathe 2.8s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

.box-scene {
  perspective: 700px;
  margin: 38px 0 30px;
  animation: floaty 5s ease-in-out infinite;
}
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.box { position: relative; width: 230px; height: 150px; transform-style: preserve-3d; }
.box-base {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 104px;
  border-radius: 12px;
  background: linear-gradient(180deg, #3a2f4e 0%, #241d36 55%, #16112a 100%);
  border: 1px solid rgba(169, 152, 255, 0.25);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(200, 190, 255, 0.12);
}
.box-carve {
  position: absolute;
  inset: 14px 18px;
  border: 1px solid rgba(169, 152, 255, 0.18);
  border-radius: 8px;
}
.box-clasp {
  position: absolute;
  top: -7px; left: 50%;
  width: 22px; height: 26px;
  margin-left: -11px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, #b7a86a, #6e6034);
  box-shadow: 0 0 10px rgba(210, 190, 120, 0.35);
  z-index: 3;
}
.box-lid {
  position: absolute;
  left: -6px; right: -6px; bottom: 96px;
  height: 46px;
  border-radius: 12px 12px 6px 6px;
  background: linear-gradient(180deg, #4a3d63 0%, #2c2344 70%, #201936 100%);
  border: 1px solid rgba(169, 152, 255, 0.3);
  box-shadow: inset 0 1px 0 rgba(200, 190, 255, 0.16);
  transform-origin: 50% 100%;
  transition: transform 1.1s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 4;
}
.lid-trim {
  position: absolute;
  inset: 8px 16px;
  border: 1px solid rgba(169, 152, 255, 0.2);
  border-radius: 6px;
}
.box-glow {
  position: absolute;
  left: 12px; right: 12px; bottom: 8px;
  height: 92px;
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 217, 138, 0.9) 0%, rgba(255, 217, 138, 0) 70%);
  opacity: 0;
  transform: scaleY(0.4);
  transform-origin: bottom;
  transition: opacity 0.9s ease 0.25s, transform 0.9s ease 0.25s;
  z-index: 2;
}
.box.open .box-lid { transform: rotateX(-112deg); }
.box.open .box-glow { opacity: 0.85; transform: scaleY(1.6); }
.intro.open .intro-hint { opacity: 0; animation: none; transition: opacity 0.4s; }

/* ---------- ritual: the wish stick ---------- */

.ritual { max-width: 460px; }
.stick-stage {
  position: relative;
  height: 92px;
  margin: 4px 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stick {
  position: relative;
  width: 260px;
  height: 40px;
  cursor: grab;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stick:active { cursor: grabbing; }
.stick-half {
  position: absolute;
  top: 17px;
  width: 132px;
  height: 7px;
  background: linear-gradient(180deg, #7a6248 0%, #55422f 55%, #3a2c1e 100%);
  box-shadow: 0 1px 0 rgba(255, 230, 190, 0.12) inset, 0 3px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.35s ease;
}
.stick-half.left {
  left: 0;
  border-radius: 4px 1px 1px 4px;
  clip-path: polygon(0 12%, 97% 0, 100% 38%, 96% 55%, 100% 78%, 97% 100%, 0 88%);
  transform-origin: 100% 50%;
}
.stick-half.right {
  right: 0;
  border-radius: 1px 4px 4px 1px;
  clip-path: polygon(3% 0, 100% 10%, 100% 90%, 3% 100%, 0 74%, 4% 52%, 0 30%);
  transform-origin: 0% 50%;
}
.bud {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50% 50% 50% 0;
  background: #6f8f5f;
  opacity: 0.85;
  transition: opacity 0.3s;
}
.bud.b1 { left: 38px; top: 11px; transform: rotate(-32deg); }
.bud.b2 { left: 86px; top: 24px; transform: rotate(140deg); }
.bud.b3 { right: 52px; top: 10px; transform: rotate(24deg); }
.stick.snapped .bud { opacity: 0; }
.stick-ribbon {
  position: absolute;
  left: 50%; top: 8px;
  width: 14px; height: 24px;
  margin-left: -7px;
  border-radius: 4px;
  background: #ffc46b;
  box-shadow: 0 0 14px rgba(255, 196, 107, 0.55);
  transition: background 0.3s, box-shadow 0.3s, opacity 0.3s, transform 0.35s ease;
  z-index: 2;
}
.stick-ribbon::before, .stick-ribbon::after {
  content: '';
  position: absolute;
  top: -5px;
  width: 9px; height: 9px;
  border-radius: 50% 50% 0 50%;
  background: inherit;
}
.stick-ribbon::before { left: -4px; transform: rotate(-40deg); }
.stick-ribbon::after { right: -4px; transform: rotate(130deg); }
.stick.snapped .stick-half.left { transform: translate(-30px, 22px) rotate(-26deg); transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
.stick.snapped .stick-half.right { transform: translate(30px, 18px) rotate(21deg); transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
.stick.snapped .stick-ribbon { transform: translateY(26px) rotate(12deg); opacity: 0; transition: all 0.6s ease 0.1s; }
.crack-flash {
  position: absolute;
  left: 50%; top: 20px;
  width: 8px; height: 8px;
  margin-left: -4px;
  border-radius: 50%;
  background: #fff4d6;
  box-shadow: 0 0 22px 10px rgba(255, 236, 180, 0.8);
  opacity: 0;
  z-index: 3;
}
.stick.snapped .crack-flash { animation: flash 0.55s ease-out; }
@keyframes flash {
  0% { opacity: 0; transform: scale(0.4); }
  18% { opacity: 1; transform: scale(1.5); }
  100% { opacity: 0; transform: scale(2.6); }
}
.hold-ring {
  position: absolute;
  width: 44px; height: 44px;
  left: 50%; top: 50%;
  margin: -22px 0 0 -22px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.stick-stage.holding .hold-ring { opacity: 1; }
#hold-arc { transition: none; }
.break-hint {
  font-size: 12.5px;
  color: var(--ink-dim);
  font-style: italic;
  margin-top: 14px;
  text-align: center;
}
.break-hint.ready { color: #d9d5ff; }

.mote {
  position: fixed;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #fff1c9;
  box-shadow: 0 0 18px 8px rgba(255, 220, 150, 0.75);
  z-index: 50;
  pointer-events: none;
  transition: transform 1.05s cubic-bezier(0.5, 0, 0.6, 1), opacity 0.4s ease 0.75s;
}

@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
  .wish-card, .modal-box, .toast { animation: none; }
  .tie-btn, .chip, .light-btn, .color-pill { transition: none; }
  .box-scene, .intro-hint { animation: none; }
  .box-lid, .box-glow, .intro { transition-duration: 0.15s; }
  .stick-half, .stick-ribbon, .mote { transition-duration: 0.1s; }
}
