* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #252540;
  --bg-tertiary: #2a2a4a;
  --bg-hover: #3a3a5a;
  --text-primary: #f5ead4;
  --text-secondary: #e8dcc6;
  --text-muted: #888;
  --text-dimmed: #555;
  --border-color: #444;
  --accent: #c9a227;
  --accent-hover: #d4af37;
  --accent-muted: #c9a052;
  --disc-bg: #1e3a5f;
  --disc-bg-light: #2a4a70;
  --noise-opacity: 0.03;
}

:root.light-mode {
  --bg-primary: #f5f0e6;
  --bg-secondary: #faf7f0;
  --bg-tertiary: #ebe5d9;
  --bg-hover: #e0d9cb;
  --text-primary: #2a2a2a;
  --text-secondary: #3a3a3a;
  --text-muted: #6b5d4d;
  --text-dimmed: #9a8b78;
  --border-color: #d4c9b8;
  --accent: #b8860b;
  --accent-hover: #9a7209;
  --accent-muted: #c9a052;
  --disc-bg: #2a4a7f;
  --disc-bg-light: #3a5a90;
  --noise-opacity: 0.08;
}

body {
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-family: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  font-weight: 400;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
  position: relative;
}

/* Noise texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: var(--noise-opacity);
  background-image: url('../img/noise.png');
  background-repeat: repeat;
  background-size: 200px 200px;
}

main {
  text-align: center;
  padding: 16px;
  max-width: 500px;
  width: 100%;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

body.fade-out main {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
  to { opacity: 0; }
}

#moonphase-container {
  margin: 0 auto 20px;
  position: relative;
}

.reset-date {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, background 0.2s;
  z-index: 10;
  margin-left: 10px;
}

.reset-date.visible {
  opacity: 1;
  visibility: visible;
}

.reset-date:hover {
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
}

.reset-date svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:root.light-mode .reset-date {
  background: rgba(0, 0, 0, 0.15);
  color: rgba(0, 0, 0, 0.5);
}

:root.light-mode .reset-date:hover {
  background: rgba(0, 0, 0, 0.3);
  color: rgba(0, 0, 0, 0.8);
}

#moonphase-container > svg {
  width: 100%;
  max-width: 420px;
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(1.4px 2px 2px rgba(0, 0, 0, 0.35));
}

.info {
  margin-bottom: 24px;
}

.phase-name {
  font-size: 2.25rem;
  font-weight: 700;
  font-style: italic;
  margin-bottom: 8px;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  text-shadow: 1.4px 2px 2px rgba(0, 0, 0, 0.70);
}

:root.light-mode .phase-name {
  text-shadow: 1.4px 2px 2px rgba(0, 0, 0, 0.35);
}

.moon-age {
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.full-moon-info {
  font-size: 1.05rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.full-moon-info strong {
  font-weight: 600;
  color: var(--text-secondary);
}

.date-picker {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  position: relative;
}

#today-btn,
.arrow-btn,
.date-display {
  height: 44px;
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid var(--bg-hover);
  border-radius: 8px;
  background: var(--bg-tertiary);
  color: var(--accent-muted);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#today-btn {
  padding: 0 24px;
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
  border-color: var(--accent);
}

#today-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.arrow-btn {
  padding: 0 14px;
  font-size: 1.1rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.arrow-btn:hover,
.date-display:hover {
  background: var(--bg-hover);
  border-color: var(--text-dimmed);
}

/* Custom Date Picker */
.date-selector {
  position: relative;
}

.date-display {
  padding: 0 16px;
  min-width: 140px;
}

.date-display:focus {
  outline: none;
  border-color: var(--accent);
}

.calendar-dropdown {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  z-index: 100;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  width: 280px;
}

.calendar-dropdown.hidden {
  display: none;
}

.calendar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.calendar-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 2px;
}

.calendar-header span {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.cal-nav {
  padding: 5px 9px;
  border: none;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.cal-nav:hover {
  background: var(--bg-hover);
}

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

.calendar-weekdays span {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 3px;
  font-weight: 600;
}

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

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.2s;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.calendar-day:hover {
  background: var(--bg-hover);
}

.calendar-day.other-month {
  color: var(--text-dimmed);
}

.calendar-day.today {
  border: 1px solid var(--accent);
}

.calendar-day.selected {
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
}

.calendar-day.full-moon::after {
  content: '';
  position: absolute;
  bottom: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

/* Upcoming Full Moons */
.upcoming-moons {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

.upcoming-moons h3 {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
  margin-bottom: 12px;
  letter-spacing: 0.03em;
}

#full-moon-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  max-width: 400px;
  margin: 0 auto;
}

.full-moon-item {
  padding: 12px 0;
  text-align: center;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--accent-muted);
  border: 1px solid var(--bg-hover);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.full-moon-item:hover {
  background: var(--bg-hover);
}

.full-moon-item.next {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* Theme Toggle */
.api-link {
  position: fixed;
  top: 16px;
  right: 64px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, border-color 0.3s, transform 0.2s;
  z-index: 50;
  text-decoration: none;
}

.api-link:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

.api-link svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-secondary);
  stroke-width: 2;
  fill: none;
  transition: stroke 0.3s;
}

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s, border-color 0.3s, transform 0.2s;
  z-index: 50;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.4s ease, opacity 0.3s;
}

.theme-toggle:hover svg {
  transform: rotate(15deg);
}

.theme-icon-sun,
.theme-icon-moon {
  position: absolute;
}

.theme-icon-moon {
  opacity: 1;
}

.theme-icon-sun {
  opacity: 0;
}

:root.light-mode .theme-icon-moon {
  opacity: 0;
  transform: rotate(-90deg);
}

:root.light-mode .theme-icon-sun {
  opacity: 1;
  transform: rotate(0deg);
}

/* Theme transition */
body,
main,
.date-display,
.arrow-btn,
#today-btn,
.full-moon-item,
.calendar-dropdown,
.bottom-sheet,
.upcoming-moons {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}

#moonphase-container svg {
  transition: opacity 0.2s ease;
}

