:root {
  --bg: #0f1b2d;
  --bg2: #1c2c48;
  --cream: #f6efe0;
  --muted: #a9b4c6;
  --red: #c8443c;
  --gold: #e2b659;
  --card: rgba(255, 255, 255, .07);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%) fixed;
  color: var(--cream);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- 雪 ---------- */
#snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#snow i {
  position: absolute; top: -10px;
  width: var(--s); height: var(--s);
  border-radius: 50%; background: #fff; opacity: var(--o);
  animation: fall var(--d) linear infinite;
  animation-delay: var(--dl);
}
@keyframes fall {
  to { transform: translate(var(--x), 105vh); }
}

/* ---------- レイアウト ---------- */
.app {
  position: relative;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.head { text-align: center; }
.head h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .12em; }
.head-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); display: flex; gap: 12px; justify-content: center; }

/* ---------- ツリー ---------- */
.tree-wrap { position: relative; width: 100%; aspect-ratio: 400 / 520; margin-top: 4px; }
.tree { position: absolute; inset: 0; width: 100%; height: 100%; }

#lights circle { animation: twinkle 2.4s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .25; } }

.orn {
  position: absolute;
  width: 10.5%;
  aspect-ratio: 1;
  padding: 0; border: 0; background: none;
  transform: translate(-50%, -50%);
}
.orn .face {
  position: absolute; inset: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  border: 1.5px dashed rgba(255, 255, 255, .45);
  color: rgba(255, 255, 255, .7);
  background: rgba(0, 0, 0, .12);
}
.orn.locked .face { opacity: .45; }
.orn.today .face {
  border: 2px solid var(--gold); color: var(--gold);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(226, 182, 89, .25); } }

/* 写真が入ったオーナメント */
.orn.filled::before,
.reveal-orn::before {
  content: ""; position: absolute; z-index: 1;
  left: 50%; top: -16%; width: 28%; height: 20%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #a47a2c, #f3d68b 45%, #a47a2c);
  border-radius: 2px 2px 1px 1px;
}
.orn.filled .face,
.reveal-orn .face {
  border: 2px solid var(--c);
  background-size: cover; background-position: center;
  box-shadow: 0 3px 7px rgba(0, 0, 0, .45);
  overflow: hidden;
}
.orn.filled .face::after,
.reveal-orn .face::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 255, 255, .6), transparent 32%),
    radial-gradient(circle at 70% 80%, transparent 45%, rgba(0, 0, 0, .4)),
    linear-gradient(var(--tint), var(--tint));
}
.orn.pop { animation: pop .7s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: translate(-50%, -160%) scale(.3); opacity: 0; } }

