/* advent calendar — white base, #5b33b5 accents, ice bear pins */

:root {
  --accent: #5b33b5;
  --accent-deep: #46269b;
  --accent-soft: #f1ecfb;
  --accent-muted: #c3b2ec;
  --ink: #241b3a;
  --ink-soft: #7d7396;
  --paper: #ffffff;
  --pin-shadow: 0 5px 14px rgba(36, 27, 58, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Quicksand", "Comfortaa", "Avenir Next", "Varela Round", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 64px;
  overflow-x: hidden;
}

/* ---------- header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 34px;
  text-align: center;
}

.header-bear {
  height: 84px;
  transform: rotate(-4deg);
  filter: drop-shadow(0 6px 8px rgba(36, 27, 58, 0.18));
}

.header-text h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 48px);
  letter-spacing: 0.5px;
  color: var(--ink);
  line-height: 1.1;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--accent);
  font-size: clamp(15px, 2.6vw, 19px);
  font-weight: 600;
}

.countdown {
  margin: 12px 0 0;
  display: inline-block;
  padding: 5px 16px;
  border: 2px solid var(--accent-muted);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 14px;
  background: var(--accent-soft);
}

/* ---------- calendar grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 18px 16px;
  width: 100%;
  max-width: 1060px;
}

.window {
  position: relative;
  aspect-ratio: 1 / 1.08;
  border: 3px solid var(--accent);
  border-radius: 24%;
  background: var(--paper);
  box-shadow: var(--pin-shadow), inset 0 -8px 0 rgba(91, 51, 181, 0.07);
  transform: rotate(var(--rot, 0deg));
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.window .num {
  position: absolute;
  top: 10%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(20px, 3.4vw, 27px);
  font-weight: 800;
  color: var(--accent);
  z-index: 2;
}

.window .bear {
  position: absolute;
  bottom: -16%;
  left: 50%;
  height: 82%;
  transform: translateX(-50%);
  transition: transform 0.25s ease;
  z-index: 1;
  pointer-events: none;
}

.window .caption {
  position: absolute;
  bottom: 6%;
  left: 8%;
  right: 8%;
  text-align: center;
  font-size: 10px;
  line-height: 1.25;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  padding: 3px 4px;
  display: none;
  z-index: 3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* states */

.window.locked {
  border-color: var(--accent-muted);
  box-shadow: 0 3px 8px rgba(36, 27, 58, 0.08), inset 0 -8px 0 rgba(91, 51, 181, 0.05);
  cursor: default;
}

.window.locked .num { color: var(--accent-muted); }
.window.locked .bear { opacity: 0.35; }

.window.openable:hover {
  transform: rotate(var(--rot, 0deg)) translateY(-5px) scale(1.03);
  box-shadow: 0 12px 26px rgba(36, 27, 58, 0.22), inset 0 -8px 0 rgba(91, 51, 181, 0.07);
}

.window.openable:hover .bear {
  transform: translateX(-50%) translateY(-9%);
}

.window.openable:active {
  transform: rotate(var(--rot, 0deg)) translateY(-2px) scale(0.98);
}

.window.today {
  animation: glow 2.2s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { box-shadow: var(--pin-shadow), inset 0 -8px 0 rgba(91, 51, 181, 0.07), 0 0 0 0 rgba(91, 51, 181, 0.45); }
  50%      { box-shadow: var(--pin-shadow), inset 0 -8px 0 rgba(91, 51, 181, 0.07), 0 0 0 9px rgba(91, 51, 181, 0); }
}

.window.opened {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 3px 9px rgba(70, 38, 155, 0.35);
  cursor: pointer;
}

.window.opened .num { color: #fff; }
.window.opened .bear { opacity: 0.9; bottom: -20%; height: 88%; }
.window.opened .caption { color: #fff; background: rgba(255, 255, 255, 0.14); }

.window.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: rotate(var(--rot, 0deg)) translateX(0); }
  20%      { transform: rotate(var(--rot, 0deg)) translateX(-6px); }
  40%      { transform: rotate(var(--rot, 0deg)) translateX(5px); }
  60%      { transform: rotate(var(--rot, 0deg)) translateX(-4px); }
  80%      { transform: rotate(var(--rot, 0deg)) translateX(3px); }
}

/* admin spoilers */
body.admin .window .caption { display: block; }

/* ---------- flashcard modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(91, 51, 181, 0.16);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fadein 0.25s ease;
}

.overlay[hidden] { display: none; }

@keyframes fadein {
  from { opacity: 0; }
}

.flashcard {
  width: min(400px, 92vw);
  perspective: 1400px;
  animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: rotate(-1.5deg);
}

@keyframes pop {
  from { transform: rotate(-1.5deg) scale(0.7); opacity: 0; }
}

.fc-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.4, 0.1, 0.2, 1);
}

.fc-inner.flipped {
  transform: rotateY(180deg);
}

.fc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 4px solid var(--accent);
  border-radius: 30px;
  background: var(--paper);
  box-shadow: 0 22px 55px rgba(36, 27, 58, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 26px;
}

/* front */

.fc-front .fc-bear {
  height: 52%;
  filter: drop-shadow(0 10px 14px rgba(36, 27, 58, 0.2));
}

.fc-front-day {
  margin: 20px 0 0;
  font-size: 30px;
  font-weight: 800;
  color: var(--accent);
}

.fc-front-hint {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
}

/* back */

.fc-back {
  transform: rotateY(180deg);
  justify-content: flex-start;
  text-align: center;
  overflow-y: auto;
}

.fc-day {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent-muted);
}

.fc-title {
  margin: 4px 0 10px;
  font-size: clamp(22px, 5vw, 28px);
  line-height: 1.2;
  color: var(--accent-deep);
}

.fc-note {
  margin: 0;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-line;
}

.fc-image {
  margin-top: 16px;
  max-width: 100%;
  max-height: 40%;
  border-radius: 16px;
  border: 3px solid var(--accent-soft);
}

.fc-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 2px solid var(--accent-muted);
  border-radius: 50%;
  background: var(--paper);
  color: var(--accent);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.fc-close:hover {
  background: var(--accent);
  color: #fff;
}

/* ---------- admin bar ---------- */

.adminbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--accent-deep);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  padding: 10px 18px;
  font-size: 13px;
}

.adminbar[hidden] { display: none; }

.admin-chip {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 3px 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.admin-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-field input {
  border: none;
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  color: var(--ink);
}

.admin-btn {
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: inherit;
  padding: 4px 14px;
  cursor: pointer;
}

.admin-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.admin-note {
  opacity: 0.75;
}

body.admin { padding-top: 84px; }

/* ---------- error box ---------- */

.errorbox {
  max-width: 640px;
  margin: 60px auto;
  border: 3px solid var(--accent);
  border-radius: 24px;
  background: var(--accent-soft);
  padding: 24px 28px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--accent-deep);
}

/* ---------- snow ---------- */

.snow {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.flake {
  position: absolute;
  top: -12px;
  border-radius: 50%;
  background: #e7def7;
  animation: fall linear infinite;
}

@keyframes fall {
  to { transform: translateY(112vh); }
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
    gap: 12px 10px;
  }

  .header-bear { height: 56px; }
  .header { gap: 12px; margin-bottom: 26px; }
  body { padding: 28px 12px 48px; }
  .fc-face { padding: 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .snow, .window.today { animation: none; }
  .fc-inner, .window, .window .bear { transition: none; }
}
