:root {
  --bg-deep: #0a0c10;
  --bg-card: rgba(18, 22, 30, 0.72);
  --bg-card-hover: rgba(24, 30, 42, 0.85);
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f0f2f6;
  --text-muted: #8b93a8;
  --accent: #22c55e;
  --accent-glow: rgba(34, 197, 94, 0.35);
  --accent-dark: #15803d;
  --miss: #ef4444;
  --miss-dark: #b91c1c;
  --miss-glow: rgba(239, 68, 68, 0.35);
  --flame: #f97316;
  --flame-glow: rgba(249, 115, 22, 0.25);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.5);
  --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

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

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  animation: drift 20s ease-in-out infinite;
}

.orb-1 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  top: -120px;
  right: -80px;
}

.orb-2 {
  width: 360px;
  height: 360px;
  background: radial-gradient(circle, var(--flame-glow) 0%, transparent 70%);
  bottom: 10%;
  left: -100px;
  animation-delay: -7s;
}

.orb-3 {
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.05); }
  66% { transform: translate(-20px, 25px) scale(0.95); }
}

.header {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 1rem 1rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-mark {
  color: var(--accent);
  font-size: 1.25rem;
}

.logo-text {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.tagline {
  margin-top: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.75rem;
  align-items: start;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.streak-hero {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  display: flex;
  gap: 1.25rem;
  align-items: center;
  box-shadow: var(--shadow);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.streak-hero.on-fire {
  border-color: rgba(249, 115, 22, 0.3);
  box-shadow: var(--shadow), 0 0 40px var(--flame-glow);
}

.streak-flame {
  font-size: 3.5rem;
  line-height: 1;
  filter: drop-shadow(0 0 12px var(--flame-glow));
  transition: transform 0.4s ease;
}

.streak-hero.on-fire .streak-flame {
  animation: flicker 1.5s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.08) rotate(-3deg); }
  75% { transform: scale(1.05) rotate(3deg); }
}

.streak-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 600;
}

.streak-value-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.streak-value {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 3.5rem;
  line-height: 1;
  font-weight: 400;
  background: linear-gradient(135deg, var(--text) 0%, var(--flame) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: transform 0.3s ease;
}

.streak-value.bump {
  animation: bump 0.45s ease;
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.streak-unit {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.streak-message {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  transition: background var(--transition), border-color var(--transition);
}

.stat-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.15rem;
}

.notes-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notes-header {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.notes-input {
  width: 100%;
  min-height: 5.5rem;
  resize: vertical;
  font-family: inherit;
  font-size: max(16px, 0.85rem);
  line-height: 1.5;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  transition: border-color var(--transition), background var(--transition);
}

.notes-input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.notes-input:hover {
  border-color: var(--border-strong);
}

.notes-input:focus {
  outline: none;
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
}

.notes-saved {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-height: 1em;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.notes-saved.visible {
  opacity: 1;
}

.calendar-panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.month-title {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.65rem;
  font-weight: 400;
}

.nav-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--transition), border-color var(--transition), transform 0.2s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-strong);
}

.nav-btn:active {
  transform: scale(0.94);
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.weekdays abbr {
  text-decoration: none;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
}

.day-cell {
  aspect-ratio: 1;
  min-height: 44px;
  perspective: 400px;
  min-width: 0;
}

.day-cell.empty {
  pointer-events: none;
}

.day-btn {
  width: 100%;
  height: 100%;
  min-height: 44px;
  position: relative;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  border-radius: var(--radius-sm);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.day-btn:not(:disabled):active .day-face.front {
  transform: scale(0.92);
}

.day-btn.past:not(.completed):not(.skipped) .day-face.front {
  opacity: 0.55;
}

.day-btn.past.skipped .day-face.back {
  background: linear-gradient(145deg, var(--miss) 0%, var(--miss-dark) 100%);
  box-shadow: 0 4px 20px var(--miss-glow), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.day-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-sm);
}

.day-btn.completed .day-inner,
.day-btn.skipped .day-inner {
  transform: rotateY(180deg);
}

.day-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: box-shadow var(--transition);
}

.day-face.front {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  color: var(--text);
}

.day-btn:not(:disabled):hover .day-face.front {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border-strong);
}

.day-face.back {
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  transform: rotateY(180deg);
  box-shadow: 0 4px 20px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.day-btn.completed .day-face.back::after {
  content: "✓";
  font-size: 1.1rem;
  font-weight: 700;
}

.day-btn.skipped .day-face.back {
  background: linear-gradient(145deg, var(--miss) 0%, var(--miss-dark) 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 20px var(--miss-glow), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.day-btn.skipped .day-face.back::after {
  content: "✕";
  font-size: 1rem;
  font-weight: 700;
}

.day-btn.skipped:hover .day-face.front {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
}

.day-btn.today .day-face.front {
  border-color: rgba(34, 197, 94, 0.4);
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.2);
}

.day-btn.today .day-face.front::before {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background: var(--accent);
  border-radius: 50%;
}

.day-btn.future .day-face.front {
  border-style: dashed;
  opacity: 0.85;
}

.day-btn.future:not(.completed):hover .day-face.front {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border-strong);
}

.calendar-hint {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  max-width: min(92vw, 360px);
  text-align: center;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  padding: 0.85rem 1.25rem;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 100;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 860px) {
  .app {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    max-width: none;
    width: 100%;
    padding: 0 1rem 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    gap: 1rem;
  }

  .stats-panel {
    display: contents;
  }

  .streak-hero {
    order: -2;
    width: 100%;
    padding: 1.25rem 1.25rem;
  }

  .calendar-panel {
    order: -1;
    width: 100%;
  }

  .stats-grid {
    order: 0;
    width: 100%;
  }

  .notes-section {
    order: 1;
    width: 100%;
  }

  .streak-value {
    font-size: 2.75rem;
  }

  .calendar-hint {
    font-size: 0.78rem;
    padding: 0 0.25rem;
  }
}

@media (max-width: 380px) {
  .header {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .logo-text {
    font-size: 1.65rem;
  }

  .calendar-panel {
    padding: 1rem 0.75rem;
  }

  .calendar-grid,
  .weekdays {
    gap: 0.25rem;
  }

  .day-cell {
    min-height: 40px;
  }

  .day-face {
    font-size: 0.82rem;
  }

  .month-title {
    font-size: 1.35rem;
  }

  .stats-grid {
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.85rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .orb,
  .streak-hero.on-fire .streak-flame,
  .streak-value.bump {
    animation: none;
  }

  .day-inner {
    transition-duration: 0.15s;
  }
}
