:root {
    /* Further darkened light theme for better depth */
    --bg-color: #dcd4c6; 
    --bg-gradient-start: #eae4d9;
    --bg-gradient-mid: #dcd4c6;
    --bg-gradient-end: #c4b9a3;
    
    --text-main: #252321;
    --text-muted: #665f54;
    --primary-color: #3e4d44;
    --accent-color: #bfa36c;
    --card-bg: rgba(235, 230, 222, 0.65);
    --glass-border: rgba(255, 255, 255, 0.7);
    --btn-icon-bg: #f5f2ed;
    --modal-overlay: rgba(30, 28, 26, 0.6);

    font-family: 'Outfit', sans-serif;
    --bead-size: 54px;
}

[data-theme="dark"] {
    --bg-color: #1a1918;
    --bg-gradient-start: #2a2826;
    --bg-gradient-mid: #1a1918;
    --bg-gradient-end: #0f0e0d;
    
    --text-main: #e2e1df;
    --text-muted: #a19a91;
    --primary-color: #8fb1a0;
    --accent-color: #d8c090;
    --card-bg: rgba(40, 38, 36, 0.65);
    --glass-border: rgba(255, 255, 255, 0.1);
    --btn-icon-bg: #2d2b28;
    --modal-overlay: rgba(0, 0, 0, 0.8);
}

html[data-theme="dark"], body[data-theme="dark"] {
    background-color: var(--bg-color) !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh; /* Fixed height to prevent any scroll */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Ensure no scrollbars */
    position: relative;
    background: radial-gradient(circle at top right, var(--bg-gradient-start), var(--bg-gradient-mid), var(--bg-gradient-end));
}

.app-header {
    text-align: center;
    margin-bottom: 10px;
    z-index: 40;
    position: relative;
}

