:root {
  --bg: #ffffff;
  --bg2: #f7f7f7;
  --bg3: #efefef;
  --text: #111111;
  --text2: #555555;
  --text3: #888888;
  --border: #e0e0e0;
  --accent: #111111;
  --accent-text: #ffffff;
  --card-bg: #ffffff;
  --input-bg: #f7f7f7;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --modal-bg: rgba(0,0,0,0.4);
}

[data-theme="dark"] {
  --bg: #111111;
  --bg2: #1a1a1a;
  --bg3: #222222;
  --text: #f0f0f0;
  --text2: #aaaaaa;
  --text3: #666666;
  --border: #2a2a2a;
  --accent: #f0f0f0;
  --accent-text: #111111;
  --card-bg: #1a1a1a;
  --input-bg: #222222;
  --shadow: 0 1px 4px rgba(0,0,0,0.4);
  --modal-bg: rgba(0,0,0,0.7);
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  min-height: 100vh;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo { font-size: 1rem; font-weight: 600; }
.nav-right { display: flex; align-items: center; gap: 0.5rem; }

.nav-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  transition: background 0.2s;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }

.theme-toggle {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
}

.hero {
  max-width: 600px;
  margin: 6rem auto 4rem;
  padding: 0 2rem;
  text-align: center;
}

.hero h1 {
  font-family: 'Lora', serif;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 400;
  line-height: 1.3;
  margin-bottom: 1rem;
}

.hero p { color: var(--text2); font-size: 1rem; line-height: 1.6; margin-bottom: 2rem; }
.hero-actions { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 0.7rem 1.6rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.75; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary.full { width: 100%; padding: 0.9rem; margin-top: 0.5rem; }

.btn-secondary {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.7rem 1.6rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--bg3); }

.btn-danger {
  background: none;
  color: #e05252;
  border: 1px solid #e0525244;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-danger:hover { background: #e0525215; }

.preview-section { padding: 2rem 0 3rem; border-top: 1px solid var(--border); }

.section-label {
  text-align: center;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text3);
  margin-bottom: 1.5rem;
}

.ticker-wrapper { overflow: hidden; width: 100%; }

.ticker {
  display: flex;
  gap: 1rem;
  animation: scroll 35s linear infinite;
  width: max-content;
  padding: 0.5rem 1rem;
}
.ticker:hover { animation-play-state: paused; }

@keyframes scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.letter-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  width: 220px;
  min-height: 140px;
  flex-shrink: 0;
  position: relative;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.letter-card:hover { border-color: var(--text3); transform: translateY(-3px); }

.card-to { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); margin-bottom: 0.5rem; }

.card-msg {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text2);
  line-height: 1.6;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-from { font-size: 0.68rem; color: var(--text3); margin-top: 0.6rem; }

.card-spotify-mini {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}
.card-spotify-mini img { width: 28px; height: 28px; border-radius: 4px; flex-shrink: 0; object-fit: cover; }
.card-spotify-text { overflow: hidden; }
.card-spotify-title { font-size: 0.68rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-spotify-artist { font-size: 0.62rem; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section { padding: 4rem 2rem; display: flex; justify-content: center; border-top: 1px solid var(--border); }
.hidden { display: none !important; }

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

.form-container h2 {
  font-family: 'Lora', serif;
  font-weight: 400;
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
}

.form-desc { color: var(--text3); font-size: 0.875rem; margin-bottom: 2rem; }
.form-group { margin-bottom: 1.2rem; }

.form-group label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text2); margin-bottom: 0.4rem; }
.optional { color: var(--text3); font-weight: 400; }
.required { color: #e05252; }
.hint { display: block; font-size: 0.75rem; color: var(--text3); margin-top: 0.3rem; }

input, textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}
input:focus, textarea:focus { border-color: var(--text2); }

.spotify-search-row { position: relative; display: flex; align-items: center; }
.spotify-search-row input { padding-right: 2.5rem; }
.spotify-icon { position: absolute; right: 0.8rem; font-size: 1rem; pointer-events: none; }

