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

:root {
  --bg: #16130f;
  --card: #221d17;
  --card2: #2b241c;
  --text: #f0e9dd;
  --muted: #a89a86;
  --accent: #e8963f;
  --accent-dark: #b96f22;
  --danger: #d95f4c;
  --radius: 14px;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

.hidden { display: none !important; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* ---- Auth ---- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-box { width: 100%; max-width: 360px; text-align: center; }
.logo { font-size: 2rem; margin-bottom: 6px; }
.logo.small { font-size: 1.2rem; margin: 0; }
.tagline { color: var(--muted); margin-bottom: 24px; font-size: 0.95rem; }

input, textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid #3a3229;
  border-radius: var(--radius);
  color: var(--text);
  padding: 13px 14px;
  font-size: 1rem;
  margin-bottom: 10px;
  font-family: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--accent-dark); border-color: transparent; }

.btn {
  border: none;
  border-radius: var(--radius);
  background: var(--card2);
  color: var(--text);
  padding: 13px 18px;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
}
.btn.primary { background: var(--accent); color: #221604; font-weight: 700; }
.btn.primary:active { background: var(--accent-dark); }
.btn.danger { background: transparent; color: var(--danger); }

.link {
  background: none; border: none;
  color: var(--accent); cursor: pointer;
  font-size: 0.92rem; margin-top: 14px;
}
.error { color: var(--danger); font-size: 0.9rem; margin: 4px 0 10px; }
.hint { color: var(--muted); font-size: 0.82rem; margin: -4px 0 10px 4px; min-height: 1em; }

/* ---- Main layout ---- */
#main-screen { max-width: 640px; margin: 0 auto; padding: 0 14px 90px; }
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 2px 10px;
}
header .link { margin: 0; color: var(--muted); }

.searchbar input { margin-bottom: 4px; }