.app-title {
    font-size: clamp(24px, 8vw, 42px); /* Dynamically shrinks on small screens to fit */
    font-weight: 800;
    letter-spacing: 4px;
    white-space: nowrap; /* Forces one line */
    color: var(--primary-color);
    text-transform: uppercase;
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .app-title {
    color: var(--accent-color);
    text-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

/* --- Background Geometric Design --- */
.bg-low-poly {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
    opacity: 1;
}

.poly-lines {
    stroke: var(--glass-border);
    stroke-width: 1.5;
    stroke-linejoin: round;
}

.poly-shard {
    transition: all 0.5s ease;
}

.poly-1  { fill: rgba(255, 255, 255, 0.04); }
.poly-2  { fill: rgba(0, 0, 0, 0.02); }
.poly-3  { fill: rgba(255, 255, 255, 0.02); }
.poly-4  { fill: rgba(0, 0, 0, 0.03); }
.poly-5  { fill: rgba(255, 255, 255, 0.05); }
.poly-6  { fill: rgba(0, 0, 0, 0.01); }

.poly-7  { fill: rgba(255, 255, 255, 0.03); }
.poly-8  { fill: rgba(0, 0, 0, 0.04); }
.poly-9  { fill: rgba(255, 255, 255, 0.01); }
.poly-10 { fill: rgba(0, 0, 0, 0.02); }
.poly-11 { fill: rgba(255, 255, 255, 0.04); }
.poly-12 { fill: rgba(0, 0, 0, 0.03); }

.poly-13 { fill: rgba(255, 255, 255, 0.02); }
.poly-14 { fill: rgba(0, 0, 0, 0.03); }
.poly-15 { fill: rgba(255, 255, 255, 0.05); }
.poly-16 { fill: rgba(0, 0, 0, 0.01); }
.poly-17 { fill: rgba(255, 255, 255, 0.03); }
.poly-18 { fill: rgba(0, 0, 0, 0.04); }

[data-theme="dark"] .bg-low-poly {
    opacity: 0.6;
}
[data-theme="dark"] .poly-lines {
    stroke: rgba(255, 255, 255, 0.04);
}

/* --- Top Buttons --- */
.top-options-bar {
    position: absolute;
    top: 25px;
    right: 25px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    z-index: 50;
    justify-content: flex-end;
}

[dir="rtl"] .top-options-bar {
    right: auto;
    left: 25px;
}

.btn-top-right,
.btn-top-action {
    height: 48px;
    border-radius: 24px;
    background: var(--btn-icon-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 14px;
    font-family: var(--font-family);
    box-shadow:
        0 8px 16px rgba(0, 0, 0, 0.1),
        inset 0 1px 2px var(--glass-border);
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    padding: 0 15px;
    gap: 8px;
}

.btn-top-right {
    width: 48px;
    padding: 0;
    border-radius: 50%;
}

.btn-top-action {
    position: absolute;
    top: 25px;
    left: 25px;
    z-index: 50;
}

[dir="rtl"] .btn-top-action {
    left: auto;
    right: 25px;
}

.btn-top-right:hover,
.btn-top-action:hover {
    color: #ffffff;
    background: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.15), inset 0 1px 2px var(--glass-border);
}

.btn-top-right:active,
.btn-top-action:active {
    transform: translateY(0);
}

.btn-top-right.active,
.btn-top-action.active {
    color: var(--primary-color);
    background: rgba(85, 107, 96, 0.1);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05), inset 0 1px 2px var(--glass-border);
}

[data-theme="dark"] .btn-top-right.active,
[data-theme="dark"] .btn-top-action.active {
    background: rgba(255, 255, 255, 0.08); 
}

.lang-select-inline {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    text-align: center;
    text-align-last: center;
    font-weight: 800;
    outline: none;
    padding: 0;
}
.lang-select-inline option {
    background: var(--bg-color);
    color: var(--text-main);
    font-weight: 600;
}
.lang-select-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.lang-select-inline {
    padding-right: 14px; /* Space for the arrow */
    background: transparent;
}
.lang-select-wrapper::after {
    content: "";
    position: absolute;
    right: 4px;
    width: 12px;
    height: 12px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23665f54' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
}

/* --- Center UI Container --- */
.app-container {
    position: relative;
    z-index: 30; /* Increased to be above mala-container which is 20 */
    width: 100%;
    max-width: 460px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px; /* Greatly reduced to avoid vertical stretching/scrolling */
    margin-top: 30px; /* Reduced buffer */
}

header h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 30px;
    text-shadow: 0 2px 10px rgba(85, 107, 96, 0.15);
}

/* --- Advanced Counter Card --- */
.advanced-counter-card {
    background: var(--card-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
    border-radius: 40px;
    padding: 30px 20px;
    box-shadow:
        0 25px 45px rgba(0, 0, 0, 0.15),
        inset 0 2px 5px var(--glass-border),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    width: 100%;
}

.target-indicator {
    background: var(--card-bg);
    padding: 6px 16px;
    border-radius: 20px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--glass-border);
}

#target-display {
    font-size: 14px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 2px;
}

.count-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

#count-display {
    font-size: 110px;
    font-weight: 800;
    line-height: 1;
    color: var(--primary-color);
    letter-spacing: -4px;
    text-shadow: 0 10px 30px rgba(85, 107, 96, 0.15);
}

/* Custom Target Input */
.custom-target-input {
    width: 100%;
    padding: 10px 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: var(--card-bg);
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-main);
    outline: none;
    text-align: center;
    font-weight: 700;
    transition: all 0.2s;
}
.custom-target-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(85, 107, 96, 0.2);
}

/* --- Stats Dashboard --- */
.stats-dashboard {
    display: flex;
    justify-content: center;
    gap: 15px;
    width: 100%;
    margin-top: -10px;
}

.stat-box {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 800;
    letter-spacing: 1px;
    text-align: center;
    display: block;
    width: 100%;
    line-height: 1.2;
    white-space: nowrap; /* Keep labels like "THIS MONTH" on one line */
}

