* { box-sizing: border-box; }

:root {
  --bg: #121212;
  --surface: #1c1c1e;
  --surface-2: #262629;
  --text: #f2f2f2;
  --text-dim: #9a9a9e;
  --orange: #ff7a18;
  --gold: #ffc700;
  --green: #4caf6d;
  --red: #e85555;
  --border: #303033;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  transition: background 0.8s ease;
}

body.lit {
  background:
    radial-gradient(ellipse 140% 90% at 50% 75%, #ffb238 0%, #ff7a18 28%, #d43f0e 55%, #4a1503 82%, var(--bg) 100%);
}

#app {
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.category-picker select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  max-width: 55vw;
}

.main-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px;
  padding-top: 8vh;
  padding-bottom: 40px;
  gap: 22px;
}

.streak-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.campfire {
  position: relative;
  width: 88px;
  height: 88px;
  font-size: 64px;
  line-height: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.campfire-logs {
  display: block;
  filter: grayscale(0.35) brightness(0.8);
  transition: filter 0.6s ease;
}

.campfire.lit .campfire-logs {
  filter: none;
}

.campfire-flame {
  position: absolute;
  left: 50%;
  bottom: 46%;
  transform: translateX(-50%) scale(0);
  transform-origin: 50% 100%;
  opacity: 0;
  pointer-events: none;
}

.campfire.lit .campfire-flame {
  animation: flame-grow-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
             flame-flicker 1.8s ease-in-out 0.5s infinite;
  filter: drop-shadow(0 0 22px rgba(255, 122, 24, 0.65));
}

@keyframes flame-grow-in {
  0% { transform: translateX(-50%) scale(0); opacity: 0; }
  55% { opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes flame-flicker {
  0%, 100% { transform: translateX(-50%) scale(1) rotate(-2deg); }
  50% { transform: translateX(-50%) scale(1.06) rotate(2deg); }
}

.streak-number-wrap {
  position: relative;
  width: 240px;
  max-width: 100%;
  height: 80px;
  overflow: hidden;
  margin: 0 auto;
}

.streak-number {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  text-align: center;
  transform: translateY(-50%);
  font-size: 72px;
  font-weight: 800;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--orange), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease, filter 0.6s ease;
}

body.lit .streak-number {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 14px rgba(0, 0, 0, 0.35));
}

.streak-number.enter {
  transform: translateY(-150%);
  opacity: 0;
}

.streak-number.leave {
  transform: translateY(50%);
  opacity: 0;
}

.streak-label {
  font-size: 15px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: color 0.6s ease, text-shadow 0.6s ease;
}

body.lit .streak-label {
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.freeze-indicator {
  margin-top: 8px;
  font-size: 14px;
  color: #8ec9ff;
  min-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.6s ease, text-shadow 0.6s ease;
}

body.lit .freeze-indicator {
  color: #eaf4ff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.check-in-btn {
  width: 100%;
  max-width: 340px;
  padding: 18px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--orange), var(--gold));
  color: #1a1200;
  box-shadow: 0 8px 24px rgba(255, 122, 24, 0.3);
}

.check-in-btn:active {
  transform: scale(0.97);
}

.check-in-btn.done {
  background: var(--surface-2);
  color: var(--text-dim);
  box-shadow: none;
  border: 1px solid var(--border);
}

.check-in-btn.pulse {
  animation: btn-pulse 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes btn-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.checkin-area {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.checkin-hint {
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.checkin-switch[hidden] {
  display: none;
}

.checkin-switch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.checkin-switch-track {
  position: relative;
  width: 160px;
  height: 50px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  touch-action: none;
}

.checkin-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--orange), var(--gold));
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.checkin-switch-track.locked {
  background: linear-gradient(135deg, var(--orange), var(--gold));
  border-color: transparent;
}

.checkin-switch-track.locked .checkin-switch-thumb {
  background: var(--surface);
  box-shadow: none;
}

.celebration-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: rgba(10, 6, 2, 0);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, background 0.4s ease;
}

.celebration-overlay.show {
  opacity: 1;
  background: rgba(8, 5, 2, 0.82);
}

.streamer-field {
  position: absolute;
  inset: 0;
}

.streamer {
  position: absolute;
  top: -12vh;
  border-radius: 3px;
  opacity: 0;
}

.celebration-overlay.show .streamer {
  animation: streamer-fall linear forwards;
}

@keyframes streamer-fall {
  0% { transform: translateY(0) translateX(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(130vh) translateX(var(--drift, 40px)) rotate(var(--rot, 480deg)); opacity: 0.9; }
}

.celebration-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transform: scale(0.5);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
}

.celebration-overlay.show .celebration-card {
  transform: scale(1);
  opacity: 1;
}

.celebration-flame {
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 0 26px rgba(255, 122, 24, 0.7));
  margin-bottom: 4px;
}

.celebration-number {
  font-size: 96px;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--orange), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.45));
}

.celebration-label {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

.confetti-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.confetti-burst span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  transform: translate(-50%, -50%);
  animation: confetti-fly 0.85s ease-out forwards;
}

@keyframes confetti-fly {
  0% { transform: translate(-50%, -50%) rotate(0deg); opacity: 1; }
  100% {
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) rotate(360deg);
    opacity: 0;
  }
}

.content-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  animation: fade-in 0.5s ease;
}

.content-card.hidden {
  display: none;
}

.content-body {
  font-size: 16px;
  line-height: 1.5;
  text-align: center;
  white-space: pre-line;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.history-panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.history-panel.hidden {
  display: none;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.history-header h2 {
  font-size: 18px;
  margin: 0;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  overflow-y: auto;
}

.history-grid .cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--surface-2);
}

.cell.done { background: var(--green); }
.cell.frozen { background: #4a8ecf; }
.cell.missed { background: var(--surface-2); border: 1px solid var(--border); }
.cell.pending { background: transparent; border: 1px dashed var(--border); }
.cell.future { background: transparent; }

.history-legend {
  display: flex;
  gap: 18px;
  justify-content: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-dim);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.dot-done { background: var(--green); }
.dot-frozen { background: #4a8ecf; }
.dot-missed { background: var(--surface-2); border: 1px solid var(--border); }

.onboarding {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.onboarding.hidden {
  display: none;
}

.onboarding-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}

.onboarding-emoji {
  font-size: 56px;
  line-height: 1;
  filter: grayscale(0.4) brightness(0.85);
}

.onboarding-card h1 {
  font-size: 24px;
  margin: 4px 0 0;
}

.onboarding-card p {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}

.onboarding-card input {
  width: 100%;
  padding: 16px;
  font-size: 20px;
  text-align: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin-top: 8px;
}

.onboarding-card input:focus {
  outline: 2px solid var(--orange);
}

.onboarding-card .check-in-btn {
  margin-top: 4px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  text-decoration: underline;
  padding: 8px;
}

.text-btn:active {
  opacity: 0.7;
}

.reminder-settings {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.reminder-hour-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.reminder-settings select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 15px;
}

.reminder-btn {
  align-self: center;
  margin-top: 4px;
}

.reminder-btn:disabled {
  text-decoration: none;
  opacity: 0.6;
}