/* 25日目の星 */
.orn.star { width: 16%; }
.orn.star .face,
.reveal-orn.star .face {
  border-radius: 0; border: 0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background-color: rgba(226, 182, 89, .3);
  color: var(--gold);
}
.orn.star.filled::before, .reveal-orn.star::before { display: none; }
.orn.star.filled, .reveal-orn.star { filter: drop-shadow(0 0 8px rgba(255, 220, 130, .9)); }
.orn.star.filled .face::after, .reveal-orn.star .face::after {
  border-radius: 0;
  background: linear-gradient(160deg, rgba(255, 230, 150, .45), rgba(226, 150, 40, .25));
}
.orn.star.today .face { background-color: rgba(226, 182, 89, .55); color: #3a2a05; }

body.complete #lights circle { animation-duration: 1s; }

/* ---------- カード ---------- */
.card {
  margin-top: 8px;
  padding: 18px 18px 20px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 18px;
  text-align: center;
  backdrop-filter: blur(6px);
}
.card-label { margin: 0; font-size: 12px; color: var(--gold); letter-spacing: .1em; }
.card-prompt { margin: 6px 0 14px; font-size: 22px; font-weight: 700; line-height: 1.4; }
.card-note { margin: 6px 0 14px; font-size: 14px; color: var(--muted); line-height: 1.7; }
.card-foot { margin: 14px 0 0; font-size: 12px; color: var(--muted); }
.link { background: none; border: 0; padding: 4px; color: var(--muted); text-decoration: underline; font-size: 12px; }

.btn {
  display: inline-block;
  min-height: 46px; padding: 0 26px;
  border: 0; border-radius: 999px;
  background: var(--red); color: #fff;
  font-weight: 700; font-size: 15px;
  box-shadow: 0 4px 0 #8f2b25;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #8f2b25; }
.btn.ghost { background: transparent; border: 1.5px solid rgba(255, 255, 255, .4); box-shadow: none; }
.btn.small { min-height: 38px; padding: 0 16px; font-size: 13px; box-shadow: none; }

/* ---------- シート・演出 ---------- */
dialog {
  border: 0; color: var(--cream);
  background: #18263f;
  border-radius: 22px;
  width: min(92vw, 400px);
  padding: 24px 20px;
  text-align: center;
}
dialog::backdrop { background: rgba(5, 10, 20, .7); }

.sheet-close {
  position: absolute; top: 8px; right: 10px;
  width: 40px; height: 40px; border: 0; background: none;
  font-size: 24px; color: var(--muted);
}
.sheet-day { margin: 0 0 12px; font-size: 14px; color: var(--gold); letter-spacing: .1em; }
.sheet-preview:empty { display: none; }
.sheet-preview { width: 56%; margin: 44px auto 18px; }
.sheet-label { margin: 0; font-size: 11px; color: var(--muted); }
.sheet-prompt { margin: 4px 0 0; font-size: 22px; font-weight: 700; line-height: 1.4; }
.prompt-edit { display: flex; gap: 8px; margin-top: 8px; }
.prompt-edit[hidden] { display: none; }
.prompt-edit input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px;
  border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(0, 0, 0, .25); color: var(--cream); font: inherit; font-size: 16px;
}
.sheet-actions { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }

.card-save { margin: 14px 0 0; }
.card-from { margin: -8px 0 14px; font-size: 12px; color: var(--muted); }
.card-foot .link { margin: 0 2px; }
.card-hint { margin: 16px 0 0; font-size: 12px; color: var(--muted); }

textarea {
  display: block; width: 100%; margin-top: 14px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(0, 0, 0, .25); color: var(--cream);
  font: inherit; font-size: 16px; line-height: 1.6; resize: vertical;
}
textarea::placeholder { color: var(--muted); }
.sheet-note {
  margin: 14px 0 0; padding: 12px 14px;
  background: rgba(255, 255, 255, .06); border-radius: 12px;
  text-align: left; font-size: 15px; line-height: 1.8;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.sheet-note[hidden], .note-edit[hidden] { display: none; }
.note-edit .btn { margin-top: 10px; }

#cropCanvas {
  display: block; width: 78%; margin: 4px auto 0;
  border-radius: 50%; outline: 3px solid var(--gold);
  touch-action: none; cursor: grab; background: #000;
}
#cropCanvas.star {
  border-radius: 0; outline: 0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.crop-hint { margin: 12px 0 6px; font-size: 12px; color: var(--muted); }
#cropZoom { width: 78%; accent-color: var(--gold); }

.reveal-orn { position: relative; width: 100%; aspect-ratio: 1; }
.reveal-orn .face { position: absolute; inset: 0; border-radius: 50%; border-width: 4px; }

.reveal { overflow: visible; }
.reveal-stage { position: relative; width: 62%; margin: 30px auto 10px; transform-origin: 50% -60px; animation: swing 2.2s ease-in-out infinite; }
.reveal-string { position: absolute; left: 50%; top: -70px; width: 2px; height: 60px; background: var(--gold); }
.reveal[open] .reveal-orn { animation: drop .8s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes drop { from { transform: translateY(-80px) scale(.4); opacity: 0; } }
@keyframes swing { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.reveal-text { margin: 18px 0 16px; font-size: 16px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 999px;
  background: rgba(0, 0, 0, .8); font-size: 13px;
  opacity: 0; pointer-events: none; transition: .25s;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