.stat-value {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary-color);
}

/* --- Controls Modern --- */
.controls-modern {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
}

button {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.btn-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--btn-icon-bg);
    color: var(--text-muted);
    box-shadow:
        0 10px 20px rgba(0, 0, 0, 0.1),
        inset 0 1px 2px var(--glass-border);
    border: 1px solid var(--glass-border);
}

.btn-icon:hover {
    color: #ffffff;
    background: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: 0 15px 25px rgba(140, 130, 115, 0.2), inset 0 1px 2px #fff;
}

.btn-icon:active {
    transform: translateY(0) scale(0.95);
}

.btn-main-action {
    position: relative;
	padding: 0 48px;
	height: 80px;
	border-radius: 40px;
	background: linear-gradient(135deg, #5f8a77, #2f4f40); /* Brighter, more prominent */
    color: #ffffff;
	font-size: 20px;
    font-weight: 800;
    letter-spacing: 2px;
    box-shadow:
		0 18px 36px rgba(85, 107, 96, 0.45),
		inset 0 -3px 10px rgba(0, 0, 0, 0.25),
		inset 0 3px 6px rgba(255, 255, 255, 0.45);
	border: 1px solid rgba(255, 255, 255, 0.2);
	text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.btn-main-action .btn-text {
    position: relative;
    z-index: 2;
}

.btn-main-action:hover {
	transform: translateY(-3px) scale(1.02);
	box-shadow:
		0 24px 46px rgba(85, 107, 96, 0.5),
		inset 0 -3px 10px rgba(0, 0, 0, 0.25),
		inset 0 4px 8px rgba(255, 255, 255, 0.5);
}

.btn-main-action:focus-visible {
	outline: none;
	box-shadow:
		0 0 0 4px rgba(95, 138, 119, 0.25),
		0 20px 36px rgba(85, 107, 96, 0.4),
		inset 0 -3px 10px rgba(0, 0, 0, 0.25);
}

.btn-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.3) 0%, transparent 60%);
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.btn-main-action:hover .btn-glow {
	opacity: 0.5;
}

.btn-main-action:active .btn-glow {
    opacity: 1;
}

.btn-main-action:active {
    transform: scale(0.95);
    box-shadow: 0 8px 15px rgba(85, 107, 96, 0.2);
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* --- Settings Toggle --- */
.settings-link {
    width: 100%;
    display: flex;
    justify-content: center;
}

.toggle-group {
    display: flex;
    gap: 8px;
    background: var(--card-bg);
    padding: 6px;
    border-radius: 16px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--glass-border);
}

.toggle-group input[type="radio"] {
    display: none;
}

.toggle-group label {
    padding: 8px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.toggle-group input[type="radio"]:checked+label {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 10px rgba(85, 107, 96, 0.2);
}

/* --- Save Progress Section --- */
.save-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    margin-top: -10px;
    border-top: 1px solid rgba(200, 190, 180, 0.3);
    padding-top: 20px;
}

#dhikr-name {
    width: 100%;
    padding: 14px 20px;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    background: var(--card-bg);
    font-family: var(--font-family);
    font-size: 15px;
    color: var(--text-main);
    outline: none;
    transition: all 0.2s;
}

#dhikr-name:focus {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(85, 107, 96, 0.1);
}

.btn-secondary {
    padding: 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: #ffffff;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 1px;
    box-shadow: 0 8px 15px rgba(46, 204, 113, 0.3);
    border: none;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #27ae60, #219653);
    transform: translateY(-2px);
    box-shadow: 0 12px 20px rgba(46, 204, 113, 0.4);
}

