:root {
  --primary: #fec6d8;
  --secondary: #f8a5c2;
  --dark: #d6307e;
  --text: #5a2d57;
  --light: #fff9fc;
  --shadow: 0 4px 20px rgba(235, 149, 197, 0.3);
  --bg-gradient: linear-gradient(135deg, #fec6d8, #f8a5c2);
}

[data-theme="dark"] {
  --primary: #4a1942;
  --secondary: #6a2c5e;
  --dark: #ff69b4;
  --text: #f0d4e8;
  --light: #2a1328;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --bg-gradient: linear-gradient(135deg, #2a1328, #4a1942);
}

[data-theme="ocean"] {
  --primary: #a8e6cf;
  --secondary: #7fcbb3;
  --dark: #3d8b6f;
  --text: #2d5f4f;
  --light: #f0fff8;
  --shadow: 0 4px 20px rgba(127, 203, 179, 0.3);
  --bg-gradient: linear-gradient(135deg, #a8e6cf, #7fcbb3);
}

[data-theme="sunset"] {
  --primary: #ffd1a9;
  --secondary: #ffb088;
  --dark: #ff6b6b;
  --text: #5a3d2f;
  --light: #fff9f5;
  --shadow: 0 4px 20px rgba(255, 177, 136, 0.3);
  --bg-gradient: linear-gradient(135deg, #ffd1a9, #ffb088);
}

[data-theme="lavender"] {
  --primary: #e0c3fc;
  --secondary: #c39bff;
  --dark: #8b5cf6;
  --text: #4c2a85;
  --light: #faf5ff;
  --shadow: 0 4px 20px rgba(195, 155, 255, 0.3);
  --bg-gradient: linear-gradient(135deg, #e0c3fc, #c39bff);
}

[data-theme="cherry"] {
  --primary: #ffadad;
  --secondary: #ffd6a5;
  --dark: #ff6b6b;
  --text: #5a2d2d;
  --light: #fff9f9;
  --shadow: 0 4px 20px rgba(255, 173, 173, 0.3);
  --bg-gradient: linear-gradient(135deg, #ffadad, #ffd6a5);
}

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

body {
  font-family: 'Quicksand', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  transition: all 0.3s ease;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* === ANIMATIONS === */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 10px var(--primary); }
  50% { box-shadow: 0 0 20px var(--dark); }
}

/* === SCREENS === */
.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.4s ease;
}

/* === PASSWORD SCREEN === */
#password-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 2rem;
}

.lock-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: pulse 2s infinite;
}

.password-container {
  background: rgba(255,255,255,0.95);
  padding: 2.5rem;
  border-radius: 24px;
  box-shadow: var(--shadow);
  max-width: 400px;
  width: 100%;
  animation: slideDown 0.5s ease;
}

.password-container h2 {
  color: var(--dark);
  margin-bottom: 0.5rem;
  font-size: 1.5rem;
}

.password-container p {
  color: var(--text);
  margin-bottom: 1.5rem;
}

.password-input {
  width: 100%;
  padding: 1rem;
  border: 2px solid var(--primary);
  border-radius: 12px;
  font-size: 1.1rem;
  margin-bottom: 1rem;
  font-family: inherit;
  transition: border-color 0.3s;
}

.password-input:focus {
  outline: none;
  border-color: var(--dark);
}

/* === WELCOME SCREEN === */
#welcome-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 2rem;
  gap: 1.5rem;
}

.container {
  max-width: 500px;
  width: 100%;
}

.logo {
  font-size: 3rem;
  font-weight: 700;
  color: var(--dark);
  letter-spacing: 1px;
  animation: slideDown 0.6s ease;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
  font-size: 1.2rem;
  color: var(--dark);
  margin-bottom: 1rem;
  opacity: 0.9;
}

.form-group input {
  width: 100%;
  max-width: 320px;
  padding: 1rem;
  border: none;
  border-radius: 16px;
  background: rgba(255,255,255,0.9);
  font-size: 1.1rem;
  text-align: center;
  box-shadow: var(--shadow);
  outline: none;
  font-family: inherit;
  transition: transform 0.2s;
}

.form-group input:focus {
  transform: scale(1.02);
}

.language-switcher {
  margin: 1rem 0;
}

.language-switcher label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text);
  font-weight: 600;
}

.language-switcher select {
  padding: 0.8rem 1.2rem;
  border-radius: 12px;
  border: 2px solid var(--secondary);
  background: white;
  font-weight: bold;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--dark);
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 25px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  font-family: inherit;
  width: 100%;
  max-width: 320px;
}

