:root {
  --bg: #f3f4f6; --card: #ffffff; --primary: #4f46e5; --primary-light: #e0e7ff;
  --danger: #ef4444; --danger-bg: #fef2f2; --text: #1f2937; --text-secondary: #6b7280;
  --border: #e5e7eb; --speaker1: #3b82f6; --speaker2: #10b981; --speaker3: #f59e0b;
  --translate: #8b5cf6; --translate-light: #ede9fe;
  --music: #f59e0b; --music-light: #fef3c7;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100dvh;
  overflow-x: hidden; -webkit-font-smoothing: antialiased;
}

/* NAV */
#nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 8px;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
#nav h1 { flex: 1; font-size: 20px; font-weight: 700; }
#nav-right { display: flex; gap: 4px; }
.nav-btn {
  background: none; border: none; color: var(--text); cursor: pointer;
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; transition: background .15s;
}
.nav-btn:active { background: var(--bg); }

/* SEARCH */
#search-bar { padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border); }
#search-input {
  width: 100%; padding: 12px 16px; border: 1px solid var(--border);
  border-radius: 12px; font-size: 16px; background: var(--bg); outline: none;
}
#search-input:focus { border-color: var(--primary); }

/* VIEWS */
.view { display: none; padding: 20px; padding-bottom: calc(32px + var(--safe-bottom)); }
.view.active { display: block; }

/* RECORDING INDICATOR */
#recording-indicator {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 20px; margin-bottom: 20px;
  background: var(--danger-bg); border: 1px solid #fecaca;
  border-radius: var(--radius); font-size: 16px; font-weight: 600; color: var(--danger);
}
.red-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s ease-in-out infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.2; } }
#rec-timer { font-variant-numeric: tabular-nums; margin-left: auto; font-size: 18px; font-weight: 700; }

/* IDLE PROMPT */
#idle-prompt { margin-bottom: 20px; }

/* MODE TOGGLE */
.mode-toggle { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; }
.mode-btn {
  flex: 1; padding: 10px 6px; border: none; background: none; border-radius: 10px;
  font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer; transition: all .2s;
}
.mode-btn.active { background: var(--card); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.mode-btn[data-mode="translate"].active { color: var(--translate); }
.mode-btn[data-mode="music"].active { color: var(--music); }

/* WAVEFORM */
.waveform-wrap {
  background: var(--card); border-radius: var(--radius); padding: 24px 20px;
  margin-bottom: 28px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  transition: border-color .3s, box-shadow .3s; border: 2px solid transparent;
}
.waveform-wrap.is-recording { border-color: #fca5a5; box-shadow: 0 0 0 4px rgba(239,68,68,.08), 0 2px 8px rgba(239,68,68,.12); }
.waveform-wrap.is-translating { border-color: #c4b5fd; box-shadow: 0 0 0 4px rgba(139,92,246,.08), 0 2px 8px rgba(139,92,246,.12); }
.waveform-wrap.is-music { border-color: #fcd34d; box-shadow: 0 0 0 4px rgba(245,158,11,.08), 0 2px 8px rgba(245,158,11,.12); }
#waveform { width: 100%; height: 110px; display: block; }

/* RECORD BUTTON */
#record-btn {
  display: flex; align-items: center; justify-content: center;
  width: 88px; height: 88px; border-radius: 50%; border: none;
  background: var(--danger); color: white; cursor: pointer;
  margin: 0 auto 20px; box-shadow: 0 4px 20px rgba(239,68,68,.4);
  transition: transform .15s, box-shadow .15s, width .2s, height .2s, border-radius .2s, background .2s;
  position: relative;
}
#record-btn.translate-mode { background: var(--translate); box-shadow: 0 4px 20px rgba(139,92,246,.4); }
#record-btn.music-mode { background: var(--music); box-shadow: 0 4px 20px rgba(245,158,11,.4); }
#record-btn:active { transform: scale(0.93); }
#record-btn.recording { width: 72px; height: 72px; border-radius: 20px; animation: pulse 1.5s infinite; }
#record-btn.translate-mode.recording { animation: pulse-t 1.5s infinite; }
#record-btn.music-mode.recording { animation: pulse-m 1.5s infinite; }
#record-btn.recording .rec-icon { width: 24px; height: 24px; border-radius: 5px; }
.rec-icon { width: 32px; height: 32px; border-radius: 50%; background: white; transition: all .2s; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); } 50% { box-shadow: 0 0 0 20px rgba(239,68,68,0); } }
@keyframes pulse-t { 0%,100% { box-shadow: 0 0 0 0 rgba(139,92,246,.5); } 50% { box-shadow: 0 0 0 20px rgba(139,92,246,0); } }
@keyframes pulse-m { 0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.5); } 50% { box-shadow: 0 0 0 20px rgba(245,158,11,0); } }

#status-text { text-align: center; font-size: 15px; color: var(--text-secondary); margin-bottom: 20px; min-height: 22px; }

/* STOP & SAVE */
.btn-stop {
  display: block; width: 100%; padding: 18px; margin-bottom: 20px;
  background: var(--danger); color: white; border: none;
  border-radius: var(--radius); font-size: 18px; font-weight: 700;
  cursor: pointer; box-shadow: 0 4px 15px rgba(239,68,68,.3);
}
.btn-stop:active { opacity: .85; transform: scale(0.98); }