/* ========================================================
   HISTORY MODAL
   ======================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--modal-overlay);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--bg-color);
    width: 90%;
    max-width: 450px;
    max-height: 80vh;
    border-radius: 30px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
	z-index: 110;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 20px;
    color: var(--primary-color);
}

.btn-close {
    background: transparent;
    color: var(--text-muted);
    box-shadow: none;
    width: 40px;
    height: 40px;
}

.btn-close:hover {
    color: #d9534f;
    background: rgba(217, 83, 79, 0.1);
    border-radius: 50%;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 5px;
}

.hist-name, .hist-date {
	white-space: normal;
}

[dir="rtl"] .history-item {
	text-align: right;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
    background: #dcd6cc;
    border-radius: 4px;
}

.history-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 16px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--glass-border);
}

.hist-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hist-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 16px;
}

.hist-date {
    font-size: 12px;
    color: var(--text-muted);
}

.hist-count {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary-color);
    background: rgba(85, 107, 96, 0.1);
    padding: 6px 14px;
    border-radius: 12px;
}

.btn-delete-hist {
    background: transparent;
    border: none;
    color: #eab308;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    margin-left: 10px;
    border-radius: 8px;
    transition: all 0.2s;
}

.btn-delete-hist:hover {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

/* ========================================================
   FULL WIDTH DROOPING MALA (TASBEEH)
   ======================================================== */
.hanging-mala-container {
    position: fixed;
    bottom: 0px;
    left: 0;
    width: 100vw;
    height: 480px;
    /* Taller area for thicker curve */
    z-index: 20;
    pointer-events: none;
}

.mala-curve-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.mala-beads-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Prominent, vibrant colored bead clearly visible with threading hole */
.mala-bead {
    width: var(--bead-size);
    height: calc(var(--bead-size) - 2px);
    /* slightly oblate */
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 0;

    /* Changed from pale ivory to a more prominent deep amber/gold to be very clear against beige */
    background: radial-gradient(circle at 35% 25%, #fde047 0%, #ca8a04 35%, #713f12 70%, #451a03 100%);

    box-shadow:
        /* External falling shadow */
        4px 10px 15px rgba(69, 26, 3, 0.4),
        /* Deep internal shadow core */
        inset -8px -8px 14px rgba(0, 0, 0, 0.45),
        /* Bright rim light */
        inset 4px 6px 12px rgba(255, 255, 255, 0.85);

    transform: translate(-50%, -50%);
    /* Centers over the exact math line */
    transition: top 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), left 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.4s ease;
}

/* Dark threaded hole directly in the middle ensuring it overlays exactly on the wire */
.mala-bead::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    background: #27272a;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: inset 2px 2px 5px #000, 0 1px 3px rgba(255, 255, 255, 0.4);
    z-index: 2;
}

/* Sharp Glass reflection */
.mala-bead::after {
    content: '';
    position: absolute;
    top: 10%;
    left: 15%;
    width: 35%;
    height: 30%;
    background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0) 70%);
    border-radius: 50%;
    transform: rotate(-30deg);
    pointer-events: none;
}

/* Marker Bead - distinctive color (Vibrant Teal/Cyan to contrast the amber) */
.mala-bead.marker {
    width: calc(var(--bead-size) + 6px);
    height: calc(var(--bead-size) + 4px);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 25%, #67e8f9 0%, #06b6d4 30%, #083344 70%, #020617 100%);
    box-shadow:
        5px 12px 20px rgba(8, 51, 68, 0.4),
        inset -8px -8px 14px rgba(0, 0, 0, 0.5),
        inset 4px 6px 14px rgba(255, 255, 255, 0.7);
}

/* ========================================================
   ADDITIONAL GLOBAL MODIFICATIONS
   ======================================================== */

/* Eye Protection Overlay (Fixes z-index/fixed positioning bugs) */
.eye-protection-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    background: rgba(255, 140, 0, 0.08); /* Warm tint */
    mix-blend-mode: multiply;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s;
}
body.eye-protection .eye-protection-overlay {
    opacity: 1;
}

