* { box-sizing: border-box; }

:root {
  --bg: #14161c;
  --panel: #1d2029;
  --panel-alt: #23273240;
  --text: #eae6da;
  --muted: #9a9aa5;
  --accent: #d9a441;
  --grid-line: #2c303c;
  --red: #b3232f;
  --red-dark: #7a1620;
  --green: #2f8f4e;
  --green-dark: #1d5c32;
  --charcoal: #3a3d44;
  --charcoal-dark: #24262b;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse at top, #23273a 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  padding: 24px 16px 60px;
}

.app {
  max-width: 920px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 8px;
}

.app-header h1 {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  min-width: 260px;
  text-align: center;
  margin: 0;
}

.nav-btn {
  background: var(--panel);
  border: 1px solid var(--grid-line);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.nav-btn:hover {
  background: #2a2e3a;
  transform: scale(1.06);
}

.legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 14px 0 20px;
  font-size: 0.85rem;
  color: var(--muted);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-candle {
  display: inline-block;
  width: 8px;
  height: 18px;
  border-radius: 2px;
}
.mini-red { background: linear-gradient(var(--red), var(--red-dark)); box-shadow: 0 0 8px 2px rgba(220,80,60,0.55); }
.mini-grey { background: linear-gradient(var(--charcoal), var(--charcoal-dark)); }
.mini-green { background: linear-gradient(var(--green), var(--green-dark)); box-shadow: 0 0 8px 2px rgba(80,200,120,0.5); }

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  min-height: 92px;
  padding: 6px 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.day-cell:hover {
  border-color: #4a4f5e;
  background: #21242f;
}
.day-cell.empty {
  background: transparent;
  border: none;
  cursor: default;
  pointer-events: none;
}
.day-cell.today {
  border-color: var(--accent);
}

.day-number {
  font-size: 0.8rem;
  color: var(--muted);
  align-self: flex-end;
}
.day-cell.today .day-number {
  color: var(--accent);
  font-weight: 700;
}

.event-label {
  font-size: 0.62rem;
  color: #b6f0c4;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.holiday-label {
  font-size: 0.6rem;
  color: #f0b6b6;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Candle ---------- */
.candle-wrap {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 46px;
  justify-content: flex-end;
}

.flame {
  width: 10px;
  height: 14px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #fff6d0 0%, #ffd35c 35%, #ff9b2e 65%, #ff5a1f 100%);
  opacity: 0;
  transform-origin: bottom center;
  transform: scaleY(0.1);
  margin-bottom: -2px;
  position: relative;
  z-index: 2;
}

.candle-body {
  width: 16px;
  height: 26px;
  border-radius: 3px 3px 2px 2px;
  position: relative;
  z-index: 1;
}

.wick {
  width: 2px;
  height: 5px;
  background: #55483a;
  margin-bottom: -1px;
  z-index: 2;
}

/* unlit grey candle */
.candle.unlit .candle-body {
  background: linear-gradient(180deg, var(--charcoal) 0%, var(--charcoal-dark) 100%);
}
.candle.unlit .flame { display: none; }
.candle.unlit .wick { opacity: 0.7; }

/* holiday red candle, always lit */
.candle.holiday .candle-body {
  background: linear-gradient(180deg, #d64550 0%, var(--red-dark) 100%);
  box-shadow: 0 0 10px 1px rgba(200,40,40,0.25);
}
.candle.holiday .flame {
  opacity: 1;
  transform: scaleY(1);
  filter: drop-shadow(0 0 6px rgba(255,150,50,0.85)) drop-shadow(0 0 14px rgba(255,90,30,0.5));
  animation: flicker 2.6s ease-in-out infinite;
}

/* event green candle */
.candle.event .candle-body {
  background: linear-gradient(180deg, #4bc774 0%, var(--green-dark) 100%);
  box-shadow: 0 0 10px 1px rgba(60,200,110,0.25);
}
.candle.event .flame {
  opacity: 1;
  transform: scaleY(1);
  filter: drop-shadow(0 0 6px rgba(255,150,50,0.85)) drop-shadow(0 0 14px rgba(120,255,160,0.45));
  animation: flicker 2.6s ease-in-out infinite;
}

/* the one-shot "lighting up" animation played when an event is freshly added */
.candle.event.lighting .flame {
  animation: ignite 0.9s cubic-bezier(.34,1.56,.64,1) forwards, flicker 2.6s ease-in-out 0.9s infinite;
}

@keyframes ignite {
  0%   { opacity: 0; transform: scaleY(0.05); }
  40%  { opacity: 1; transform: scaleY(1.35); }
  65%  { transform: scaleY(0.8); }
  100% { opacity: 1; transform: scaleY(1); }
}

@keyframes flicker {
  0%, 100% { transform: scaleY(1) scaleX(1) rotate(0deg); }
  20% { transform: scaleY(0.95) scaleX(1.05) rotate(-2deg); }
  45% { transform: scaleY(1.08) scaleX(0.95) rotate(1.5deg); }
  70% { transform: scaleY(0.92) scaleX(1.02) rotate(-1deg); }
  85% { transform: scaleY(1.05) scaleX(0.97) rotate(2deg); }
}

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,11,15,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border: 1px solid var(--grid-line);
  border-radius: 14px;
  padding: 22px 24px 20px;
  width: min(90vw, 360px);
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

.modal h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}

.modal-holiday {
  color: #f0b6b6;
  font-size: 0.85rem;
  margin: 0 0 10px;
}

.modal label {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

.modal textarea {
  width: 100%;
  resize: vertical;
  background: #14161c;
  border: 1px solid var(--grid-line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.1); }

.btn-primary { background: var(--green); color: #fff; margin-left: auto; }
.btn-secondary { background: var(--red-dark); color: #fff; }
.hidden { display: none !important; }

/* ---------- Event reaction popup ---------- */
.event-reaction {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: min(260px, 40vw);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
}

.event-reaction.show {
  animation: reactionPopup 4s ease forwards;
}

@keyframes reactionPopup {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 560px) {
  .day-cell { min-height: 74px; padding: 4px; }
  .app-header h1 { font-size: 1.2rem; min-width: 0; }
}
