/* ================================================================
   KRIAT HATORAH · Parchment & Ink · Édition Sacrée
   ================================================================ */

/* --- TOKENS --- */
:root {
    /* Palette Parchemin */
    --cream-50:  #FDFAF5;
    --cream-100: #F7F2E8;
    --cream-200: #EEE6D8;
    --cream-300: #E1D6C6;
    --cream-400: #CEBFAB;
    --stone:     #B0A494;

    /* Encre */
    --ink-900: #12100D;
    --ink-800: #1E1B17;
    --ink-700: #2E2924;
    --ink-600: #4A4238;
    --ink-500: #6B5F55;
    --ink-400: #8E8177;
    --ink-300: #B3A89F;

    /* Terracotta / Sienna — accent principal */
    --sienna:      #B5461A;
    --sienna-dark: #8A340F;
    --sienna-mid:  #CE5E30;
    --sienna-pale: rgba(181, 70, 26, 0.10);
    --sienna-glow: rgba(181, 70, 26, 0.22);

    /* Or ancien */
    --gold:        #8F7020;
    --gold-light:  #B99434;
    --gold-pale:   rgba(143, 112, 32, 0.12);

    /* Sémantique */
    --bg:            var(--cream-100);
    --bg-card:       #FFFFFF;
    --bg-surface:    var(--cream-200);

    --text-primary:   var(--ink-900);
    --text-secondary: var(--ink-600);
    --text-muted:     var(--ink-400);

    --border:        rgba(18, 16, 13, 0.08);
    --border-med:    rgba(18, 16, 13, 0.15);
    --border-strong: rgba(18, 16, 13, 0.28);

    /* Couleurs des 5 livres */
    --book-1: #1B3A5C;   /* Berechit  — bleu nuit */
    --book-2: #B5461A;   /* Shemot    — terracotta */
    --book-3: #2D5A3D;   /* Vayikra   — forêt     */
    --book-4: #7A5C18;   /* Bamidbar  — or        */
    --book-5: #4A2B6A;   /* Devarim   — prune     */

    /* Forme & mouvement */
    --radius-xs:   4px;
    --radius-sm:   8px;
    --radius-md:   12px;
    --radius-lg:   18px;
    --radius-xl:   24px;
    --radius-full: 999px;

    --ease:   cubic-bezier(0.16, 1, 0.3, 1);
    --fast:   0.16s var(--ease);
    --normal: 0.30s var(--ease);
    --slow:   0.50s var(--ease);
}

/* --- MODE SOMBRE --- */
html[data-theme="dark"] {
    --cream-50:  #18140F;
    --cream-100: #1E1A14;
    --cream-200: #26211A;
    --cream-300: #302B22;
    --cream-400: #3D3730;
    --stone:     #5C5248;

    --ink-300: #B5A89E;
    --ink-400: #8A7E74;

    --bg:         #18140F;
    --bg-card:    #211D17;
    --bg-surface: #28231C;

    --text-primary:   #EDE7DC;
    --text-secondary: #A89C90;
    --text-muted:     #736860;

    --border:        rgba(237, 231, 220, 0.07);
    --border-med:    rgba(237, 231, 220, 0.13);
    --border-strong: rgba(237, 231, 220, 0.24);

    --sienna-pale: rgba(206, 94, 48, 0.13);
    --sienna-glow: rgba(206, 94, 48, 0.28);
}

/* En mode sombre, le grain passe en screen pour ne pas assombrir davantage */
html[data-theme="dark"] body::after {
    mix-blend-mode: screen;
    opacity: 0.04;
}

/* Transition douce entre les modes */
html {
    transition: background-color 0.3s ease, color 0.3s ease;
}

body,
.player-bar,
.book-card,
.search-bar,
summary,
.aliya-grid button {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: 110px;
}

/* Grain texture subtil */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    opacity: 0.028;
    pointer-events: none;
    z-index: 9000;
    mix-blend-mode: multiply;
}

/* --- ACCENT TOP BAR --- */
.top-accent {
    height: 3px;
    background: var(--sienna);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1002;
}

/* --- HEADER --- */
header {
    background: var(--cream-50);
    border-bottom: 1px solid var(--border-med);
    padding: 72px 24px 52px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

/* Grand texte hébreu en filigrane */
.header-bg-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(140px, 28vw, 260px);
    font-weight: 700;
    color: var(--text-primary);
    opacity: 0.055;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    z-index: 0;
    letter-spacing: -0.02em;
}

html[data-theme="dark"] .header-bg-text {
    opacity: 0.1;
}

.header-inner {
    position: relative;
    z-index: 1;
}