#moonphase-container svg.theme-fading {
  opacity: 0;
}

#moonphase-container svg.theme-fading-in {
  transition: opacity 0.3s ease;
}

.theme-transition {
  transition: fill 0.4s ease, stroke 0.4s ease;
}

.dev-toggle {
  position: fixed;
  top: 10px;
  right: 64px;
  padding: 8px 12px;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: pointer;
  display: none;
}

.dev-toggle.visible {
  display: block;
}

.dev-menu {
  position: fixed;
  top: 50px;
  right: 10px;
  width: 240px;
  max-height: calc(100vh - 70px);
  overflow-y: auto;
  padding: 15px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.85rem;
}

.dev-menu.hidden {
  display: none;
}

.dev-menu h3 {
  margin: 10px 0 5px;
  font-size: 0.9rem;
  color: var(--accent);
}

.dev-menu h3:first-child {
  margin-top: 0;
}

.dev-menu label {
  display: block;
  margin: 8px 0;
  color: var(--text-muted);
}

.dev-menu input[type="range"] {
  width: 100%;
  margin-top: 4px;
}

.dev-menu span {
  color: var(--text-primary);
  font-family: monospace;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.slider-row label {
  margin: 0;
}

.slider-row input[type="color"] {
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.slider-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.slider-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.slider-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.reset-btn {
  padding: 2px 6px;
  font-size: 0.75rem;
  border: 1px solid var(--text-dimmed);
  border-radius: 3px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: pointer;
}

.reset-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.star-group {
  background: var(--bg-primary);
  padding: 8px;
  margin: 8px 0;
  border-radius: 4px;
}

.star-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--accent);
}

.star-slider {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  font-size: 0.8rem;
}

.star-slider label {
  width: 35px;
  margin: 0;
}

.star-slider input {
  flex: 1;
}

.star-slider span {
  width: 35px;
  text-align: right;
}

#copy-values {
  margin-top: 15px;
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 4px;
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
  cursor: pointer;
}

/* Bottom Sheet */
.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.bottom-sheet-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-radius: 16px 16px 0 0;
  padding: 12px 20px 40px;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
}

.bottom-sheet.visible {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--text-dimmed);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.bottom-sheet .calendar-header {
  margin-bottom: 16px;
}

.bottom-sheet .calendar-header span {
  font-size: 1.1rem;
}

.bottom-sheet .cal-nav {
  padding: 8px 14px;
  font-size: 1rem;
}

.bottom-sheet .calendar-weekdays {
  margin-bottom: 8px;
}

.bottom-sheet .calendar-weekdays span {
  font-size: 0.85rem;
  padding: 8px 4px;
}

.bottom-sheet .calendar-days {
  grid-template-rows: repeat(6, 1fr);
}

.bottom-sheet .calendar-day {
  font-size: 1rem;
  height: 48px;
  aspect-ratio: auto;
}

/* Mobile styles */
@media (max-width: 768px) {
  body {
    padding-top: 40px;
  }

  #full-moon-list {
    gap: 8px;
    max-width: 100%;
  }

  .full-moon-item {
    padding: 14px 0;
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  main {
    padding: 12px;
  }

  .date-picker {
    gap: 6px;
  }

  .arrow-btn,
  .date-display {
    height: 40px;
    font-size: 0.9rem;
  }

  .arrow-btn {
    padding: 0 10px;
  }

  .date-display {
    min-width: 120px;
    padding: 0 10px;
  }

  .phase-name {
    font-size: 2.1rem;
  }

  .moon-age {
    font-size: 1rem;
  }

  .api-link {
    top: 12px;
    right: 56px;
    width: 36px;
    height: 36px;
  }

  .api-link svg {
    width: 16px;
    height: 16px;
  }

  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
}

@media (max-width: 360px) {
  #full-moon-list {
    gap: 6px;
  }

  .full-moon-item {
    padding: 12px 0;
    font-size: 0.9rem;
  }
}

@media (min-width: 600px) {
  #moonphase-container svg {
    max-width: 480px;
  }

  .phase-name {
    font-size: 2.5rem;
  }

  main {
    padding: 20px;
  }
}
