@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&family=DM+Sans:wght@300;400;500&display=swap');

:root {
  --bg: #0c1a14;
  --bg2: #111f18;
  --bg3: #172a1f;
  --surface: #1a2e22;
  --surface2: #1e3628;
  --border: #2a4035;
  --jade: #4a8c60;
  --jade-light: #6aad7d;
  --jade-dim: #2d5c3e;
  --amber: #c4a862;
  --amber-light: #dcc47a;
  --text: #e8e0d4;
  --text-dim: #8fa898;
  --text-muted: #4a6058;
  --red: #c45a5a;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 300;
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ---- LAYOUT ---- */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.view { display: none; flex-direction: column; flex: 1; padding-bottom: 80px; }
.view.active { display: flex; }

/* ---- NAV ---- */
#nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1; border: none; background: none; color: var(--text-muted);
  padding: 12px 4px 10px;
  cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  font-size: 10px; font-family: var(--font-body); letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.nav-btn svg { width: 22px; height: 22px; stroke-width: 1.5; }
.nav-btn.active { color: var(--jade-light); }
.nav-btn:active { opacity: 0.7; }

/* ---- HEADER ---- */
.page-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 300;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.page-subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 4px; }

/* ---- DASHBOARD ---- */
.dashboard-hero {
  padding: 32px 20px 24px;
  background: linear-gradient(160deg, var(--bg3) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.dashboard-hero::before {
  content: '';
  position: absolute; top: -40px; right: -30px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(74,140,96,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.hero-greeting {
  font-family: var(--font-display);
  font-size: 1.1rem; font-weight: 300; font-style: italic;
  color: var(--text-dim); margin-bottom: 6px;
}
.hero-title {
  font-family: var(--font-display);
  font-size: 2.8rem; font-weight: 300;
  line-height: 1.1; margin-bottom: 20px;
}
.hero-title span { color: var(--jade-light); }

.stats-row { display: flex; gap: 12px; margin-bottom: 24px; }
.stat-card {
  flex: 1; background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 300;
  color: var(--amber);
  line-height: 1;
}
.stat-label {
  font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
  margin-top: 4px;
}

.btn-start {
  width: 100%;
  background: var(--jade);
  color: #fff;
  border: none; border-radius: var(--radius);
  padding: 16px 24px;
  font-family: var(--font-display);
  font-size: 1.3rem; font-weight: 400; letter-spacing: 0.04em;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-start:active { background: var(--jade-light); transform: scale(0.98); }

.section { padding: 20px; }
.section-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-muted); margin-bottom: 14px;
}

.level-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 10px;
}
.level-badge {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--jade-dim);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 1.1rem;
  color: var(--jade-light); flex-shrink: 0;
}
.level-badge.locked { background: var(--surface2); color: var(--text-muted); }
.level-info { flex: 1; }
.level-name { font-weight: 500; font-size: 0.95rem; }
.level-desc { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }
.level-progress {
  height: 3px; background: var(--border);
  border-radius: 2px; margin-top: 8px; overflow: hidden;
}
.level-progress-fill {
  height: 100%; background: var(--jade);
  border-radius: 2px; transition: width 0.6s ease;
}

/* ---- SESSION SETUP ---- */
.setup-section { padding: 20px; }
.setup-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); margin-bottom: 12px;
}

.duration-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 6px;
}
.duration-btn {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px; text-align: center;
  cursor: pointer; transition: all var(--transition);
  color: var(--text);
}
.duration-btn .d-mins {
  font-family: var(--font-display); font-size: 1.6rem; font-weight: 300;
  line-height: 1; color: var(--amber);
}
.duration-btn .d-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 2px; }
.duration-btn.selected { border-color: var(--jade); background: var(--jade-dim); }
.duration-btn.selected .d-label { color: var(--jade-light); }

.playlist-select {
  width: 100%;
  background: var(--surface); border: 1.5px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 12px 16px; font-family: var(--font-body);
  font-size: 0.95rem; cursor: pointer;
  appearance: none; -webkit-appearance: none;
}
.select-wrapper { position: relative; }
.select-wrapper::after {
  content: '⌄'; position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%); pointer-events: none;
  color: var(--text-muted);
}