/* Ornement horizontal */
.header-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-bottom: 22px;
}

.header-ornament::before,
.header-ornament::after {
    content: '';
    height: 1px;
    width: 52px;
}

.header-ornament::before {
    background: linear-gradient(to right, transparent, var(--sienna));
}

.header-ornament::after {
    background: linear-gradient(to left, transparent, var(--sienna));
}

.header-ornament-symbol {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--sienna);
    letter-spacing: 4px;
    text-transform: uppercase;
    opacity: 0.75;
}

header h1 {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(2.2rem, 6vw, 4rem);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-primary);
    margin-bottom: 10px;
    line-height: 1.1;
}

.header-subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.25rem;
    font-weight: 400;
    font-style: italic;
    color: var(--sienna);
    margin-bottom: 6px;
}

.header-tagline {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--ink-400);
    letter-spacing: 3.5px;
    text-transform: uppercase;
    margin-top: 2px;
}

/* Bouton toggle thème */
.theme-toggle {
    position: absolute;
    top: 18px;
    right: 20px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-med);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    transition: all var(--fast);
    z-index: 2;
    box-shadow: 0 2px 8px rgba(18, 16, 13, 0.1);
}

.theme-toggle:hover {
    border-color: var(--sienna);
    color: var(--sienna);
    transform: rotate(20deg);
    box-shadow: 0 2px 10px var(--sienna-glow);
}

/* Petite barre au bas du header */
header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 48px;
    height: 2px;
    background: var(--sienna);
}

/* --- SEARCH BAR --- */
.search-wrapper {
    max-width: 620px;
    margin: 36px auto 0;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-med);
    border-radius: var(--radius-sm);
    padding: 11px 20px;
    box-shadow: 0 2px 10px rgba(18, 16, 13, 0.06), 0 0 0 0px var(--sienna-pale);
    transition: border-color var(--fast), box-shadow var(--fast);
}

.search-bar:focus-within {
    border-color: var(--sienna);
    box-shadow: 0 2px 10px rgba(18, 16, 13, 0.06), 0 0 0 3px var(--sienna-pale);
}

.search-icon {
    color: var(--ink-400);
    font-size: 0.88rem;
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.93rem;
}

.search-bar input::placeholder {
    color: var(--ink-300);
}

.search-clear {
    background: none;
    border: none;
    color: var(--ink-400);
    cursor: pointer;
    font-size: 0.82rem;
    padding: 4px;
    display: none;
    transition: color var(--fast);
    line-height: 1;
}

.search-clear:hover { color: var(--sienna); }

.search-clear.visible { display: block; }

.stats-bar {
    text-align: center;
    padding: 12px 0 0;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--ink-400);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* --- CONTAINER --- */
.container {
    max-width: 860px;
    margin: 30px auto;
    padding: 0 20px;
}

/* --- LOADING --- */
.loading-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--ink-400);
    font-family: 'DM Sans', sans-serif;
}

.loading-spinner {
    width: 34px;
    height: 34px;
    border: 2px solid var(--border-med);
    border-top-color: var(--sienna);
    border-radius: 50%;
    margin: 0 auto 18px;
    animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- BOOK CARDS --- */
.book-card {
    margin-bottom: 10px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    overflow: hidden;
    transition: border-color var(--normal), box-shadow var(--normal), transform var(--normal);
    animation: slideUp 0.45s var(--ease) both;
    position: relative;
}

/* Barre d'accent colorée en haut de chaque livre */
.book-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--book-accent, var(--sienna));
    opacity: 0;
    transition: opacity var(--normal);
}

.book-card:nth-child(1) { --book-accent: var(--book-1); }
.book-card:nth-child(2) { --book-accent: var(--book-2); }
.book-card:nth-child(3) { --book-accent: var(--book-3); }
.book-card:nth-child(4) { --book-accent: var(--book-4); }
.book-card:nth-child(5) { --book-accent: var(--book-5); }

.book-card:hover::before,
.book-card[open]::before { opacity: 1; }

.book-card:hover {
    border-color: var(--border-med);
    box-shadow: 0 4px 18px rgba(18, 16, 13, 0.07);
}

