/* 认识日历 · My First Calendar — layout & skin.
   Design: the calendar is the hero; the orbit scene is its mirror.
   Single state (selectedDate) drives both; the scene is never operable. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
}

/* ---------------------------------------------------------- shell layout */

.cal-shell {
  height: calc(100dvh - 64px);
  padding: clamp(8px, 2vmin, 24px);
  /* a deeper bottom margin: the month flipper sits at the panel's foot
     and needs breathing room (plus the floating today button) */
  padding-bottom: max(clamp(16px, 3.5vmin, 36px), env(safe-area-inset-bottom));
  display: grid;
  gap: clamp(8px, 2vmin, 20px);
  /* landscape: calendar left, orbit right */
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  grid-template-rows: minmax(0, 1fr);
}

.cal-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: clamp(4px, 1vmin, 10px);
}

/* portrait: orbit on top, calendar below — same layout as clock */
@media (max-aspect-ratio: 4/5) {
  .cal-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 2fr) minmax(0, 3fr);
  }
  .cal-panel  { order: 2; }
  .orbit-panel{ order: 1; }
}

/* ---------------------------------------------------------- month bar */

.month-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vmin, 32px);
}

.month-title {
  margin: 0;
  font-family: var(--font-cn-display);
  font-weight: 800;
  font-size: clamp(18px, 3vmin, 28px);
  color: var(--ink);
  min-width: 6.5em;
  text-align: center;
}

.month-nav {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(16px, 2.6vmin, 24px);
  line-height: 1;
  color: var(--ink);
  background: var(--paper-card);
  border: 3px solid var(--ink);
  border-radius: 50%;
  width: 1.6em;
  height: 1.6em;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.month-nav:hover  { transform: translateY(-2px); box-shadow: 0 5px 0 var(--ink); }
.month-nav:active { transform: translateY(2px);  box-shadow: 0 1px 0 var(--ink); }

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

.weekday-row,
.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(3px, 0.8vmin, 8px);
}

.weekday-row span {
  text-align: center;
  font-family: var(--font-cn-display);
  font-weight: 700;
  font-size: clamp(14px, 2.2vmin, 20px);
  color: var(--ink-3);
}
.weekday-row .weekend { color: var(--coral); }

.day-grid { flex: 1 1 auto; min-height: 0; }

.day-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18%;
  background: var(--paper-card);
  border: 2px solid transparent;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(18px, 4.4vmin, 40px);
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 140ms ease;
}
.day-cell.weekend { background: #f7e3c8; }      /* warm rest-day tint */
.day-cell.blank { background: transparent; cursor: default; }

.day-cell .emoji {
  position: absolute;
  right: 4%;
  bottom: 2%;
  font-size: 0.55em;
}

.day-cell .mini-label {
  position: absolute;
  top: 2%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-cn-display);
  font-weight: 700;
  font-size: clamp(10px, 1.6vmin, 14px);
  color: var(--ink-3);
  white-space: nowrap;
}

.day-cell.today {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--coral) 35%, transparent);
  animation: today-breathe 2.4s ease-in-out infinite;
}
@keyframes today-breathe {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--coral) 35%, transparent); }
  50%      { box-shadow: 0 0 0 7px color-mix(in srgb, var(--coral) 18%, transparent); }
}

.day-cell.selected {
  background: var(--ink);
  color: var(--paper-card);
}
.day-cell.selected .mini-label { color: var(--paper-2); }

.day-cell.pop { animation: cell-pop 260ms ease-out; }
@keyframes cell-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* ---------------------------------------------------------- reading */

.reading {
  position: relative;
  text-align: center;
  min-height: 3.2em;
}

.reading-main {
  font-family: var(--font-cn-display);
  font-weight: 800;
  font-size: clamp(24px, 4vmin, 40px);
  line-height: 1.2;
  color: var(--ink);
}

.reading-en {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(13px, 2vmin, 18px);
  color: var(--ink-3);
  letter-spacing: 0.03em;
  min-height: 1.2em;
}

.reading-special {
  font-family: var(--font-cn-display);
  font-weight: 700;
  font-size: clamp(16px, 2.6vmin, 24px);
  color: var(--coral);
  min-height: 1.2em;
}

/* ---------------------------------------------------------- orbit scene */

.orbit-panel {
  position: relative;
  min-height: 0;
  border-radius: 24px;
  overflow: hidden;
  transition: background 900ms ease;
  /* seasonal atmosphere — set via data-season on the panel */
  background: #dcecd6;
}
.orbit-panel[data-season="summer"] { background: #f5e2c2; }
.orbit-panel[data-season="autumn"] { background: #eed9b8; }
.orbit-panel[data-season="winter"] { background: #d7e4ee; }
.orbit-panel[data-season="spring"] { background: #dcecd6; }

#orbit-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#orbit-canvas.dragging { cursor: grabbing; }

/* season labels follow the solar pill pattern: EN chip + 中文 */
.orbit-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 3px 10px 4px;
  border: 1.5px solid rgba(255, 250, 240, 0.78);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
  font-family: var(--font-cn);
  font-weight: 700;
  font-size: clamp(12px, 1.9vmin, 16px);
  line-height: 1.3;
  color: var(--ink);
  pointer-events: none;
  white-space: nowrap;
}
.orbit-label b {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--season-color, var(--ink));
  color: var(--paper-card);
  font-family: var(--font-body);
  font-size: 0.62em;
  font-weight: 700;
  letter-spacing: 1px;
}
.orbit-label[data-season="spring"] { --season-color: #6f8c5a; }
.orbit-label[data-season="summer"] { --season-color: #c47b5a; }
.orbit-label[data-season="autumn"] { --season-color: #c9a64a; }
.orbit-label[data-season="winter"] { --season-color: #5a6c8d; }

/* back-to-today — round icon button, bottom-right (same spot as clock) */
.today-btn {
  position: fixed;
  right: clamp(12px, 3vmin, 28px);
  bottom: clamp(12px, 3vmin, 28px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(48px, 8vmin, 64px);
  height: clamp(48px, 8vmin, 64px);
  color: var(--ink);
  background: var(--paper-card);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.today-btn:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.today-btn:active { transform: translateY(2px);  box-shadow: 0 2px 0 var(--ink); }

/* birthday easter egg */
.confetti {
  position: fixed;
  z-index: 50;
  font-size: 28px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: confetti-fly 1.5s ease-out forwards;
}
@keyframes confetti-fly {
  0%   { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) scale(0.6); }
  20%  { opacity: 1; transform: translate(calc(-50% + var(--dx) * 0.3), calc(-50% + var(--dy) * 0.3)) rotate(calc(var(--rot) * 0.3)) scale(1.1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1); }
}