.btn-primary:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(214, 48, 126, 0.4);
}

.btn-primary:active {
  transform: scale(0.98);
}

/* === JOURNAL SCREEN === */
#journal-screen {
  padding: 1.5rem;
  background: var(--light);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

#greeting {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--dark);
  animation: slideDown 0.5s ease;
}

.toolbar {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  font-size: 1.2rem;
  color: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  transform: scale(1.1);
  animation: glow 1s infinite;
}

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

/* === SEARCH & FILTERS === */
.search-filter-bar {
  margin-bottom: 1rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  animation: slideDown 0.6s ease;
}

.search-box {
  flex: 1;
  min-width: 200px;
  padding: 0.8rem 1.2rem;
  border: 2px solid var(--primary);
  border-radius: 20px;
  font-size: 1rem;
  background: white;
  font-family: inherit;
  transition: all 0.3s;
}

.search-box:focus {
  outline: none;
  border-color: var(--dark);
  box-shadow: 0 0 10px rgba(214, 48, 126, 0.2);
}

.filter-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  animation: slideDown 0.7s ease;
}

.tag-filter {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  border: 2px solid var(--primary);
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
  font-family: inherit;
}

.tag-filter:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.tag-filter.active {
  background: var(--dark);
  color: white;
  border-color: var(--dark);
}

/* === STATS PANEL === */
.stats-panel {
  background: white;
  padding: 1.5rem;
  border-radius: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  display: none;
}

.stats-panel.active {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  animation: slideDown 0.5s ease;
}

.stat-item {
  text-align: center;
  padding: 1rem;
  background: var(--light);
  border-radius: 12px;
  transition: transform 0.2s;
}

.stat-item:hover {
  transform: scale(1.05);
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--dark);
}

.stat-label {
  font-size: 0.9rem;
  color: var(--text);
  margin-top: 0.5rem;
}

/* === ENTRIES GRID === */
.entries-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.entry-card {
  background: white;
  padding: 1.2rem;
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: left;
  transition: all 0.3s;
  cursor: pointer;
  border-left: 4px solid var(--secondary);
  position: relative;
  animation: slideUp 0.4s ease;
}

.entry-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 30px rgba(235, 149, 197, 0.4);
}

.entry-card.pinned {
  border-left: 4px solid gold;
  background: linear-gradient(135deg, #fff9e6, white);
}

.entry-card .pin-badge {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  font-size: 1.2rem;
  animation: pulse 2s infinite;
}

.entry-card h3 {
  font-size: 1.1rem;
  color: var(--dark);
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.4;
}

.entry-card .date {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 0.5rem;
}

.entry-card .mood {
  font-size: 1.5rem;
  margin-bottom: 0.6rem;
}

.entry-tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.entry-tag {
  background: var(--primary);
  color: var(--dark);
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.entry-card p {
  color: #555;
  line-height: 1.5;
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-card-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 0.8rem;
}

/* === MODAL === */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  backdrop-filter: blur(5px);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.modal-content {
  background: white;
  margin: 5vh auto;
  width: 95%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 24px;
  padding: 2rem 1.5rem;
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  animation: slideUp 0.4s ease;
}

.small-modal {
  max-width: 400px;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.8rem;
  background: none;
  border: none;
  cursor: pointer;
  color: #aaa;
  transition: all 0.2s;
  z-index: 10;
}

.modal-close:hover {
  color: var(--dark);
  transform: scale(1.2);
}

.modal-content h2 {
  color: var(--dark);
  margin-bottom: 1.5rem;
  font-size: 1.4rem;
}

.modal-content input,
.modal-content textarea {
  width: 100%;
  padding: 1rem;
  border: 2px solid #f0e6f2;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 1rem;
  resize: none;
  transition: border-color 0.3s;
}

.modal-content input:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--dark);
}

.modal-content textarea {
  min-height: 180px;
  font-size: 1.05rem;
  line-height: 1.6;
}

/* === TAGS INPUT === */
.tags-input-container {
  margin-bottom: 1rem;
}

.tags-input-container label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

/* === MOOD SELECTOR === */
.mood-selector {
  margin: 1rem 0;
  text-align: center;
}