.book-card[open] {
    border-color: var(--border-med);
    box-shadow: 0 6px 24px rgba(18, 16, 13, 0.09);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.book-card:nth-child(1) { animation-delay: 0.04s; }
.book-card:nth-child(2) { animation-delay: 0.08s; }
.book-card:nth-child(3) { animation-delay: 0.12s; }
.book-card:nth-child(4) { animation-delay: 0.16s; }
.book-card:nth-child(5) { animation-delay: 0.20s; }

/* --- SUMMARY (En-tête de livre) --- */
summary {
    padding: 18px 22px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.22rem;
    font-weight: 600;
    color: var(--text-primary);
    list-style: none;
    user-select: none;
    transition: background var(--fast);
    gap: 12px;
}

summary::-webkit-details-marker { display: none; }

summary:hover { background: var(--cream-100); }

.book-icon {
    font-size: 1.05rem;
    flex-shrink: 0;
}

.book-name {
    flex: 1;
    font-family: 'Cormorant Garamond', serif;
}

.book-count {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--ink-500);
    background: var(--cream-200);
    padding: 3px 10px;
    border-radius: var(--radius-full);
    letter-spacing: 0.3px;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.arrow {
    color: var(--sienna);
    font-size: 0.68rem;
    transition: transform var(--normal);
    flex-shrink: 0;
    opacity: 0.7;
}

.book-card[open] summary .arrow { transform: rotate(180deg); }

.book-card[open] summary {
    border-bottom: 1px solid var(--border);
}

/* --- PARACHA --- */
.paracha-container {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.22s ease both;
}

.paracha-container:last-child { border-bottom: none; }

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.paracha-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 13px;
}

.paracha-header h3 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.02rem;
    font-weight: 500;
    font-style: italic;
    color: var(--sienna);
    white-space: nowrap;
}

.paracha-divider {
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* --- ALIYA BUTTONS --- */
.aliya-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 6px;
}

.aliya-grid button {
    position: relative;
    background: var(--cream-100);
    border: 1.5px solid var(--border-med);
    color: var(--text-secondary);
    padding: 10px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.76rem;
    font-weight: 500;
    letter-spacing: 0.2px;
    transition: all var(--fast);
    overflow: hidden;
}

.aliya-grid button:hover {
    border-color: var(--sienna);
    color: var(--sienna);
    background: var(--sienna-pale);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--sienna-glow);
}

.aliya-grid button.active {
    background: var(--ink-900);
    border-color: var(--ink-900);
    color: var(--cream-200);
    font-weight: 600;
    box-shadow: 0 3px 12px rgba(18, 16, 13, 0.22);
    transform: translateY(-1px);
}

.aliya-grid button.active::after {
    content: '';
    position: absolute;
    top: 5px;
    right: 5px;
    width: 5px;
    height: 5px;
    background: var(--sienna-mid);
    border-radius: 50%;
    animation: pulse-dot 1.5s ease infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.35; transform: scale(0.65); }
}

/* --- PLAYER BAR --- */
.player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    background: var(--ink-800);
    border-top: 2px solid var(--sienna);
    padding: 12px 28px 14px;
    box-shadow: 0 -8px 40px rgba(18, 16, 13, 0.28);
    transition: border-top-color var(--fast);
}

.player-bar.playing {
    border-top-color: var(--sienna-mid);
}

.player-inner {
    max-width: 980px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 24px;
}

/* Infos piste */
.player-track-info {
    flex: 1;
    min-width: 0;
}

.player-now-playing {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 7px;
}

/* Waveform */
.waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 14px;
    opacity: 0;
    transition: opacity var(--fast);
    flex-shrink: 0;
}

.player-bar.playing .waveform { opacity: 1; }

.waveform span {
    display: block;
    width: 3px;
    background: var(--sienna-mid);
    border-radius: 1px;
    animation: wave 1.0s ease-in-out infinite;
}

.waveform span:nth-child(1) { height: 5px;  animation-delay: 0.0s; }
.waveform span:nth-child(2) { height: 11px; animation-delay: 0.15s; }
.waveform span:nth-child(3) { height: 8px;  animation-delay: 0.30s; }
.waveform span:nth-child(4) { height: 13px; animation-delay: 0.45s; }

@keyframes wave {
    0%, 100% { transform: scaleY(1); }
    50%       { transform: scaleY(0.28); }
}

.now-playing-dot {
    width: 6px;
    height: 6px;
    background: var(--sienna-mid);
    border-radius: 50%;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--fast);
}

.player-bar.playing .now-playing-dot {
    opacity: 1;
    animation: pulse-dot 1.5s ease infinite;
}

#current-track {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--cream-200);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* Barre de progression */
.player-progress {
    display: flex;
    align-items: center;
    gap: 10px;
}

.time-label {
    font-size: 0.66rem;
    color: var(--ink-400);
    font-variant-numeric: tabular-nums;
    min-width: 30px;
    font-family: 'DM Sans', sans-serif;
}

