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

:root {
  --primary:       #ff385c;
  --primary-light: #ff6b85;
  --accent:        #f7971e;
  --purple:        #7c3aed;
  --cyan:          #06b6d4;
  --green:         #10b981;
  --bg:            #f3f4f8;
  --card:          #ffffff;
  --text:          #1a1a2e;
  --text-2:        #6b7280;
  --radius:        14px;
  --radius-sm:     8px;
  --shadow:        0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.18);
  --search-h:      52px;
  --cat-h:         48px;
  --transition:    .28s cubic-bezier(.4,0,.2,1);
  /* Dynamic viewport and safe area variables (set by JS) */
  --vh:            1vh;
  --safe-top:      0px;
  --safe-bottom:   0px;
}

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  padding-top: 56px; /* Space for fixed top nav */
}

/* =========================================================
   TOP NAVIGATION BAR
   ========================================================= */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  z-index: 1000;
  padding-top: env(safe-area-inset-top);
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
  text-align: center;
}

/* =========================================================
   BANNER
   ========================================================= */
.banner {
  position: relative;
  width: 100%;
  height: 25vh;
  min-height: 200px;
  overflow: hidden;
  background: #1a1a2e;
}

.banner-track {
  display: flex;
  height: 100%;
  width: 100%;
  transition: transform .5s cubic-bezier(.4,0,.2,1);
  will-change: transform;
}

.banner-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.banner-slide::before {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  filter: brightness(.85);
}

.banner-slide-content { position: relative; z-index: 1; }