.mood-selector span {
  display: block;
  margin-bottom: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.moods {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.mood-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--light);
  font-size: 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mood-btn:hover {
  transform: scale(1.15);
  background: var(--primary);
}

.mood-btn.selected {
  transform: scale(1.2);
  background: var(--dark);
  box-shadow: 0 4px 15px rgba(214, 48, 126, 0.4);
}

/* === IMAGE UPLOAD === */
.image-upload-section {
  margin: 1rem 0;
}

.image-upload-label {
  display: block;
  padding: 1rem;
  background: var(--light);
  border: 2px dashed var(--primary);
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 600;
  color: var(--text);
}

.image-upload-label:hover {
  background: var(--primary);
  color: white;
}

.image-preview {
  margin-top: 1rem;
}

.image-preview img {
  width: 100%;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.image-preview button {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: #ff4444;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

/* === READ MODAL === */
.read-modal-content {
  max-width: 600px;
}

.entry-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.action-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.action-btn:hover {
  transform: scale(1.1);
}

.delete-btn {
  background: #ffcccc;
}

.delete-btn:hover {
  background: #ff4444;
}

.read-date {
  color: #aaa;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.read-mood {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.read-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.read-tags .entry-tag {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.read-image {
  margin-bottom: 1.5rem;
}

.read-image img {
  width: 100%;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.read-content {
  color: var(--text);
  line-height: 1.8;
  font-size: 1.05rem;
  white-space: pre-wrap;
}

/* === THEME SELECTOR === */
.theme-selector {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
}

.theme-option {
  background: white;
  border: 2px solid #eee;
  border-radius: 12px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
  font-family: inherit;
}

.theme-option:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--dark);
}

.theme-preview {
  width: 100%;
  height: 60px;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.theme-option span {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

/* === SETTINGS === */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.settings-btn {
  width: 100%;
  padding: 1rem;
  background: var(--light);
  border: 2px solid var(--primary);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  text-align: left;
  font-family: inherit;
  color: var(--text);
}

.settings-btn:hover {
  background: var(--primary);
  transform: translateX(5px);
}

.link-btn {
  text-decoration: none;
  color: var(--text);
  display: block;
}

.link-btn:hover {
  background: var(--dark);
  color: white;
}

.info-btn {
  cursor: default;
  background: #e8f5e9;
  border-color: #4caf50;
}

.info-btn:hover {
  transform: none;
  background: #e8f5e9;
}

.settings-divider {
  height: 1px;
  background: #eee;
  margin: 0.5rem 0;
}

.danger-btn {
  border-color: #ff4444;
  color: #ff4444;
}

.danger-btn:hover {
  background: #ff4444;
  color: white;
}

/* === ABOUT MODAL === */
.about-content {
  text-align: center;
  line-height: 1.6;
}

.about-content a {
  color: var(--dark);
  font-weight: bold;
  text-decoration: none;
}

.about-content a:hover {
  text-decoration: underline;
}

.about-content ul {
  list-style: none;
  padding: 0;
}

.about-content li {
  padding: 0.3rem 0;
}

.about-content li:before {
  content: "✨ ";
  margin-right: 0.5rem;
}

/* === CONNECTION INDICATOR === */
.connection-indicator {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  padding: 0.8rem 1.5rem;
  border-radius: 25px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.connection-indicator.show {
  opacity: 1;
  pointer-events: auto;
}

.connection-indicator.offline {
  background: #fff3cd;
  border: 2px solid #ffc107;
}

.connection-indicator.online {
  background: #d4edda;
  border: 2px solid #28a745;
}

#connection-text {
  font-weight: 600;
  font-size: 0.9rem;
}

/* === RESPONSIVE === */
@media (min-width: 768px) {
  .entries-grid {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }

  .modal-content {
    padding: 2.5rem;
  }

  #greeting {
    font-size: 1.8rem;
  }

  .logo {
    font-size: 3.5rem;
  }
}

@media (max-width: 480px) {
  .entries-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    justify-content: center;
  }

  .search-filter-bar {
    flex-direction: column;
  }

  .stats-panel.active {
    grid-template-columns: repeat(2, 1fr);
  }

  .moods {
    gap: 0.5rem;
  }

  .mood-btn {
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
  }
}

/* === SAFE AREA === */
@supports (padding: max(0px)) {
  body {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--light);
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--dark);
}

/* === LOADING ANIMATION === */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text);
  font-style: italic;
  animation: fadeIn 0.5s ease;
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* === DRAGGING === */
.dragging {
  opacity: 0.5;
}

.drag-over {
  border: 2px dashed var(--dark);
}