:root {
  --bg: #141210;
  --surface: #1e1b18;
  --surface-2: #28241f;
  --line: #36302a;
  --text: #f3ece4;
  --muted: #9c9187;
  --accent: #ff7a3d;
  --accent-soft: rgba(255, 122, 61, .14);
  --rec: #ff3d4f;
  --ok: #6cc48a;
  --warn: #e8b84a;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + var(--safe-b));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.page { max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  max-width: 720px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar .spacer { flex: 1; }
.brand { font-weight: 800; font-size: 26px; letter-spacing: -.02em; padding: 0 4px; }
.brand b { color: var(--accent); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; font-size: 20px; line-height: 1;
}
.saved { font-size: 13px; color: var(--muted); flex: 1; text-align: center; transition: opacity .3s; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px 16px calc(8px + var(--safe-b));
  background: rgba(20, 18, 16, .92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 200px; text-align: center; text-decoration: none;
  font-size: 12px; color: var(--muted); padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar a.active { color: var(--accent); }
.tabbar .ti { font-size: 20px; line-height: 1; }
body.in-idea .tabbar { display: none; }
body.in-idea { padding-bottom: 24px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px; border: 1px solid transparent;
  background: var(--accent); color: #1a0f08; font-weight: 700; text-decoration: none;
}
.btn.ghost { background: var(--surface-2); color: var(--text); border-color: var(--line); font-weight: 600; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.danger { background: transparent; color: #ff8a8a; border-color: #5a2a2a; }

/* ---------- Home ---------- */
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 16px; }
.hero-actions .btn { padding: 14px; border-radius: var(--radius); }
.hero-actions .btn.rec-now { background: var(--rec); color: #fff; }
.search {
  width: 100%; padding: 11px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); outline: none;
}
.search:focus { border-color: var(--accent); }
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 14px; }
.idea-card {
  display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.idea-card:active { transform: scale(.99); }
.idea-card h3 { margin: 0 0 4px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.idea-card .snippet { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idea-card .stats { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.semilla { background: var(--warn); }
.dot.proceso { background: var(--accent); }
.dot.demo { background: var(--ok); }
.empty {
  text-align: center; color: var(--muted); padding: 40px 16px;
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* ---------- Idea ---------- */
.idea-title {
  width: 100%; background: none; border: 0; outline: none;
  font-size: 28px; font-weight: 800; letter-spacing: -.02em; padding: 4px 0 10px;
}
.idea-title::placeholder { color: #5d544c; }
.meta { display: grid; grid-template-columns: 1.1fr 1.4fr .8fr; gap: 8px; }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field .row { display: flex; gap: 4px; }
.field select, .field input {
  width: 100%; min-width: 0; padding: 9px 8px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); font-size: 15px;
  text-transform: none; letter-spacing: 0; color: var(--text);
}
.jump { display: flex; gap: 6px; overflow-x: auto; margin: 14px -16px 4px; padding: 0 16px 4px; scrollbar-width: none; }
.jump::-webkit-scrollbar { display: none; }
.jump button {
  flex: none; padding: 6px 12px; border-radius: 999px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 16px; margin-top: 12px; scroll-margin-top: 70px;
}
.card h2 {
  margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  display: flex; align-items: center; justify-content: space-between;
}
textarea {
  width: 100%; min-height: 90px; resize: none; overflow: hidden;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; outline: none; line-height: 1.6;
}
textarea:focus, .rec-name:focus, .rec-note:focus { border-color: var(--accent); }
textarea.lyrics { min-height: 180px; font-size: 17px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; }
.diatonic { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: center; }
.diatonic small { color: var(--muted); width: 100%; font-size: 12px; }
.diatonic button {
  padding: 5px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line);
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px;
}
.diatonic button i { font-style: normal; color: var(--muted); font-size: 11px; margin-left: 4px; }

/* ---------- Recorder ---------- */
.recorder {
  display: flex; align-items: center; gap: 16px;
  padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line);
}
.rec-btn {
  width: 64px; height: 64px; flex: none; border-radius: 50%;
  border: 3px solid var(--text); background: transparent; display: grid; place-items: center; padding: 0;
}
.rec-btn span { width: 44px; height: 44px; border-radius: 50%; background: var(--rec); transition: all .2s; }
.recorder.on .rec-btn span { width: 24px; height: 24px; border-radius: 6px; }
.recorder.on { border-color: var(--rec); box-shadow: 0 0 0 4px rgba(255, 61, 79, .12); }
.rec-info { flex: 1; min-width: 0; }
.rec-time { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.recorder.on .rec-time { color: var(--rec); }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--warn) 70%, var(--rec)); transition: width .06s; }
.rec-hint { font-size: 13px; color: var(--muted); }

/* ---------- Recording items ---------- */
.filters { display: flex; gap: 6px; overflow-x: auto; margin: 12px 0 0; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.rec-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 12px; }
.rec-item { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.rec-head { display: flex; align-items: center; gap: 8px; }
.fav { background: none; border: 0; font-size: 20px; color: #5d544c; padding: 0 2px; line-height: 1; }
.fav.on { color: var(--warn); }
.rec-name {
  flex: 1; min-width: 0; background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 4px 6px; font-weight: 600; outline: none;
}
.rec-meta { flex: none; font-size: 12px; color: var(--muted); white-space: nowrap; }
.rec-note {
  width: 100%; margin-top: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: 14px; outline: none;
}
.rec-item audio { width: 100%; height: 40px; margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.chip {
  padding: 4px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip.add { border-style: dashed; }
.rec-item:not(.editing) .chip.tag:not(.on) { display: none; }
.rec-item:not(.editing) .tag-input { display: none; }
.rec-item.editing .chip.add { border-style: solid; color: var(--text); }
.tag-input {
  width: 120px; padding: 4px 10px; border-radius: 999px; font-size: 13px;
  background: var(--bg); border: 1px solid var(--line); outline: none;
}
.rec-actions { display: flex; justify-content: flex-end; gap: 14px; margin-top: 8px; font-size: 13px; }
.rec-actions a, .rec-actions button { background: none; border: 0; color: var(--muted); padding: 0; text-decoration: none; }
.rec-actions .del { color: #d07070; }
.muted-empty { color: var(--muted); font-size: 14px; padding: 10px 2px 0; }

/* ---------- Images ---------- */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-bottom: 12px; }
.img-grid:empty { display: none; }
.img-cell { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); }
.img-cell img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.img-cell button {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 14px; line-height: 1;
}
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .92);
  display: grid; place-items: center; padding: 20px; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.danger-zone { margin-top: 28px; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}
.toast[hidden] { display: none; }

.section-intro { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

@media (max-width: 420px) {
  .meta { grid-template-columns: 1fr 1fr; }
  .meta .field:first-child { grid-column: 1 / -1; }
}