.banner-tag {
  display: inline-block;
  background: rgba(255,255,255,.22);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  font-size: .72rem;
  letter-spacing: .08em;
  padding: 3px 12px;
  border-radius: 20px;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.banner-title {
  color: #fff;
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 8px;
  text-shadow: 0 2px 12px rgba(0,0,0,.3);
}

.banner-sub {
  color: rgba(255,255,255,.85);
  font-size: .82rem;
  line-height: 1.5;
}

/* decorative circles */
.banner-slide .deco {
  position: absolute;
  border-radius: 50%;
  opacity: .18;
  pointer-events: none;
}
.banner-slide .deco-1 { width: 160px; height: 160px; background: #fff; top: -40px; right: -30px; }
.banner-slide .deco-2 { width: 100px; height: 100px; background: #fff; bottom: -20px; left: -20px; }

.banner-dots {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 2;
}

.banner-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.5);
  cursor: pointer;
  transition: var(--transition);
}
.banner-dot.active {
  width: 20px;
  border-radius: 3px;
  background: #fff;
}

/* =========================================================
   SEARCH BAR — stays in normal document flow
   ========================================================= */
.search-bar {
  position: relative;
  z-index: 100;
  padding: 8px 14px;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 16px rgba(0,0,0,.10);
}

.search-inner {
  display: flex;
  align-items: center;
  background: #f1f3f8;
  border-radius: 100px;
  padding: 0 14px;
  height: var(--search-h);
  gap: 8px;
  border: 1.5px solid transparent;
  transition: border-color .2s, background .2s;
}
.search-inner:focus-within {
  background: #fff;
  border-color: var(--primary);
}

.search-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-2); }

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: .95rem;
  color: var(--text);
}
.search-input::placeholder { color: #adb5bd; }

.search-clear {
  width: 22px; height: 22px;
  border: none; background: #d1d5db;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s;
  flex-shrink: 0;
}
.search-clear svg { width: 12px; height: 12px; color: #fff; }
.search-clear.show { opacity: 1; }

.search-btn {
  width: 32px; height: 32px;
  border: none;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 8px;
  transition: background .2s, transform .2s;
}
.search-btn svg { width: 16px; height: 16px; color: #fff; }
.search-btn:active {
  transform: scale(.95);
  background: #e0234e;
}

/* =========================================================
   CATEGORY FILTER BAR
   ========================================================= */
.category-section {
  display: flex;
  align-items: center;
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  position: sticky;
  top: 0;
  z-index: 90;
  transition: top var(--transition);
}


.category-scroll {
  display: flex;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
/* hide scrollbar */
.category-scroll::-webkit-scrollbar { display: none; }
.category-scroll { scrollbar-width: none; }

.cat-chip {
  flex-shrink: 0;
  padding: 6px 16px;
  border-radius: 100px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  color: var(--text-2);
  white-space: nowrap;
  transition: all .2s;
  user-select: none;
}
.cat-chip:active { transform: scale(.95); }
.cat-chip.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 12px rgba(255,56,92,.35);
}

.filter-toggle-btn {
  flex-shrink: 0;
  width: 40px; height: 40px;
  margin: 4px 10px 4px 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255,56,92,.4);
  transition: transform .15s;
}
.filter-toggle-btn:active { transform: scale(.92); }
.filter-toggle-btn svg { width: 18px; height: 18px; }

/* =========================================================
   NOTES WATERFALL GRID
   ========================================================= */
.notes-grid {
  padding: 12px 10px 8px;
  columns: 2;
  column-gap: 10px;
}

.note-card {
  break-inside: avoid;
  margin-bottom: 10px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  display: block;
  text-decoration: none;
  color: inherit;
}
.note-card:active { transform: scale(.97); box-shadow: var(--shadow-lg); }

.note-img-wrap {
  position: relative;
  width: 100%;
  overflow: hidden;
}
.note-img-wrap img {
  width: 100%;
  display: block;
  object-fit: cover;
  transition: transform .35s, opacity .4s;
}
.note-card:active .note-img-wrap img { transform: scale(1.04); }

/* Lazy image: fade in once loaded */
.note-img-wrap img.lazy-img { opacity: 0; }
.note-img-wrap img.lazy-img.loaded { opacity: 1; }

/* gradient shimmer placeholder while image loads */
.note-img-wrap .img-placeholder {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, #ececec 30%, #f5f5f5 50%, #ececec 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

.note-body { padding: 9px 10px 11px; }

.note-title {
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.note-cat-badge {
  font-size: .68rem;
  padding: 2px 8px;
  border-radius: 100px;
  font-weight: 600;
}

/* category badge colors */
.badge-study   { background: #ede9fe; color: #7c3aed; }
.badge-travel  { background: #d1fae5; color: #059669; }
.badge-food    { background: #fff7ed; color: #ea580c; }
.badge-fashion { background: #fce7f3; color: #db2777; }
.badge-tech    { background: #dbeafe; color: #2563eb; }
.badge-sports  { background: #fef3c7; color: #d97706; }
.badge-art     { background: #f0fdf4; color: #16a34a; }
.badge-all     { background: #f3f4f6; color: #6b7280; }

/* =========================================================
   LOAD MORE / SPINNER
   ========================================================= */
.load-sentinel {
  display: flex;
  justify-content: center;
  padding: 20px 0 10px;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.no-more {
  text-align: center;
  color: var(--text-2);
  font-size: .8rem;
  padding: 16px 0 32px;
}

/* =========================================================
   FLOATING LANGUAGE BUTTON
   ========================================================= */
.float-lang-btn {
  position: fixed;
  bottom: 20px;
  left: -22px; /* Half hidden: button width is 44px, so -22px hides half */
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 2px 2px 12px rgba(124,58,237,.4);
  transition: left .3s cubic-bezier(.4,0,.2,1), transform .18s, box-shadow .18s;
}

/* Show full button on hover/touch */
.float-lang-btn:hover {
  left: 16px;
  box-shadow: 0 4px 16px rgba(124,58,237,.5);
}

.float-lang-btn:active {
  transform: scale(.92);
}

.float-lang-btn svg {
  width: 18px;
  height: 18px;
  display: none; /* Hide icon, only show label */
}

.float-lang-label {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

/* Remove pulse ring animation for minimalist look */
.float-lang-btn::after {
  content: none;
}

/* =========================================================
   OVERLAY
   ========================================================= */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  backdrop-filter: blur(2px);
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* =========================================================
   FILTER DRAWER (right side)
   ========================================================= */
.filter-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 400;
  width: 82vw;
  max-width: 340px;
  background: var(--card);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .32s cubic-bezier(.4,0,.2,1);
  border-radius: var(--radius) 0 0 var(--radius);
  overflow: hidden;
}
.filter-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid #f0f0f5;
  background: linear-gradient(135deg, #fff5f7, #fff);
}
.drawer-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.drawer-close {
  width: 32px; height: 32px;
  border: none; background: #f3f4f8;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-2);
}
.drawer-close svg { width: 14px; height: 14px; }

.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; }

.filter-group { margin-bottom: 22px; }
.filter-group-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 10px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
}
.filter-chip {
  padding: 6px 14px;
  border-radius: 100px;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  color: var(--text-2);
  transition: all .18s;
  user-select: none;
}
.filter-chip:active { transform: scale(.95); }
.filter-chip.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,56,92,.3);
}

/* Smaller, lighter mapping range (映射关系) shown next to age name */
.filter-chip-sub {
  margin-left: 5px;
  font-size: .68rem;
  font-weight: 500;
  color: var(--text-2);
  opacity: .75;
}
.filter-chip.active .filter-chip-sub {
  color: #fff;
  opacity: .85;
}

.drawer-footer {
  display: flex; gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid #f0f0f5;
  background: #fff;
}

.btn-reset {
  flex: 1;
  padding: 13px;
  border-radius: 100px;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  transition: all .18s;
}
.btn-reset:active { background: #f3f4f8; }

.btn-apply {
  flex: 2;
  padding: 13px;
  border-radius: 100px;
  border: none;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  font-size: .9rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 14px rgba(255,56,92,.4);
  transition: transform .15s, box-shadow .15s;
}
.btn-apply:active { transform: scale(.97); box-shadow: none; }

/* =========================================================
   LANGUAGE / COUNTRY BOTTOM SHEET
   ========================================================= */
.lang-modal {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 400;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  max-height: 80vh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}
.lang-modal.open { transform: translateY(0); }

/* First-time language selection - always visible, can't close */
.lang-modal.first-time {
  z-index: 500;
}
.lang-modal.first-time .modal-close {
  display: none; /* Hide close button on first-time selection */
}
.lang-modal.first-time .modal-handle {
  display: none; /* Hide drag handle on first-time selection */
}

/* Welcome message for first-time users */
.lang-welcome {
  text-align: center;
  padding: 20px 20px 10px;
  border-bottom: 1px solid #f0f0f5;
}
.lang-welcome-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}
.lang-welcome-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.lang-welcome-subtitle {
  font-size: .85rem;
  color: var(--text-2);
  line-height: 1.5;
}

.modal-handle {
  width: 40px; height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid #f0f0f5;
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.modal-close {
  width: 32px; height: 32px;
  border: none; background: #f3f4f8;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-2);
}
.modal-close svg { width: 14px; height: 14px; }

.modal-body { flex: 1; overflow-y: auto; padding: 16px 18px 8px; }

.settings-group { margin-bottom: 24px; }
.settings-group-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 10px;
}

.settings-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.settings-option {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  transition: all .18s;
  user-select: none;
}
.settings-option:active { transform: scale(.97); }
.settings-option.active {
  border-color: var(--primary);
  background: #fff5f7;
  box-shadow: 0 0 0 3px rgba(255,56,92,.1);
}

.settings-option-flag { font-size: 1.4rem; flex-shrink: 0; }
.settings-option-text { display: flex; flex-direction: column; }
.settings-option-name { font-size: .82rem; font-weight: 600; color: var(--text); }
.settings-option-sub  { font-size: .7rem; color: var(--text-2); }
.settings-option-check {
  margin-left: auto;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all .18s;
}
.settings-option.active .settings-option-check {
  background: var(--primary);
  border-color: var(--primary);
}
.settings-option.active .settings-option-check::after {
  content: '';
  width: 6px; height: 4px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
  display: block;
}

.modal-footer {
  padding: 12px 18px 24px;
  border-top: 1px solid #f0f0f5;
}
.modal-footer .btn-apply { width: 100%; flex: none; }

/* =========================================================
   EMPTY STATE
   ========================================================= */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
}
.empty-state svg {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  color: #d1d5db;
  display: block;
}
.empty-state p { color: var(--text-2); font-size: .88rem; }

/* =========================================================
   FLOATING FEEDBACK BUTTON (bottom-right)
   ========================================================= */
.float-feedback-btn {
  position: fixed;
  bottom: 15px;
  right: 15px;
  z-index: 1000;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6b9d 0%, #c239b3 100%);
  border: none;
  box-shadow: 0 4px 20px rgba(255,107,157,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .24s, box-shadow .24s;
}
.float-feedback-btn svg {
  width: 24px;
  height: 24px;
  color: #fff;
}
.float-feedback-btn:active {
  transform: scale(.92);
  box-shadow: 0 2px 12px rgba(255,107,157,.3);
}

/* =========================================================
   FEEDBACK MODAL
   ========================================================= */
.feedback-modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.15);
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.4,0,.2,1);
  max-width: 600px;
  margin: 0 auto;
}
.feedback-modal[aria-hidden="false"] { transform: translateY(0); }

.feedback-textarea {
  width: 100%;
  padding: 12px;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  font-size: .88rem;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  transition: border-color .2s;
}
.feedback-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,56,92,.1);
}
.feedback-textarea::placeholder {
  color: var(--text-2);
}

/* =========================================================
   FEEDBACK TOAST
   ========================================================= */
.feedback-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(.8);
  z-index: 2000;
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  padding: 20px 32px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.feedback-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.feedback-toast-emoji {
  font-size: 2.5rem;
  line-height: 1;
}
.feedback-toast-text {
  font-size: .9rem;
  white-space: nowrap;
}

/* =========================================================
   MISC UTILITIES
   ========================================================= */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Safe area bottom padding */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .drawer-footer,
  .modal-footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}