/* LANGUAGE INDICATOR */
#language-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; margin-bottom: 12px;
  background: var(--translate-light); border: 1px solid #c4b5fd;
  border-radius: var(--radius); font-size: 14px; font-weight: 600; color: var(--translate);
}
.lang-icon {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--translate); color: white; font-size: 14px; font-weight: 700; flex-shrink: 0;
}

/* TRANSCRIPT */
#transcript-area {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  max-height: 400px; overflow-y: auto; box-shadow: 0 1px 3px rgba(0,0,0,.05); margin-bottom: 20px;
}
#transcript-content { font-size: 18px; line-height: 1.7; white-space: pre-wrap; }
.speaker-1 { color: var(--speaker1); font-weight: 600; }
.speaker-2 { color: var(--speaker2); font-weight: 600; }
.speaker-3 { color: var(--speaker3); font-weight: 600; }

/* SAVE BAR */
#save-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text-secondary); cursor: pointer; }
.toggle-label input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
.btn-primary {
  padding: 14px 32px; background: var(--primary); color: white;
  border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn-primary:active { opacity: .8; }
.btn-danger { padding: 10px 18px; background: none; color: var(--danger); border: 1px solid var(--danger); border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }

/* FOLDER TABS */
.folder-tabs {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 16px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.folder-tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 16px; border: 1px solid var(--border); border-radius: 22px;
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: all .2s; background: var(--card); color: var(--text-secondary);
}
.tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.tab[data-folder="Translations"].active { background: var(--translate); border-color: var(--translate); }
.tab[data-folder="Music"].active { background: var(--music); border-color: var(--music); }

/* NOTE CARDS */
#notes-list { display: flex; flex-direction: column; gap: 12px; }
.note-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  cursor: pointer; transition: transform .1s; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  border: 1px solid var(--border);
}
.note-card:active { transform: scale(0.98); }
.note-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; line-height: 1.3; }
.note-card .meta { font-size: 13px; color: var(--text-secondary); display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.note-card .preview { font-size: 14px; color: var(--text-secondary); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.folder-badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 10px;
  font-size: 12px; background: var(--primary-light); color: var(--primary); font-weight: 600;
}
.lang-badge {
  display: inline-flex; padding: 3px 10px; border-radius: 10px;
  font-size: 12px; background: var(--translate-light); color: var(--translate); font-weight: 600;
}
.audio-badge {
  display: inline-flex; padding: 3px 10px; border-radius: 10px;
  font-size: 12px; background: #dbeafe; color: #2563eb; font-weight: 600;
}
.music-badge {
  display: inline-flex; padding: 3px 10px; border-radius: 10px;
  font-size: 12px; background: var(--music-light); color: #b45309; font-weight: 600;
}

/* AUDIO PLAYER */
#audio-player {
  background: var(--card); border-radius: var(--radius); padding: 14px 18px;
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.05); border: 1px solid var(--border);
}
.player-controls { display: flex; align-items: center; gap: 12px; }
.player-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--primary); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.player-btn:active { opacity: .8; }
#audio-progress-wrap {
  flex: 1; height: 6px; background: var(--border); border-radius: 3px;
  cursor: pointer; position: relative;
}
#audio-progress-bar { height: 100%; background: var(--primary); border-radius: 3px; width: 0; transition: width .1s; }
#audio-time, #audio-duration { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; min-width: 32px; }
.audio-sep { font-size: 13px; color: var(--border); }

/* TERRAIN MAP */
#terrain-wrap {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.05); border: 1px solid var(--border);
}
#flow-legend {
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center;
  padding: 10px 16px; font-size: 12px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border); background: #fefce8;
}
#flow-legend strong { color: var(--text); font-size: 13px; }
#terrain-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
#terrain-canvas { display: block; }

/* LYRICS */
#lyrics-panel {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  font-size: 18px; line-height: 2; border: 1px solid var(--border);
}
.lyric-word {
  display: inline; padding: 2px 4px; border-radius: 6px;
  cursor: pointer; transition: background .15s, color .15s;
}
.lyric-word:hover { background: var(--bg); }
.lyric-word.active {
  background: var(--primary-light); color: var(--primary); font-weight: 700;
}

/* NOTE DETAIL */
#note-header { margin-bottom: 16px; }
#note-title { font-size: 24px; font-weight: 700; line-height: 1.3; }
#note-meta { font-size: 14px; color: var(--text-secondary); margin-top: 8px; }
#note-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
#note-body {
  font-size: 18px; line-height: 1.8; white-space: pre-wrap;
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

/* EMPTY STATE */
#empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); font-size: 16px; }

/* LOADING */
#loading {
  position: fixed; inset: 0; background: rgba(255,255,255,.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 200; backdrop-filter: blur(4px);
}
.spinner {
  width: 44px; height: 44px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .7s linear infinite; margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-size: 15px; color: var(--text-secondary); }

/* OFFLINE BANNER */
#offline-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fbbf24; color: #78350f; text-align: center;
  padding: 12px; font-size: 14px; font-weight: 600; z-index: 150;
}

.hidden { display: none !important; }

@media (min-width: 600px) {
  .view { max-width: 580px; margin: 0 auto; }
  #record-btn { width: 96px; height: 96px; }
  #record-btn.recording { width: 80px; height: 80px; }
}
