:root {
    --bg-dark: #0f0f0f; --bg-surface: #1c1c1e; --primary-orange: #f26130;
    --primary-hover: #d95325; --text-main: #ffffff; --text-muted: #a3a3a6;
    --gradient-top: #2c1a14; --transition-speed: 0.3s;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; -webkit-tap-highlight-color: transparent; }
body { background-color: var(--bg-dark); color: var(--text-main); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }
.active-view { animation: fadeIn var(--transition-speed) ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.scale-on-click:active { transform: scale(0.92); }
.shadow-hover { transition: transform var(--transition-speed), box-shadow var(--transition-speed); }
.shadow-hover:hover { transform: translateY(-5px); box-shadow: 0 15px 30px rgba(0,0,0,0.6); }

/* Inputs & Buttons */
.input-group input, .sleek-input { width: 100%; padding: 16px; margin-bottom: 15px; border-radius: 12px; border: 1px solid #333; background: var(--bg-dark); color: var(--text-main); font-size: 16px; outline: none; transition: border 0.2s; }
.input-group input:focus, .sleek-input:focus { border-color: var(--primary-orange); }
.primary-btn, .secondary-btn, .ghost-btn { width: 100%; padding: 14px; border-radius: 30px; font-size: 15px; font-weight: 600; cursor: pointer; border: none; transition: background 0.2s, transform 0.1s; margin-bottom: 10px; }
.primary-btn { background: var(--primary-orange); color: white; }
.primary-btn:hover { background: var(--primary-hover); }
.secondary-btn { background: transparent; color: var(--text-muted); border: 1px solid var(--text-muted); }
.secondary-btn:hover { background: rgba(255,255,255,0.05); color: white; }
.ghost-btn { background: transparent; color: var(--text-main); text-align: left; padding: 10px 15px; }
.ghost-btn:hover { background: rgba(255,255,255,0.05); }

/* Screens */
.gradient-bg { background: linear-gradient(180deg, var(--gradient-top) 0%, var(--bg-dark) 80%); }
#login-screen { display: flex; justify-content: center; align-items: center; height: 100vh; background: radial-gradient(circle at top, #2a1610 0%, var(--bg-dark) 70%); }
.login-container { background: var(--bg-surface); padding: 40px; border-radius: 24px; width: 90%; max-width: 400px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.5); }

/* Welcome Screen */
#welcome-screen { display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }
.welcome-content { flex-grow: 1; display: flex; flex-direction: column; align-items: center; padding: 20px; }
.welcome-actions { display: flex; gap: 15px; margin-top: 30px; width: 100%; max-width: 600px;}
.sessions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; width: 100%; max-width: 800px; }
.session-card { background: var(--bg-surface); border-radius: 16px; padding: 15px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; transition: transform 0.2s; border: 1px solid #333; position: relative;}
.session-card:hover { transform: translateY(-3px); border-color: var(--primary-orange); }
.sc-header { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); font-weight: bold;}
.sc-body { display: flex; gap: 15px; align-items: center; }
.sc-cover { width: 60px; height: 60px; background-size: contain; background-repeat: no-repeat; background-position: center; border-radius: 8px; background-color: #000; flex-shrink: 0;}
.sc-info h4 { font-size: 14px; margin-bottom: 5px; }
.sc-info p { font-size: 12px; color: var(--text-muted); }
.sc-delete { position: absolute; top: 10px; right: 10px; font-size: 14px; cursor: pointer; color: #ff4444; }

/* Sidebar & Profile */
#main-app { display: flex; height: 100vh; width: 100vw; position: relative; }
.sidebar { background-color: var(--bg-surface); width: 320px; height: 100vh; padding: 20px; display: flex; flex-direction: column; position: absolute; z-index: 100; left: 0; top: 0; transform: translateX(-100%); transition: transform var(--transition-speed) ease; box-shadow: 5px 0 20px rgba(0,0,0,0.5); }
.sidebar.open { transform: translateX(0); }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.profile-block { display: flex; align-items: center; gap: 15px; padding: 15px; background: rgba(255,255,255,0.05); border-radius: 12px; cursor: pointer; transition: background 0.2s; margin-top: 20px;}
.profile-block:hover { background: rgba(255,255,255,0.1); }
.profile-pic { width: 40px; height: 40px; border-radius: 50%; background: #333; display: flex; align-items: center; justify-content: center; overflow: hidden; font-size: 20px; background-size: cover; background-position: center;}
.mini-pic { width: 32px; height: 32px; font-size: 16px; }

/* Player UI Header - Centered Properly */
.player-area { flex-grow: 1; display: flex; flex-direction: column; }
.player-header { display: flex; justify-content: space-between; padding: 20px 30px; align-items: center; position: relative; }
.header-title { font-size: 14px; color: var(--text-muted); letter-spacing: 1px; position: absolute; left: 50%; transform: translateX(-50%); text-align: center; white-space: nowrap; }
.icon-btn { background: none; border: none; color: white; font-size: 24px; cursor: pointer; }

/* Listeners Dropdown */
.listeners-dropdown-container { position: relative; }
.active-listeners-top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-main); background: rgba(0,0,0,0.4); padding: 8px 14px; border-radius: 20px; cursor: pointer; border: 1px solid #333; }
.pulse-dot { width: 8px; height: 8px; background: #00ff66; border-radius: 50%; box-shadow: 0 0 8px #00ff66; }
.listeners-list { position: absolute; top: 110%; right: 0; background: var(--bg-surface); border-radius: 12px; padding: 10px; list-style: none; width: 150px; box-shadow: 0 10px 20px rgba(0,0,0,0.5); border: 1px solid #333; z-index: 50;}
.listeners-list li { padding: 8px; font-size: 13px; border-bottom: 1px solid #222; }

/* Safely pad bottom so phone UI doesn't clip */
.player-content { flex-grow: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 20px calc(30px + env(safe-area-inset-bottom, 10px)) 20px; }
.cover-art { width: 320px; height: 320px; background-color: var(--bg-dark); background-size: contain; background-repeat: no-repeat; background-position: center; border-radius: 8px; margin-bottom: 20px; display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 40px rgba(0,0,0,0.6); }
.cover-placeholder { color: var(--text-muted); font-weight: 600; text-align: center; padding: 20px;}
.track-info { text-align: center; margin-bottom: 30px; width: 100%; max-width: 400px; }
.track-info h2 { font-size: 26px; margin-bottom: 8px; line-height: 1.2;}

/* Modals */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.7); z-index: 200; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(5px); }
.modal-content { background: var(--bg-surface); width: 90%; max-width: 450px; border-radius: 20px; padding: 30px; box-shadow: 0 20px 50px rgba(0,0,0,0.8); }
.library-content { max-height: 80vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.file-upload-label { display: block; background: rgba(255,255,255,0.08); text-align: center; padding: 12px; border-radius: 12px; cursor: pointer; margin-bottom: 10px; font-size: 14px; border: 1px dashed var(--text-muted); }

/* Library List with Cover */
.book-list { list-style: none; }
.li-library-item { padding: 12px 15px; margin-bottom: 8px; background: rgba(255,255,255,0.03); border-radius: 8px; cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 15px; transition: background 0.2s; }
.li-library-item:hover { background: rgba(255,255,255,0.1); }
.li-cover { width: 40px; height: 40px; background-size: contain; background-position: center; background-repeat: no-repeat; border-radius: 4px; background-color: #000; flex-shrink:0; }
.li-info { flex-grow: 1; font-size: 14px; }
.edit-icon { opacity: 0.6; padding: 5px; } .edit-icon:hover { opacity: 1; }

/* Admin Panel Table */
.admin-table { display: flex; flex-direction: column; width: 100%; }
.admin-table-header { display: grid; grid-template-columns: 2fr 1.5fr 1fr 1fr; font-size: 12px; color: var(--text-muted); padding-bottom: 10px; border-bottom: 1px solid #333; margin-bottom: 10px; }
.admin-list { list-style: none; max-height: 350px; overflow-y: auto; }
.admin-row { display: grid; grid-template-columns: 2fr 1.5fr 1fr 1fr; align-items: center; padding: 10px 0; border-bottom: 1px solid #222; font-size: 14px; gap: 5px;}
.admin-row select { background: var(--bg-dark); color: white; border: 1px solid #444; border-radius: 4px; padding: 5px; outline: none; }
.admin-row input[type="checkbox"] { transform: scale(1.2); }

/* Sleep Timer */
.sleep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 15px; }

/* Progress Bar & Audio Controls */
.progress-section { width: 100%; max-width: 400px; margin-bottom: 20px; }
.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.mini-btn { font-size: 16px; color: var(--text-muted); font-weight: bold; }
.custom-slider { -webkit-appearance: none; width: 100%; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; outline: none; cursor: pointer; }
.custom-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #ffffff; cursor: pointer; box-shadow: 0 0 10px rgba(0,0,0,0.5); }
.time-display { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 10px; font-weight: 600;}

.controls { display: flex; align-items: center; justify-content: center; gap: 30px; margin-top: 10px; }
.control-btn { background: none; border: none; cursor: pointer; color: white; display: flex; align-items: center; justify-content: center; }
.secondary-control { color: var(--text-muted); transition: color 0.2s; }
.secondary-control:hover { color: white; }
.play-btn { width: 80px; height: 80px; background: #ffffff; color: #000; border-radius: 50%; box-shadow: 0 10px 25px rgba(0,0,0,0.4); transition: transform 0.1s; display: flex; align-items: center; justify-content: center; }

/* Add Book Upload Form */
.cover-upload-box { width: 200px; height: 200px; margin: 0 auto 20px auto; border: 2px dashed #555; border-radius: 12px; display: flex; justify-content: center; align-items: center; cursor: pointer; background-size: cover; background-position: center; background-repeat: no-repeat; position: relative; overflow: hidden; transition: all 0.2s ease; background-color: var(--bg-dark); }
.cover-upload-box:hover { border-color: var(--primary-orange); box-shadow: 0 10px 20px rgba(0,0,0,0.4); }
.cover-upload-box::after { content: "🖼️ Tap to edit"; position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.8); color: white; text-align: center; padding: 10px; font-size: 13px; font-weight: 600; opacity: 0; transition: opacity 0.2s; }
.cover-upload-box:hover::after { opacity: 1; }

.files-table-container { border: 2px solid #333; border-radius: 12px; overflow: hidden; background: var(--bg-surface); }
.files-table-header { display: grid; grid-template-columns: 3fr 2fr 1.5fr 40px; padding: 12px 15px; font-size: 12px; color: var(--text-muted); font-weight: bold; background: var(--bg-dark); border-bottom: 2px solid #333; }
.files-table-body { max-height: 200px; overflow-y: auto; }
.file-row { display: grid; grid-template-columns: 3fr 2fr 1.5fr 40px; padding: 12px 15px; font-size: 13px; border-bottom: 1px solid #333; align-items: center; }
.file-row:last-child { border-bottom: none; }
.file-row .ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 10px; }
.add-files-row-btn { width: 100%; padding: 12px; border: none; background: #333; color: var(--text-muted); font-weight: bold; cursor: pointer; transition: all 0.2s; text-align: center; }
.add-files-row-btn:hover { background: #444; color: white; }