.btn-primary {
  background: var(--jade); color: #fff; border: none;
  border-radius: var(--radius); padding: 15px 24px;
  font-family: var(--font-body); font-size: 1rem; font-weight: 500;
  cursor: pointer; width: 100%;
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:active { background: var(--jade-light); transform: scale(0.98); }
.btn-primary:disabled { background: var(--surface2); color: var(--text-muted); cursor: not-allowed; }

.btn-secondary {
  background: transparent; color: var(--text-dim);
  border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 12px 20px;
  font-family: var(--font-body); font-size: 0.9rem;
  cursor: pointer; width: 100%;
  transition: border-color var(--transition), color var(--transition);
}
.btn-secondary:hover { border-color: var(--jade); color: var(--jade-light); }

/* ---- SESSION PLAYER ---- */
#view-session {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: none; flex-direction: column;
}
#view-session.active { display: flex; }

.session-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.session-phase {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--jade-light); font-weight: 500;
}
.session-overall-timer {
  font-family: var(--font-display); font-size: 1rem;
  color: var(--text-dim);
}
.btn-end-session {
  background: none; border: 1px solid var(--red);
  color: var(--red); border-radius: 6px; padding: 6px 12px;
  font-size: 0.8rem; cursor: pointer;
}

.session-progress-bar {
  height: 3px; background: var(--border);
}
.session-progress-fill {
  height: 100%; background: var(--jade);
  transition: width 1s linear;
}

.movement-area {
  flex: 1; display: flex; flex-direction: column;
  padding: 24px 20px 16px;
  overflow-y: auto;
}

.movement-image-area {
  width: 100%; aspect-ratio: 16/9; max-height: 220px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden; margin-bottom: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.movement-image-area img { width: 100%; height: 100%; object-fit: cover; }
.movement-image-placeholder {
  text-align: center; padding: 20px; color: var(--text-muted);
}
.movement-image-placeholder .placeholder-char {
  font-family: var(--font-display); font-size: 4rem;
  color: var(--jade-dim); display: block; line-height: 1;
}

.movement-chinese {
  font-family: var(--font-display); font-size: 0.9rem; font-style: italic;
  color: var(--jade-light); margin-bottom: 4px;
}
.movement-name {
  font-family: var(--font-display); font-size: 2rem; font-weight: 300;
  line-height: 1.2; margin-bottom: 10px;
}
.movement-description {
  font-size: 0.9rem; color: var(--text-dim); line-height: 1.6;
  margin-bottom: 16px;
}

.cue-list { list-style: none; }
.cue-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 0.88rem; color: var(--text-dim);
  transition: color var(--transition);
}
.cue-item.active { color: var(--text); }
.cue-item.done { color: var(--text-muted); }
.cue-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--border); margin-top: 7px; flex-shrink: 0;
  transition: background var(--transition);
}
.cue-item.active .cue-dot { background: var(--jade); }

.session-controls {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
}

.movement-timer {
  text-align: center; margin-bottom: 16px;
}
.timer-ring-wrap {
  display: flex; align-items: center; justify-content: center;
  gap: 20px;
}
.timer-digits {
  font-family: var(--font-display); font-size: 3rem; font-weight: 300;
  color: var(--amber); line-height: 1; min-width: 90px; text-align: center;
}
.timer-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); text-align: center; margin-top: 4px;
}

.controls-row { display: flex; align-items: center; justify-content: center; gap: 16px; }

.ctrl-btn {
  width: 52px; height: 52px; border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition);
  background: var(--surface); color: var(--text);
}
.ctrl-btn svg { width: 22px; height: 22px; }
.ctrl-btn.play-pause {
  width: 64px; height: 64px;
  background: var(--jade); color: #fff;
}
.ctrl-btn.play-pause:active { background: var(--jade-light); }
.ctrl-btn:active { opacity: 0.7; }

