/* ===================== Reset & Base ===================== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --night-deep: #0a0e1a;
  --night-mid: #0f1525;
  --night-light: #1a2340;
  --night-horizon: #1c2a4a;
  --day-sky-top: #5b9bd5;
  --day-sky-mid: #87ceeb;
  --day-sky-bot: #b8dff0;
  --day-cloud: rgba(255,255,255,0.7);
  --star-warm: #ffd866;
  --star-cool: #b0d4f0;
  --star-pink: #f0a8c8;
  --star-orange: #f0a050;
  --star-lavender: #b8a0d8;
  --star-white: #e8e8f0;
  --text-primary: #e8e0d8;
  --text-secondary: #8a8a9a;
  --text-muted: #5a5a7a;
  --text-day: #2a3a4a;
  --text-day-secondary: #5a7a8a;
  --moon-glow: rgba(200, 180, 140, 0.08);
  --font-cn: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

html, body {
  height: 100%; width: 100%;
  font-family: var(--font-cn);
  background: var(--night-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100%; width: 100%;
  max-width: 480px; margin: 0 auto;
  position: relative; overflow: hidden;
  background: var(--night-deep);
}

/* ===================== Screens ===================== */
.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* ===================== Auth ===================== */
#auth-screen {
  justify-content: center; align-items: center; padding: 24px;
  background: linear-gradient(160deg, #0a0e1a 0%, #101828 40%, #162040 100%);
}
.auth-container {
  width: 100%; max-width: 340px; padding: 36px 24px;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px; border: 1px solid rgba(255,255,255,0.06);
  text-align: center;
}
.auth-logo { font-size: 52px; margin-bottom: 6px; filter: drop-shadow(0 0 20px rgba(255,215,0,0.2)); }
.auth-title { font-size: 24px; font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.auth-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }
.auth-form { text-align: left; }
.auth-form .input-group { margin-bottom: 14px; }
.auth-form label { display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.auth-form input {
  width: 100%; padding: 13px 16px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px; font-size: 15px; font-family: var(--font-cn);
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  outline: none; transition: border-color 0.2s;
}
.auth-form input:focus { border-color: var(--star-warm); }
.auth-form input::placeholder { color: var(--text-muted); }
.auth-error { color: #e87474; font-size: 12px; margin-bottom: 8px; min-height: 18px; text-align: center; }
.auth-tip { font-size: 12px; color: var(--text-muted); margin-top: 14px; }

/* ===================== Buttons ===================== */
.btn {
  border: none; border-radius: 12px; font-family: var(--font-cn);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, #2a3a6a, #1a2a5a);
  color: var(--text-primary);
  padding: 13px 24px;
  border: 1px solid rgba(255,215,0,0.15);
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; }

.icon-btn {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--text-secondary);
  padding: 6px 10px; border-radius: 8px;
  transition: background 0.2s; line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: rgba(255,255,255,0.08); }

/* ===================== Header ===================== */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(10,14,26,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  position: relative; flex-shrink: 0; z-index: 5;
}
.header-title { font-size: 16px; font-weight: 600; color: var(--text-primary); letter-spacing: 2px; }

/* ===================== Menu ===================== */
.menu-dropdown {
  position: absolute; top: 54px; left: 12px;
  background: rgba(20,28,50,0.95); backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 12px; border: 1px solid rgba(255,255,255,0.06);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4); z-index: 100; overflow: hidden; min-width: 150px;
}
.menu-dropdown.hidden { display: none; }
.menu-item {
  display: block; width: 100%; padding: 12px 18px; border: none;
  background: none; font-family: var(--font-cn); font-size: 14px;
  color: var(--text-secondary); text-align: left; cursor: pointer; transition: background 0.15s;
}
.menu-item:active { background: rgba(255,255,255,0.05); color: var(--text-primary); }

/* ===================== Views ===================== */
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; flex-direction: column; }

