/* ─── Reset & Variables ──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0d1117;
    --bg2: #141b24;
    --bg3: #1c2633;
    --border: rgba(255, 255, 255, 0.07);
    --border-hover: rgba(255, 255, 255, 0.14);
    --gold: #c8a96e;
    --gold-light: #e5c99a;
    --gold-dim: rgba(200, 169, 110, 0.15);
    --text: #e8e3d8;
    --text-dim: #7a8496;
    --text-muted: #3d4a5c;
    --green: #3ecf8e;
    --green-dim: rgba(62, 207, 142, 0.12);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.12);
    --blue: #60a5fa;
    --blue-dim: rgba(96, 165, 250, 0.12);
    --radius: 14px;
    --radius-sm: 8px;
    --font-arabic: 'Scheherazade New', 'Noto Naskh Arabic', serif;
    --font-ui: 'Amiri', Georgia, serif;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --arabic-text: #f0e9d6;
    --arabic-size: 30px;
    --turkish-size: 15px;

    --full-arabic-size: 44px;
    --full-turkish-size: 24px;
}

/* ─── Light Theme ────────────────────────────────────────────── */
body.light {
    --bg: #f5f0e8;
    --bg2: #fdfaf4;
    --bg3: #f0ebe0;
    --border: rgba(0, 0, 0, 0.09);
    --border-hover: rgba(0, 0, 0, 0.16);
    --gold: #9a6f2e;
    --gold-light: #7a5520;
    --gold-dim: rgba(154, 111, 46, 0.12);
    --text: #2a1f0e;
    --text-dim: #6b5a3e;
    --text-muted: #b8a88a;
    --green: #1a7a52;
    --green-dim: rgba(26, 122, 82, 0.1);
    --red: #c0392b;
    --red-dim: rgba(192, 57, 43, 0.1);
    --blue: #2563a8;
    --blue-dim: rgba(37, 99, 168, 0.1);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --arabic-text: #1a0f00;
}

body.light::before {
    background:
        radial-gradient(ellipse 60% 40% at 20% 20%, rgba(154, 111, 46, 0.07) 0%, transparent 70%),
        radial-gradient(ellipse 50% 60% at 80% 80%, rgba(37, 99, 168, 0.04) 0%, transparent 70%);
}

body.light .site-header {
    background: rgba(245, 240, 232, 0.92);
}

body.light audio {
    filter: none;
}

body.light .noise-overlay {
    opacity: 0.3;
}

/* ─── Noise Texture ──────────────────────────────────────────── */
.noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
    opacity: 0.6;
}

/* ─── Body & Background ──────────────────────────────────────── */
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    min-height: 100vh;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 60% 40% at 20% 20%, rgba(200, 169, 110, 0.06) 0%, transparent 70%),
        radial-gradient(ellipse 50% 60% at 80% 80%, rgba(96, 165, 250, 0.04) 0%, transparent 70%);
}

/* ─── Header ─────────────────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    background: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(12px);
    padding: 16px 28px;
}

.panel-settings,
.panel-playback {
    position: sticky;
    top: 92px;
    max-height: calc(100vh - 112px);
    overflow: auto;
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-mark {
    font-family: var(--font-arabic);
    font-size: 34px;
    color: var(--gold);
    line-height: 1;
    text-shadow: 0 0 20px rgba(200, 169, 110, 0.4);
}

.header-text h1 {
    font-family: var(--font-ui);
    font-size: 22px;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 0.5px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 0.3px;
    margin-top: 2px;
}

/* ─── Workspace 3-Column ─────────────────────────────────────── */
.workspace {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    grid-template-areas: "settings ayahs playback";
    gap: 20px;
    max-width: 1400px;
    margin: 24px auto;
    padding: 0 20px 40px;
    align-items: start;
}

/* ─── Panels ─────────────────────────────────────────────────── */
.panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: border-color 0.3s;
}

.panel-ayahs {
    min-height: calc(100vh - 140px);
}

#ayahs_container {
    scroll-behavior: smooth;
}

.ayah-box {
    cursor: pointer;
    scroll-margin-top: 120px;
}

.ayah-box.clicked-focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 1px var(--blue-dim), 0 0 20px rgba(96, 165, 250, 0.12);
}

.panel-header-with-action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.font-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.font-control-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.font-control-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.font-btn {
    padding: 6px 8px;
    min-width: 38px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all 0.2s;
}

.font-btn:hover {
    border-color: var(--gold);
    color: var(--gold-light);
    background: var(--gold-dim);
}