/* --- Limit Warning Toast --- */
.limit-warning {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #eab308;
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    box-shadow: 0 10px 25px rgba(234, 179, 8, 0.4);
    z-index: 1000;
    transition: top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}

.limit-warning.show {
    top: 40px;
}

[data-theme="dark"] .limit-warning {
    background: #ca8a04;
    color: #ffffff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

/* Desktop fit mode for normal 100% browser zoom */
@media (min-width: 481px) and (max-height: 900px) {
    .top-options-bar,
    .btn-top-action {
        top: 14px;
    }

    .app-container {
        margin-top: 8px;
        margin-bottom: 10px;
        max-width: 430px;
    }

    .app-header {
        margin-bottom: 4px;
    }

    .app-title {
        font-size: clamp(20px, 3.2vw, 34px);
        letter-spacing: 3px;
    }

    .advanced-counter-card {
        padding: 22px 18px;
        gap: 14px;
        border-radius: 30px;
    }

    #count-display {
        font-size: 88px;
    }

    .btn-main-action {
        height: 68px;
        padding: 0 38px;
    }

    .btn-icon {
        width: 56px;
        height: 56px;
    }

    .hanging-mala-container {
        height: 390px;
    }
}

/* Extra compact desktop fit so full tool (including Save) is visible */
@media (min-width: 481px) and (max-height: 780px) {
    body {
        justify-content: center;
        padding-top: 0;
    }

    .top-options-bar,
    .btn-top-action {
        top: 10px;
    }

    .app-container {
        margin-top: 18px;
        margin-bottom: 16px;
        transform: scale(0.99);
        transform-origin: top center;
    }

    .app-header {
        margin-bottom: 0;
    }

    header h1 {
        margin-bottom: 14px;
    }

    .advanced-counter-card {
        gap: 12px;
        padding: 20px 16px;
    }

    .hanging-mala-container {
        height: 320px;
    }
}

/* Incognito/short-height desktop fit so whole card stays above fold */
@media (min-width: 481px) and (max-height: 860px) {
    .top-options-bar,
    .btn-top-action {
        top: 10px;
    }

    .btn-top-right,
    .btn-top-action {
        height: 42px;
        border-radius: 21px;
        font-size: 13px;
    }

    .btn-top-right {
        width: 42px;
    }

    .app-container {
        max-width: 420px;
        margin-top: 8px;
        margin-bottom: 6px;
    }

    .app-header {
        margin-bottom: 2px;
    }

    .app-title {
        font-size: clamp(20px, 3vw, 32px);
        letter-spacing: 2.5px;
    }

    header h1 {
        margin-bottom: 12px;
    }

    .advanced-counter-card {
        padding: 18px 16px;
        gap: 10px;
        border-radius: 28px;
    }

    .target-indicator {
        padding: 5px 14px;
    }

    #target-display {
        font-size: 12px;
        letter-spacing: 1.5px;
    }

    #count-display {
        font-size: 78px;
    }

    .controls-modern {
        gap: 14px;
    }

    .btn-main-action {
        height: 60px;
        padding: 0 30px;
        font-size: 17px;
    }

    .btn-icon {
        width: 48px;
        height: 48px;
    }

    .toggle-group label {
        padding: 6px 12px;
        font-size: 12px;
    }

    .stats-dashboard {
        gap: 8px;
        margin-top: -4px;
    }

    .stat-box {
        padding: 8px 6px;
        border-radius: 12px;
    }

    .stat-label {
        font-size: 10px;
    }

    .stat-value {
        font-size: 15px;
    }

    .save-section {
        gap: 8px;
        margin-top: -4px;
        padding-top: 12px;
    }

    #dhikr-name {
        padding: 10px 14px;
        font-size: 13px;
    }

    .btn-secondary {
        padding: 10px;
        font-size: 14px;
    }

    .hanging-mala-container {
        height: 260px;
    }
}