/* ===================== SKY VIEW (shared) ===================== */
#sky-view {
  position: relative;
  transition: background 0.8s ease;
}

/* --- Night mode --- uses image + dark overlay --- */
.sky-night {
  background: linear-gradient(rgba(5,8,18,0.55), rgba(5,8,18,0.65)),
              url('bg.png') center / cover no-repeat;
  background-blend-mode: overlay;
}
.sky-night .sky-greeting { color: rgba(255,255,255,0.7); }
.sky-night .sky-sub { color: rgba(255,255,255,0.45); }
.sky-night .star-label { color: rgba(255,255,255,0.4); }

/* --- Day mode --- uses image + lighter overlay --- */
.sky-day {
  background: linear-gradient(rgba(180,210,240,0.3), rgba(180,210,240,0.2)),
              url('bg.png') center / cover no-repeat;
  background-blend-mode: soft-light;
}
.sky-day .sky-greeting { color: rgba(255,255,255,0.8); text-shadow: 0 1px 4px rgba(0,0,0,0.3); }
.sky-day .sky-sub { color: rgba(255,255,255,0.6); }
.sky-day .star-label { color: rgba(255,255,255,0.5); }

/* Day-mode header & menu adjustments */
.mode-day .header {
  background: rgba(74,143,200,0.85);
  border-bottom-color: rgba(255,255,255,0.15);
}
.mode-day .header .header-title { color: white; }
.mode-day .header .icon-btn { color: rgba(255,255,255,0.7); }
.mode-day .menu-dropdown {
  background: rgba(74,143,200,0.92);
  border-color: rgba(255,255,255,0.12);
}
.mode-day .menu-item { color: rgba(255,255,255,0.75); }
.mode-day .menu-item:active { background: rgba(255,255,255,0.1); color: white; }

/* Night-mode header */
.mode-night .header {
  background: rgba(10,14,26,0.9);
  border-bottom-color: rgba(255,255,255,0.04);
}
.mode-night .header .header-title { color: var(--text-primary); }
.mode-night .header .icon-btn { color: var(--text-secondary); }
.mode-night .menu-dropdown {
  background: rgba(20,28,50,0.95);
  border-color: rgba(255,255,255,0.06);
}

/* --- Celestial bodies --- */
.sky-moon, .sky-sun {
  position: absolute; z-index: 1;
  transition: opacity 0.8s ease;
}
.sky-moon { top: 12px; right: 24px; font-size: 28px; }
.sky-moon.on {
  opacity: 0.7;
  filter: drop-shadow(0 0 30px rgba(200,180,140,0.15));
  animation: moonGlow 4s ease-in-out infinite;
}
.sky-moon.off { opacity: 0; }

.sky-sun { top: 14px; right: 28px; font-size: 32px; }
.sky-sun.on {
  opacity: 0.9;
  filter: drop-shadow(0 0 40px rgba(255,200,50,0.25));
  animation: sunGlow 4s ease-in-out infinite;
}
.sky-sun.off { opacity: 0; }

@keyframes moonGlow {
  0%, 100% { opacity: 0.6; filter: drop-shadow(0 0 20px rgba(200,180,140,0.1)); }
  50% { opacity: 0.8; filter: drop-shadow(0 0 40px rgba(200,180,140,0.2)); }
}
@keyframes sunGlow {
  0%, 100% { filter: drop-shadow(0 0 30px rgba(255,200,50,0.2)); }
  50% { filter: drop-shadow(0 0 50px rgba(255,200,50,0.35)); }
}

/* --- Day clouds --- */
.day-clouds {
  position: absolute; top: 0; left: 0; right: 0;
  height: 40%; pointer-events: none; overflow: hidden;
}
.day-cloud {
  position: absolute; font-size: 44px; opacity: 0.3;
  animation: dayCloudDrift 25s linear infinite;
}
.day-cloud:nth-child(1) { top: 6%; font-size: 38px; animation-duration: 28s; left: -60px; }
.day-cloud:nth-child(2) { top: 16%; font-size: 28px; animation-duration: 35s; animation-delay: -10s; left: -60px; }
.day-cloud:nth-child(3) { top: 25%; font-size: 32px; animation-duration: 22s; animation-delay: -20s; left: -60px; }