.tabs { display: flex; gap: 8px; margin: 10px 0 14px; }
.tab {
  flex: 1; border: none; cursor: pointer;
  background: var(--card); color: var(--muted);
  padding: 10px; border-radius: var(--radius); font-size: 0.95rem;
}
.tab.active { background: var(--accent); color: #221604; font-weight: 700; }

/* ---- Song cards ---- */
.song-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
}
.song-thumb {
  width: 54px; height: 54px; flex-shrink: 0;
  border-radius: 10px;
  background: var(--card2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  overflow: hidden;
}
.song-thumb img { width: 100%; height: 100%; object-fit: cover; }
.song-info { flex: 1; min-width: 0; }
.song-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-artist { color: var(--muted); font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-meta { color: var(--muted); font-size: 0.78rem; margin-top: 3px; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; line-height: 1.6; }

/* ---- Add button ---- */
#add-btn {
  position: fixed; right: 18px; bottom: 22px;
  width: 58px; height: 58px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--accent); color: #221604;
  font-size: 2rem; line-height: 1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

/* ---- Modals ---- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-card {
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  width: 100%; max-width: 640px;
  max-height: 88vh; overflow-y: auto;
}
.modal-card h2 { margin-bottom: 14px; font-size: 1.15rem; }
.row { display: flex; gap: 10px; margin-top: 6px; }

.photo-label {
  display: block;
  background: var(--card);
  border: 1px dashed #4a4034;
  border-radius: var(--radius);
  color: var(--muted);
  padding: 13px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: 0.95rem;
}
#photo-preview {
  width: 100%; max-height: 240px; object-fit: contain;
  border-radius: var(--radius); margin-bottom: 10px;
  background: var(--card);
}

/* ---- Detail ---- */
.detail-img {
  width: 100%; max-height: 45vh; object-fit: contain;
  border-radius: var(--radius); background: var(--card);
  cursor: zoom-in; margin-bottom: 12px;
}
.detail-artist { color: var(--muted); margin-bottom: 12px; }
.detail-notes {
  background: var(--card); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px;
  color: var(--text); font-size: 0.95rem; white-space: pre-wrap;
}
.detail-stats { color: var(--muted); font-size: 0.88rem; margin-bottom: 14px; }
.detail-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---- Fullscreen viewer ---- */
#img-viewer {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.95);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
#img-viewer img { max-width: 100%; max-height: 100%; }

/* ---- Small buttons / rows ---- */
.btn.small { width: auto; padding: 10px 12px; font-size: 0.9rem; white-space: nowrap; flex-shrink: 0; }
.yt-row { display: flex; gap: 8px; align-items: flex-start; }
.yt-row input { flex: 1; }
#photo-remove { margin: -4px 0 10px; display: block; color: var(--danger); }

/* ---- Video + chords in detail ---- */
.detail-video {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: #000; margin-bottom: 12px;
}
.detail-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.detail-chords {
  background: var(--card); border-radius: var(--radius);
  padding: 12px; margin-bottom: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem; line-height: 1.6; white-space: pre-wrap; color: var(--text);
  overflow-x: auto;
}

/* ---- Tuner ---- */
.tuner { text-align: center; padding: 10px 0 20px; }
.tuner-note-wrap { display: flex; align-items: baseline; justify-content: center; gap: 4px; margin: 10px 0; }
.tuner-note { font-size: 6rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; transition: color 0.15s; }
.tuner-note.ok { color: #6fcf7a; }
.tuner-octave { font-size: 1.6rem; color: var(--muted); }
.tuner-meter { margin: 16px 6px 8px; }
.tuner-scale {
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 0.75rem; margin-bottom: 6px; padding: 0 2px;
}
.tuner-scale .center { color: var(--text); font-weight: 700; }
.tuner-track {
  position: relative; height: 46px; border-radius: 12px;
  background: linear-gradient(90deg, var(--card) 0%, var(--card2) 50%, var(--card) 100%);
  overflow: hidden;
}
.tuner-center { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--muted); transform: translateX(-50%); }
.tuner-needle {
  position: absolute; top: 4px; bottom: 4px; width: 8px; border-radius: 4px;
  left: 50%; transform: translateX(-50%);
  background: var(--muted); transition: left 0.08s linear, background 0.15s;
}
.tuner-needle.ok { background: #6fcf7a; box-shadow: 0 0 14px #6fcf7a88; }
.tuner-needle.close { background: var(--accent); }
.tuner-needle.off { background: var(--danger); }
.tuner-readout { display: flex; justify-content: center; gap: 16px; color: var(--muted); font-size: 0.95rem; margin-bottom: 18px; }
.tuner-readout span:first-child { color: var(--text); font-weight: 700; min-width: 90px; text-align: right; }
.tuner-strings { display: flex; gap: 8px; justify-content: center; margin-bottom: 18px; }
.tuner-string {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--card); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.05rem; transition: all 0.15s;
}
.tuner-string small { font-size: 0.65rem; margin-left: 1px; }
.tuner-string.active { background: var(--accent); color: #221604; transform: scale(1.1); }
.tuner-status { color: var(--muted); font-size: 0.88rem; margin-bottom: 16px; min-height: 1.2em; }

/* ---- Sheet (letra con acordes) ---- */
textarea.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.85rem; white-space: pre; overflow-x: auto; }
.sheet-actions { margin: 0 0 6px; }
.sheet-actions .btn { flex: 1; }

#sheet-view {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.sheet-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 6px;
}
.sheet-bar .link { margin: 0; flex-shrink: 0; }
.sheet-bar-spacer { flex-shrink: 0; width: 72px; }
.sheet-title { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; }
.sheet-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-title span { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-tools {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 4px 10px 8px; flex-wrap: wrap;
}
.tool {
  border: none; cursor: pointer;
  background: var(--card); color: var(--text);
  border-radius: 10px; padding: 8px 12px; font-size: 0.95rem; min-width: 42px;
}
.tool.on { background: var(--accent); color: #221604; font-weight: 700; }
.tool-label { color: var(--accent); font-weight: 700; min-width: 28px; text-align: center; }
.tool-sep { width: 8px; }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px 14px calc(50vh) ;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px; line-height: 1.45;
  white-space: pre; overflow-x: auto;
}
.sh-chords { color: var(--accent); font-weight: 700; }
.sh-chords .ch { color: var(--accent); }
.sh-lyric { color: var(--text); }
.sh-section { color: var(--muted); font-weight: 700; margin-top: 0.6em; }
.sh-blank { height: 0.7em; }
.sheet-empty { color: var(--muted); text-align: center; padding: 40px 20px; white-space: normal; font-family: inherit; }

/* ---- Chord diagrams ---- */
.sh-chords .ch { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.sh-chords .ch:active { background: var(--accent); color: #221604; }
.chord-strip {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 12px 8px;
  border-bottom: 1px solid #2b241c; flex-shrink: 0;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chord-strip::-webkit-scrollbar { display: none; }
.chord-strip.hidden { display: none; }
.chord-chip {
  flex-shrink: 0; display: flex; flex-direction: column; align-items: center;
  background: var(--card); border-radius: 10px; padding: 4px 6px 2px; cursor: pointer;
  color: var(--text);
}
.chord-chip b { color: var(--accent); font-size: 0.85rem; line-height: 1; margin-bottom: 2px; }
.chord-chip .chord-svg { width: 58px; height: 70px; }
.chord-chip:active { background: var(--card2); }
.chord-card { text-align: center; }
.chord-head { display: flex; align-items: center; justify-content: space-between; }
.chord-head h2 { margin: 0; font-size: 1.8rem; color: var(--accent); }
.chord-head .link { margin: 0; font-size: 1.1rem; }
.chord-diagram { display: flex; justify-content: center; margin: 10px 0 6px; color: var(--text); }
.chord-diagram .chord-svg { width: 200px; height: 240px; }
.chord-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 8px; }
.chord-frets { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.15em; text-align: center; margin: 0 0 4px; }
.chord-card .hint { text-align: center; margin: 0 0 6px; }
#chord-modal { z-index: 60; }
