:root {
  --bg: #140a24;
  --bg-2: #22113a;
  --ink: #f6ecff;
  --ink-dim: #c7b4e2;
  --pink: #ff5fae;
  --pink-2: #ff8cc6;
  --violet: #8f5bff;
  --line: rgba(255, 255, 255, 0.14);
  --gold: #ffd98a;
  --radius: 14px;
  --font-title: "Baloo 2", cursive;
  --font-num: "Baloo 2", system-ui, sans-serif;
  /* portrait calendar (3:4, like kiyomi-bg.jpeg): as wide as possible while the
     whole thing still fits on screen under the header */
  --cal-w: min(100%, 760px, max(460px, calc((100svh - 130px) * 3 / 4)));
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(143, 91, 255, 0.35), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 95, 174, 0.25), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.top {
  max-width: calc(var(--cal-w) + 48px);
  margin: 0 auto;
  padding: 28px 24px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap;
}

h1 {
  font-family: var(--font-title);
  font-weight: 400;
  /* title and button share one row; the title scales down to fit beside the button */
  font-size: clamp(1.15rem, 4.6vw, 2.1rem);
  min-width: 0;
  white-space: nowrap;
  line-height: 1.3;
  padding: 0 0.15em 0.1em 0;
  margin: 0;
  background: linear-gradient(90deg, #fff, var(--pink-2) 60%, var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}


.picker { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.file-note:empty { display: none; }
.file-note { margin: 0; font-size: 0.82rem; color: var(--ink-dim); max-width: 340px; text-align: right; overflow-wrap: anywhere; }
.file-note.ready { color: var(--pink-2); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 999px;
  font: 600 0.95rem Inter, sans-serif;
  cursor: pointer;
  border: 0;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  box-shadow: 0 6px 24px rgba(255, 95, 174, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(255, 95, 174, 0.45); }
.picker.nudge .btn-primary { animation: nudge 0.6s ease 2; }
@keyframes nudge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(255, 95, 174, 0.25); }
}

/* ---------- Calendar ---------- */
main { max-width: calc(var(--cal-w) + 48px); margin: 0 auto; padding: 0 24px 40px; }

.calendar {
  --gap: 1.1%;
  position: relative;
  aspect-ratio: 3 / 4;
  width: 100%;
  container-type: inline-size;
  padding: var(--gap);
  border-radius: var(--radius);
  background: #2a1546 url("kiyomi-bg.jpeg") 50% 30% / cover no-repeat;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 30px 80px rgba(0, 0, 0, 0.55),
    0 0 120px rgba(143, 91, 255, 0.25);
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(6, 1fr);
  grid-template-areas:
    "A B C C D"
    "E F G H I"
    "J K K L M"
    "N K K O P"
    "Q R S T U"
    "V V W X Y";
  overflow: hidden;
}

.door {
  position: relative;
  perspective: 900px;
  border-radius: 6px;
  min-width: 0;
  min-height: 0;
}

/* the hole behind the door */
.door .behind {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 95, 174, 0.35), transparent 70%),
    linear-gradient(160deg, #2b1245, #12071f);
  box-shadow: inset 0 4px 18px rgba(0, 0, 0, 0.75);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: var(--ink);
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease 0.15s;
}
.door .behind svg { width: clamp(20px, 6cqw, 44px); height: auto; fill: var(--pink-2); filter: drop-shadow(0 0 12px rgba(255, 95, 174, 0.8)); }
.door .behind span { font: 600 clamp(0.6rem, 2.4cqw, 0.9rem) Inter, sans-serif; color: var(--ink-dim); }

/* the door leaf: shows its own slice of the photo so the picture is seamless */
.door .leaf {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background-image: url("kiyomi-bg.jpeg");
  background-repeat: no-repeat;
  background-size: var(--bw, 0) var(--bh, 0);
  background-position: var(--bx, 0) var(--by, 0);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.3s ease;
  outline: 2px dashed rgba(255, 255, 255, 0.55);
  outline-offset: -5px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  backface-visibility: hidden;
}
.door .leaf::after {
  /* soft tint so numbers read over any part of the photo */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(20, 8, 40, 0.18));
}

.door .num {
  position: absolute;
  z-index: 1;
  font-family: var(--font-num);
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 10px rgba(30, 5, 60, 0.85), 0 0 2px rgba(30, 5, 60, 0.9);
  font-size: 6.4cqw;
}
.door.big .num { font-size: 13cqw; }