.progress-bar-wrapper {
    flex: 1;
    position: relative;
    height: 18px;
    display: flex;
    align-items: center;
}

.progress-bar-bg {
    position: absolute;
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 1px;
    overflow: hidden;
    pointer-events: none;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--sienna-mid);
    border-radius: 1px;
    transition: width 0.1s linear;
}

.seek-slider {
    position: absolute;
    width: 100%;
    height: 18px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    z-index: 2;
}

.seek-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--cream-100);
    border-radius: 50%;
    border: 2px solid var(--sienna);
    opacity: 0;
    transition: opacity var(--fast);
}

.progress-bar-wrapper:hover .seek-slider::-webkit-slider-thumb { opacity: 1; }

.seek-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--cream-100);
    border-radius: 50%;
    border: 2px solid var(--sienna);
}

/* Contrôles */
.player-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.player-btn {
    background: none;
    border: none;
    color: var(--ink-300);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    transition: all var(--fast);
}

.player-btn:hover {
    color: var(--cream-100);
    background: rgba(255, 255, 255, 0.07);
}

.player-btn-main {
    width: 46px;
    height: 46px;
    background: var(--sienna);
    color: var(--cream-50);
    font-size: 1rem;
    border-radius: 50%;
    box-shadow: 0 4px 18px var(--sienna-glow);
    transition: all var(--fast);
}

.player-btn-main:hover {
    color: var(--cream-50);
    background: var(--sienna-mid);
    transform: scale(1.06);
    box-shadow: 0 6px 22px var(--sienna-glow);
}

.player-btn-sm {
    width: 30px;
    height: 30px;
    font-size: 0.70rem;
}

#speed-label {
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    font-size: 0.67rem;
}

/* Volume */
.volume-control {
    position: relative;
    display: flex;
    align-items: center;
}

.volume-slider-wrapper {
    width: 0;
    overflow: hidden;
    transition: width var(--normal);
}

.volume-control:hover .volume-slider-wrapper,
.volume-control.active .volume-slider-wrapper {
    width: 70px;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 60px;
    height: 2px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 1px;
    outline: none;
    margin-left: 8px;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: var(--cream-200);
    border-radius: 50%;
    border: none;
}

.volume-slider::-moz-range-thumb {
    width: 10px;
    height: 10px;
    background: var(--cream-200);
    border-radius: 50%;
    border: none;
}

.player-extras {
    display: flex;
    align-items: center;
    gap: 2px;
}

.player-btn.active-mode {
    color: var(--sienna-mid);
    background: rgba(181, 70, 26, 0.18);
}

/* --- NO RESULTS --- */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.no-results i {
    font-size: 2rem;
    margin-bottom: 14px;
    display: block;
    opacity: 0.3;
}

.no-results p {
    font-size: 0.9rem;
    font-family: 'DM Sans', sans-serif;
}

/* --- FOOTER --- */
.site-footer {
    text-align: center;
    padding: 48px 20px 24px;
    color: var(--ink-400);
    font-size: 0.78rem;
    font-family: 'DM Sans', sans-serif;
    letter-spacing: 0.3px;
    border-top: 1px solid var(--border);
    margin: 0 20px;
}

/* --- UTILITIES --- */
.hidden { display: none !important; }

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--cream-200); }
::-webkit-scrollbar-thumb { background: var(--stone); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-400); }

/* --- SELECTION --- */
::selection {
    background: var(--sienna-pale);
    color: var(--sienna);
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    header { padding: 60px 20px 44px; }
    header h1 { font-size: 2rem; }

    .container { margin: 20px auto; }

    .player-bar { padding: 10px 16px 14px; }
    .player-inner { flex-wrap: wrap; gap: 6px; }
    .player-track-info { width: 100%; order: 1; }
    .player-controls { width: 100%; justify-content: center; order: 2; gap: 4px; }
    .player-extras { display: none; }
    .player-btn-main { width: 44px; height: 44px; }
    #repeat-btn { width: 34px; height: 34px; font-size: 0.78rem; }

    .book-card { border-radius: var(--radius-md); }
    summary { padding: 16px 18px; font-size: 1.1rem; }
    .paracha-container { padding: 14px 18px; }
    .aliya-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 5px; }
}

@media (max-width: 480px) {
    header { padding: 52px 16px 38px; }
    header h1 { font-size: 1.65rem; }
    .header-bg-text { font-size: 120px; }
    .search-wrapper { margin-top: 28px; }
    summary .book-count { display: none; }
    .aliya-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
    .aliya-grid button { padding: 9px 6px; font-size: 0.72rem; }
}