.spotify-dropdown {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 0.4rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.spotify-item { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 1rem; cursor: pointer; transition: background 0.15s; }
.spotify-item:hover { background: var(--bg3); }
.spotify-item img { width: 40px; height: 40px; border-radius: 4px; object-fit: cover; flex-shrink: 0; }
.spotify-item-info { overflow: hidden; }
.spotify-item-name { font-size: 0.88rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spotify-item-artist { font-size: 0.78rem; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.spotify-selected { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.6rem; padding: 0.7rem 1rem; background: var(--bg3); border-radius: 8px; border: 1px solid var(--border); }
.spotify-selected img { width: 40px; height: 40px; border-radius: 4px; object-fit: cover; flex-shrink: 0; }
.sel-info { flex: 1; overflow: hidden; }
.sel-info span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sel-name { font-size: 0.88rem; font-weight: 500; color: var(--text); }
#sel-artist { font-size: 0.78rem; color: var(--text3); }
.sel-remove { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 0.9rem; padding: 0.2rem 0.4rem; border-radius: 4px; }
.sel-remove:hover { background: var(--border); }

#send-status { margin-top: 0.8rem; font-size: 0.875rem; text-align: center; padding: 0.6rem; border-radius: 6px; }
#send-status.success { background: #e8f5e9; color: #2e7d32; }
#send-status.error { background: #fdecea; color: #c62828; }
[data-theme="dark"] #send-status.success { background: #1a2e1a; color: #81c784; }
[data-theme="dark"] #send-status.error { background: #2e1a1a; color: #ef9a9a; }

.search-row { display: flex; gap: 0.6rem; }
.search-row input { flex: 1; }

.result-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  margin-top: 1rem;
  background: var(--card-bg);
  cursor: pointer;
  transition: border-color 0.2s;
}
.result-card:hover { border-color: var(--text3); }

.result-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.6rem; }
.result-from { font-size: 0.75rem; color: var(--text3); }

.result-msg {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-spotify {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.8rem;
  padding: 0.7rem;
  background: var(--bg3);
  border-radius: 8px;
}
.result-spotify img { width: 36px; height: 36px; border-radius: 4px; object-fit: cover; }
.result-spotify-info { overflow: hidden; }
.result-spotify-name { font-size: 0.82rem; font-weight: 500; color: var(--text); display: block; }
.result-spotify-artist { font-size: 0.75rem; color: var(--text3); display: block; }

.no-result { text-align: center; color: var(--text3); font-style: italic; padding: 2rem 0; font-size: 0.9rem; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}

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

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg3);
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  color: var(--text2);
  font-size: 0.9rem;
}
.modal-close:hover { color: var(--text); }

.modal h3 { font-family: 'Lora', serif; font-weight: 400; font-size: 1.3rem; margin-bottom: 0.3rem; }

.modal-to { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text3); margin-bottom: 1rem; }

.modal-msg {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.8;
  margin-bottom: 1.2rem;
  white-space: pre-wrap;
}

.modal-meta { font-size: 0.78rem; color: var(--text3); margin-bottom: 1rem; }

.modal-spotify {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem;
  background: var(--bg3);
  border-radius: 8px;
  text-decoration: none;
  margin-bottom: 1rem;
}
.modal-spotify:hover { opacity: 0.8; }
.modal-spotify img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; }
.modal-spotify-info span { display: block; }
.modal-spotify-name { font-size: 0.9rem; font-weight: 500; color: var(--text); }
.modal-spotify-artist { font-size: 0.8rem; color: var(--text3); }

.modal-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

#delete-status { margin-top: 0.8rem; font-size: 0.875rem; text-align: center; padding: 0.5rem; border-radius: 6px; }
#delete-status.error { background: #fdecea; color: #c62828; }
[data-theme="dark"] #delete-status.error { background: #2e1a1a; color: #ef9a9a; }