.music-mini {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  margin-bottom: 14px;
}
.music-mini-name { flex: 1; font-size: 0.82rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.music-mini-btn {
  background: none; border: none; color: var(--jade-light);
  cursor: pointer; padding: 2px;
  display: flex; align-items: center;
}
.music-mini-btn svg { width: 18px; height: 18px; }

/* ---- HISTORY ---- */
.history-empty {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted); font-family: var(--font-display);
  font-size: 1.2rem; font-style: italic;
}

.session-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
}
.session-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--jade); flex-shrink: 0;
}
.session-dot.incomplete { background: var(--text-muted); }
.session-info { flex: 1; }
.session-date { font-size: 0.82rem; color: var(--text-dim); }
.session-detail { font-size: 0.9rem; margin-top: 2px; }
.session-mins {
  font-family: var(--font-display); font-size: 1.1rem; color: var(--amber);
}

/* ---- MUSIC ---- */
.playlist-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.playlist-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.playlist-card-name { font-size: 1rem; font-weight: 500; }
.playlist-track-count { font-size: 0.78rem; color: var(--text-muted); }
.track-list { list-style: none; }
.track-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.track-item:last-child { border-bottom: none; }
.track-num { color: var(--text-muted); font-size: 0.75rem; width: 18px; text-align: right; flex-shrink: 0; }
.track-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px 4px; font-size: 1rem; }

.add-track-row {
  display: flex; gap: 8px; margin-top: 12px;
}
.add-track-row select {
  flex: 1;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font-body); font-size: 0.85rem;
}
.btn-small {
  background: var(--jade-dim); color: var(--jade-light);
  border: 1px solid var(--jade-dim);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: 0.85rem; cursor: pointer; white-space: nowrap;
}

.new-playlist-row {
  display: flex; gap: 10px; margin-bottom: 20px;
}
.input-text {
  flex: 1; background: var(--surface); border: 1.5px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 12px 14px; font-family: var(--font-body); font-size: 0.9rem;
}
.input-text:focus { outline: none; border-color: var(--jade); }
.input-text::placeholder { color: var(--text-muted); }

/* ---- SETTINGS ---- */
.settings-section { padding: 20px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; border-bottom: 1px solid var(--border);
}
.settings-label { font-size: 0.95rem; }
.settings-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* Toggle switch */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 12px;
  cursor: pointer; transition: background var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-muted); left: 3px; top: 3px;
  transition: transform var(--transition), background var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--jade); }
.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px); background: #fff;
}

.time-input {
  background: var(--surface); border: 1.5px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 8px 12px; font-family: var(--font-body); font-size: 0.95rem;
}
.time-input:focus { outline: none; border-color: var(--jade); }

.danger-btn {
  background: transparent; border: 1px solid var(--red);
  color: var(--red); border-radius: var(--radius-sm);
  padding: 10px 16px; cursor: pointer; font-size: 0.85rem;
}

/* ---- MODALS ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.75);
  display: none; align-items: flex-end; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: var(--bg2); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom, 24px));
  width: 100%; max-width: 500px;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-title {
  font-family: var(--font-display); font-size: 1.4rem; font-weight: 300;
  margin-bottom: 16px;
}

/* ---- TOAST ---- */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 24px;
  font-size: 0.85rem; opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 500; white-space: nowrap; pointer-events: none;
}
#toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ---- UTILITIES ---- */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.gap-10 { gap: 10px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 500;
}
.badge-jade { background: var(--jade-dim); color: var(--jade-light); }
.badge-amber { background: rgba(196,168,98,0.15); color: var(--amber-light); }
.badge-muted { background: var(--surface2); color: var(--text-muted); }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---- RESPONSIVE ---- */
@media (min-width: 480px) {
  .duration-grid { grid-template-columns: repeat(5, 1fr); }
  .movement-name { font-size: 2.4rem; }
}

@media (min-width: 768px) {
  #nav { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; }
  .view { max-width: 480px; margin: 0 auto; }
  #view-session { max-width: 480px; left: 50%; transform: translateX(-50%); }
}

/* ---- ANIMATIONS ---- */
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