.fullscreen-btn {
    padding: 8px 12px;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.fullscreen-btn:hover {
    border-color: var(--gold);
    color: var(--gold-light);
    background: var(--gold-dim);
}

body.full-mode {
    overflow: hidden;
}

body.full-mode .site-header,
body.full-mode .panel-settings,
body.full-mode .panel-playback {
    display: none;
}

body.full-mode .workspace {
    display: block;
    max-width: none;
    margin: 0;
    padding: 0;
}

body.full-mode .panel-ayahs {
    position: fixed;
    inset: 0;
    z-index: 999;
    border: none;
    border-radius: 0;
    margin: 0;
    padding: 0 24px 28px;
    background: var(--bg);
    overflow-y: auto;
    min-height: 100vh;
}

body.full-mode .panel-ayahs .panel-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg);
    padding-top: 16px;
    padding-bottom: 16px;
    margin-bottom: 18px;
}

body.full-mode .ayah-number {
    display: none;
}

body.full-mode .ayah-box {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
    padding: 28px 30px;
}

body.full-mode .arabic {
    font-size: var(--full-arabic-size);
    line-height: 2.1;
    margin-bottom: 18px;
}

body.full-mode .turkish {
    font-size: var(--full-turkish-size);
    line-height: 1.9;
    font-style: normal;
}

.arabic {
    font-family: var(--font-arabic);
    font-size: var(--arabic-size);
    line-height: 2;
    direction: rtl;
    text-align: right;
    color: var(--arabic-text);
    margin-bottom: 12px;
}

.turkish {
    font-size: var(--turkish-size);
    line-height: 1.7;
    color: var(--text-dim);
    font-style: italic;
}

.panel:hover {
    border-color: var(--border-hover);
}

.panel-settings {
    grid-area: settings;
}

.panel-ayahs {
    grid-area: ayahs;
}

.panel-playback {
    grid-area: playback;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.panel-icon {
    font-size: 16px;
    opacity: 0.7;
}

.panel-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gold);
}

/* ─── Form Elements ──────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.select-wrapper {
    position: relative;
}

.select-wrapper::after {
    content: '▾';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gold);
    pointer-events: none;
    font-size: 12px;
}

select {
    width: 100%;
    padding: 10px 32px 10px 12px;
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-ui);
    appearance: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}

.number-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.number-input-wrapper:focus-within {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}

.num-btn {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: transparent;
    color: var(--gold);
    border: none;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    user-select: none;
}

.num-btn:hover {
    background: var(--gold-dim);
}

input[type="number"] {
    flex: 1;
    padding: 10px 4px;
    text-align: center;
    background: transparent;
    color: var(--text);
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    font-size: 15px;
    font-family: var(--font-ui);
    -moz-appearance: textfield;
    min-width: 0;
}

input[type="number"]::-webkit-inner-spin-button {
    display: none;
}

input[type="number"]:focus {
    outline: none;
}

/* ─── Divider ────────────────────────────────────────────────── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

/* ─── Mode Tabs ──────────────────────────────────────────────── */
.mode-selector {
    margin-bottom: 18px;
}

.mode-selector>label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.mode-tabs {
    display: flex;
    gap: 8px;
}

.mode-tab {
    flex: 1;
    padding: 10px 6px;
    background: var(--bg3);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.mode-tab:hover {
    color: var(--text);
    border-color: var(--border-hover);
}

.mode-tab.active {
    background: var(--gold-dim);
    color: var(--gold-light);
    border-color: var(--gold);
}

.mode-icon {
    font-size: 18px;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-icon {
    font-size: 12px;
}

.btn-primary {
    background: var(--gold);
    color: var(--bg);
    border-color: var(--gold);
    grid-column: 1 / -1;
}

.btn-primary:hover:not(:disabled) {
    background: var(--gold-light);
    box-shadow: 0 4px 16px rgba(200, 169, 110, 0.3);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg3);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--blue-dim);
    color: var(--blue);
    border-color: var(--blue);
}

.btn-danger {
    background: var(--bg3);
    color: var(--text);
    border-color: var(--border);
    grid-column: 1 / -1;
}