/* vary where numbers sit, like a printed calendar */
.door[data-pos="tl"] .num { top: 12%; left: 12%; }
.door[data-pos="tr"] .num { top: 12%; right: 12%; }
.door[data-pos="bl"] .num { bottom: 12%; left: 12%; }
.door[data-pos="br"] .num { bottom: 12%; right: 12%; }
.door[data-pos="c"] .num { top: 50%; left: 50%; transform: translate(-50%, -50%); }

/* locked doors: quiet, not clickable */
.door.locked .num { opacity: 0.8; }
.door.locked .leaf { outline-color: rgba(255, 255, 255, 0.35); }

/* openable doors */
button.door {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
button.door .leaf {
  outline-color: rgba(255, 220, 240, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 22px rgba(255, 95, 174, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}
button.door:hover .leaf,
button.door:focus-visible .leaf { transform: rotateY(-16deg); }
button.door:focus-visible { outline: 3px solid var(--pink-2); outline-offset: 3px; }

button.door.open .leaf { transform: rotateY(-108deg); box-shadow: none; outline-color: transparent; }
/* The number and tint are children of the leaf and don't inherit its hidden backface,
   so once the door swings past edge-on they'd poke out (mirrored) over the neighbour door. */
.door .num,
.door .leaf::before,
.door .leaf::after { backface-visibility: hidden; transition: opacity 0.25s ease; }
button.door.open .num,
button.door.open .leaf::before,
button.door.open .leaf::after { opacity: 0; transition-delay: 0.2s; }
button.door.open .behind { opacity: 1; }

/* ---------- Modal player ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 3, 20, 0.78);
  backdrop-filter: blur(8px);
  animation: fade 0.25s ease;
}
.modal-card {
  position: relative;
  width: min(960px, 100%);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--bg-2), #170b29);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.6), 0 0 80px rgba(255, 95, 174, 0.2);
  overflow: hidden;
  animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(10px); } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px 20px;
}
.modal-head h2 { margin: 0; font: 400 1.6rem var(--font-title); line-height: 1.3; }
.clip-range { margin: 2px 0 0; font-size: 0.85rem; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.stage { position: relative; background: #000; min-height: 0; }
.stage video {
  display: block;
  width: 100%;
  max-height: calc(100vh - 200px);
  background: #000;
  cursor: pointer;
}
.big-play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  box-shadow: 0 10px 40px rgba(255, 95, 174, 0.5);
  display: grid;
  place-items: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.big-play svg { width: 34px; height: 34px; fill: #fff; margin-left: 4px; }
.big-play:hover { transform: translate(-50%, -50%) scale(1.06); }
.modal.playing .big-play { opacity: 0; pointer-events: none; }

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 14px;
}
.icon-btn {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#playBtn svg { fill: currentColor; stroke: none; }
#playBtn .i-replay { fill: currentColor; }
#playBtn .i-pause, #playBtn .i-replay { display: none; }
.modal.playing #playBtn .i-play { display: none; }
.modal.playing #playBtn .i-pause { display: block; }
.modal.ended #playBtn .i-play { display: none; }
.modal.ended #playBtn .i-replay { display: block; }
.i-muted { display: none; }
.modal.muted .i-vol { display: none; }
.modal.muted .i-muted { display: block; }

.scrub {
  position: relative;
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  touch-action: none;
}
.scrub::before { content: ""; position: absolute; inset: -10px 0; }
.scrub:focus-visible { outline: 2px solid var(--pink-2); outline-offset: 4px; }
.scrub-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--pink), var(--violet));
}
.scrub-knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 4px rgba(255, 95, 174, 0.35);
}
.time { flex: none; font-size: 0.85rem; color: var(--ink-dim); font-variant-numeric: tabular-nums; min-width: 88px; text-align: center; }

.warn { margin: 0; padding: 0 18px 14px; color: var(--gold); font-size: 0.85rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translate(-50%, 20px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #2b1548;
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .top { padding: 20px 16px 14px; align-items: center; }
}
/* phones: not enough room for title + button side by side, so the button drops below */
@media (max-width: 520px) {
  .top { flex-wrap: wrap; }
  /* sized so "Kiyomi's Advent Calendar '26" stays on one line; retune if the title changes */
  h1 { font-size: min(1.7rem, calc((100vw - 40px) / 13.5)); }
}
@media (max-width: 640px) {
  .picker { align-items: flex-start; }
  .file-note { text-align: left; }
  main { padding: 0 16px 28px; }
  .controls { gap: 6px; padding: 10px; }
  .time { min-width: 0; font-size: 0.75rem; }
  #fsBtn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .door .leaf, .door .behind, .modal-card, .modal-backdrop { transition: none; animation: none; }
}