/* Responsive Overrides */
@media (max-width: 480px) {
    body {
        justify-content: flex-start;
        padding-top: 0;
    }

    :root {
        --bead-size: 36px; /* Dynamically shrink beads for mobile */
    }
    
    .top-options-bar {
        position: fixed;
        top: 56px !important;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 90%;
        max-width: 320px;
        padding: 4px 10px;
        background: var(--card-bg);
        backdrop-filter: blur(14px);
        border-radius: 30px;
        border: 1px solid var(--glass-border);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        justify-content: space-between;
        gap: 0;
    }
    
    .btn-top-right {
        width: 34px;
        height: 34px;
        background: transparent;
        border: none;
        box-shadow: none;
    }
    
    .btn-top-right:hover {
        background: var(--btn-icon-bg);
    }
    
    .btn-top-action {
        position: fixed;
        top: 98px !important;
        bottom: auto;
        left: 50%;
        transform: translateX(-50%);
        height: 36px;
        font-size: 12px;
        padding: 0 12px;
        z-index: 60;
    }
    .app-container {
        padding: 10px;
        margin-bottom: 74px;
        margin-top: 4px !important;
    }
    .app-header {
        margin-bottom: 0 !important;
    }
    header h1 {
        margin-bottom: 4px !important;
    }
    .advanced-counter-card {
        margin-top: 74px;
    }
    .advanced-counter-card {
        padding: 14px 12px;
        border-radius: 20px;
        gap: 8px;
    }

    .app-title {
        font-size: clamp(18px, 7vw, 28px);
        letter-spacing: 2px;
    }

    #target-display {
        font-size: 11px;
        letter-spacing: 1px;
    }

    #count-display {
        font-size: 62px;
    }

    .controls-modern {
        gap: 10px;
    }

    .btn-main-action {
        padding: 0 22px;
        height: 48px;
        font-size: 16px;
    }
    .btn-icon {
        width: 42px;
        height: 42px;
    }

    .settings-link {
        transform: scale(0.84);
    }

    .toggle-group label {
        padding: 5px 8px;
        font-size: 11px;
    }

    .stats-dashboard {
        gap: 6px;
        margin-top: -2px;
    }

    .stat-box {
        padding: 7px 5px;
        border-radius: 10px;
    }

    .stat-label {
        font-size: 9px;
        letter-spacing: 0.6px;
    }

    .stat-value {
        font-size: 14px;
    }

    .save-section {
        gap: 6px;
        margin-top: -4px;
        padding-top: 10px;
    }

    #dhikr-name {
        padding: 9px 12px;
        font-size: 12px;
    }

    .btn-secondary {
        padding: 10px;
        font-size: 13px;
    }
    
    .hanging-mala-container {
        height: 230px;
    }

    /* Keep mobile top controls centered in RTL too */
    [dir="rtl"] .top-options-bar {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        direction: ltr; /* preserve same icon flow as English */
    }

    [dir="rtl"] .btn-top-action {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }
}

/* Ultra compact mobile screens (small-height phones) */
@media (max-width: 480px) and (max-height: 740px) {
    .top-options-bar {
        top: 48px !important;
    }

    .btn-top-action {
        top: 86px !important;
        height: 34px;
    }

    .advanced-counter-card {
        margin-top: 66px;
        padding: 12px 10px;
        gap: 7px;
    }

    #count-display {
        font-size: 56px;
    }

    .btn-main-action {
        height: 44px;
        padding: 0 18px;
        font-size: 14px;
    }

    .btn-icon {
        width: 38px;
        height: 38px;
    }

    .hanging-mala-container {
        height: 200px;
    }
}

/* RTL Support for Arabic */
[dir="rtl"] {
    /* Keep same sizing metrics as English layout */
    font-family: 'Outfit', sans-serif;
}
[dir="rtl"] .btn-top-action {
    left: auto;
    right: 25px;
}
@media (max-width: 480px) {
    [dir="rtl"] .btn-top-action {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}