.btn-danger:hover:not(:disabled) {
    background: var(--red-dim);
    color: var(--red);
    border-color: var(--red);
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ─── Ayah Cards ─────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 40px;
    margin-bottom: 14px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

.ayah-box {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px 18px;
    margin-bottom: 14px;
    background: var(--bg3);
    transition: border-color 0.3s, box-shadow 0.3s;
    animation: slideIn 0.3s ease;
}

.ayah-box:hover {
    border-color: var(--gold-dim);
    box-shadow: 0 0 0 1px var(--gold-dim);
}

.ayah-box.active {
    border-color: var(--gold);
    background: linear-gradient(135deg, rgba(200, 169, 110, 0.06), var(--bg3));
    box-shadow: 0 0 20px rgba(200, 169, 110, 0.1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ayah-number {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gold);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ayah-number::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ─── Playback Panel ─────────────────────────────────────────── */
.status-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.playing {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.paused {
    background: var(--gold);
}

.status-dot.stopped {
    background: var(--red);
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 4px var(--green);
    }

    50% {
        box-shadow: 0 0 12px var(--green);
    }
}

.status-text {
    font-size: 14px;
    color: var(--text);
}

.progress-info {
    margin-bottom: 20px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}

.info-value {
    font-size: 14px;
    color: var(--text);
    font-weight: 600;
}

/* ─── Full mode scrollbar ───────────────────────────────────── */
body.full-mode .panel-ayahs {
    scrollbar-width: thin;
    scrollbar-color: var(--gold) var(--bg2);
}

body.full-mode .panel-ayahs::-webkit-scrollbar {
    width: 12px;
}

body.full-mode .panel-ayahs::-webkit-scrollbar-track {
    background: var(--bg2);
}

body.full-mode .panel-ayahs::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 999px;
    border: 3px solid var(--bg2);
}

body.full-mode .panel-ayahs::-webkit-scrollbar-thumb:hover {
    background: var(--gold-light);
}

/* ─── Waveform ───────────────────────────────────────────────── */
.waveform-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    margin-bottom: 16px;
}

.waveform {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 100%;
}

.bar {
    width: 4px;
    border-radius: 2px;
    background: var(--gold);
    opacity: 0.3;
    height: 8px;
    transition: height 0.1s;
}

.waveform.active .bar {
    animation: wave 1.2s ease-in-out infinite;
    opacity: 0.8;
}

.waveform.active .bar:nth-child(1) {
    animation-delay: 0.0s;
}

.waveform.active .bar:nth-child(2) {
    animation-delay: 0.1s;
}

.waveform.active .bar:nth-child(3) {
    animation-delay: 0.2s;
}

.waveform.active .bar:nth-child(4) {
    animation-delay: 0.3s;
}

.waveform.active .bar:nth-child(5) {
    animation-delay: 0.4s;
}

.waveform.active .bar:nth-child(6) {
    animation-delay: 0.5s;
}

.waveform.active .bar:nth-child(7) {
    animation-delay: 0.4s;
}

.waveform.active .bar:nth-child(8) {
    animation-delay: 0.3s;
}

.waveform.active .bar:nth-child(9) {
    animation-delay: 0.2s;
}

.waveform.active .bar:nth-child(10) {
    animation-delay: 0.1s;
}

.waveform.active .bar:nth-child(11) {
    animation-delay: 0.0s;
}

.waveform.active .bar:nth-child(12) {
    animation-delay: 0.1s;
}

@keyframes wave {

    0%,
    100% {
        height: 6px;
    }

    50% {
        height: 36px;
    }
}

/* ─── Audio Player ───────────────────────────────────────────── */
.audio-wrapper {
    margin-top: 4px;
}

audio {
    width: 100%;
    height: 36px;
    border-radius: var(--radius-sm);
    filter: invert(1) hue-rotate(180deg) brightness(0.8);
}

/* ─── Theme Toggle ───────────────────────────────────────────── */
.theme-toggle {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}

.toggle-track {
    position: relative;
    width: 48px;
    height: 26px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s;
}

.toggle-track:hover {
    border-color: var(--gold);
}

.toggle-track input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--gold);
    transition: transform 0.3s cubic-bezier(.34, 1.56, .64, 1), background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
}

.toggle-track input:checked~.toggle-thumb {
    transform: translateX(22px);
}

.toggle-icon-dark {
    display: block;
}

.toggle-icon-light {
    display: none;
}

body.light .toggle-icon-dark {
    display: none;
}

body.light .toggle-icon-light {
    display: block;
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 260px 1fr 260px;
    }
}

@media (max-width: 860px) {
    .workspace {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "settings playback"
            "ayahs ayahs";
    }

    .panel-ayahs {
        grid-column: 1 / -1;
    }
}

@media (max-width: 560px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-areas:
            "settings"
            "playback"
            "ayahs";
        padding: 0 12px 32px;
    }

    .arabic {
        font-size: 26px;
    }

    .button-grid {
        grid-template-columns: 1fr;
    }

    .btn-primary,
    .btn-danger {
        grid-column: auto;
    }
}

@media (max-width: 860px) {

    .panel-settings,
    .panel-playback {
        position: static;
        top: auto;
        max-height: none;
        overflow: visible;
    }
}

@media (max-width: 700px) {
    .panel-header-with-action {
        align-items: flex-start;
    }

    .panel-header-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .font-controls {
        width: 100%;
    }

    .font-control-group {
        flex-wrap: wrap;
    }
}