@keyframes dayCloudDrift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 120px)); }
}

/* Sky header shared */
.sky-header {
  position: relative; z-index: 2;
  padding: 32px 20px 8px; text-align: center;
}
.sky-greeting {
  font-size: 15px;
  font-weight: 400; letter-spacing: 3px; margin-bottom: 2px;
}
.sky-sub {
  font-size: 12px;
  font-weight: 300; letter-spacing: 1px;
}

/* Constellation / stars container */
#stars-container {
  position: relative; flex: 1; overflow: hidden;
  margin: 0 8px;
}

/* ===================== STAR ===================== */
.star {
  position: absolute;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: starAppear 0.6s ease backwards;
  transition: transform 0.2s;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.star:active { transform: scale(1.2) !important; }

@keyframes starAppear {
  from { opacity: 0; transform: scale(0) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.star-body {
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  position: relative;
  overflow: visible;
}

.star-body svg {
  display: block;
  filter: drop-shadow(0 0 6px var(--star-glow-color));
}

.star-body.twinkle svg {
  animation: twinkle 3s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.65; transform: scale(0.82); }
}

.star-emoji {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
  pointer-events: none;
}

.star-label {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  font-size: 9px; color: var(--text-muted);
  white-space: nowrap; margin-top: 4px;
  font-weight: 300; letter-spacing: 1px;
  opacity: 0.5;
}

/* Star glow for all moods */
.star-glow {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
}

/* Shooting star animation for new post */
.shooting-star {
  position: absolute;
  width: 3px; height: 3px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 0 6px 2px rgba(255,255,255,0.3);
  animation: shoot 0.8s ease-out forwards;
  pointer-events: none;
  z-index: 10;
}
@keyframes shoot {
  0% { opacity: 1; transform: translateX(0) translateY(0); }
  100% { opacity: 0; transform: translateX(-80px) translateY(80px); }
}

/* Star trail */
.shooting-star::after {
  content: '';
  position: absolute;
  top: 50%; right: 100%;
  width: 40px; height: 1px;
  background: linear-gradient(to left, rgba(255,255,255,0.4), transparent);
}

/* ===================== Empty State ===================== */
.empty-state {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; z-index: 2;
}
.empty-state .empty-icon { font-size: 44px; margin-bottom: 8px; opacity: 0.6; }
.empty-state .empty-title {
  font-size: 15px; font-weight: 400; color: var(--text-muted); margin-bottom: 4px;
}
.empty-state .empty-hint { font-size: 12px; color: var(--text-muted); opacity: 0.6; }

/* Loading */
.loading-spinner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
}
.spinner {
  width: 24px; height: 24px;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: var(--star-warm);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Write View ===================== */
#write-view { background: linear-gradient(180deg, #0a0e1a 0%, #101e3a 100%); }
.write-header {
  display: flex; align-items: center; padding: 12px 12px 4px;
}
.write-header h2 {
  flex: 1; text-align: center; font-size: 16px; font-weight: 500;
  color: var(--text-primary); letter-spacing: 2px;
}

.write-form { padding: 8px 20px 24px; flex: 1; display: flex; flex-direction: column; }

.mood-label {
  font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 10px;
  letter-spacing: 1px;
}
.mood-options {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px;
  justify-content: center;
}
.mood-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  font-size: 22px; cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mood-btn:active { transform: scale(0.9); }
.mood-btn.selected {
  border-color: var(--star-warm);
  background: rgba(255,215,0,0.1);
  box-shadow: 0 0 20px rgba(255,215,0,0.1);
  transform: scale(1.1);
}

/* --- Emoji Picker --- */
.mood-selector { position: relative; }

.selected-mood-display {
  font-size: 13px; font-weight: 300; margin-left: 4px;
}

.mood-picker-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  color: var(--text-primary); cursor: pointer;
  font-size: 28px; font-family: var(--font-cn);
  transition: border-color 0.2s; margin-bottom: 8px;
  -webkit-tap-highlight-color: transparent;
}
.mood-picker-btn:active { border-color: var(--star-warm); }
.mood-picker-arrow { font-size: 10px; color: var(--text-muted); }

.emoji-picker {
  background: rgba(15,20,35,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 12px 8px;
  margin-bottom: 12px;
  animation: fadeIn 0.2s ease;
  max-height: 280px;
  overflow-y: auto;
}
.emoji-picker.hidden { display: none; }

.emoji-categories {
  display: flex; gap: 4px;
  margin-bottom: 10px; padding: 0 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.emoji-cat {
  flex-shrink: 0;
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  padding: 4px 10px; border-radius: 8px;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.4;
}
.emoji-cat.active { opacity: 1; background: rgba(255,255,255,0.06); }
.emoji-cat:active { background: rgba(255,255,255,0.08); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-item {
  background: none; border: none;
  font-size: 26px; cursor: pointer;
  padding: 4px; border-radius: 8px;
  text-align: center;
  transition: background 0.12s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}
.emoji-item:active {
  background: rgba(255,255,255,0.08);
  transform: scale(1.2);
}

.write-textarea-wrap { flex: 1; margin-bottom: 14px; }
.write-form textarea {
  width: 100%; height: 100%; min-height: 160px;
  padding: 16px 18px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  font-size: 15px; font-family: var(--font-cn); line-height: 1.9;
  background: rgba(255,255,255,0.03);
  color: var(--text-primary); resize: none; outline: none;
  transition: border-color 0.2s;
}
.write-form textarea:focus { border-color: rgba(255,215,0,0.3); }
.write-form textarea::placeholder { color: var(--text-muted); }

/* ===================== Read Modal ===================== */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal.hidden { display: none; }

.modal-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(5,8,18,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
  position: relative; width: 100%; max-width: 340px;
  max-height: 70vh; overflow-y: auto;
  background: linear-gradient(160deg, rgba(20,28,50,0.95), rgba(15,20,40,0.98));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px; padding: 32px 24px 20px;
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: starBurst 0.5s ease backwards;
}
@keyframes starBurst {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px;
}
.modal-mood { font-size: 32px; line-height: 1; }
#modal-close-btn { font-size: 16px; color: var(--text-muted); }

.modal-time {
  font-size: 11px; color: var(--text-muted); margin-bottom: 18px; letter-spacing: 1px;
}

.modal-body {
  font-size: 15px; line-height: 2.1;
  color: var(--text-primary);
  white-space: pre-wrap; word-break: break-word;
  padding: 4px 0; font-weight: 300;
}

.modal-footer {
  text-align: center; margin-top: 20px; padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.btn-delete {
  background: none; border: none;
  font-family: var(--font-cn); font-size: 12px;
  color: var(--text-muted); cursor: pointer;
  padding: 6px 14px; border-radius: 8px;
  transition: all 0.2s; opacity: 0.4;
  -webkit-tap-highlight-color: transparent;
}
.btn-delete:active { opacity: 0.8; background: rgba(255,255,255,0.04); }

/* ===================== Toast ===================== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(20,28,50,0.9); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text-primary);
  padding: 10px 22px; border-radius: 20px;
  font-size: 13px; font-family: var(--font-cn);
  z-index: 300; animation: toastIn 0.3s ease;
  max-width: 320px; text-align: center; pointer-events: none;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.hidden { display: none !important; }

/* Scrollbar */
.modal-content::-webkit-scrollbar { width: 2px; }
.modal-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* Constellation connector lines (subtle) */
.constellation-line {
  position: absolute; z-index: 1;
  opacity: 0.06;
  pointer-events: none;
}
